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