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 | if (config.nav && config.nav.length) parseNav(config);
|
42 | };
|
43 |
|
44 | exports.build = config => {
|
45 | before(config);
|
46 |
|
47 | walkmd(config, () => {
|
48 | const site = path.resolve(process.cwd(), 'site');
|
49 | sh(`rm -rf ${site}`);
|
50 |
|
51 | const compiler = webpack(parseWPConfig(config, true));
|
52 | compiler.run((err, stats) => {
|
53 |
|
54 | });
|
55 | });
|
56 | }
|
57 |
|
58 | exports.dev = config => {
|
59 | before(config);
|
60 |
|
61 | walkmd(config, () => {
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | const server = require('./server');
|
72 | const wpConfig = parseWPConfig(config, false);
|
73 | server(config, wpConfig);
|
74 |
|
75 | });
|
76 | } |
\ | No newline at end of file |