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