Skip to content

Commit

Permalink
fix: support multiple css inputs on the commandline produced by find/…
Browse files Browse the repository at this point in the history
…glob [#317]
  • Loading branch information
bezoerb committed Nov 28, 2018
1 parent 8b22c9b commit ccaeae1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,22 @@ function showError(err) {
}

function run(data) {
const {_: inputs, ...opts} = {...normalizedFlags};
const [input] = inputs || [];
const {_: inputs = [], css, ...opts} = {...normalizedFlags};

// Detect css globbing
const cssBegin = process.argv.findIndex(el => ['--css', '-c'].includes(el));
const cssEnd = process.argv.findIndex((el, index) => index > cssBegin && el.startsWith('-'));
const cssCheck = process.argv.slice(cssBegin, cssEnd > 0 ? cssEnd : undefined);
const additionalCss = inputs.filter(file => cssCheck.includes(file));
// Just take the first html input as we don't support multiple html sources for
const [input] = inputs.filter(file => !additionalCss.includes(file));

if (Array.isArray(css)) {
opts.css = [...css, ...additionalCss].filter(file => file);
} else if (css || additionalCss.length > 0) {
opts.css = [css, ...additionalCss].filter(file => file);
}

ok = true;

if (data) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('CLI', () => {
expect(args).toMatchObject({
width: 300,
height: 400,
css: 'css',
css: ['css'],
inline: true,
extract: true,
});
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('CLI', () => {
expect(args).toMatchObject({
width: 300,
height: 400,
css: 'css',
css: ['css'],
inline: true,
extract: true,
});
Expand Down

0 comments on commit ccaeae1

Please sign in to comment.