Skip to content
Merged
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
12 changes: 11 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
## <small>0.7.5 (2020-08-19)</small>

* docs: about escaping when use pattern ([ae3db76](https://github.com/posthtml/posthtml-cli/commit/ae3db76))
* fix: incorrect resolve ignoring folder/files, close #317 ([8cc3e69](https://github.com/posthtml/posthtml-cli/commit/8cc3e69)), closes [#317](https://github.com/posthtml/posthtml-cli/issues/317)
* test: ignoring folder/files, issue #317 ([7a4e8dc](https://github.com/posthtml/posthtml-cli/commit/7a4e8dc)), closes [#317](https://github.com/posthtml/posthtml-cli/issues/317)



## <small>0.7.4 (2020-08-19)</small>

* build: perf runner test script ([40237d0](https://github.com/posthtml/posthtml-cli/commit/40237d0))
* 0.7.4 ([158e2cc](https://github.com/posthtml/posthtml-cli/commit/158e2cc))
* Fix order for plugin set with config and cli ([bb3973a](https://github.com/posthtml/posthtml-cli/commit/bb3973a))
* build: perf runner test script ([40237d0](https://github.com/posthtml/posthtml-cli/commit/40237d0))
* build: update changelog ([c187bc0](https://github.com/posthtml/posthtml-cli/commit/c187bc0))



Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthtml-cli",
"version": "0.7.4",
"version": "0.7.5",
"description": "CLI for posthtml",
"license": "MIT",
"repository": "posthtml/posthtml-cli",
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ $ posthtml --help
$ posthtml input.html
$ posthtml input.html -o output.html
$ posthtml inputFolder/*.html !unicorn.html
$ posthtml '**/*.html' '\!**/unicorn.html'
$ posthtml input-one.html input-two.html -o outputFolder
$ posthtml input.html -o output.html -c posthtml.js
$ posthtml input.html -o output.html -u posthtml-bem --posthtml-bem.elemPrefix __
$ posthtml inputFolder/*.html -o outputFolder
$ posthtml inputFolder/**/*.html -o outputFolder -a
$ posthtml inputFolder/**/*.html -o outputFolder -a -r inputFolder
```
> ⚠️ Please note that when using patterns on the command line `*` and `!` escaping of characters is necessary. When using as npc scripts, you only need to screen the pattern `*`. [About the reasons](https://github.com/posthtml/posthtml-cli/issues/317#issuecomment-676330082)

## Options

Expand Down
25 changes: 21 additions & 4 deletions src/cfg-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,28 @@ export default ({input, flags = {}}) => {
use = [].concat(use).reduce((cfg, name) => {
let cliOptions = flags[toCamelCase(name)];
let configOptions = configPluginOptions[name];

// We merge this way because options can be both strings and objects.
const merged = mergeOptions({ [name]: configOptions }, { [name]: cliOptions || {}});
const merged = mergeOptions({[name]: configOptions}, {[name]: cliOptions || {}});

// Assigning as we loop `use` makes sure that the order in cfg.plugins is correct.
cfg.plugins[name] = merged[name];

if (configOptions) {
delete configPluginOptions[name];
}

return cfg;
}, { plugins: {} });
}, {plugins: {}});

// Add the remaining plugins if there is any.
if (config && config.plugins) {
for (let name in configPluginOptions) {
use.plugins[name] = configPluginOptions[name];
if (configPluginOptions[name]) {
use.plugins[name] = configPluginOptions[name];
}
}

// Now all the plugins are in `use.plugins`.
// Delete `config.plugins` for correct merging later: mergeOptions(config, {...}, use)
delete config.plugins;
Expand All @@ -53,7 +60,17 @@ export default ({input, flags = {}}) => {
input = []
.concat(input && input.length > 0 ? input : config?.input)
.filter(Boolean)
.map(file => path.join(path.resolve(root), file));
.map(file => {
const ignoreFile = file.startsWith('!');
let ignoreSymbol = '';

if (ignoreFile) {
ignoreSymbol = '!';
file = file.slice(1);
}

return path.join(ignoreSymbol, path.resolve(root), file);
});

if (input.length === 0) {
throw new TypeError('input files not found');
Expand Down
1 change: 1 addition & 0 deletions test/expected/output-ignoring/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>input-nesting-index</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>input-nesting-child/index</div>
1 change: 1 addition & 0 deletions test/fixtures/input-ignoring/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>input-nesting-index</div>
21 changes: 21 additions & 0 deletions test/test-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,24 @@ test('Specify the root of the output folder structure with root option', async t
(await read(`${outputPath}/input-nesting-child/input-nesting.html`))
);
});

test('Ignoring files by pattern', async t => {
const outputPath = 'test/expected/output-ignoring';
rimraf.sync(outputPath);
t.plan(3);
await execa(cli, [
'**/*.html',
'!ignoring-input-child/**/*.html',
'-o',
outputPath,
'-a',
'-r',
'test/fixtures/input-ignoring'
]);
t.true(await pathExists(outputPath));
t.is(
(await read('test/fixtures/input-ignoring/input.html')),
(await read(`${outputPath}/input.html`))
);
t.false(await pathExists('test/expected/input-ignoring/ignoring-input-child'));
});