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 1b30a9a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 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
11 changes: 9 additions & 2 deletions src/sassdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,20 @@ export default function sassdoc(...args) {
onEmpty(data, env);
});

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

/* jshint ignore:start */

/**
* Returned Promise await the full sequence,
* instead of just the parsing step.
*/
filter.promise = new Promise((resolve, reject) => {
transform.promise = new Promise((resolve, reject) => {

async function documentize() {
try {
Expand All @@ -179,7 +186,7 @@ export default function sassdoc(...args) {

/* jshint ignore:end */

return filter;
return transform;
}
}

Expand Down

0 comments on commit 1b30a9a

Please sign in to comment.