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