-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
44 lines (41 loc) · 1.43 KB
/
index.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
const vuepress = require("vuepress");
const path =require("path");
const parseOptions = require("./lib/parseOptions");
const makeFiles = require("./lib/makeFiles");
const genNavAndSidebar = require("./lib/genNavAndSidebar");
const chokidar = require('chokidar');
const _ = require("lodash")
let vuepressOptions={
theme: '@vuepress/default',
cache:false,
"debug":true,
"clearScreen:":false
};
module.exports={
async dev(){
let options = await parseOptions("dev");
let docsDir = await makeFiles(options);
await genNavAndSidebar(docsDir,options);
process.chdir(__dirname);
vuepressOptions.sourceDir=docsDir;
watchFiles(options);
vuepress.dev(vuepressOptions);
},
async build(){
global.isBuild=true;
let options = await parseOptions("build");
let docsDir = await makeFiles(options);
await genNavAndSidebar(docsDir,options);
process.chdir(__dirname);
vuepressOptions.dest=path.join(options.cwd,options.dest);
vuepressOptions.sourceDir=docsDir;
vuepress.build(vuepressOptions);
}
}
function watchFiles(options){
let files = _.concat(options.home, options.components,options.docs);
chokidar.watch(files,{ignoreInitial:true,cwd:options.cwd}).on('all',async (event, path, details)=>{
let docsDir = await makeFiles(options);
await genNavAndSidebar(docsDir,options);
})
}