[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #314 from posthtml/milestone-0.7.3
Browse files Browse the repository at this point in the history
Milestone 0.7.3
  • Loading branch information
Scrum committed Aug 18, 2020
2 parents 27d39ba + e6ab03f commit 4616152
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@babel/preset-env",
{
"targets": {
"node": 8
"node": 10
}
}
],
Expand Down
23 changes: 23 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
## <small>0.7.3 (2020-08-18)</small>

* perf: default for base config ([8d93107](https://github.com/posthtml/posthtml-cli/commit/8d93107))
* perf: tree options from for plugins, #303 ([981e911](https://github.com/posthtml/posthtml-cli/commit/981e911)), closes [#303](https://github.com/posthtml/posthtml-cli/issues/303)
* test: async/await not needed ([3165971](https://github.com/posthtml/posthtml-cli/commit/3165971))
* test: default for base config ([7a96127](https://github.com/posthtml/posthtml-cli/commit/7a96127))
* test: fix input file param, issue #308,#313 ([d76f655](https://github.com/posthtml/posthtml-cli/commit/d76f655)), closes [#308](https://github.com/posthtml/posthtml-cli/issues/308) [#313](https://github.com/posthtml/posthtml-cli/issues/313)
* test: fix not remove expected files/folders ([f744687](https://github.com/posthtml/posthtml-cli/commit/f744687))
* test: fix one/two io ([e72206a](https://github.com/posthtml/posthtml-cli/commit/e72206a))
* test: if input not found ([4360836](https://github.com/posthtml/posthtml-cli/commit/4360836))
* test: input from config, issue #308,#313 ([c8f9a54](https://github.com/posthtml/posthtml-cli/commit/c8f9a54)), closes [#308](https://github.com/posthtml/posthtml-cli/issues/308) [#313](https://github.com/posthtml/posthtml-cli/issues/313)
* test: output resolve from config, issue #308 ([c13d78b](https://github.com/posthtml/posthtml-cli/commit/c13d78b)), closes [#308](https://github.com/posthtml/posthtml-cli/issues/308)
* test: resolve output when CLI priority ([4ad0c33](https://github.com/posthtml/posthtml-cli/commit/4ad0c33))
* fix: input map is not defined ([144a101](https://github.com/posthtml/posthtml-cli/commit/144a101))
* fix: resolve incommitg input, close #313 ([4540719](https://github.com/posthtml/posthtml-cli/commit/4540719)), closes [#313](https://github.com/posthtml/posthtml-cli/issues/313)
* fix: resolve or error inputs file, close #313 ([0b53fa2](https://github.com/posthtml/posthtml-cli/commit/0b53fa2)), closes [#313](https://github.com/posthtml/posthtml-cli/issues/313)
* fix: resolve output from config, close #308 ([8588060](https://github.com/posthtml/posthtml-cli/commit/8588060)), closes [#308](https://github.com/posthtml/posthtml-cli/issues/308)
* build: up node targets for preset env ([3a01485](https://github.com/posthtml/posthtml-cli/commit/3a01485))



## <small>0.7.2 (2020-08-17)</small>

* 0.7.2 ([81b6217](https://github.com/posthtml/posthtml-cli/commit/81b6217))
* build: commit lint incorrect work on v9.1.2, #312 ([255ceb1](https://github.com/posthtml/posthtml-cli/commit/255ceb1)), closes [#312](https://github.com/posthtml/posthtml-cli/issues/312)
* build: update changelog ([83181f7](https://github.com/posthtml/posthtml-cli/commit/83181f7))
* build: update dep dev ([44a79b3](https://github.com/posthtml/posthtml-cli/commit/44a79b3))
* ci: skip test on window, #308 ([850c93a](https://github.com/posthtml/posthtml-cli/commit/850c93a)), closes [#308](https://github.com/posthtml/posthtml-cli/issues/308)
* docs: describe list input file to folder ([e6d06a0](https://github.com/posthtml/posthtml-cli/commit/e6d06a0))
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.2",
"version": "0.7.3",
"description": "CLI for posthtml",
"license": "MIT",
"repository": "posthtml/posthtml-cli",
Expand Down
26 changes: 21 additions & 5 deletions src/cfg-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import mergeOptions from 'merge-options';

export default ({input, flags = {}}) => {
const explorer = cosmiconfigSync('posthtml');
let {config, use, options = {}, output, root = './', allInOutput} = flags;
let {
config,
use,
options = {},
output,
root = './',
allInOutput = false
} = flags;

if (config) {
({config} = explorer.load(config));
Expand All @@ -19,11 +26,20 @@ export default ({input, flags = {}}) => {
({config} = explorer.search());
}

return mergeOptions(config || {}, {
input: input.map(file => path.join(path.resolve(root), file)),
output,
input = []
.concat(input && input.length > 0 ? input : config?.input)
.filter(Boolean)
.map(file => path.join(path.resolve(root), file));

if (input.length === 0) {
throw new TypeError('input files not found');
}

return mergeOptions(config ?? {}, {
input,
output: output ?? config?.output,
options,
root,
allInOutput
}, use || {});
}, use ?? {});
};
5 changes: 3 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ const cli = meow(`
root: {
type: 'string',
alias: 'r',
default: '.'
default: './'
},
allInOutput: {
type: 'boolean',
default: false,
alias: 'a'
}
}
Expand Down Expand Up @@ -93,7 +94,7 @@ const processing = async file => {

makeDir(path.dirname(output))
.then(read.bind(undefined, file))
.then(html => Promise.resolve(posthtml(plugins).process(html, config.options)))
.then(html => Promise.resolve(posthtml(plugins).process(html, {...config.options, from: file})))
.then(({html}) => {
fs.writeFile(output, html, error => {
if (error) {
Expand Down
3 changes: 3 additions & 0 deletions test/config/.config-input
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
'input': 'src/**/*.html'
}
3 changes: 3 additions & 0 deletions test/config/.config-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
'output': 'dist/output.html'
}
3 changes: 3 additions & 0 deletions test/config/.config-output-priority
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
'output': 'dist/output.html'
}
7 changes: 2 additions & 5 deletions test/fixtures/by-config/one-io/.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"input": [
"test/fixtures/by-config/two-io/input-1.html",
"test/fixtures/by-config/two-io/input-2.html"
],
"output": "test/expected/by-config/two-io/",
"input": "test/fixtures/by-config/one-io/input.html",
"output": "test/expected/by-config/one-io/output.html",
"plugins": {}
}
7 changes: 5 additions & 2 deletions test/fixtures/by-config/two-io/.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"input": "test/fixtures/by-config/one-io/input.html",
"output": "test/expected/by-config/one-io/output.html",
"input": [
"test/fixtures/by-config/two-io/input-1.html",
"test/fixtures/by-config/two-io/input-2.html"
],
"output": "test/expected/by-config/two-io/",
"plugins": {}
}
95 changes: 80 additions & 15 deletions test/test-cfg-resolve.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,147 @@
import test from 'ava';
import path from 'path';
import cfgResolve from '../lib/cfg-resolve';

test('should return function', t => {
t.true(typeof cfgResolve === 'function');
});

test('should return config with one use key without property', async t => {
test('should throw error `input files not found`', t => {
const error = t.throws(() => {
cfgResolve({});
}, {instanceOf: TypeError});

t.is(error.message, 'input files not found');
});

test('should return simple config', t => {
const input = 'input.html';
const flags = {};
const config = cfgResolve({input, flags});
const expected = {
allInOutput: false,
input: [path.resolve('input.html')],
options: {},
output: undefined,
plugins: {
'posthtml-custom-elements': {}
},
root: './'
};

t.deepEqual(config, expected);
});

test('should return config plugins with one use key without property', t => {
const input = 'input.html';
const flags = {
use: 'posthtml-bem'
};
const config = await cfgResolve({flags});
const config = cfgResolve({input, flags});
const expected = {'posthtml-bem': {}};

t.deepEqual(config.plugins, expected);
});

test('should return config with one use key with one property', async t => {
test('should return config with one use key with one property', t => {
const input = 'input.html';
const flags = {
use: 'posthtml-bem',
posthtmlBem: {
prefix: '__'
}
};
const config = await cfgResolve({flags});
const config = cfgResolve({input, flags});
const expected = {'posthtml-bem': {prefix: '__'}};

t.deepEqual(config.plugins, expected);
});

test('should return config with key config plugins', async t => {
test('should return config with key config plugins', t => {
const input = 'input.html';
const flags = {
config: 'test/config/.config-plugins'
};
const config = await cfgResolve({flags});
const config = cfgResolve({input, flags});
const expected = {'posthtml-bem': {}};

t.deepEqual(config.plugins, expected);
});

test('should return config with key config options', async t => {
test('should return config with key config options', t => {
const input = 'input.html';
const flags = {
config: 'test/config/.config-options'
};
const config = await cfgResolve({flags});
const config = cfgResolve({input, flags});
const expected = {sync: true};

t.deepEqual(config.options, expected);
});

test('should return config options', async t => {
test('should return config options', t => {
const input = 'input.html';
const flags = {
options: {sync: true}
};
const config = await cfgResolve({flags});
const config = cfgResolve({input, flags});
const expected = {sync: true};

t.deepEqual(config.options, expected);
});

test('should return config with key config and use key', async t => {
test('should return config with key config and use key', t => {
const input = 'input.html';
const flags = {
use: 'posthtml-assets',
config: 'test/config/.config-plugins'
};
const config = await cfgResolve({flags});
const config = cfgResolve({input, flags});
const expected = {'posthtml-bem': {}, 'posthtml-assets': {}};

t.deepEqual(config.plugins, expected);
});

test('should return config when CLI params priority', async t => {
test('should return config when input param from config', t => {
const flags = {
config: 'test/config/.config-input'
};
const config = cfgResolve({flags});
const expected = [path.resolve('src/**/*.html')];

t.deepEqual(config.input, expected);
});

test('should return config when output param from config', t => {
const input = 'input.html';
const flags = {
config: 'test/config/.config-output'
};
const config = cfgResolve({input, flags});
const expected = 'dist/output.html';

t.deepEqual(config.output, expected);
});

test('should return config when CLI input param priority', t => {
const input = 'src/template/**/*.html';
const flags = {
config: 'test/config/.config-input-priority'
};
const config = await cfgResolve({input, flags});
const expected = 'src/template/**/*.html';
const config = cfgResolve({input, flags});
const expected = [path.resolve('src/template/**/*.html')];

t.deepEqual(config.input, expected);
});

test('should return config when CLI output param priority', t => {
const input = 'input.html';
const flags = {
output: 'public/output.html',
config: 'test/config/.config-output-priority'
};
const config = cfgResolve({input, flags});
const expected = 'public/output.html';

t.deepEqual(config.output, expected);
});
Loading

0 comments on commit 4616152

Please sign in to comment.