1 |
|
2 |
|
3 |
|
4 |
|
5 | require("babel-core/register");
|
6 | require('babel-polyfill');
|
7 | const wpconfig = require('../webpack.config');
|
8 | const webpack = require('webpack');
|
9 | const walkmd = require('./walkmd');
|
10 | const sh = require('child_process').execSync;
|
11 | const path = require('path');
|
12 | const fs = require('fs');
|
13 | const parseNav = require('./parseNav');
|
14 | const babelFiles = require('./babelFiles');
|
15 |
|
16 | const node_modules = path.resolve(__dirname, '../node_modules');
|
17 | const wpconfigPath = path.resolve(__dirname, '../webpack.config.js');
|
18 |
|
19 |
|
20 | function parseWPConfig(config, isProduction) {
|
21 | let res = wpconfig(isProduction);
|
22 | if (config.setWebpackConfig) {
|
23 | res = config.setWebpackConfig(res);
|
24 | }
|
25 | return res;
|
26 | }
|
27 |
|
28 | async function before(config) {
|
29 |
|
30 | let src;
|
31 | let dist = path.resolve(__dirname, '../theme');
|
32 |
|
33 |
|
34 |
|
35 | if (!config.theme || config.theme == 'default') {
|
36 | src = path.resolve(__dirname, '../theme_default');
|
37 | } else {
|
38 | src = path.resolve(process.cwd(), config.theme);
|
39 | }
|
40 | sh(`rm -rf ${dist}`);
|
41 | sh(`cp -R ${src} ${dist}`);
|
42 | config.theme = dist;
|
43 |
|
44 |
|
45 | await babelFiles(dist, dist);
|
46 |
|
47 |
|
48 | const www = path.resolve(__dirname, '../www');
|
49 |
|
50 | sh(`rm -rf ${www}`);
|
51 | sh(`mv ${path.join(dist, './static')} ${www}`);
|
52 |
|
53 |
|
54 | const tmp = config.theme + '/tmp';
|
55 | if (fs.existsSync(tmp)) sh(`rm -rf ${tmp}`);
|
56 | fs.mkdirSync(tmp);
|
57 |
|
58 | parseNav(config);
|
59 | };
|
60 |
|
61 |
|
62 | exports.dev = async config => {
|
63 | before(config);
|
64 |
|
65 | await walkmd(config);
|
66 |
|
67 | const server = require('./server');
|
68 | const wpConfig = parseWPConfig(config, false);
|
69 | server(config, wpConfig);
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | }
|
87 |
|
88 | exports.build = config => {
|
89 | before(config);
|
90 |
|
91 | walkmd(config, () => {
|
92 | const site = path.resolve(process.cwd(), 'site');
|
93 | sh(`rm -rf ${site}`);
|
94 |
|
95 | const compiler = webpack(parseWPConfig(config, true));
|
96 | compiler.run((err, stats) => {
|
97 |
|
98 | });
|
99 | });
|
100 | }
|