Skip to content

Commit 25c6bb0

Browse files
committed
fix: config file without extension, close #255
1 parent 44e1f7c commit 25c6bb0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cli.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ var argv = require('yargs')
1515
.alias('u', 'use')
1616
.array('use')
1717
.pkgConf('posthtml')
18-
.config()
18+
.config('config', function (config) {
19+
return JSON.parse(fs.readFileSync(config, 'utf-8'))
20+
})
1921
.alias('c', 'config')
2022
.version()
2123
.alias('v', 'version')
@@ -36,10 +38,11 @@ function processing(file, output) {
3638
// get htmls
3739
var html = fs.readFileSync(file, 'utf8')
3840
var plugins;
41+
var fileConfig = argv.config && JSON.parse(fs.readFileSync(argv.config, 'utf-8'));
3942

4043
if (argv.autoOff) {
4144
var use = argv.use ? argv.use : [];
42-
var cfg = argv.config ? Object.keys(require(path.resolve(argv.config))) : [];
45+
var cfg = argv.config ? Object.keys(fileConfig) : [];
4346
plugins = [].concat(use, cfg).map((plugin) => {
4447
try {
4548
return require(plugin)(argv[plugin])
@@ -61,7 +64,7 @@ function processing(file, output) {
6164
}
6265

6366
if (argv.config) {
64-
config = Object.assign(require(path.resolve(argv.config)), config)
67+
config = Object.assign(fileConfig, config)
6568
}
6669
}
6770

0 commit comments

Comments
 (0)