-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepply.js
61 lines (49 loc) · 1.42 KB
/
prepply.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
import _ from 'lodash';
import 'minimist';
import path from 'path';
import machinery from './src/machinery.js'
import readConfig from './src/read_config.js';
import minimist from 'minimist';
// Main app for prepply static generator
function usage(){
console.log(`
usage:
$ node prepply.js <options>
where <options> are
--indir <dir> :: input site directory of .md etc.
--outdir <dir> :: output site directory of html
--config <file> :: config yml file to use (default = <indir>/config.yml)
--clean | --noclean :: clean output dir (default = true, clean output dir)
`);
}
function argsValid(args, config){
return _.every(['indir', 'outdir'], p => _.has(args, p) || _.has(config, p));
}
async function run(args){
return await machinery.run(args);
}
const args = minimist(process.argv.slice(2), {
string: ['indir', 'outdir', 'config'],
boolean: ['clean'],
default: {
clean: true,
config: `config.yml`
}
});
const config = readConfig(path.resolve(args.config));
if(!argsValid(args, config)){
usage();
process.exit(1);
}
if(!_.isEmpty(args._)){
args.files = args._.map(f => path.resolve(f));
}
args.clean = args.noclean === true ? false : args.clean;
args.indir = path.resolve(args.indir || config.indir);
args.outdir = path.resolve(args.outdir || config.outdir);
args.config = path.resolve(args.config);
console.log(args);
run(args).then(() => {
console.log('All done.');
});