Skip to content

Commit

Permalink
CLI: Overrides default version info.
Browse files Browse the repository at this point in the history
* Based on sindresorhus/meow#2.
* Adds alias -v.
* Improves info text; inspired by Less CLI. :)

PR URL: sass#717.
  • Loading branch information
am11 committed Feb 28, 2015
1 parent aa70dbb commit 004777d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
19 changes: 10 additions & 9 deletions bin/node-sass
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#!/usr/bin/env node
var Emitter = require('events').EventEmitter,
path = require('path'),
Gaze = require('gaze'),
meow = require('meow'),
stdin = require('get-stdin'),
grapher = require('sass-graph'),
render = require('../lib/render');
meow = require('meow'),
path = require('path'),
render = require('../lib/render'),
stdin = require('get-stdin');

/**
* Initialize CLI
*/

var cli = meow({
pkg: '../package.json',
version: process.sassInfo,
help: [
require('../lib/').info(),
'',
'Usage',
' node-sass [options] <input.scss> [output.css]',
' cat <input.scss> | node-sass > output.css',
Expand All @@ -38,6 +37,7 @@ var cli = meow({
' --include-path Path to look for imported files',
' --precision The amount of precision allowed in decimal numbers',
' --importer Path to custom importer',
' --version Prints version info',
' --help Print usage info'
].join('\n')
}, {
Expand All @@ -56,12 +56,13 @@ var cli = meow({
'precision'
],
alias: {
c: 'source-comments',
i: 'indented-syntax',
o: 'output',
w: 'watch',
r: 'recursive',
x: 'omit-source-map-url',
c: 'source-comments',
r: 'recursive'
v: 'version',
w: 'watch'
},
default: {
'include-path': process.cwd(),
Expand Down
12 changes: 11 additions & 1 deletion lib/extensions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var fs = require('fs');
var eol = require('os').EOL,
fs = require('fs'),
package = require('../package.json');

/**
* Get Runtime Info
Expand Down Expand Up @@ -35,5 +37,13 @@ function getBinaryIdentifiableName() {
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.sassInfo = getSassInfo();
process.sassBinaryName = getBinaryIdentifiableName();
9 changes: 1 addition & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,4 @@ module.exports.renderSync = function(options) {
* @api public
*/

module.exports.info = function() {
var package = require('../package.json');

return [
'node-sass version: ' + package.version,
'libsass version: ' + package.libsass
].join('\n');
};
module.exports.info = process.sassInfo;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"cross-spawn": "^0.2.6",
"gaze": "^0.5.1",
"get-stdin": "^4.0.1",
"meow": "^3.0.0",
"meow": "^3.1.0",
"mkdirp": "^0.5.0",
"nan": "^1.6.2",
"npmconf": "^2.1.1",
Expand Down
13 changes: 9 additions & 4 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,16 @@ describe('api', function() {
});

describe('.info()', function() {
var package = require('../package.json'),
info = sass.info;

it('should return a correct version info', function(done) {
assert.equal(sass.info(), [
'node-sass version: ' + require('../package.json').version,
'libsass version: ' + require('../package.json').libsass
].join('\n'));
assert(info.indexOf(package.version) > 0);
assert(info.indexOf('(Wrapper)') > 0);
assert(info.indexOf('[JavaScript]') > 0);
assert(info.indexOf(package.libsass) > 0);
assert(info.indexOf('(Sass Compiler)') > 0);
assert(info.indexOf('[C/C++]') > 0);

done();
});
Expand Down

0 comments on commit 004777d

Please sign in to comment.