Skip to content

Commit 23df2ce

Browse files
authored
Merge pull request #250 from posthtml/milestone-0.3.0
Milestone 0.3.0
2 parents e016c25 + b93c713 commit 23df2ce

9 files changed

Lines changed: 7523 additions & 6494 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- v8
34
- v7
45
- v6
56
- v5

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
environment:
22
matrix:
3+
- nodejs_version: "8"
34
- nodejs_version: "7"
45
- nodejs_version: "6"
56
- nodejs_version: "5"

cli.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var argv = require('yargs')
1515
.alias('u', 'use')
1616
.array('use')
1717
.pkgConf('posthtml')
18-
.config('c')
18+
.config()
1919
.alias('c', 'config')
2020
.version(function () {
2121
return require('./package.json').version
@@ -37,23 +37,40 @@ var argv = require('yargs')
3737
function processing(file, output) {
3838
// get htmls
3939
var html = fs.readFileSync(file, 'utf8')
40+
var plugins;
4041

41-
// config
42-
var config = {}
42+
console.log(argv);
4343

44-
// create config extends for post-load-plugins
45-
if (argv.use) {
46-
argv.use.forEach(function (plugin) {
47-
config[plugin] = argv[plugin] || {}
48-
})
49-
}
44+
if (argv.autoOff) {
45+
var use = argv.use ? argv.use : [];
46+
var cfg = argv.config ? Object.keys(require(path.resolve(argv.config))) : [];
47+
plugins = [].concat(use, cfg).map((plugin) => {
48+
try {
49+
return require(plugin)(argv[plugin])
50+
} catch (e) {
51+
if (err.code === 'MODULE_NOT_FOUND') {
52+
throw new TypeError('Plugin Error: Cannot find module ' + plugin);
53+
}
54+
}
55+
});
56+
} else {
57+
// config
58+
var config = {}
5059

51-
if (argv.config) {
52-
config = Object.assign(require(path.resolve(argv.config)), config)
60+
// create config extends for post-load-plugins
61+
if (argv.use) {
62+
argv.use.forEach(function (plugin) {
63+
config[plugin] = argv[plugin] || {}
64+
})
65+
}
66+
67+
if (argv.config) {
68+
config = Object.assign(require(path.resolve(argv.config)), config)
69+
}
5370
}
5471

5572
// processing
56-
posthtml(require('post-load-plugins')(config))
73+
posthtml(argv.autoOff ? plugins : require('post-load-plugins')(config))
5774
.process(html)
5875
.then(function (result) {
5976
fs.writeFileSync(output, result.html)

0 commit comments

Comments
 (0)