Skip to content

[WIP] Default to ./ when no <src> and support - as stdin #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ test: test/data/expected.stream.json dist
mocha test/env/*.test.js test/utils/*.test.js
rm -rf sassdoc && $(MOCHA) test/api/*.test.js
$(SASSDOC) --parse test/data/test.scss | diff - test/data/expected.json
$(SASSDOC) --parse < test/data/test.scss | diff - test/data/expected.stream.json
$(SASSDOC) --parse - < test/data/test.scss | diff - test/data/expected.stream.json
cd test/data && $(SASSDOC) --parse | diff - expected.json
rm -rf sassdoc && $(SASSDOC) test/data/test.scss && [ -d sassdoc ]
rm -rf sassdoc && $(SASSDOC) < test/data/test.scss && [ -d sassdoc ]
rm -rf sassdoc && $(SASSDOC) - < test/data/test.scss && [ -d sassdoc ]

test/data/expected.stream.json: test/data/expected.json
test/data/stream $< > $@
Expand Down
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