Skip to content

Commit

Permalink
Default to ./ when no <src> and support - as stdin
Browse files Browse the repository at this point in the history
* See #347
  • Loading branch information
valeriangalliat committed Jan 29, 2015
1 parent 0b2b44a commit 9948a05
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"concat-stream": "^1.4.7",
"core-js": "^0.4.3",
"docopt": "^0.4.1",
"event-stream": "^3.2.1",
"glob": "^4.3.1",
"glob2base": "0.0.12",
"js-yaml": "^3.2.1",
Expand Down
30 changes: 25 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Options:
`;

const docopt = require('docopt').docopt;
const es = require('event-stream');
const vfs = require('vinyl-fs');
const source = require('vinyl-source-stream');
const pkg = require('../package.json');
const Environment = require('./environment');
Expand Down Expand Up @@ -70,13 +72,31 @@ export default function cli(argv = process.argv.slice(2)) {
}

if (!options['<src>'].length) {
return process.stdin
.pipe(source())
.pipe(handler(env))
.on('data', cb);
options['<src>'].push('.');
}

handler(options['<src>'], env).then(cb);
let stdin = false;

let sources = vfs.src(options['<src>'].filter(x => {
if (x === '-') {
stdin = true;
return false;
}

return true;
}));

if (stdin) {
sources = es.merge(
process.stdin.pipe(source()),
sources
);
}

let stream = handler(env);
stream.promise.then(cb);

sources.pipe(stream).resume();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/recurse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const vfs = require('vinyl-fs');
*/
export default function recurse() {
return through.obj(function (file, enc, cb) {
if (file.isBuffer()) {
if (file.isBuffer() || file.isStream()) {
// Pass-through.
return cb(null, file);
}
Expand Down
20 changes: 14 additions & 6 deletions src/sassdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ export function parseFilter(env = {}) {
let parser = new Parser(env, env.theme && env.theme.annotations);
let filter = parser.stream();

filter.promise
let transform = pipe(
recurse(),
exclude(env.exclude || []),
converter({ from: 'sass', to: 'scss' }),
filter
);

transform.promise = filter.promise
.then(data => sorter(data));

return filter;
return transform;
}

/**
Expand Down Expand Up @@ -199,9 +206,7 @@ export function parse(...args) { // jshint ignore:line
* @return {Promise}
*/
async function documentize(env) {
let data = await baseDocumentize(env);

return data;
return await baseDocumentize(env);
}

/* jshint ignore:end */
Expand All @@ -220,7 +225,10 @@ export function parse(...args) { // jshint ignore:line
}, cb);
});

return pipe(parse, filter);
let transform = pipe(parse, filter);
transform.promise = parse.promise;

return transform;
}
}

Expand Down

0 comments on commit 9948a05

Please sign in to comment.