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 | const babel = require('babel-core');
|
14 |
|
15 | const node_modules = path.resolve(__dirname, '../node_modules');
|
16 | const wpconfigPath = path.resolve(__dirname, '../webpack.config.js');
|
17 |
|
18 |
|
19 | function parseWPConfig(config, isProduction) {
|
20 | let res = wpconfig(isProduction);
|
21 | if (config.setWebpackConfig) {
|
22 | res = config.setWebpackConfig(res);
|
23 | }
|
24 | return res;
|
25 | }
|
26 |
|
27 | function before(config) {
|
28 |
|
29 | let src;
|
30 | let dist = path.resolve(__dirname, '../theme');
|
31 |
|
32 |
|
33 |
|
34 | if (config.theme == 'default' || !config.theme) {
|
35 | src = path.resolve(__dirname, '../lib/theme_default');
|
36 | } else {
|
37 | src = path.resolve(process.cwd(), config.theme);
|
38 | }
|
39 | sh(`rm -rf ${dist}`);
|
40 | sh(`cp -R ${src} ${dist}`);
|
41 | config.theme = dist;
|
42 |
|
43 |
|
44 |
|
45 | const www = path.resolve(__dirname, '../www');
|
46 | console.log(path.join(dist, './static'));
|
47 | sh(`rm -rf ${www}`);
|
48 | sh(`mv ${path.join(dist, './static')} ${www}`);
|
49 |
|
50 |
|
51 | const tmp = config.theme + '/tmp';
|
52 | if (fs.existsSync(tmp)) sh(`rm -rf ${tmp}`);
|
53 | fs.mkdirSync(tmp);
|
54 |
|
55 | parseNav(config);
|
56 | };
|
57 |
|
58 | exports.build = config => {
|
59 | before(config);
|
60 |
|
61 | walkmd(config, () => {
|
62 | const site = path.resolve(process.cwd(), 'site');
|
63 | sh(`rm -rf ${site}`);
|
64 |
|
65 | const compiler = webpack(parseWPConfig(config, true));
|
66 | compiler.run((err, stats) => {
|
67 |
|
68 | });
|
69 | });
|
70 | }
|
71 |
|
72 | exports.dev = async config => {
|
73 | before(config);
|
74 |
|
75 | await walkmd(config);
|
76 |
|
77 | const server = require('./server');
|
78 | const wpConfig = parseWPConfig(config, false);
|
79 | server(config, wpConfig);
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | } |
\ | No newline at end of file |