diff --git a/CHANGELOG.md b/CHANGELOG.md
index 75092fb..12d939c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,20 @@
+## [0.2.0] - 05-05-2016
+### Added
+- Added #72, options --use
+
+### Change
+- Update #73, devDep
+- Update config posthtml in package.json for test
+- Update #75, readme
+- Update tests for options --use
+
+### Fixed
+- Fixed linter report error
+- Fixed #79, test for windows
+
+## Removed
+- Remove temp-write now used tempfile
+
## [0.1.2] - 28-04-2016
### Added
- Added #68, node 6 to config travis
diff --git a/README.md b/README.md
index 002f1a8..2a24ac7 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ npm install --global posthtml-cli
$ posthtml --help
Usage
- posthtml --output|-o output.html --input|-i input.html [--config|-c path/to/json/config]
+ posthtml [-o output-file/directory|-r] [-i input-file/directory] [--config|-c path/to/file/config] [--use|-u plugin]
Options
--config, -c Path to JSON file [string]
@@ -62,7 +62,8 @@ $ posthtml --help
### ```[name].[ext]```
-#### JS
+#### ```JS```
+
```js
module.exports = {
bem: {
@@ -79,6 +80,7 @@ module.exports = {
}
}
```
+
#### ```JSON```
```json
@@ -100,12 +102,12 @@ module.exports = {
## Examples
-### Example sample
+### Sample
```console
$ posthtml -o output.html -i input.html
```
-### Example options config
+### Options config
```console
$ posthtml -o output.html -i input.html -c posthtml.json
```
@@ -114,7 +116,19 @@ $ posthtml -o output.html -i input.html -c posthtml.json
$ posthtml -o output.html -i input.html -c posthtml.js
```
-### Example read dir
+### Options use
+```console
+$ posthtml
+ -o output.html
+ -i input.html
+ -c config.json
+ -u posthtml-bem
+ --posthtml-bem.elemPrefix __
+ --posthtml-bem.elemMod _
+ -u posthtml-custom-elements
+```
+
+### Read dir
```console
$ posthtml -o outputFolder/ -i inputFolder/*.html
```
@@ -123,6 +137,15 @@ $ posthtml -o outputFolder/ -i inputFolder/*.html
$ posthtml -o outputFolder/ -i inputFolder/**/*.html
```
+### Replace
+```console
+$ posthtml -i input.html -r
+```
+
+```console
+$ posthtml -i inputFolder/*.html -r
+```
+
## License
MIT
diff --git a/cli.js b/cli.js
index 6c66342..ee419b5 100755
--- a/cli.js
+++ b/cli.js
@@ -1,18 +1,20 @@
#!/usr/bin/env node
-var posthtml = require('posthtml');
-var globby = require('globby');
var path = require('path');
-const pathExists = require('path-exists');
var fs = require('fs');
+var posthtml = require('posthtml');
+var globby = require('globby');
+var pathExists = require('path-exists');
var argv = require('yargs')
- .usage('Usage: $0 --output|-o output.html/outputFolder --input|-i input.html/inputFolder [--config|-c config.(js|json)] [--replace|-r]')
+ .usage('Usage: $0 [-o output-file/directory|-r] [-i input-file/directory] [--config|-c path/to/file/config]')
.example('posthtml -o output.html -i input.html', 'Default example')
.alias('i', 'input')
+ .array('input')
+ .demand(['i'])
.alias('o', 'output')
.alias('r', 'replace')
- .demand(['i'])
- .array('input')
+ .alias('u', 'use')
+ .array('use')
.pkgConf('posthtml')
.config('c')
.alias('c', 'config')
@@ -36,9 +38,17 @@ var argv = require('yargs')
function processing(file, output) {
// get htmls
var html = fs.readFileSync(file, 'utf8');
+ var ext = {};
+
+ // create config extends for posthtml-load-plugins
+ if (argv.use) {
+ argv.use.forEach(function (plugin) {
+ ext[plugin] = argv[plugin] || {};
+ });
+ }
// processing
- posthtml(require('posthtml-load-plugins')(argv.config))
+ posthtml(require('posthtml-load-plugins')(argv.config, ext))
.process(html)
.then(function (result) {
fs.writeFileSync(output, result.html);
@@ -73,6 +83,7 @@ globby(argv.input).then(function (files) {
if (argv.output !== undefined) {
createFolder(argv.output);
}
+
files.forEach(function (file) {
var output = isFile(argv.output) ? argv.output : getOutput(file);
processing(file, output);
diff --git a/package.json b/package.json
index c70ded6..8aba9c6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "posthtml-cli",
- "version": "0.1.2",
+ "version": "0.2.0",
"description": "CLI for posthtml",
"bin": {
"posthtml": "./cli.js"
@@ -30,8 +30,8 @@
"homepage": "https://github.com/GitScrum/posthtml-cli#readme",
"dependencies": {
"globby": "^4.0.0",
- "posthtml": "^0.8.6",
- "posthtml-load-plugins": "^0.9.5",
+ "posthtml": "^0.8.7",
+ "posthtml-load-plugins": "^0.10.0",
"yargs": "^4.6.0"
},
"devDependencies": {
@@ -41,15 +41,15 @@
"cpy": "^4.0.0",
"execa": "^0.4.0",
"nyc": "^6.4.1",
- "path-exists": "^2.1.0",
+ "path-exists": "^3.0.0",
+ "posthtml-bem": "^0.2.2",
"posthtml-custom-elements": "^1.0.3",
"read-pkg": "^1.1.0",
- "temp-write": "^2.1.0",
"tempfile": "^1.1.1",
"updtr": "^0.1.10",
- "xo": "^0.13.0"
+ "xo": "^0.15.0"
},
"posthtml": {
- "posthtmlCustomElements": {}
+ "customElements": {}
}
}
diff --git a/test/expected/output-bem.html b/test/expected/output-bem.html
new file mode 100644
index 0000000..b6fdd6e
--- /dev/null
+++ b/test/expected/output-bem.html
@@ -0,0 +1,4 @@
+
+
Super Title
+
Awesome Text
+
diff --git a/test/fixtures/config-for-bem.json b/test/fixtures/config-for-bem.json
new file mode 100644
index 0000000..2a627ec
--- /dev/null
+++ b/test/fixtures/config-for-bem.json
@@ -0,0 +1,10 @@
+{
+ "bem": {
+ "elemPrefix": "__",
+ "modPrefix": "-",
+ "modDlmtr": "--"
+ },
+ "customElements": {
+ "defaultTag": "span"
+ }
+}
diff --git a/test/fixtures/input-bem.html b/test/fixtures/input-bem.html
new file mode 100644
index 0000000..d00be0d
--- /dev/null
+++ b/test/fixtures/input-bem.html
@@ -0,0 +1,4 @@
+
+ Super Title
+ Awesome Text
+
diff --git a/test/test-cli.js b/test/test-cli.js
index 0b0abfb..fb335fc 100644
--- a/test/test-cli.js
+++ b/test/test-cli.js
@@ -1,16 +1,16 @@
+const path = require('path');
+const fs = require('fs');
const test = require('ava');
const execa = require('execa');
-const tempWrite = require('temp-write');
const pathExists = require('path-exists');
-const path = require('path');
const readPkg = require('read-pkg');
const copy = require('cpy');
-const readFile = require('fs').readFile;
const tempfile = require('tempfile');
+const cli = path.resolve('../cli.js');
function read(pathFile) {
return new Promise((resolve, reject) => {
- readFile(pathFile, 'utf8', (err, data) => {
+ fs.readFile(pathFile, 'utf8', (err, data) => {
if (err) {
reject(err);
}
@@ -20,47 +20,47 @@ function read(pathFile) {
}
test('Missing required arguments -i, -o', t => {
- t.throws(execa('../cli.js', []));
+ t.throws(execa(cli, []));
});
test('Missing required arguments -o', t => {
- t.throws(execa('../cli.js', ['-i', 'fixtures/input.html']));
+ t.throws(execa(cli, ['-i', 'fixtures/input.html']));
});
test('Missing required arguments -i', t => {
- const filename = tempWrite.sync('output.html');
- t.throws(execa('../cli.js', [`-o ${filename}`]));
+ const filename = tempfile('.html');
+ t.throws(execa(cli, ['-o', filename]));
});
test('One of the arguments', t => {
- const filename = tempWrite.sync('output.html');
- t.throws(execa('../cli.js', ['-o', filename, '-r', '-i', 'fixtures/input.html']));
+ const filename = tempfile('.html');
+ t.throws(execa(cli, ['-o', filename, '-r', '-i', 'fixtures/input.html']));
});
test('Check version', async t => {
- t.is((await execa('../cli.js', ['-v'])).stdout, (await readPkg(path.dirname(__dirname))).version);
+ t.is((await execa(cli, ['-v'])).stdout, (await readPkg(path.dirname(__dirname))).version);
});
test('Transform html witch config in package.json', async t => {
t.plan(2);
- const filename = await tempWrite('output.html', 'output.html');
- await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename]);
+ const filename = tempfile('.html');
+ await execa(cli, ['-i', 'fixtures/input.html', '-o', filename]);
t.true(await pathExists(filename));
t.is((await read('expected/output-config-pkg.html')), (await read(filename)));
});
test('Transform html witch indent', async t => {
t.plan(2);
- const filename = await tempWrite('output.html', 'output.html');
- await execa('../cli.js', ['-i', 'fixtures/input-indent.html', '-o', filename]);
+ const filename = tempfile('.html');
+ await execa(cli, ['-i', 'fixtures/input-indent.html', '-o', filename]);
t.true(await pathExists(filename));
t.is((await read('expected/output-indent.html')), (await read(filename)));
});
test('Transform html witch config in file', async t => {
t.plan(2);
- const filename = await tempWrite('output.html', 'output.html');
- await execa('../cli.js', ['-i', 'fixtures/input.html', '-o', filename, '-c', 'fixtures/config.json']);
+ const filename = tempfile('.html');
+ await execa(cli, ['-i', 'fixtures/input.html', '-o', filename, '-c', 'fixtures/config.json']);
t.true(await pathExists(filename));
t.is((await read('expected/output-config-file.html')), (await read(filename)));
});
@@ -68,7 +68,7 @@ test('Transform html witch config in file', async t => {
test('Transform html from folder', async t => {
t.plan(2);
const folder = await tempfile();
- await execa('../cli.js', ['-i', 'fixtures/*.html', '-o', `${folder}/`]);
+ await execa(cli, ['-i', 'fixtures/*.html', '-o', `${folder}/`]);
t.is((await read('expected/output-config-pkg.html')), (await read(`${folder}/input.html`)));
t.is((await read('expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
});
@@ -77,7 +77,30 @@ test('Transform html witch options replace', async t => {
t.plan(2);
const folder = await tempfile();
await copy(['fixtures/*.html'], `${folder}/`);
- await execa('../cli.js', ['-i', `${folder}/*.html`, '-r']);
+ await execa(cli, ['-i', `${folder}/*.html`, '-r']);
t.is((await read('expected/output-config-pkg.html')), (await read(`${folder}/input.html`)));
t.is((await read('expected/output-indent.html')), (await read(`${folder}/input-indent.html`)));
});
+
+test('Transform html witch config in file and stdin options use', async t => {
+ t.plan(2);
+ const filename = tempfile('.html');
+ await execa(cli, [
+ '-o',
+ filename,
+ '-i',
+ 'fixtures/input-bem.html',
+ '-c',
+ 'fixtures/config.json',
+ '-u',
+ 'posthtml-bem',
+ '--posthtml-bem.elemPrefix',
+ '__',
+ '--posthtml-bem.elemMod',
+ '_',
+ '-u',
+ 'posthtml-custom-elements'
+ ]);
+ t.true(await pathExists(filename));
+ t.is((await read('expected/output-bem.html')), (await read(filename)));
+});