wirejs-scripts 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/bin.js +110 -110
- package/configs/webpack.config.js +305 -295
- package/package.json +1 -1
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto
|
package/bin.js
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const process = require('process');
|
|
4
|
-
const rimraf = require('rimraf');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
|
|
8
|
-
const webpack = require('webpack');
|
|
9
|
-
const webpackConfigure = require('./configs/webpack.config');
|
|
10
|
-
const WebpackDevServer = require('webpack-dev-server');
|
|
11
|
-
|
|
12
|
-
const CWD = process.cwd();
|
|
13
|
-
const webpackConfig = webpackConfigure(process.env, process.argv);
|
|
14
|
-
const [_nodeBinPath, _scriptPath, action] = process.argv;
|
|
15
|
-
const processes = [];
|
|
16
|
-
|
|
17
|
-
async function compile(watch = false) {
|
|
18
|
-
const stats = await new Promise((resolve, reject) => {
|
|
19
|
-
if (watch) {
|
|
20
|
-
compiler = webpack({
|
|
21
|
-
...webpackConfig,
|
|
22
|
-
mode: 'development'
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const server = new WebpackDevServer({
|
|
26
|
-
static: {
|
|
27
|
-
directory: path.join(CWD, 'dist')
|
|
28
|
-
},
|
|
29
|
-
open: true,
|
|
30
|
-
}, compiler);
|
|
31
|
-
|
|
32
|
-
console.log('Starting server...');
|
|
33
|
-
server.start().then(() => {
|
|
34
|
-
resolve({});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
resolve({});
|
|
38
|
-
} else {
|
|
39
|
-
console.log('wirejs instantiating webpack compiler');
|
|
40
|
-
compiler = webpack(webpackConfig);
|
|
41
|
-
compiler.run((err, res) => {
|
|
42
|
-
console.log('wirejs invoking webpack compiler');
|
|
43
|
-
if (err) {
|
|
44
|
-
console.error('wirejs webpack compiler failed');
|
|
45
|
-
console.error(err);
|
|
46
|
-
reject(err);
|
|
47
|
-
} else {
|
|
48
|
-
console.error('wirejs webpack compiler succeeded');
|
|
49
|
-
resolve(res);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (stats?.compilation?.errors?.length > 0) {
|
|
56
|
-
console.log('wirejs compilation errors', stats.compilation.errors);
|
|
57
|
-
throw new Error('Build failed.');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return stats;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const engine = {
|
|
64
|
-
async build({ watch = false } = {}) {
|
|
65
|
-
console.log('wirejs build starting');
|
|
66
|
-
|
|
67
|
-
rimraf.sync('dist');
|
|
68
|
-
console.log('wirejs cleared old dist folder');
|
|
69
|
-
|
|
70
|
-
fs.mkdirSync('dist');
|
|
71
|
-
console.log('wirejs recreated dist folder');
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
|
|
75
|
-
await compile(watch);
|
|
76
|
-
console.log('wirejs finished compile');
|
|
77
|
-
} catch (err) {
|
|
78
|
-
console.log(err);
|
|
79
|
-
}
|
|
80
|
-
console.log('wirejs build finished')
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
async start() {
|
|
84
|
-
console.log('wirejs starting')
|
|
85
|
-
this.build({ watch: true });
|
|
86
|
-
|
|
87
|
-
await new Promise(resolve => {
|
|
88
|
-
function exitGracefully() {
|
|
89
|
-
console.log('Exiting gracefully ...');
|
|
90
|
-
processes.forEach(p => p.kill());
|
|
91
|
-
resolve();
|
|
92
|
-
}
|
|
93
|
-
process.on('SIGINT', exitGracefully);
|
|
94
|
-
process.on('SIGTERM', exitGracefully);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// explicit exit forces lingering child processes to die.
|
|
98
|
-
console.log('wirejs stopping')
|
|
99
|
-
process.exit();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
if (typeof engine[action] === 'function') {
|
|
105
|
-
console.log(`Running ${action} ... `);
|
|
106
|
-
engine[action]().then(() => {
|
|
107
|
-
console.log('All done!');
|
|
108
|
-
});
|
|
109
|
-
} else {
|
|
110
|
-
console.error(`Invalid wirejs-scripts action: ${action}`);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const process = require('process');
|
|
4
|
+
const rimraf = require('rimraf');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const webpack = require('webpack');
|
|
9
|
+
const webpackConfigure = require('./configs/webpack.config');
|
|
10
|
+
const WebpackDevServer = require('webpack-dev-server');
|
|
11
|
+
|
|
12
|
+
const CWD = process.cwd();
|
|
13
|
+
const webpackConfig = webpackConfigure(process.env, process.argv);
|
|
14
|
+
const [_nodeBinPath, _scriptPath, action] = process.argv;
|
|
15
|
+
const processes = [];
|
|
16
|
+
|
|
17
|
+
async function compile(watch = false) {
|
|
18
|
+
const stats = await new Promise((resolve, reject) => {
|
|
19
|
+
if (watch) {
|
|
20
|
+
compiler = webpack({
|
|
21
|
+
...webpackConfig,
|
|
22
|
+
mode: 'development'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const server = new WebpackDevServer({
|
|
26
|
+
static: {
|
|
27
|
+
directory: path.join(CWD, 'dist')
|
|
28
|
+
},
|
|
29
|
+
open: true,
|
|
30
|
+
}, compiler);
|
|
31
|
+
|
|
32
|
+
console.log('Starting server...');
|
|
33
|
+
server.start().then(() => {
|
|
34
|
+
resolve({});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
resolve({});
|
|
38
|
+
} else {
|
|
39
|
+
console.log('wirejs instantiating webpack compiler');
|
|
40
|
+
compiler = webpack(webpackConfig);
|
|
41
|
+
compiler.run((err, res) => {
|
|
42
|
+
console.log('wirejs invoking webpack compiler');
|
|
43
|
+
if (err) {
|
|
44
|
+
console.error('wirejs webpack compiler failed');
|
|
45
|
+
console.error(err);
|
|
46
|
+
reject(err);
|
|
47
|
+
} else {
|
|
48
|
+
console.error('wirejs webpack compiler succeeded');
|
|
49
|
+
resolve(res);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (stats?.compilation?.errors?.length > 0) {
|
|
56
|
+
console.log('wirejs compilation errors', stats.compilation.errors);
|
|
57
|
+
throw new Error('Build failed.');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return stats;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const engine = {
|
|
64
|
+
async build({ watch = false } = {}) {
|
|
65
|
+
console.log('wirejs build starting');
|
|
66
|
+
|
|
67
|
+
rimraf.sync('dist');
|
|
68
|
+
console.log('wirejs cleared old dist folder');
|
|
69
|
+
|
|
70
|
+
fs.mkdirSync('dist');
|
|
71
|
+
console.log('wirejs recreated dist folder');
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
|
|
75
|
+
await compile(watch);
|
|
76
|
+
console.log('wirejs finished compile');
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
}
|
|
80
|
+
console.log('wirejs build finished')
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
async start() {
|
|
84
|
+
console.log('wirejs starting')
|
|
85
|
+
this.build({ watch: true });
|
|
86
|
+
|
|
87
|
+
await new Promise(resolve => {
|
|
88
|
+
function exitGracefully() {
|
|
89
|
+
console.log('Exiting gracefully ...');
|
|
90
|
+
processes.forEach(p => p.kill());
|
|
91
|
+
resolve();
|
|
92
|
+
}
|
|
93
|
+
process.on('SIGINT', exitGracefully);
|
|
94
|
+
process.on('SIGTERM', exitGracefully);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// explicit exit forces lingering child processes to die.
|
|
98
|
+
console.log('wirejs stopping')
|
|
99
|
+
process.exit();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
if (typeof engine[action] === 'function') {
|
|
105
|
+
console.log(`Running ${action} ... `);
|
|
106
|
+
engine[action]().then(() => {
|
|
107
|
+
console.log('All done!');
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
console.error(`Invalid wirejs-scripts action: ${action}`);
|
|
111
111
|
}
|
|
@@ -1,295 +1,305 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const glob = require('glob');
|
|
4
|
-
const { exec } = require('child_process');
|
|
5
|
-
const process = require('process');
|
|
6
|
-
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
7
|
-
const marked = require('marked');
|
|
8
|
-
|
|
9
|
-
const CWD = process.cwd();
|
|
10
|
-
|
|
11
|
-
// https://marked.js.org/using_advanced
|
|
12
|
-
marked.setOptions({
|
|
13
|
-
highlight: function (code, lang) {
|
|
14
|
-
try {
|
|
15
|
-
const highlighter = require('highlight.js');
|
|
16
|
-
const language = highlighter.getLanguage(lang) ? lang : 'plaintext';
|
|
17
|
-
return highlighter.highlight(code, { language }).value;
|
|
18
|
-
} catch (e) {
|
|
19
|
-
console.log("highlight.js not installed. Skipping syntax highlighting.");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const BUILD_ID = (new Date()).getTime();
|
|
25
|
-
|
|
26
|
-
fs.writeFileSync('./src/build_id.json', JSON.stringify(BUILD_ID.toString()));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// TODO: Refactor these transforms out of here.
|
|
30
|
-
// TODO: Create a separate package to manage all of this for easy reuse on
|
|
31
|
-
// other projects.
|
|
32
|
-
// TODO: consider whether using the front-end framework for SSG would be safe,
|
|
33
|
-
// and intuitive, rather than having two completely separate rendering modes.
|
|
34
|
-
|
|
35
|
-
function distPath({ subpathOut = '', subpathIn = '' } = {}) {
|
|
36
|
-
return function ({ context, absoluteFilename }) {
|
|
37
|
-
const prefixIn = path.resolve(context, subpathIn);
|
|
38
|
-
const prefixOut = path.resolve(context, 'dist', subpathOut);
|
|
39
|
-
const relativeName = path.join('./', absoluteFilename.slice(prefixIn.toString().length));
|
|
40
|
-
const fullOutPath = path.resolve(prefixOut, relativeName)
|
|
41
|
-
.replace(/\.md$/, ".html");
|
|
42
|
-
console.log(`Mapping ${relativeName} to ${fullOutPath}`);
|
|
43
|
-
return fullOutPath;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const layouts = {};
|
|
48
|
-
const CollectLayouts = {
|
|
49
|
-
transformer: (content, path) => {
|
|
50
|
-
// add one to dirname prefix to include separating slash
|
|
51
|
-
const relativePath = path.slice(CWD.length + 1);
|
|
52
|
-
layouts[relativePath] = content.toString();
|
|
53
|
-
return layouts[relativePath];
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const SSG = {
|
|
58
|
-
transformer: async (content, _path) => {
|
|
59
|
-
let _meta = {};
|
|
60
|
-
function meta(o) {
|
|
61
|
-
_meta = o;
|
|
62
|
-
return '';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
noErrorOnMissing: true,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const glob = require('glob');
|
|
4
|
+
const { exec } = require('child_process');
|
|
5
|
+
const process = require('process');
|
|
6
|
+
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
7
|
+
const marked = require('marked');
|
|
8
|
+
|
|
9
|
+
const CWD = process.cwd();
|
|
10
|
+
|
|
11
|
+
// https://marked.js.org/using_advanced
|
|
12
|
+
marked.setOptions({
|
|
13
|
+
highlight: function (code, lang) {
|
|
14
|
+
try {
|
|
15
|
+
const highlighter = require('highlight.js');
|
|
16
|
+
const language = highlighter.getLanguage(lang) ? lang : 'plaintext';
|
|
17
|
+
return highlighter.highlight(code, { language }).value;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.log("highlight.js not installed. Skipping syntax highlighting.");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const BUILD_ID = (new Date()).getTime();
|
|
25
|
+
|
|
26
|
+
fs.writeFileSync('./src/build_id.json', JSON.stringify(BUILD_ID.toString()));
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// TODO: Refactor these transforms out of here.
|
|
30
|
+
// TODO: Create a separate package to manage all of this for easy reuse on
|
|
31
|
+
// other projects.
|
|
32
|
+
// TODO: consider whether using the front-end framework for SSG would be safe,
|
|
33
|
+
// and intuitive, rather than having two completely separate rendering modes.
|
|
34
|
+
|
|
35
|
+
function distPath({ subpathOut = '', subpathIn = '' } = {}) {
|
|
36
|
+
return function ({ context, absoluteFilename }) {
|
|
37
|
+
const prefixIn = path.resolve(context, subpathIn);
|
|
38
|
+
const prefixOut = path.resolve(context, 'dist', subpathOut);
|
|
39
|
+
const relativeName = path.join('./', absoluteFilename.slice(prefixIn.toString().length));
|
|
40
|
+
const fullOutPath = path.resolve(prefixOut, relativeName)
|
|
41
|
+
.replace(/\.md$/, ".html");
|
|
42
|
+
console.log(`Mapping ${relativeName} to ${fullOutPath}`);
|
|
43
|
+
return fullOutPath;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const layouts = {};
|
|
48
|
+
const CollectLayouts = {
|
|
49
|
+
transformer: (content, path) => {
|
|
50
|
+
// add one to dirname prefix to include separating slash
|
|
51
|
+
const relativePath = path.slice(CWD.length + 1);
|
|
52
|
+
layouts[relativePath] = content.toString();
|
|
53
|
+
return layouts[relativePath];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const SSG = {
|
|
58
|
+
transformer: async (content, _path) => {
|
|
59
|
+
let _meta = {};
|
|
60
|
+
function meta(o) {
|
|
61
|
+
_meta = o;
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const _require = require;
|
|
66
|
+
const WD = path.dirname(_path);
|
|
67
|
+
|
|
68
|
+
let body;
|
|
69
|
+
try {
|
|
70
|
+
require = (requirePath) => {
|
|
71
|
+
const absolutePath = _require.resolve(requirePath, {paths: [WD]});
|
|
72
|
+
return _require(absolutePath);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (_path.endsWith('.md')) {
|
|
76
|
+
let isInCodeBlock = false;
|
|
77
|
+
const escapedMarkdown = content.toString().split(/\n/)
|
|
78
|
+
.reduce((lines, line) => {
|
|
79
|
+
if (isInCodeBlock) {
|
|
80
|
+
lines[lines.length - 1] += "\n" + line;
|
|
81
|
+
} else {
|
|
82
|
+
lines.push(line);
|
|
83
|
+
}
|
|
84
|
+
if (line.startsWith('```')) {
|
|
85
|
+
isInCodeBlock = !isInCodeBlock;
|
|
86
|
+
}
|
|
87
|
+
return lines;
|
|
88
|
+
}, [])
|
|
89
|
+
.map(l => l.trim()).join('\n')
|
|
90
|
+
.replace(/(``+)/g, m => Array(m.length).fill('\\`').join(''))
|
|
91
|
+
;
|
|
92
|
+
const bodyMarkdown = eval('`' + escapedMarkdown + '`');
|
|
93
|
+
body = marked(bodyMarkdown);
|
|
94
|
+
} else {
|
|
95
|
+
body = eval('`' + content + '`');
|
|
96
|
+
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
console.error(`Could not parse page ${_path}`, err);
|
|
99
|
+
throw err;
|
|
100
|
+
} finally {
|
|
101
|
+
require = _require;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const metatags = Object.entries(_meta).map(([tag, content]) => {
|
|
105
|
+
tag = tag.replace(/"/g, '"');
|
|
106
|
+
content = content.replace(/"/g, '"');
|
|
107
|
+
return `<meta name="${tag}" content="${content}" />`;
|
|
108
|
+
}).join('\n');
|
|
109
|
+
|
|
110
|
+
let title = _meta.title;
|
|
111
|
+
|
|
112
|
+
// apply no layout if the document has already provided the
|
|
113
|
+
// overarching html structure.
|
|
114
|
+
if (!_meta.layout && body && (
|
|
115
|
+
String(body).startsWith('<!doctype html>')
|
|
116
|
+
|| String(body).startsWith('<html'))
|
|
117
|
+
) {
|
|
118
|
+
return body;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const layoutPath = path.join(
|
|
122
|
+
'src',
|
|
123
|
+
'layouts',
|
|
124
|
+
(_meta.layout || 'default')
|
|
125
|
+
) + '.html';
|
|
126
|
+
|
|
127
|
+
const layout = layouts[layoutPath];
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
return eval('`' + layout + '`');
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.error(`Could not parse layout ${layoutPath}`, err);
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
module.exports = (env, argv) => {
|
|
139
|
+
var devtool = 'source-map';
|
|
140
|
+
if (argv.mode == 'development') {
|
|
141
|
+
devtool = 'eval-cheap-source-map';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const sources = ['./src/index.js']
|
|
145
|
+
.concat(glob.sync('./src/layouts/**/*.js'))
|
|
146
|
+
.concat(glob.sync('./src/routes/**/*.js'))
|
|
147
|
+
;
|
|
148
|
+
|
|
149
|
+
const entry = sources.reduce((files, path) => {
|
|
150
|
+
if (path.match(/src\/routes/)) {
|
|
151
|
+
files[path.toString().slice('./src/routes'.length)] = path;
|
|
152
|
+
} else if (path.match(/src\/layouts/)) {
|
|
153
|
+
files[path.toString().slice('./src/'.length)] = path;
|
|
154
|
+
}
|
|
155
|
+
return files;
|
|
156
|
+
}, {});
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
/*
|
|
160
|
+
devServer: {
|
|
161
|
+
contentBase: path.join(CWD, 'dist'),
|
|
162
|
+
compress: true,
|
|
163
|
+
open: true,
|
|
164
|
+
port: 9999,
|
|
165
|
+
watchContentBase: true,
|
|
166
|
+
// liveReload: true,
|
|
167
|
+
// hot: true
|
|
168
|
+
},
|
|
169
|
+
*/
|
|
170
|
+
watchOptions: {
|
|
171
|
+
ignored: [
|
|
172
|
+
"**/dist/*",
|
|
173
|
+
"**/node_modules/*"
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
node: {
|
|
177
|
+
__filename: true
|
|
178
|
+
},
|
|
179
|
+
entry,
|
|
180
|
+
output: {
|
|
181
|
+
filename: "[name]"
|
|
182
|
+
},
|
|
183
|
+
devtool,
|
|
184
|
+
plugins: [
|
|
185
|
+
|
|
186
|
+
// TODO: does it make sense to actually handle static assets
|
|
187
|
+
// first? then layouts? then everything else?
|
|
188
|
+
|
|
189
|
+
// handle layouts first. other things depend on them.
|
|
190
|
+
new CopyWebpackPlugin({
|
|
191
|
+
patterns: [
|
|
192
|
+
{
|
|
193
|
+
from: './src/layouts/**/*.html',
|
|
194
|
+
to: distPath({
|
|
195
|
+
subpathIn: 'src/layouts',
|
|
196
|
+
subpathOut: 'layouts'
|
|
197
|
+
}),
|
|
198
|
+
transform: CollectLayouts,
|
|
199
|
+
noErrorOnMissing: true,
|
|
200
|
+
},
|
|
201
|
+
]
|
|
202
|
+
}),
|
|
203
|
+
|
|
204
|
+
// now pages, etc.
|
|
205
|
+
new CopyWebpackPlugin({
|
|
206
|
+
patterns: [
|
|
207
|
+
{
|
|
208
|
+
from: 'static',
|
|
209
|
+
noErrorOnMissing: true,
|
|
210
|
+
priority: 10,
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
from: './src/routes/**/*.md',
|
|
214
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
215
|
+
transform: SSG,
|
|
216
|
+
noErrorOnMissing: true,
|
|
217
|
+
priority: 3,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
from: './src/routes/**/*.html',
|
|
221
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
222
|
+
transform: SSG,
|
|
223
|
+
noErrorOnMissing: true,
|
|
224
|
+
priority: 3,
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
from: './src/routes/**/*.css',
|
|
228
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
229
|
+
noErrorOnMissing: true,
|
|
230
|
+
// trasform: ???
|
|
231
|
+
priority: 3,
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
from: './src/routes/**/*.png',
|
|
235
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
236
|
+
noErrorOnMissing: true,
|
|
237
|
+
priority: 3,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
from: './src/routes/**/*.jpg',
|
|
241
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
242
|
+
noErrorOnMissing: true,
|
|
243
|
+
priority: 3,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
from: './src/routes/**/*.json',
|
|
247
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
248
|
+
noErrorOnMissing: true,
|
|
249
|
+
priority: 3,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
from: './src/routes/**/*.svg',
|
|
253
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
254
|
+
noErrorOnMissing: true,
|
|
255
|
+
priority: 3,
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
from: './src/routes/**/*.mp3',
|
|
259
|
+
to: distPath({ subpathIn: 'src/routes' }),
|
|
260
|
+
noErrorOnMissing: true,
|
|
261
|
+
priority: 3,
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
})
|
|
265
|
+
],
|
|
266
|
+
module: {
|
|
267
|
+
rules: [
|
|
268
|
+
{
|
|
269
|
+
test: /\.css$/,
|
|
270
|
+
use: [
|
|
271
|
+
"style-loader",
|
|
272
|
+
// path.resolve(__dirname, '../node_modules/style-loader'),
|
|
273
|
+
{
|
|
274
|
+
loader: "css-loader",
|
|
275
|
+
// loader: path.resolve(__dirname, '../node_modules/css-loader'),
|
|
276
|
+
options: {
|
|
277
|
+
// don't try to require() url assets
|
|
278
|
+
url: false
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
]
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
test: /\.html$/,
|
|
285
|
+
loader: "file-loader",
|
|
286
|
+
// loader: path.resolve(__dirname, '../node_modules/file-loader'),
|
|
287
|
+
options: {
|
|
288
|
+
name: "[name].[ext]",
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
test: /\.mjs$/,
|
|
293
|
+
resolve: {
|
|
294
|
+
fullySpecified: false
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
test: /\.(md|tpl)$/,
|
|
299
|
+
use: "raw-loader",
|
|
300
|
+
// use: path.resolve(__dirname, '../node_modules/raw-loader')
|
|
301
|
+
},
|
|
302
|
+
]
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
};
|