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 |
|
12 | const node_modules = path.resolve(__dirname, '../node_modules');
|
13 | const wpconfigPath = path.resolve(__dirname, '../webpack.config.js');
|
14 |
|
15 | const parseWPConfig = (config, isProduction) => {
|
16 | let res = wpconfig(isProduction);
|
17 | if (config.setWebpackConfig) {
|
18 | res = config.setWebpackConfig(res);
|
19 | }
|
20 | return res;
|
21 | };
|
22 |
|
23 | const before = (config) => {
|
24 |
|
25 |
|
26 | if (config.theme == 'default' || !config.theme) {
|
27 | config.theme = path.resolve(__dirname, '../theme_default/');
|
28 | } else {
|
29 | config.theme = path.resolve(process.cwd(), config.theme);
|
30 | }
|
31 | };
|
32 |
|
33 | exports.build = config => {
|
34 | before(config);
|
35 |
|
36 | walkmd(config, () => {
|
37 | const site = path.resolve(process.cwd(), 'site');
|
38 | sh(`rm -rf ${site}`);
|
39 |
|
40 | const compiler = webpack(parseWPConfig(config, true));
|
41 | compiler.run((err, stats) => {
|
42 |
|
43 | });
|
44 | });
|
45 | }
|
46 |
|
47 | exports.dev = config => {
|
48 | before(config);
|
49 |
|
50 | walkmd(config, () => {
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | return;
|
61 | const server = require('./server');
|
62 | const wpConfig = parseWPConfig(config, false);
|
63 | server(config, wpConfig);
|
64 |
|
65 | });
|
66 | } |
\ | No newline at end of file |