Commit 10018d90 by Nick Schonning

Merge pull request #205 from nschonni/jshinting

Add JSHinting and EditorConfig
parents f4cb0f4e bf2e9293
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true
[*]
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = spaces
indent_size = 2
node_modules/
\ No newline at end of file
...@@ -6,5 +6,10 @@ ...@@ -6,5 +6,10 @@
"trailing": true, "trailing": true,
"undef": true, "undef": true,
"unused": true, "unused": true,
"expr":true "expr":true,
"multistr": true,
"globals": {
"it": true,
"describe": true
}
} }
\ No newline at end of file
#!/usr/bin/env node #!/usr/bin/env node
var cp = require('child_process'), var cp = require('child_process'),
fs = require('fs'), fs = require('fs'),
path = require('path'), path = require('path'),
Mocha = require('mocha'); Mocha = require('mocha');
// Parse args // Parse args
var force = false, debug = false; var force = false, debug = false;
var arch = process.arch, var arch = process.arch,
platform = process.platform, platform = process.platform,
v8 = /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0]; v8 = /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0];
var args = process.argv.slice(2).filter(function(arg) { var args = process.argv.slice(2).filter(function(arg) {
if (arg === '-f') { if (arg === '-f') {
force = true; force = true;
return false; return false;
} else if (arg.substring(0, 13) === '--target_arch') { } else if (arg.substring(0, 13) === '--target_arch') {
arch = arg.substring(14); arch = arg.substring(14);
} else if (arg === '--debug') { } else if (arg === '--debug') {
debug = true; debug = true;
} }
return true; return true;
}); });
if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) { if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) {
console.error('Unsupported (?) architecture: `'+ arch+ '`'); console.error('Unsupported (?) architecture: `'+ arch+ '`');
process.exit(1); process.exit(1);
} }
// Test for pre-built library // Test for pre-built library
var modPath = platform + '-' + arch + '-v8-' + v8; var modPath = platform + '-' + arch + '-v8-' + v8;
if (!force && !process.env.SKIP_NODE_SASS_TESTS) { if (!force && !process.env.SKIP_NODE_SASS_TESTS) {
try { try {
fs.statSync(path.join(__dirname, 'bin', modPath, 'binding.node')); fs.statSync(path.join(__dirname, 'bin', modPath, 'binding.node'));
console.log('`'+ modPath+ '` exists; testing'); console.log('`'+ modPath+ '` exists; testing');
var mocha = new Mocha({
reporter: 'dot',
ui: 'bdd',
timeout: 999999
});
mocha.addFile(path.resolve(__dirname, "test", "test.js"));
var runner = mocha.run(function (done) { var mocha = new Mocha({
if (done !== 0) { reporter: 'dot',
console.log('Problem with the binary; manual build incoming'); ui: 'bdd',
console.log('Please consider contributing the release binary to https://github.com/andrew/node-sass-binaries for npm distribution.'); timeout: 999999
build(); });
} else {
console.log('Binary is fine; exiting'); mocha.addFile(path.resolve(__dirname, "test", "test.js"));
}
}); mocha.run(function (done) {
} catch (ex) { if (done !== 0) {
// Stat failed console.log('Problem with the binary; manual build incoming');
build(); console.log('Please consider contributing the release binary to https://github.com/andrew/node-sass-binaries for npm distribution.');
} build();
} else {
console.log('Binary is fine; exiting');
}
});
} catch (ex) {
// Stat failed
build();
}
} else { } else {
build(); build();
} }
// Build it // Build it
function build() { function build() {
cp.spawn( cp.spawn(
process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp', process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp',
['rebuild'].concat(args), ['rebuild'].concat(args),
{customFds: [0, 1, 2]}) {customFds: [0, 1, 2]})
.on('exit', function(err) { .on('exit', function(err) {
if (err) { if (err) {
if (err === 127) { if (err === 127) {
console.error( console.error(
'node-gyp not found! Please upgrade your install of npm! You need at least 1.1.5 (I think) '+ 'node-gyp not found! Please upgrade your install of npm! You need at least 1.1.5 (I think) '+
'and preferably 1.1.30.' 'and preferably 1.1.30.'
); );
} else { } else {
console.error('Build failed'); console.error('Build failed');
} }
return process.exit(err); return process.exit(err);
} }
afterBuild(); afterBuild();
}); });
} }
// Move it to expected location // Move it to expected location
function afterBuild() { function afterBuild() {
var targetPath = path.join(__dirname, 'build', debug ? 'Debug' : 'Release', 'binding.node'); var targetPath = path.join(__dirname, 'build', debug ? 'Debug' : 'Release', 'binding.node');
var installPath = path.join(__dirname, 'bin', modPath, 'binding.node'); var installPath = path.join(__dirname, 'bin', modPath, 'binding.node');
try { try {
fs.mkdirSync(path.join(__dirname, 'bin', modPath)); fs.mkdirSync(path.join(__dirname, 'bin', modPath));
} catch (ex) {} } catch (ex) {}
try { try {
fs.statSync(targetPath); fs.statSync(targetPath);
} catch (ex) { } catch (ex) {
console.error('Build succeeded but target not found'); console.error('Build succeeded but target not found');
process.exit(1); process.exit(1);
} }
fs.renameSync(targetPath, installPath); fs.renameSync(targetPath, installPath);
console.log('Installed in `'+ installPath+ '`'); console.log('Installed in `'+ installPath+ '`');
} }
...@@ -3,21 +3,21 @@ ...@@ -3,21 +3,21 @@
* Module dependencies. * Module dependencies.
*/ */
var connect = require('connect') var connect = require('connect'),
, sass = require('../sass'); sass = require('../sass');
// Setup server // Setup server
// $ curl http://localhost:3000/test.css // $ curl http://localhost:3000/test.css
var server = connect.createServer( var server = connect.createServer(
sass.middleware({ sass.middleware({
src: __dirname src: __dirname,
, dest: __dirname + '/public' dest: __dirname + '/public',
, debug: true debug: true,
, outputStyle: 'compressed' outputStyle: 'compressed'
}), }),
connect.static(__dirname + '/public') connect.static(__dirname + '/public')
); );
server.listen(3000); server.listen(3000);
console.log('server listening on port 3000'); console.log('server listening on port 3000');
\ No newline at end of file
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
"scripts": { "scripts": {
"install": "node build.js", "install": "node build.js",
"test": "mocha test", "test": "mocha test",
"pretest": "jshint .",
"prepublish": "bash scripts/prepublish.sh" "prepublish": "bash scripts/prepublish.sh"
}, },
"bin": { "bin": {
...@@ -42,5 +43,8 @@ ...@@ -42,5 +43,8 @@
"mocha": "1.13.x", "mocha": "1.13.x",
"chalk": "~0.3.0", "chalk": "~0.3.0",
"nan": "~0.6.0" "nan": "~0.6.0"
},
"devDependencies": {
"jshint": "~2.4.0"
} }
} }
...@@ -24,14 +24,14 @@ var SASS_OUTPUT_STYLE = { ...@@ -24,14 +24,14 @@ var SASS_OUTPUT_STYLE = {
expanded: 1, expanded: 1,
compact: 2, compact: 2,
compressed: 3 compressed: 3
}; };
var SASS_SOURCE_COMMENTS = { var SASS_SOURCE_COMMENTS = {
none: 0, none: 0,
// This is called default in libsass, but is a reserved keyword here // This is called default in libsass, but is a reserved keyword here
normal: 1, normal: 1,
map: 2 map: 2
}; };
var prepareOptions = function(options) { var prepareOptions = function(options) {
var paths, style, comments; var paths, style, comments;
...@@ -52,7 +52,7 @@ var deprecatedRender = function(css, callback, options) { ...@@ -52,7 +52,7 @@ var deprecatedRender = function(css, callback, options) {
var errCallback = function(err) { var errCallback = function(err) {
callback(err); callback(err);
}; };
var oldCallback = function(css, err) { var oldCallback = function(css) {
callback(null, css); callback(null, css);
}; };
return binding.render(css, oldCallback, errCallback, options.paths.join(':'), options.style, options.comments); return binding.render(css, oldCallback, errCallback, options.paths.join(':'), options.style, options.comments);
......
var sass = require('./sass');
var scssStr = '#navbar {\
width: 80%;\
height: 23px; }\
#navbar ul {\
list-style-type: none; }\
#navbar li {\
float: left;\
a {\
font-weight: bold; }}';
sass.render(scssStr, function(err, css){
console.log(css)
})
...@@ -2,7 +2,6 @@ var path = require('path'), ...@@ -2,7 +2,6 @@ var path = require('path'),
assert = require('assert'), assert = require('assert'),
fs = require('fs'), fs = require('fs'),
exec = require('child_process').exec, exec = require('child_process').exec,
sass = require('../sass'),
cli = require('../lib/cli'), cli = require('../lib/cli'),
cliPath = path.resolve(__dirname, '../bin/node-sass'), cliPath = path.resolve(__dirname, '../bin/node-sass'),
...@@ -37,7 +36,7 @@ describe('cli', function() { ...@@ -37,7 +36,7 @@ describe('cli', function() {
exec('node ' + cliPath + ' ' + sampleFilename, { exec('node ' + cliPath + ' ' + sampleFilename, {
cwd: __dirname cwd: __dirname
}, function(err, stdout, stderr) { }, function() {
fs.exists(resultPath, function(exists) { fs.exists(resultPath, function(exists) {
assert(exists); assert(exists);
...@@ -46,12 +45,12 @@ describe('cli', function() { ...@@ -46,12 +45,12 @@ describe('cli', function() {
}); });
}); });
it('should compile sample.scss to ../out.css', function(done) { it('should compile sample.scss to ../out.css', function(done) {
var resultPath = path.resolve(__dirname, '../out.css'); var resultPath = path.resolve(__dirname, '../out.css');
exec('node ' + cliPath + ' ' + sampleFilename + ' ../out.css', { exec('node ' + cliPath + ' ' + sampleFilename + ' ../out.css', {
cwd: __dirname cwd: __dirname
}, function(err, stdout, stderr) { }, function() {
fs.exists(resultPath, function(exists) { fs.exists(resultPath, function(exists) {
assert(exists); assert(exists);
...@@ -95,7 +94,7 @@ describe('cli', function() { ...@@ -95,7 +94,7 @@ describe('cli', function() {
var resultPath = path.join(__dirname, '../output.css'); var resultPath = path.join(__dirname, '../output.css');
var emitter = cli(['--output', resultPath, path.join(__dirname, 'sample.scss')]); var emitter = cli(['--output', resultPath, path.join(__dirname, 'sample.scss')]);
emitter.on('error', done); emitter.on('error', done);
emitter.on('write', function(err, file, css){ emitter.on('write', function(){
fs.exists(resultPath, function(exists) { fs.exists(resultPath, function(exists) {
assert(exists); assert(exists);
fs.unlink(resultPath, done); fs.unlink(resultPath, done);
...@@ -139,5 +138,4 @@ describe('cli', function() { ...@@ -139,5 +138,4 @@ describe('cli', function() {
}); });
}); });
}); });
...@@ -4,21 +4,6 @@ var assert = require('assert'); ...@@ -4,21 +4,6 @@ var assert = require('assert');
var sampleFilename = require('path').resolve(__dirname, 'sample.scss'); var sampleFilename = require('path').resolve(__dirname, 'sample.scss');
var scssStr = '#navbar {\
width: 80%;\
height: 23px; }\
#navbar ul {\
list-style-type: none; }\
#navbar li {\
float: left;\
a {\
font-weight: bold; }}\
@mixin keyAnimation($name, $attr, $value) {\
@-webkit-keyframes #{$name} {\
0% { #{$attr}: $value; }\
}\
}';
var expectedCommentsScssStr = '/* line 1, ' + sampleFilename + ' */\n\ var expectedCommentsScssStr = '/* line 1, ' + sampleFilename + ' */\n\
#navbar {\n\ #navbar {\n\
width: 80%;\n\ width: 80%;\n\
...@@ -35,23 +20,6 @@ var expectedCommentsScssStr = '/* line 1, ' + sampleFilename + ' */\n\ ...@@ -35,23 +20,6 @@ var expectedCommentsScssStr = '/* line 1, ' + sampleFilename + ' */\n\
#navbar li a {\n\ #navbar li a {\n\
font-weight: bold; }\n'; font-weight: bold; }\n';
var expectedDebugScssStr = '@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\000031}}\n\
#navbar {\n\
width: 80%;\n\
height: 23px; }\n\
\n\
@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\000035}}\n\
#navbar ul {\n\
list-style-type: none; }\n\
\n\
@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\000038}}\n\
#navbar li {\n\
float: left; }\n\
@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\0000310}}\n\
#navbar li a {\n\
font-weight: bold; }\n';
describe("compile file with source comments", function() { describe("compile file with source comments", function() {
it("should compile with render and comment outputs", function(done) { it("should compile with render and comment outputs", function(done) {
sass.render({ sass.render({
......
...@@ -38,7 +38,7 @@ var expectedRender = '#navbar {\n\ ...@@ -38,7 +38,7 @@ var expectedRender = '#navbar {\n\
describe("DEPRECATED: compile scss", function() { describe("DEPRECATED: compile scss", function() {
it("should compile with render", function(done) { it("should compile with render", function(done) {
sass.render(scssStr, function(err, css) { sass.render(scssStr, function(err) {
done(err); done(err);
}); });
}); });
...@@ -98,6 +98,7 @@ describe("compile scss", function() { ...@@ -98,6 +98,7 @@ describe("compile scss", function() {
sass.render({ sass.render({
data: '{zzz}', data: '{zzz}',
success: function(css) { success: function(css) {
console.log(css);
}, },
error: function(error, status) { error: function(error, status) {
assert.equal(status, 1); assert.equal(status, 1);
...@@ -128,7 +129,7 @@ describe("compile file with include paths", function(){ ...@@ -128,7 +129,7 @@ describe("compile file with include paths", function(){
error: function (error) { error: function (error) {
done(error); done(error);
} }
}) });
}); });
}); });
...@@ -145,7 +146,7 @@ describe("compile file", function() { ...@@ -145,7 +146,7 @@ describe("compile file", function() {
}); });
}); });
it("should compile with renderSync", function(done) { it("should compile with renderSync", function(done) {
done(assert.ok(sass.renderSync({file: sampleFilename}))); done(assert.ok(sass.renderSync({file: sampleFilename})));
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment