Commit e016d857 by Adeel

CLI: Overrides default version info.

* Based on sindresorhus/meow#2.
* Adds alias -v.
* Improves info text; inspired by Less CLI. :)
* Updates readme.

PR URL: #717.
parent 9bd034c2
...@@ -232,14 +232,19 @@ console.log(result.stats); ...@@ -232,14 +232,19 @@ console.log(result.stats);
### Version information (v2 change) ### Version information (v2 change)
Both `node-sass` and `libsass` version info is now present in `package.json` and is exposed via `info()` method: Both `node-sass` and `libsass` version info is now present in `package.json` and is exposed via `info` method:
```javascript ```javascript
require('node-sass').info(); var sass = require('node-sass');
console.log(sass.info);
/*
it will output something like:
// outputs something like: node-sass 2.0.1 (Wrapper) [JavaScript]
// node-sass version: 2.0.0-beta libsass 3.1.0 (Sass Compiler) [C/C++]
// libsass version: 3.1.0-beta */
``` ```
## Integrations ## Integrations
...@@ -329,6 +334,7 @@ Output will be saved with the same name as input SASS file into the current work ...@@ -329,6 +334,7 @@ Output will be saved with the same name as input SASS file into the current work
-o, --output Output directory -o, --output Output directory
-x, --omit-source-map-url Omit source map URL comment from output -x, --omit-source-map-url Omit source map URL comment from output
-i, --indented-syntax Treat data from stdin as sass code (versus scss) -i, --indented-syntax Treat data from stdin as sass code (versus scss)
-v, --version Prints version info
--output-style CSS output style (nested|expanded|compact|compressed) --output-style CSS output style (nested|expanded|compact|compressed)
--source-comments Include debug info in output --source-comments Include debug info in output
--source-map Emit source map --source-map Emit source map
......
#!/usr/bin/env node #!/usr/bin/env node
var Emitter = require('events').EventEmitter, var Emitter = require('events').EventEmitter,
path = require('path'),
Gaze = require('gaze'), Gaze = require('gaze'),
meow = require('meow'),
stdin = require('get-stdin'),
grapher = require('sass-graph'), grapher = require('sass-graph'),
render = require('../lib/render'); meow = require('meow'),
path = require('path'),
render = require('../lib/render'),
stdin = require('get-stdin');
/** /**
* Initialize CLI * Initialize CLI
...@@ -13,9 +13,8 @@ var Emitter = require('events').EventEmitter, ...@@ -13,9 +13,8 @@ var Emitter = require('events').EventEmitter,
var cli = meow({ var cli = meow({
pkg: '../package.json', pkg: '../package.json',
version: process.sassInfo,
help: [ help: [
require('../lib/').info(),
'',
'Usage', 'Usage',
' node-sass [options] <input.scss> [output.css]', ' node-sass [options] <input.scss> [output.css]',
' cat <input.scss> | node-sass > output.css', ' cat <input.scss> | node-sass > output.css',
...@@ -30,6 +29,7 @@ var cli = meow({ ...@@ -30,6 +29,7 @@ var cli = meow({
' -o, --output Output directory', ' -o, --output Output directory',
' -x, --omit-source-map-url Omit source map URL comment from output', ' -x, --omit-source-map-url Omit source map URL comment from output',
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)', ' -i, --indented-syntax Treat data from stdin as sass code (versus scss)',
' -v, --version Prints version info',
' --output-style CSS output style (nested|expanded|compact|compressed)', ' --output-style CSS output style (nested|expanded|compact|compressed)',
' --source-comments Include debug info in output', ' --source-comments Include debug info in output',
' --source-map Emit source map', ' --source-map Emit source map',
...@@ -56,12 +56,13 @@ var cli = meow({ ...@@ -56,12 +56,13 @@ var cli = meow({
'precision' 'precision'
], ],
alias: { alias: {
c: 'source-comments',
i: 'indented-syntax', i: 'indented-syntax',
o: 'output', o: 'output',
w: 'watch', r: 'recursive',
x: 'omit-source-map-url', x: 'omit-source-map-url',
c: 'source-comments', v: 'version',
r: 'recursive' w: 'watch'
}, },
default: { default: {
'include-path': process.cwd(), 'include-path': process.cwd(),
......
var fs = require('fs'); var eol = require('os').EOL,
fs = require('fs'),
package = require('../package.json');
/** /**
* Get Runtime Info * Get Runtime Info
...@@ -35,5 +37,13 @@ function getBinaryIdentifiableName() { ...@@ -35,5 +37,13 @@ function getBinaryIdentifiableName() {
v8SemVersion].join(''); v8SemVersion].join('');
} }
function getSassInfo() {
return [
['node-sass', package.version, '(Wrapper)', '[JavaScript]'].join('\t'),
['libsass ', package.libsass, '(Sass Compiler)', '[C/C++]'].join('\t'),
].join(eol);
}
process.runtime = getRuntimeInfo(); process.runtime = getRuntimeInfo();
process.sassInfo = getSassInfo();
process.sassBinaryName = getBinaryIdentifiableName(); process.sassBinaryName = getBinaryIdentifiableName();
...@@ -259,11 +259,4 @@ module.exports.renderSync = function(options) { ...@@ -259,11 +259,4 @@ module.exports.renderSync = function(options) {
* @api public * @api public
*/ */
module.exports.info = function() { module.exports.info = process.sassInfo;
var package = require('../package.json');
return [
'node-sass version: ' + package.version,
'libsass version: ' + package.libsass
].join('\n');
};
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
"cross-spawn": "^0.2.6", "cross-spawn": "^0.2.6",
"gaze": "^0.5.1", "gaze": "^0.5.1",
"get-stdin": "^4.0.1", "get-stdin": "^4.0.1",
"meow": "^3.0.0", "meow": "^3.1.0",
"mkdirp": "^0.5.0", "mkdirp": "^0.5.0",
"nan": "^1.6.2", "nan": "^1.6.2",
"npmconf": "^2.1.1", "npmconf": "^2.1.1",
......
...@@ -792,11 +792,16 @@ describe('api', function() { ...@@ -792,11 +792,16 @@ describe('api', function() {
}); });
describe('.info()', function() { describe('.info()', function() {
var package = require('../package.json'),
info = sass.info;
it('should return a correct version info', function(done) { it('should return a correct version info', function(done) {
assert.equal(sass.info(), [ assert(info.indexOf(package.version) > 0);
'node-sass version: ' + require('../package.json').version, assert(info.indexOf('(Wrapper)') > 0);
'libsass version: ' + require('../package.json').libsass assert(info.indexOf('[JavaScript]') > 0);
].join('\n')); assert(info.indexOf(package.libsass) > 0);
assert(info.indexOf('(Sass Compiler)') > 0);
assert(info.indexOf('[C/C++]') > 0);
done(); done();
}); });
......
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