wirejs-scripts 3.0.188 → 3.0.189
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/bin.js +23 -7
- package/package.json +3 -3
- package/ssg.js +27 -5
package/bin.js
CHANGED
|
@@ -321,6 +321,19 @@ async function compile(watch = false) {
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Resolve output extension for an SSG entrypoint.
|
|
326
|
+
*
|
|
327
|
+
* Conventions:
|
|
328
|
+
* - page.ts => page.html
|
|
329
|
+
* - page.ext.ts => page.ext
|
|
330
|
+
*/
|
|
331
|
+
function getSsgOutputExtension(ssgFile) {
|
|
332
|
+
const withoutTs = ssgFile.replace(/\.ts$/, '');
|
|
333
|
+
const explicitExt = path.extname(withoutTs).replace(/^\./, '');
|
|
334
|
+
return explicitExt || 'html';
|
|
335
|
+
}
|
|
336
|
+
|
|
324
337
|
/**
|
|
325
338
|
* Build SSG files and write the generated HTML to dist/.
|
|
326
339
|
* Also produces browser-compatible IIFE bundles at dist/*.js so that
|
|
@@ -369,20 +382,23 @@ async function compile(watch = false) {
|
|
|
369
382
|
}
|
|
370
383
|
|
|
371
384
|
await Promise.all(ssgFiles.map(async ssgFile => {
|
|
372
|
-
// 3. Run ssg.js on each server-side bundle to produce
|
|
385
|
+
// 3. Run ssg.js on each server-side bundle to produce final output.
|
|
373
386
|
// Pass CWD/pre-dist as SRC_DIR so ssg.js strips the correct prefix
|
|
374
387
|
// when building the hydration <script src="..."> path (e.g. /index.js).
|
|
375
388
|
const compiledSsgFile = path.join(preSsgDir, path.relative(ssgDir, ssgFile)).replace(/\.[^.]+$/, '.js');
|
|
389
|
+
const outputExtension = getSsgOutputExtension(ssgFile);
|
|
376
390
|
try {
|
|
377
|
-
const relative =
|
|
391
|
+
const relative = outputExtension === 'html'
|
|
392
|
+
? path.relative(preSsgDir, compiledSsgFile).replace(/\.js$/, '.html')
|
|
393
|
+
: path.relative(preSsgDir, compiledSsgFile).replace(/\.js$/, '');
|
|
378
394
|
console.log(`Generating ${relative}`);
|
|
379
|
-
const
|
|
380
|
-
`node ${path.join(__dirname, 'ssg.js')} ${preDist} ${compiledSsgFile}`,
|
|
395
|
+
const output = (await execPromise(
|
|
396
|
+
`node ${path.join(__dirname, 'ssg.js')} ${preDist} ${compiledSsgFile} ${outputExtension}`,
|
|
381
397
|
{ stdio: ['pipe', 'pipe', 'pipe'] }
|
|
382
398
|
)).stdout.toString();
|
|
383
|
-
const
|
|
384
|
-
await fs.promises.mkdir(path.dirname(
|
|
385
|
-
await fs.promises.writeFile(
|
|
399
|
+
const outPath = path.join(distDir, relative);
|
|
400
|
+
await fs.promises.mkdir(path.dirname(outPath), { recursive: true });
|
|
401
|
+
await fs.promises.writeFile(outPath, output);
|
|
386
402
|
} catch (err) {
|
|
387
403
|
logger.error(`Could not generate SSG page ${compiledSsgFile}`, err);
|
|
388
404
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-scripts",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.189",
|
|
4
4
|
"description": "Basic build and start commands for wirejs apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"node-cron": "^4.2.1",
|
|
29
29
|
"rimraf": "^6.0.1",
|
|
30
30
|
"wirejs-dom": "^1.0.44",
|
|
31
|
-
"wirejs-hosting": "^0.1.
|
|
32
|
-
"wirejs-resources": "^0.1.
|
|
31
|
+
"wirejs-hosting": "^0.1.191",
|
|
32
|
+
"wirejs-resources": "^0.1.191"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/ssg.js
CHANGED
|
@@ -4,15 +4,37 @@ import { useJSDOM } from 'wirejs-dom/v2';
|
|
|
4
4
|
|
|
5
5
|
const SRC_DIR = process.argv[2];
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function serializeNonHtml(value, outputExtension) {
|
|
8
|
+
if (value === undefined || value === null) {
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
if (Buffer.isBuffer(value)) {
|
|
12
|
+
return value.toString('utf8');
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'string') {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
if (outputExtension === 'json') {
|
|
18
|
+
return `${JSON.stringify(value, null, 2)}\n`;
|
|
19
|
+
}
|
|
20
|
+
return String(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function build(filename, outputExtension = 'html') {
|
|
8
24
|
useJSDOM(JSDOM);
|
|
9
25
|
|
|
10
26
|
try {
|
|
11
27
|
const module = await import(filename);
|
|
12
28
|
|
|
13
29
|
if (typeof module.generate === 'function') {
|
|
14
|
-
const
|
|
15
|
-
|
|
30
|
+
const generated = await module.generate(filename);
|
|
31
|
+
|
|
32
|
+
if (outputExtension !== 'html') {
|
|
33
|
+
return serializeNonHtml(generated, outputExtension);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const doc = generated;
|
|
37
|
+
const doctype = doc?.parentNode?.doctype?.name || '';
|
|
16
38
|
|
|
17
39
|
let hydrationsFound = 0;
|
|
18
40
|
while (globalThis.pendingDehydrations?.length > 0) {
|
|
@@ -31,7 +53,7 @@ async function build(filename) {
|
|
|
31
53
|
doc.outerHTML
|
|
32
54
|
].join('');
|
|
33
55
|
} else {
|
|
34
|
-
return;
|
|
56
|
+
return '';
|
|
35
57
|
}
|
|
36
58
|
} catch (err) {
|
|
37
59
|
console.error(`Could not generate page ${filename}`, err);
|
|
@@ -39,4 +61,4 @@ async function build(filename) {
|
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
|
|
42
|
-
console.log(await build(process.argv[3]));
|
|
64
|
+
console.log(await build(process.argv[3], process.argv[4] || 'html'));
|