node-sass
Advanced tools
Comparing version 1.0.1 to 1.0.2-alpha
170
lib/cli.js
@@ -1,2 +0,2 @@ | ||
var watch = require('node-watch'), | ||
var watch = require('node-watch'), | ||
render = require('./render'), | ||
@@ -6,70 +6,66 @@ path = require('path'), | ||
stdin = require('get-stdin'), | ||
meow = require('meow'), | ||
cwd = process.cwd(); | ||
var yargs = require('yargs') | ||
.usage('Compile .scss files with node-sass.\nUsage: $0 [options] <input.scss> [<output.css>]') | ||
.version(require('../package.json').version, 'version').alias('version', 'V') | ||
.options('output-style', { | ||
describe: 'CSS output style (nested|expanded|compact|compressed)', | ||
'default': 'nested' | ||
}) | ||
.options('source-comments', { | ||
describe: 'Include debug info in output (none|normal|map)', | ||
'default': 'none' | ||
}) | ||
.options('source-map', { | ||
describe: 'Emit source map' | ||
}) | ||
.options('include-path', { | ||
describe: 'Path to look for @import-ed files', | ||
'default': cwd | ||
}) | ||
.options('image-path', { | ||
describe: 'Path to prepend when using the image-url(…) helper', | ||
'default': '' | ||
}) | ||
.options('precision', { | ||
describe: 'The amount of precision allowed in decimal numbers', | ||
'default': 5 | ||
}) | ||
.options('watch', { | ||
describe: 'Watch a directory or file', | ||
alias: 'w', | ||
type: 'boolean' | ||
}) | ||
.options('output', { | ||
describe: 'Output css file', | ||
alias: 'o' | ||
}) | ||
.options('stdout', { | ||
describe: 'Print the resulting CSS to stdout', | ||
type: 'boolean' | ||
}) | ||
.options('omit-source-map-url', { | ||
describe: 'Omit source map URL comment from output', | ||
type: 'boolean', | ||
alias: 'x' | ||
}) | ||
.options('indented-syntax', { | ||
describe: 'Treat data from stdin as sass code (versus scss)', | ||
type: 'boolean', | ||
alias: 'i' | ||
}) | ||
.options('help', { | ||
describe: 'Print usage info', | ||
type: 'string', | ||
alias: 'help' | ||
}) | ||
.check(function(argv) { | ||
if (argv.help) { return true; } | ||
if (!argv._.length && (process.stdin.isTTY || process.env.isTTY)) { | ||
return false; | ||
function init(args) { | ||
return meow({ | ||
argv: args, | ||
pkg: '../package.json', | ||
help: [ | ||
' Usage', | ||
' node-sass [options] <input.scss> [output.css]', | ||
' cat <input.scss> | node-sass > output.css', | ||
'', | ||
' Example', | ||
' node-sass --output-style compressed foobar.scss foobar.css', | ||
' cat foobar.scss | node-sass --output-style compressed > foobar.css', | ||
'', | ||
' Options', | ||
' -w, --watch Watch a directory or file', | ||
' -o, --output Output CSS file', | ||
' -x, --omit-source-map-url Omit source map URL comment from output', | ||
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)', | ||
' --output-style CSS output style (nested|expanded|compact|compressed)', | ||
' --source-comments Include debug info in output (none|normal|map)', | ||
' --source-map Emit source map', | ||
' --include-path Path to look for imported files', | ||
' --image-path Path to prepend when using the `image-url()` helper', | ||
' --precision The amount of precision allowed in decimal numbers', | ||
' --stdout Print the resulting CSS to stdout', | ||
' --help Print usage info' | ||
].join('\n') | ||
}, { | ||
boolean: [ | ||
'indented-syntax', | ||
'omit-source-map-url', | ||
'stdout', | ||
'watch' | ||
], | ||
string: [ | ||
'image-path', | ||
'include-path', | ||
'output', | ||
'output-style', | ||
'precision', | ||
'source-comments' | ||
], | ||
alias: { | ||
i: 'indented-syntax', | ||
o: 'output', | ||
w: 'watch', | ||
x: 'omit-source-map-url' | ||
}, | ||
default: { | ||
'image-path': '', | ||
'include-path': cwd, | ||
'output-style': 'nested', | ||
precision: 5, | ||
'source-comments': 'none' | ||
} | ||
}); | ||
} | ||
// throttle function, used so when multiple files change at the same time | ||
// (e.g. git pull) the files are only compiled once. | ||
function throttle(fn) { | ||
var timer; | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
var args = [].slice.call(arguments, 1); | ||
@@ -90,14 +86,6 @@ return function() { | ||
function run(options, emitter) { | ||
if (!Array.isArray(options.includePaths)) { | ||
options.includePaths = [options.includePaths]; | ||
if (!Array.isArray(options.includePath)) { | ||
options.includePath = [options.includePath]; | ||
} | ||
if (Array.isArray(options.outputStyle)) { | ||
options.outputStyle = options.outputStyle[0]; | ||
} | ||
if (Array.isArray(options.sourceComments)) { | ||
options.sourceComments = options.sourceComments[0]; | ||
} | ||
if (options.sourceMap) { | ||
@@ -138,23 +126,7 @@ if (options.sourceMap === true) { | ||
module.exports = function(args) { | ||
var argv = yargs.parse(args); | ||
var cli = init(args); | ||
var emitter = new Emitter(); | ||
var options = { | ||
imagePath: argv['image-path'], | ||
includePaths: argv['include-path'], | ||
omitSourceMapUrl: argv['omit-source-map-url'], | ||
indentedSyntax: argv['indented-syntax'], | ||
outputStyle: argv['output-style'], | ||
precision: argv.precision, | ||
sourceComments: argv['source-comments'], | ||
sourceMap: argv['source-map'], | ||
stdout: argv.stdout, | ||
watch: argv.w | ||
}; | ||
var input = cli.input; | ||
var options = cli.flags; | ||
if (argv.help) { | ||
yargs.showHelp(); | ||
process.exit(); | ||
return; | ||
} | ||
emitter.on('error', function(err) { | ||
@@ -165,4 +137,4 @@ console.error(err); | ||
options.src = argv._[0]; | ||
options.dest = argv.o || argv._[1]; | ||
options.src = input[0] || null; | ||
options.dest = options.output || input[1] || null; | ||
@@ -178,2 +150,12 @@ if (!options.dest && (process.stdout.isTTY || process.env.isTTY)) { | ||
if (process.stdin.isTTY || process.env.isTTY) { | ||
if (!input.length) { | ||
console.error([ | ||
'Provide a sass file to render', | ||
'', | ||
' Example', | ||
' node-sass --output-style compressed foobar.scss foobar.css', | ||
' cat foobar.scss | node-sass --output-style compressed > foobar.css' | ||
].join('\n')); | ||
process.exit(1); | ||
} | ||
run(options, emitter); | ||
@@ -189,3 +171,1 @@ } else { | ||
}; | ||
module.exports.yargs = yargs; |
@@ -8,6 +8,6 @@ var sass = require('../sass'), | ||
imagePath: options.imagePath, | ||
includePaths: options.includePaths, | ||
includePaths: options.includePath, | ||
omitSourceMapUrl: options.omitSourceMapUrl, | ||
indentedSyntax: options.indentedSyntax, | ||
outFile: options.outFile, | ||
outFile: options.dest, | ||
outputStyle: options.outputStyle, | ||
@@ -14,0 +14,0 @@ precision: options.precision, |
@@ -5,3 +5,3 @@ { | ||
"description": "wrapper around libsass", | ||
"version": "1.0.1", | ||
"version": "1.0.2-alpha", | ||
"homepage": "https://github.com/sass/node-sass", | ||
@@ -46,4 +46,6 @@ "keywords": [ | ||
"chalk": "~0.5.1", | ||
"get-stdin": "~3.0.0", | ||
"meow": "^2.0.0", | ||
"mkdirp": "~0.5.0", | ||
"mocha": "~1.21.4", | ||
"mocha": "~1.21.5", | ||
"nan": "~1.3.0", | ||
@@ -53,5 +55,3 @@ "node-watch": "~0.3.4", | ||
"shelljs": "~0.3.0", | ||
"sinon": "~1.10.3", | ||
"yargs": "~1.3.1", | ||
"get-stdin": "~3.0.0" | ||
"sinon": "~1.10.3" | ||
}, | ||
@@ -58,0 +58,0 @@ "devDependencies": { |
@@ -74,7 +74,7 @@ var path = require('path'), | ||
// it means that data is recieved, so we are ok to go. | ||
emitter.stdout.on('data', function() { done(); }); | ||
emitter.stdout.on('data', function() { done(); }); | ||
src.pipe(emitter.stdin); | ||
}); | ||
it('should print help when run with no arguments', function(done) { | ||
it('should print usage when run with no arguments', function(done) { | ||
var env = assign(process.env, { isTTY: true }); | ||
@@ -84,3 +84,3 @@ exec('node ' + cliPath, { | ||
}, function(err, stdout, stderr) { | ||
done(assert(stderr.trim().indexOf('Compile .scss files with node-sass') === 0)); | ||
done(assert(stderr.trim().indexOf('Provide a sass file to render') === 0)); | ||
}); | ||
@@ -87,0 +87,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21552594
18
22334
1
+ Addedmeow@^2.0.0
+ Addedcamelcase@1.2.1(transitive)
+ Addedcamelcase-keys@1.0.0(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedindent-string@1.2.2(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@2.1.0(transitive)
+ Addedobject-assign@2.1.1(transitive)
+ Addedrepeating@1.1.3(transitive)
- Removedyargs@~1.3.1
- Removedyargs@1.3.3(transitive)
Updatedmocha@~1.21.5