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 | const www = path.resolve(__dirname, '../www');
|
45 | console.log(path.join(dist, './static'));
|
46 | sh(`rm -rf ${www}`);
|
47 | sh(`mv ${path.join(dist, './static')} ${www}`);
|
48 |
|
49 |
|
50 | const tmp = config.theme + '/tmp';
|
51 | if (fs.existsSync(tmp)) sh(`rm -rf ${tmp}`);
|
52 | fs.mkdirSync(tmp);
|
53 |
|
54 | parseNav(config);
|
55 | };
|
56 |
|
57 | exports.build = config => {
|
58 | before(config);
|
59 |
|
60 | walkmd(config, () => {
|
61 | const site = path.resolve(process.cwd(), 'site');
|
62 | sh(`rm -rf ${site}`);
|
63 |
|
64 | const compiler = webpack(parseWPConfig(config, true));
|
65 | compiler.run((err, stats) => {
|
66 |
|
67 | });
|
68 | });
|
69 | }
|
70 |
|
71 | exports.dev = async config => {
|
72 |
|
73 |
|
74 | await walkmd(config);
|
75 |
|
76 | const server = require('./server');
|
77 | const wpConfig = parseWPConfig(config, false);
|
78 | server(config, wpConfig);
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | } |
\ | No newline at end of file |