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