Skip to content

Commit 3bef66e

Browse files
committed
CLI: Overrides default version info.
* Based on sindresorhus/meow#2. * Adds alias -v. * Improves info text; inspired by Less CLI. :) PR URL: sass#717.
1 parent aa70dbb commit 3bef66e

File tree

6 files changed

+44
-29
lines changed

6 files changed

+44
-29
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# node-sass
1+
# node-sass
22

33
<table>
44
<tr>
@@ -232,14 +232,19 @@ console.log(result.stats);
232232

233233
### Version information (v2 change)
234234

235-
Both `node-sass` and `libsass` version info is now present in `package.json` and is exposed via `info()` method:
235+
Both `node-sass` and `libsass` version info is now present in `package.json` and is exposed via `info` method:
236236

237237
```javascript
238-
require('node-sass').info();
238+
var sass = require('node-sass');
239+
240+
console.log(sass.info);
241+
242+
/*
243+
it will output something like:
239244
240-
// outputs something like:
241-
// node-sass version: 2.0.0-beta
242-
// libsass version: 3.1.0-beta
245+
node-sass 2.0.1 (Wrapper) [JavaScript]
246+
libsass 3.1.0 (Sass Compiler) [C/C++]
247+
*/
243248
```
244249

245250
## Integrations
@@ -329,6 +334,7 @@ Output will be saved with the same name as input SASS file into the current work
329334
-o, --output Output directory
330335
-x, --omit-source-map-url Omit source map URL comment from output
331336
-i, --indented-syntax Treat data from stdin as sass code (versus scss)
337+
-v, --version Prints version info
332338
--output-style CSS output style (nested|expanded|compact|compressed)
333339
--source-comments Include debug info in output
334340
--source-map Emit source map

bin/node-sass

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#!/usr/bin/env node
22
var Emitter = require('events').EventEmitter,
3-
path = require('path'),
43
Gaze = require('gaze'),
5-
meow = require('meow'),
6-
stdin = require('get-stdin'),
74
grapher = require('sass-graph'),
8-
render = require('../lib/render');
5+
meow = require('meow'),
6+
path = require('path'),
7+
render = require('../lib/render'),
8+
stdin = require('get-stdin');
99

1010
/**
1111
* Initialize CLI
1212
*/
1313

1414
var cli = meow({
1515
pkg: '../package.json',
16+
version: process.sassInfo,
1617
help: [
17-
require('../lib/').info(),
18-
'',
1918
'Usage',
2019
' node-sass [options] <input.scss> [output.css]',
2120
' cat <input.scss> | node-sass > output.css',
@@ -30,6 +29,7 @@ var cli = meow({
3029
' -o, --output Output directory',
3130
' -x, --omit-source-map-url Omit source map URL comment from output',
3231
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)',
32+
' -v, --version Prints version info',
3333
' --output-style CSS output style (nested|expanded|compact|compressed)',
3434
' --source-comments Include debug info in output',
3535
' --source-map Emit source map',
@@ -56,12 +56,13 @@ var cli = meow({
5656
'precision'
5757
],
5858
alias: {
59+
c: 'source-comments',
5960
i: 'indented-syntax',
6061
o: 'output',
61-
w: 'watch',
62+
r: 'recursive',
6263
x: 'omit-source-map-url',
63-
c: 'source-comments',
64-
r: 'recursive'
64+
v: 'version',
65+
w: 'watch'
6566
},
6667
default: {
6768
'include-path': process.cwd(),

lib/extensions.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
var fs = require('fs');
1+
var eol = require('os').EOL,
2+
fs = require('fs'),
3+
package = require('../package.json');
24

35
/**
46
* Get Runtime Info
@@ -35,5 +37,13 @@ function getBinaryIdentifiableName() {
3537
v8SemVersion].join('');
3638
}
3739

40+
function getSassInfo() {
41+
return [
42+
['node-sass', package.version, '(Wrapper)', '[JavaScript]'].join('\t'),
43+
['libsass ', package.libsass, '(Sass Compiler)', '[C/C++]'].join('\t'),
44+
].join(eol);
45+
}
46+
3847
process.runtime = getRuntimeInfo();
48+
process.sassInfo = getSassInfo();
3949
process.sassBinaryName = getBinaryIdentifiableName();

lib/index.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,4 @@ module.exports.renderSync = function(options) {
259259
* @api public
260260
*/
261261

262-
module.exports.info = function() {
263-
var package = require('../package.json');
264-
265-
return [
266-
'node-sass version: ' + package.version,
267-
'libsass version: ' + package.libsass
268-
].join('\n');
269-
};
262+
module.exports.info = process.sassInfo;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"cross-spawn": "^0.2.6",
4848
"gaze": "^0.5.1",
4949
"get-stdin": "^4.0.1",
50-
"meow": "^3.0.0",
50+
"meow": "^3.1.0",
5151
"mkdirp": "^0.5.0",
5252
"nan": "^1.6.2",
5353
"npmconf": "^2.1.1",

test/api.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,16 @@ describe('api', function() {
792792
});
793793

794794
describe('.info()', function() {
795+
var package = require('../package.json'),
796+
info = sass.info;
797+
795798
it('should return a correct version info', function(done) {
796-
assert.equal(sass.info(), [
797-
'node-sass version: ' + require('../package.json').version,
798-
'libsass version: ' + require('../package.json').libsass
799-
].join('\n'));
799+
assert(info.indexOf(package.version) > 0);
800+
assert(info.indexOf('(Wrapper)') > 0);
801+
assert(info.indexOf('[JavaScript]') > 0);
802+
assert(info.indexOf(package.libsass) > 0);
803+
assert(info.indexOf('(Sass Compiler)') > 0);
804+
assert(info.indexOf('[C/C++]') > 0);
800805

801806
done();
802807
});

0 commit comments

Comments
 (0)