appstage 0.2.5 → 0.2.6
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/dist/bin.js +178 -41
- package/dist/index.cjs +32 -32
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +32 -32
- package/package.json +3 -2
- package/src/scripts/bin.ts +9 -5
- package/src/scripts/build.ts +1 -1
- package/src/scripts/cli.ts +18 -24
- package/src/scripts/types/BuildParams.ts +2 -2
- package/src/scripts/utils/buildClient.ts +2 -2
- package/src/scripts/utils/buildServer.ts +2 -2
- package/src/scripts/utils/buildServerCSS.ts +2 -2
- package/src/scripts/utils/createPostbuildPlugins.ts +5 -5
package/dist/bin.js
CHANGED
|
@@ -25,8 +25,146 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
|
|
28
|
-
// node_modules/
|
|
28
|
+
// node_modules/args-json/dist/index.cjs
|
|
29
29
|
var require_dist = __commonJS({
|
|
30
|
+
"node_modules/args-json/dist/index.cjs"(exports) {
|
|
31
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
32
|
+
function isKey2(x) {
|
|
33
|
+
return x.startsWith("-") && x.length === 2 && x !== "--" || x.startsWith("--") && x.length > 2;
|
|
34
|
+
}
|
|
35
|
+
var Args2 = class {
|
|
36
|
+
_values;
|
|
37
|
+
constructor(values) {
|
|
38
|
+
this._values = values ?? process.argv.slice(2);
|
|
39
|
+
}
|
|
40
|
+
hasKey(x) {
|
|
41
|
+
return isKey2(x) && this._values.includes(x);
|
|
42
|
+
}
|
|
43
|
+
getValue(key, fallback) {
|
|
44
|
+
let args = this._values;
|
|
45
|
+
let keys = Array.isArray(key) ? key : [key];
|
|
46
|
+
for (let k of keys) {
|
|
47
|
+
let i = args.indexOf(k);
|
|
48
|
+
if (i !== -1 && args[i + 1] && !isKey2(args[i + 1])) return args[i + 1];
|
|
49
|
+
}
|
|
50
|
+
return fallback;
|
|
51
|
+
}
|
|
52
|
+
getValues(key, fallback) {
|
|
53
|
+
let args = this._values;
|
|
54
|
+
let keys = Array.isArray(key) ? key : [key];
|
|
55
|
+
let values = [];
|
|
56
|
+
for (let k of keys) {
|
|
57
|
+
let i = args.indexOf(k);
|
|
58
|
+
while (i !== -1 && args[i + 1] && !isKey2(args[i + 1])) values.push(args[++i]);
|
|
59
|
+
}
|
|
60
|
+
return values.length === 0 ? fallback : values;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
function getValue(key, fallback) {
|
|
64
|
+
let args = new Args2();
|
|
65
|
+
if (fallback === void 0) return args.getValue(key);
|
|
66
|
+
return args.getValue(key, fallback);
|
|
67
|
+
}
|
|
68
|
+
function getValues(key, fallback) {
|
|
69
|
+
let args = new Args2();
|
|
70
|
+
if (fallback === void 0) return args.getValues(key);
|
|
71
|
+
return args.getValues(key, fallback);
|
|
72
|
+
}
|
|
73
|
+
function hasKey2(x) {
|
|
74
|
+
return new Args2().hasKey(x);
|
|
75
|
+
}
|
|
76
|
+
function split(x) {
|
|
77
|
+
let words = [], word = "";
|
|
78
|
+
let hasOpenSingleQuote = false;
|
|
79
|
+
let hasOpenDoubleQuote = false;
|
|
80
|
+
for (let i = 0; i < x.length; i++) {
|
|
81
|
+
let c = x[i];
|
|
82
|
+
if (/^\s/.test(c) && !hasOpenSingleQuote && !hasOpenDoubleQuote) {
|
|
83
|
+
if (word) words.push(word);
|
|
84
|
+
word = "";
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (c === "'" && x[i - 1] !== "\\") hasOpenSingleQuote = !hasOpenSingleQuote;
|
|
88
|
+
if (c === '"' && x[i - 1] !== "\\") hasOpenDoubleQuote = !hasOpenDoubleQuote;
|
|
89
|
+
word += c;
|
|
90
|
+
}
|
|
91
|
+
if (word) words.push(word);
|
|
92
|
+
return words;
|
|
93
|
+
}
|
|
94
|
+
function toCamelCase(x) {
|
|
95
|
+
let s = x.replace(/^[-_.\s~+]|[-_.\s~+]$/g, "");
|
|
96
|
+
if (!/[-_.\s~+]/.test(s)) return s.slice(0, 1).toLowerCase() + s.slice(1);
|
|
97
|
+
return s.toLowerCase().replace(/[-_.\s~+](\S)/g, (_, match) => match.toUpperCase());
|
|
98
|
+
}
|
|
99
|
+
function toKey(x) {
|
|
100
|
+
if (x === void 0 || !isKey2(x)) return;
|
|
101
|
+
if (x.startsWith("-") && x.length === 2) return toCamelCase(x.slice(1));
|
|
102
|
+
if (x.startsWith("--") && x.length > 2) return toCamelCase(x.slice(2));
|
|
103
|
+
}
|
|
104
|
+
function getDefaultInput() {
|
|
105
|
+
return typeof process === "undefined" ? [] : process.argv;
|
|
106
|
+
}
|
|
107
|
+
function parseArgs(input, map) {
|
|
108
|
+
let normalizedInput;
|
|
109
|
+
let normalizedMap;
|
|
110
|
+
if (input === void 0) normalizedInput = getDefaultInput();
|
|
111
|
+
else if (typeof input === "string") normalizedInput = split(input);
|
|
112
|
+
else if (Array.isArray(input)) normalizedInput = input.map((x) => String(x));
|
|
113
|
+
else if (input !== null && typeof input === "object") {
|
|
114
|
+
normalizedInput = getDefaultInput();
|
|
115
|
+
normalizedMap = input;
|
|
116
|
+
} else normalizedInput = [];
|
|
117
|
+
normalizedInput = normalizedInput.flatMap((item) => {
|
|
118
|
+
let normalizedItem = item.trim();
|
|
119
|
+
let k = normalizedItem.indexOf("=");
|
|
120
|
+
if (k === -1) return normalizedItem;
|
|
121
|
+
let key2 = normalizedItem.slice(0, k);
|
|
122
|
+
let value = normalizedItem.slice(k + 1);
|
|
123
|
+
if (!isKey2(key2)) return normalizedItem;
|
|
124
|
+
return [key2, value];
|
|
125
|
+
});
|
|
126
|
+
if (map) normalizedMap = map;
|
|
127
|
+
let key = "";
|
|
128
|
+
let parsedArgs = {};
|
|
129
|
+
for (let rawValue of normalizedInput) {
|
|
130
|
+
rawValue = rawValue.trim();
|
|
131
|
+
if (rawValue.startsWith('"') && rawValue.endsWith('"')) rawValue = rawValue.slice(1, -1);
|
|
132
|
+
else if (rawValue.startsWith("'") && rawValue.endsWith("'")) rawValue = rawValue.slice(1, -1);
|
|
133
|
+
let parsedKey = toKey(rawValue);
|
|
134
|
+
if (parsedKey !== void 0) {
|
|
135
|
+
let nextKey = normalizedMap?.[parsedKey] ?? parsedKey;
|
|
136
|
+
if (key && nextKey !== key && parsedArgs[key] === void 0) parsedArgs[key] = true;
|
|
137
|
+
key = nextKey;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
let parsedValue;
|
|
141
|
+
if (rawValue) try {
|
|
142
|
+
parsedValue = JSON.parse(rawValue);
|
|
143
|
+
} catch {
|
|
144
|
+
parsedValue = rawValue;
|
|
145
|
+
}
|
|
146
|
+
else parsedValue = true;
|
|
147
|
+
let prevValue = parsedArgs[key];
|
|
148
|
+
let value;
|
|
149
|
+
if (prevValue === void 0) value = key === "" ? [parsedValue] : parsedValue;
|
|
150
|
+
else if (Array.isArray(prevValue)) value = [...prevValue, parsedValue];
|
|
151
|
+
else value = [prevValue, parsedValue];
|
|
152
|
+
parsedArgs[key] = value;
|
|
153
|
+
}
|
|
154
|
+
if (key && parsedArgs[key] === void 0) parsedArgs[key] = true;
|
|
155
|
+
return parsedArgs;
|
|
156
|
+
}
|
|
157
|
+
exports.Args = Args2;
|
|
158
|
+
exports.getValue = getValue;
|
|
159
|
+
exports.getValues = getValues;
|
|
160
|
+
exports.hasKey = hasKey2;
|
|
161
|
+
exports.isKey = isKey2;
|
|
162
|
+
exports.parseArgs = parseArgs;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// node_modules/dateshape/dist/index.cjs
|
|
167
|
+
var require_dist2 = __commonJS({
|
|
30
168
|
"node_modules/dateshape/dist/index.cjs"(exports) {
|
|
31
169
|
var SEC = 1e3;
|
|
32
170
|
var MIN = 60 * SEC;
|
|
@@ -215,11 +353,15 @@ var require_dist = __commonJS({
|
|
|
215
353
|
}
|
|
216
354
|
});
|
|
217
355
|
|
|
356
|
+
// src/scripts/bin.ts
|
|
357
|
+
var import_args_json2 = __toESM(require_dist(), 1);
|
|
358
|
+
|
|
218
359
|
// src/scripts/cli.ts
|
|
360
|
+
var import_args_json = __toESM(require_dist(), 1);
|
|
219
361
|
import { rm as rm2 } from "node:fs/promises";
|
|
220
362
|
|
|
221
363
|
// src/scripts/build.ts
|
|
222
|
-
var import_dateshape = __toESM(
|
|
364
|
+
var import_dateshape = __toESM(require_dist2(), 1);
|
|
223
365
|
import { spawn } from "node:child_process";
|
|
224
366
|
|
|
225
367
|
// src/scripts/utils/buildClient.ts
|
|
@@ -291,7 +433,7 @@ async function getEntryPoints(path) {
|
|
|
291
433
|
}
|
|
292
434
|
|
|
293
435
|
// src/scripts/utils/buildClient.ts
|
|
294
|
-
async function buildClient({
|
|
436
|
+
async function buildClient({ clientDir, watch, watchClient }, plugins) {
|
|
295
437
|
let clientEntries = await getEntryPoints(["ui/index"]);
|
|
296
438
|
let buildOptions = {
|
|
297
439
|
...commonBuildOptions,
|
|
@@ -299,7 +441,7 @@ async function buildClient({ publicAssetsDir, watch, watchClient }, plugins) {
|
|
|
299
441
|
bundle: true,
|
|
300
442
|
splitting: true,
|
|
301
443
|
format: "esm",
|
|
302
|
-
outdir:
|
|
444
|
+
outdir: clientDir,
|
|
303
445
|
outbase: "src/entries",
|
|
304
446
|
minify: process.env.NODE_ENV !== "development",
|
|
305
447
|
plugins
|
|
@@ -357,14 +499,14 @@ ${content}
|
|
|
357
499
|
|
|
358
500
|
// src/scripts/utils/buildServer.ts
|
|
359
501
|
async function buildServer(params, plugins) {
|
|
360
|
-
let {
|
|
502
|
+
let { serverDir, watch, watchServer } = params;
|
|
361
503
|
await populateEntries(params);
|
|
362
504
|
let buildOptions = {
|
|
363
505
|
...commonBuildOptions,
|
|
364
506
|
entryPoints: ["src/server/index.ts"],
|
|
365
507
|
bundle: true,
|
|
366
508
|
splitting: true,
|
|
367
|
-
outdir: `${
|
|
509
|
+
outdir: `${serverDir}/server`,
|
|
368
510
|
platform: "node",
|
|
369
511
|
format: "esm",
|
|
370
512
|
packages: "external",
|
|
@@ -382,7 +524,7 @@ async function buildServer(params, plugins) {
|
|
|
382
524
|
|
|
383
525
|
// src/scripts/utils/buildServerCSS.ts
|
|
384
526
|
import esbuild3 from "esbuild";
|
|
385
|
-
async function buildServerCSS({
|
|
527
|
+
async function buildServerCSS({ serverDir, watch, watchServer }, plugins) {
|
|
386
528
|
let serverEntries = await getEntryPoints(["server", "server/index"]);
|
|
387
529
|
let buildOptions = {
|
|
388
530
|
...commonBuildOptions,
|
|
@@ -392,7 +534,7 @@ async function buildServerCSS({ targetDir, watch, watchServer }, plugins) {
|
|
|
392
534
|
})),
|
|
393
535
|
bundle: true,
|
|
394
536
|
splitting: false,
|
|
395
|
-
outdir: `${
|
|
537
|
+
outdir: `${serverDir}/server-css`,
|
|
396
538
|
platform: "node",
|
|
397
539
|
format: "esm",
|
|
398
540
|
packages: "external",
|
|
@@ -410,7 +552,7 @@ async function buildServerCSS({ targetDir, watch, watchServer }, plugins) {
|
|
|
410
552
|
|
|
411
553
|
// src/scripts/utils/createPostbuildPlugins.ts
|
|
412
554
|
import { mkdir, readdir as readdir2, rename, rm } from "node:fs/promises";
|
|
413
|
-
function createPostbuildPlugins({
|
|
555
|
+
function createPostbuildPlugins({ serverDir, clientDir }, onServerRebuild) {
|
|
414
556
|
let serverPlugins = [
|
|
415
557
|
{
|
|
416
558
|
name: "skip-css",
|
|
@@ -432,19 +574,19 @@ function createPostbuildPlugins({ targetDir, publicAssetsDir }, onServerRebuild)
|
|
|
432
574
|
name: "postbuild-server-css",
|
|
433
575
|
setup(build2) {
|
|
434
576
|
build2.onEnd(async () => {
|
|
435
|
-
let dir = `${
|
|
577
|
+
let dir = `${serverDir}/server-css`;
|
|
436
578
|
try {
|
|
437
579
|
let files = (await readdir2(dir)).filter(
|
|
438
580
|
(name) => name.endsWith(".css")
|
|
439
581
|
);
|
|
440
582
|
if (files.length === 0) return;
|
|
441
|
-
await mkdir(
|
|
583
|
+
await mkdir(clientDir, { recursive: true });
|
|
442
584
|
await Promise.all(
|
|
443
585
|
files.map(async (name) => {
|
|
444
|
-
let dir2 = `${
|
|
586
|
+
let dir2 = `${clientDir}/${name.slice(0, -4)}`;
|
|
445
587
|
await mkdir(dir2, { recursive: true });
|
|
446
588
|
await rename(
|
|
447
|
-
`${
|
|
589
|
+
`${serverDir}/server-css/${name}`,
|
|
448
590
|
`${dir2}/index.css`
|
|
449
591
|
);
|
|
450
592
|
})
|
|
@@ -480,7 +622,7 @@ async function build(params) {
|
|
|
480
622
|
inited = true;
|
|
481
623
|
}
|
|
482
624
|
if (params.start)
|
|
483
|
-
serverProcess = spawn("node", [`${params.
|
|
625
|
+
serverProcess = spawn("node", [`${params.serverDir}/server/index.js`], {
|
|
484
626
|
stdio: "inherit"
|
|
485
627
|
});
|
|
486
628
|
}
|
|
@@ -496,38 +638,32 @@ async function build(params) {
|
|
|
496
638
|
}
|
|
497
639
|
|
|
498
640
|
// src/scripts/cli.ts
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
let dirs = [
|
|
502
|
-
`${targetDir}/server`,
|
|
503
|
-
`${targetDir}/server-css`,
|
|
504
|
-
`${publicAssetsDir}/-`
|
|
505
|
-
];
|
|
641
|
+
async function clean({ serverDir, clientDir }) {
|
|
642
|
+
let dirs = [`${serverDir}/server`, `${serverDir}/server-css`, clientDir];
|
|
506
643
|
return Promise.all(
|
|
507
644
|
dirs.map((dir) => rm2(dir, { recursive: true, force: true }))
|
|
508
645
|
);
|
|
509
646
|
}
|
|
510
|
-
async function cli(
|
|
511
|
-
let
|
|
512
|
-
let
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
if (!targetDir || targetDir.startsWith("--")) targetDir = defaultTargetDir;
|
|
647
|
+
async function cli(input = []) {
|
|
648
|
+
let args = new import_args_json.Args(input);
|
|
649
|
+
let clientDir = args.getValue("--client-dir");
|
|
650
|
+
let serverDir = args.getValue("--server-dir", "dist");
|
|
651
|
+
if (!clientDir) throw new Error("Public assets directory is undefined");
|
|
516
652
|
let params = {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
silent: args.
|
|
520
|
-
watch: args.
|
|
521
|
-
watchServer: args.
|
|
522
|
-
watchClient: args.
|
|
523
|
-
start: args.
|
|
653
|
+
serverDir,
|
|
654
|
+
clientDir,
|
|
655
|
+
silent: args.hasKey("--silent"),
|
|
656
|
+
watch: args.hasKey("--watch"),
|
|
657
|
+
watchServer: args.hasKey("--watch-server"),
|
|
658
|
+
watchClient: args.hasKey("--watch-client"),
|
|
659
|
+
start: args.hasKey("--start")
|
|
524
660
|
};
|
|
525
|
-
if (args.
|
|
526
|
-
if (args.
|
|
661
|
+
if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
|
|
662
|
+
if (args.hasKey("--clean-only")) {
|
|
527
663
|
await clean(params);
|
|
528
664
|
return;
|
|
529
665
|
}
|
|
530
|
-
if (args.
|
|
666
|
+
if (args.hasKey("--clean")) await clean(params);
|
|
531
667
|
await build(params);
|
|
532
668
|
}
|
|
533
669
|
|
|
@@ -545,15 +681,16 @@ async function run() {
|
|
|
545
681
|
}
|
|
546
682
|
if (scriptName === "build") return await cli(args);
|
|
547
683
|
let nodeEnv = nodeEnvMap[scriptName];
|
|
548
|
-
let host = args.shift();
|
|
549
684
|
if (nodeEnv !== void 0) process.env.NODE_ENV = nodeEnv;
|
|
550
|
-
if (
|
|
551
|
-
let [hostname, port] =
|
|
685
|
+
if (args.length !== 0 && !(0, import_args_json2.isKey)(args[0])) {
|
|
686
|
+
let [hostname, port] = args[0].split(":");
|
|
552
687
|
if (hostname) process.env.APP_HOST = hostname;
|
|
553
688
|
if (port) process.env.APP_PORT = port;
|
|
689
|
+
args.shift();
|
|
554
690
|
}
|
|
691
|
+
if (!(0, import_args_json2.hasKey)("--client-dir")) args.push("--client-dir", "src/public/-");
|
|
555
692
|
await cli(
|
|
556
|
-
nodeEnv === "development" ? ["
|
|
693
|
+
nodeEnv === "development" ? ["--clean", "--start", "--watch", ...args] : ["--clean", "--start", "--silent", ...args]
|
|
557
694
|
);
|
|
558
695
|
}
|
|
559
696
|
await run();
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ let node_http = require("node:http");
|
|
|
29
29
|
let node_child_process = require("node:child_process");
|
|
30
30
|
let esbuild = require("esbuild");
|
|
31
31
|
esbuild = __toESM(esbuild);
|
|
32
|
+
let args_json = require("args-json");
|
|
32
33
|
let node_events = require("node:events");
|
|
33
34
|
node_events = __toESM(node_events);
|
|
34
35
|
let express = require("express");
|
|
@@ -368,7 +369,7 @@ async function getEntryPoints(path) {
|
|
|
368
369
|
* than client since their contents can also be used with the server-side
|
|
369
370
|
* rendering.
|
|
370
371
|
*/
|
|
371
|
-
async function buildClient({
|
|
372
|
+
async function buildClient({ clientDir, watch, watchClient }, plugins) {
|
|
372
373
|
let clientEntries = await getEntryPoints(["ui/index"]);
|
|
373
374
|
let buildOptions = {
|
|
374
375
|
...commonBuildOptions,
|
|
@@ -376,7 +377,7 @@ async function buildClient({ publicAssetsDir, watch, watchClient }, plugins) {
|
|
|
376
377
|
bundle: true,
|
|
377
378
|
splitting: true,
|
|
378
379
|
format: "esm",
|
|
379
|
-
outdir:
|
|
380
|
+
outdir: clientDir,
|
|
380
381
|
outbase: "src/entries",
|
|
381
382
|
minify: process.env.NODE_ENV !== "development",
|
|
382
383
|
plugins
|
|
@@ -416,14 +417,14 @@ ${content}
|
|
|
416
417
|
}
|
|
417
418
|
|
|
418
419
|
async function buildServer(params, plugins) {
|
|
419
|
-
let {
|
|
420
|
+
let { serverDir, watch, watchServer } = params;
|
|
420
421
|
await populateEntries(params);
|
|
421
422
|
let buildOptions = {
|
|
422
423
|
...commonBuildOptions,
|
|
423
424
|
entryPoints: ["src/server/index.ts"],
|
|
424
425
|
bundle: true,
|
|
425
426
|
splitting: true,
|
|
426
|
-
outdir: `${
|
|
427
|
+
outdir: `${serverDir}/server`,
|
|
427
428
|
platform: "node",
|
|
428
429
|
format: "esm",
|
|
429
430
|
packages: "external",
|
|
@@ -439,7 +440,7 @@ async function buildServer(params, plugins) {
|
|
|
439
440
|
await esbuild.default.build(buildOptions);
|
|
440
441
|
}
|
|
441
442
|
|
|
442
|
-
async function buildServerCSS({
|
|
443
|
+
async function buildServerCSS({ serverDir, watch, watchServer }, plugins) {
|
|
443
444
|
let serverEntries = await getEntryPoints(["server", "server/index"]);
|
|
444
445
|
let buildOptions = {
|
|
445
446
|
...commonBuildOptions,
|
|
@@ -449,7 +450,7 @@ async function buildServerCSS({ targetDir, watch, watchServer }, plugins) {
|
|
|
449
450
|
})),
|
|
450
451
|
bundle: true,
|
|
451
452
|
splitting: false,
|
|
452
|
-
outdir: `${
|
|
453
|
+
outdir: `${serverDir}/server-css`,
|
|
453
454
|
platform: "node",
|
|
454
455
|
format: "esm",
|
|
455
456
|
packages: "external",
|
|
@@ -465,7 +466,7 @@ async function buildServerCSS({ targetDir, watch, watchServer }, plugins) {
|
|
|
465
466
|
await esbuild.default.build(buildOptions);
|
|
466
467
|
}
|
|
467
468
|
|
|
468
|
-
function createPostbuildPlugins({
|
|
469
|
+
function createPostbuildPlugins({ serverDir, clientDir }, onServerRebuild) {
|
|
469
470
|
return {
|
|
470
471
|
serverPlugins: [{
|
|
471
472
|
name: "skip-css",
|
|
@@ -485,15 +486,15 @@ function createPostbuildPlugins({ targetDir, publicAssetsDir }, onServerRebuild)
|
|
|
485
486
|
name: "postbuild-server-css",
|
|
486
487
|
setup(build) {
|
|
487
488
|
build.onEnd(async () => {
|
|
488
|
-
let dir = `${
|
|
489
|
+
let dir = `${serverDir}/server-css`;
|
|
489
490
|
try {
|
|
490
491
|
let files = (await (0, node_fs_promises.readdir)(dir)).filter((name) => name.endsWith(".css"));
|
|
491
492
|
if (files.length === 0) return;
|
|
492
|
-
await (0, node_fs_promises.mkdir)(
|
|
493
|
+
await (0, node_fs_promises.mkdir)(clientDir, { recursive: true });
|
|
493
494
|
await Promise.all(files.map(async (name) => {
|
|
494
|
-
let dir = `${
|
|
495
|
+
let dir = `${clientDir}/${name.slice(0, -4)}`;
|
|
495
496
|
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
496
|
-
await (0, node_fs_promises.rename)(`${
|
|
497
|
+
await (0, node_fs_promises.rename)(`${serverDir}/server-css/${name}`, `${dir}/index.css`);
|
|
497
498
|
}));
|
|
498
499
|
await (0, node_fs_promises.rm)(dir, {
|
|
499
500
|
recursive: true,
|
|
@@ -521,7 +522,7 @@ async function build(params) {
|
|
|
521
522
|
log(`Build completed +${(0, dateshape.formatDuration)(Date.now() - startTime)}`);
|
|
522
523
|
inited = true;
|
|
523
524
|
}
|
|
524
|
-
if (params.start) serverProcess = (0, node_child_process.spawn)("node", [`${params.
|
|
525
|
+
if (params.start) serverProcess = (0, node_child_process.spawn)("node", [`${params.serverDir}/server/index.js`], { stdio: "inherit" });
|
|
525
526
|
}
|
|
526
527
|
let { serverPlugins, serverCSSPlugins } = createPostbuildPlugins(params, handleServerRebuild);
|
|
527
528
|
await Promise.all([
|
|
@@ -531,38 +532,37 @@ async function build(params) {
|
|
|
531
532
|
]);
|
|
532
533
|
}
|
|
533
534
|
|
|
534
|
-
|
|
535
|
-
async function clean({ targetDir, publicAssetsDir }) {
|
|
535
|
+
async function clean({ serverDir, clientDir }) {
|
|
536
536
|
let dirs = [
|
|
537
|
-
`${
|
|
538
|
-
`${
|
|
539
|
-
|
|
537
|
+
`${serverDir}/server`,
|
|
538
|
+
`${serverDir}/server-css`,
|
|
539
|
+
clientDir
|
|
540
540
|
];
|
|
541
541
|
return Promise.all(dirs.map((dir) => (0, node_fs_promises.rm)(dir, {
|
|
542
542
|
recursive: true,
|
|
543
543
|
force: true
|
|
544
544
|
})));
|
|
545
545
|
}
|
|
546
|
-
async function cli(
|
|
547
|
-
let
|
|
548
|
-
let
|
|
549
|
-
|
|
550
|
-
if (!
|
|
546
|
+
async function cli(input = []) {
|
|
547
|
+
let args = new args_json.Args(input);
|
|
548
|
+
let clientDir = args.getValue("--client-dir");
|
|
549
|
+
let serverDir = args.getValue("--server-dir", "dist");
|
|
550
|
+
if (!clientDir) throw new Error("Public assets directory is undefined");
|
|
551
551
|
let params = {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
silent: args.
|
|
555
|
-
watch: args.
|
|
556
|
-
watchServer: args.
|
|
557
|
-
watchClient: args.
|
|
558
|
-
start: args.
|
|
552
|
+
serverDir,
|
|
553
|
+
clientDir,
|
|
554
|
+
silent: args.hasKey("--silent"),
|
|
555
|
+
watch: args.hasKey("--watch"),
|
|
556
|
+
watchServer: args.hasKey("--watch-server"),
|
|
557
|
+
watchClient: args.hasKey("--watch-client"),
|
|
558
|
+
start: args.hasKey("--start")
|
|
559
559
|
};
|
|
560
|
-
if (args.
|
|
561
|
-
if (args.
|
|
560
|
+
if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
|
|
561
|
+
if (args.hasKey("--clean-only")) {
|
|
562
562
|
await clean(params);
|
|
563
563
|
return;
|
|
564
564
|
}
|
|
565
|
-
if (args.
|
|
565
|
+
if (args.hasKey("--clean")) await clean(params);
|
|
566
566
|
await build(params);
|
|
567
567
|
}
|
|
568
568
|
|
package/dist/index.d.ts
CHANGED
|
@@ -131,8 +131,8 @@ declare const lang$1: Middleware<LangParams | void>;
|
|
|
131
131
|
declare const requestEvents: Middleware;
|
|
132
132
|
|
|
133
133
|
type BuildParams = {
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
serverDir: string;
|
|
135
|
+
clientDir: string;
|
|
136
136
|
silent?: boolean;
|
|
137
137
|
watch?: boolean;
|
|
138
138
|
watchClient?: boolean;
|
|
@@ -151,7 +151,7 @@ type BuildParams = {
|
|
|
151
151
|
|
|
152
152
|
declare function build(params: BuildParams): Promise<void>;
|
|
153
153
|
|
|
154
|
-
declare function cli(
|
|
154
|
+
declare function cli(input?: string[]): Promise<void>;
|
|
155
155
|
|
|
156
156
|
type LogLevel = "error" | "debug" | "info" | "warn";
|
|
157
157
|
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { randomBytes } from "node:crypto";
|
|
|
5
5
|
import { STATUS_CODES } from "node:http";
|
|
6
6
|
import { spawn } from "node:child_process";
|
|
7
7
|
import esbuild from "esbuild";
|
|
8
|
+
import { Args } from "args-json";
|
|
8
9
|
import EventEmitter from "node:events";
|
|
9
10
|
import express from "express";
|
|
10
11
|
|
|
@@ -342,7 +343,7 @@ async function getEntryPoints(path) {
|
|
|
342
343
|
* than client since their contents can also be used with the server-side
|
|
343
344
|
* rendering.
|
|
344
345
|
*/
|
|
345
|
-
async function buildClient({
|
|
346
|
+
async function buildClient({ clientDir, watch, watchClient }, plugins) {
|
|
346
347
|
let clientEntries = await getEntryPoints(["ui/index"]);
|
|
347
348
|
let buildOptions = {
|
|
348
349
|
...commonBuildOptions,
|
|
@@ -350,7 +351,7 @@ async function buildClient({ publicAssetsDir, watch, watchClient }, plugins) {
|
|
|
350
351
|
bundle: true,
|
|
351
352
|
splitting: true,
|
|
352
353
|
format: "esm",
|
|
353
|
-
outdir:
|
|
354
|
+
outdir: clientDir,
|
|
354
355
|
outbase: "src/entries",
|
|
355
356
|
minify: process.env.NODE_ENV !== "development",
|
|
356
357
|
plugins
|
|
@@ -390,14 +391,14 @@ ${content}
|
|
|
390
391
|
}
|
|
391
392
|
|
|
392
393
|
async function buildServer(params, plugins) {
|
|
393
|
-
let {
|
|
394
|
+
let { serverDir, watch, watchServer } = params;
|
|
394
395
|
await populateEntries(params);
|
|
395
396
|
let buildOptions = {
|
|
396
397
|
...commonBuildOptions,
|
|
397
398
|
entryPoints: ["src/server/index.ts"],
|
|
398
399
|
bundle: true,
|
|
399
400
|
splitting: true,
|
|
400
|
-
outdir: `${
|
|
401
|
+
outdir: `${serverDir}/server`,
|
|
401
402
|
platform: "node",
|
|
402
403
|
format: "esm",
|
|
403
404
|
packages: "external",
|
|
@@ -413,7 +414,7 @@ async function buildServer(params, plugins) {
|
|
|
413
414
|
await esbuild.build(buildOptions);
|
|
414
415
|
}
|
|
415
416
|
|
|
416
|
-
async function buildServerCSS({
|
|
417
|
+
async function buildServerCSS({ serverDir, watch, watchServer }, plugins) {
|
|
417
418
|
let serverEntries = await getEntryPoints(["server", "server/index"]);
|
|
418
419
|
let buildOptions = {
|
|
419
420
|
...commonBuildOptions,
|
|
@@ -423,7 +424,7 @@ async function buildServerCSS({ targetDir, watch, watchServer }, plugins) {
|
|
|
423
424
|
})),
|
|
424
425
|
bundle: true,
|
|
425
426
|
splitting: false,
|
|
426
|
-
outdir: `${
|
|
427
|
+
outdir: `${serverDir}/server-css`,
|
|
427
428
|
platform: "node",
|
|
428
429
|
format: "esm",
|
|
429
430
|
packages: "external",
|
|
@@ -439,7 +440,7 @@ async function buildServerCSS({ targetDir, watch, watchServer }, plugins) {
|
|
|
439
440
|
await esbuild.build(buildOptions);
|
|
440
441
|
}
|
|
441
442
|
|
|
442
|
-
function createPostbuildPlugins({
|
|
443
|
+
function createPostbuildPlugins({ serverDir, clientDir }, onServerRebuild) {
|
|
443
444
|
return {
|
|
444
445
|
serverPlugins: [{
|
|
445
446
|
name: "skip-css",
|
|
@@ -459,15 +460,15 @@ function createPostbuildPlugins({ targetDir, publicAssetsDir }, onServerRebuild)
|
|
|
459
460
|
name: "postbuild-server-css",
|
|
460
461
|
setup(build) {
|
|
461
462
|
build.onEnd(async () => {
|
|
462
|
-
let dir = `${
|
|
463
|
+
let dir = `${serverDir}/server-css`;
|
|
463
464
|
try {
|
|
464
465
|
let files = (await readdir(dir)).filter((name) => name.endsWith(".css"));
|
|
465
466
|
if (files.length === 0) return;
|
|
466
|
-
await mkdir(
|
|
467
|
+
await mkdir(clientDir, { recursive: true });
|
|
467
468
|
await Promise.all(files.map(async (name) => {
|
|
468
|
-
let dir = `${
|
|
469
|
+
let dir = `${clientDir}/${name.slice(0, -4)}`;
|
|
469
470
|
await mkdir(dir, { recursive: true });
|
|
470
|
-
await rename(`${
|
|
471
|
+
await rename(`${serverDir}/server-css/${name}`, `${dir}/index.css`);
|
|
471
472
|
}));
|
|
472
473
|
await rm(dir, {
|
|
473
474
|
recursive: true,
|
|
@@ -495,7 +496,7 @@ async function build(params) {
|
|
|
495
496
|
log(`Build completed +${formatDuration(Date.now() - startTime)}`);
|
|
496
497
|
inited = true;
|
|
497
498
|
}
|
|
498
|
-
if (params.start) serverProcess = spawn("node", [`${params.
|
|
499
|
+
if (params.start) serverProcess = spawn("node", [`${params.serverDir}/server/index.js`], { stdio: "inherit" });
|
|
499
500
|
}
|
|
500
501
|
let { serverPlugins, serverCSSPlugins } = createPostbuildPlugins(params, handleServerRebuild);
|
|
501
502
|
await Promise.all([
|
|
@@ -505,38 +506,37 @@ async function build(params) {
|
|
|
505
506
|
]);
|
|
506
507
|
}
|
|
507
508
|
|
|
508
|
-
|
|
509
|
-
async function clean({ targetDir, publicAssetsDir }) {
|
|
509
|
+
async function clean({ serverDir, clientDir }) {
|
|
510
510
|
let dirs = [
|
|
511
|
-
`${
|
|
512
|
-
`${
|
|
513
|
-
|
|
511
|
+
`${serverDir}/server`,
|
|
512
|
+
`${serverDir}/server-css`,
|
|
513
|
+
clientDir
|
|
514
514
|
];
|
|
515
515
|
return Promise.all(dirs.map((dir) => rm(dir, {
|
|
516
516
|
recursive: true,
|
|
517
517
|
force: true
|
|
518
518
|
})));
|
|
519
519
|
}
|
|
520
|
-
async function cli(
|
|
521
|
-
let
|
|
522
|
-
let
|
|
523
|
-
|
|
524
|
-
if (!
|
|
520
|
+
async function cli(input = []) {
|
|
521
|
+
let args = new Args(input);
|
|
522
|
+
let clientDir = args.getValue("--client-dir");
|
|
523
|
+
let serverDir = args.getValue("--server-dir", "dist");
|
|
524
|
+
if (!clientDir) throw new Error("Public assets directory is undefined");
|
|
525
525
|
let params = {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
silent: args.
|
|
529
|
-
watch: args.
|
|
530
|
-
watchServer: args.
|
|
531
|
-
watchClient: args.
|
|
532
|
-
start: args.
|
|
526
|
+
serverDir,
|
|
527
|
+
clientDir,
|
|
528
|
+
silent: args.hasKey("--silent"),
|
|
529
|
+
watch: args.hasKey("--watch"),
|
|
530
|
+
watchServer: args.hasKey("--watch-server"),
|
|
531
|
+
watchClient: args.hasKey("--watch-client"),
|
|
532
|
+
start: args.hasKey("--start")
|
|
533
533
|
};
|
|
534
|
-
if (args.
|
|
535
|
-
if (args.
|
|
534
|
+
if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
|
|
535
|
+
if (args.hasKey("--clean-only")) {
|
|
536
536
|
await clean(params);
|
|
537
537
|
return;
|
|
538
538
|
}
|
|
539
|
-
if (args.
|
|
539
|
+
if (args.hasKey("--clean")) await clean(params);
|
|
540
540
|
await build(params);
|
|
541
541
|
}
|
|
542
542
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appstage",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"@types/node": "^25.4.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"args-json": "^1.3.3",
|
|
32
33
|
"dateshape": "^1.1.2",
|
|
33
|
-
"esbuild": "^0.27.
|
|
34
|
+
"esbuild": "^0.27.4"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/src/scripts/bin.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { hasKey, isKey } from "args-json";
|
|
2
3
|
import { cli } from "./cli.ts";
|
|
3
4
|
|
|
4
5
|
const availableScriptNames = new Set(["build", "dev", "prod"]);
|
|
@@ -19,21 +20,24 @@ async function run() {
|
|
|
19
20
|
if (scriptName === "build") return await cli(args);
|
|
20
21
|
|
|
21
22
|
let nodeEnv = nodeEnvMap[scriptName];
|
|
22
|
-
let host = args.shift();
|
|
23
23
|
|
|
24
24
|
if (nodeEnv !== undefined) process.env.NODE_ENV = nodeEnv;
|
|
25
25
|
|
|
26
|
-
if (
|
|
27
|
-
let [hostname, port] =
|
|
26
|
+
if (args.length !== 0 && !isKey(args[0])) {
|
|
27
|
+
let [hostname, port] = args[0].split(":");
|
|
28
28
|
|
|
29
29
|
if (hostname) process.env.APP_HOST = hostname;
|
|
30
30
|
if (port) process.env.APP_PORT = port;
|
|
31
|
+
|
|
32
|
+
args.shift();
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
if (!hasKey("--client-dir")) args.push("--client-dir", "src/public/-");
|
|
36
|
+
|
|
33
37
|
await cli(
|
|
34
38
|
nodeEnv === "development"
|
|
35
|
-
? ["
|
|
36
|
-
: ["
|
|
39
|
+
? ["--clean", "--start", "--watch", ...args]
|
|
40
|
+
: ["--clean", "--start", "--silent", ...args],
|
|
37
41
|
);
|
|
38
42
|
}
|
|
39
43
|
|
package/src/scripts/build.ts
CHANGED
|
@@ -27,7 +27,7 @@ export async function build(params: BuildParams) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
if (params.start)
|
|
30
|
-
serverProcess = spawn("node", [`${params.
|
|
30
|
+
serverProcess = spawn("node", [`${params.serverDir}/server/index.js`], {
|
|
31
31
|
stdio: "inherit",
|
|
32
32
|
});
|
|
33
33
|
}
|
package/src/scripts/cli.ts
CHANGED
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
import { rm } from "node:fs/promises";
|
|
2
|
+
import { Args } from "args-json";
|
|
2
3
|
import { build } from "./build.ts";
|
|
3
4
|
import type { BuildParams } from "./types/BuildParams.ts";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
async function clean({ targetDir, publicAssetsDir }: BuildParams) {
|
|
8
|
-
let dirs = [
|
|
9
|
-
`${targetDir}/server`,
|
|
10
|
-
`${targetDir}/server-css`,
|
|
11
|
-
`${publicAssetsDir}/-`,
|
|
12
|
-
];
|
|
6
|
+
async function clean({ serverDir, clientDir }: BuildParams) {
|
|
7
|
+
let dirs = [`${serverDir}/server`, `${serverDir}/server-css`, clientDir];
|
|
13
8
|
|
|
14
9
|
return Promise.all(
|
|
15
10
|
dirs.map((dir) => rm(dir, { recursive: true, force: true })),
|
|
16
11
|
);
|
|
17
12
|
}
|
|
18
13
|
|
|
19
|
-
export async function cli(
|
|
20
|
-
let
|
|
21
|
-
let targetDir = args[1];
|
|
14
|
+
export async function cli(input: string[] = []) {
|
|
15
|
+
let args = new Args(input);
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
let clientDir = args.getValue("--client-dir");
|
|
18
|
+
let serverDir = args.getValue("--server-dir", "dist");
|
|
25
19
|
|
|
26
|
-
if (!
|
|
20
|
+
if (!clientDir) throw new Error("Public assets directory is undefined");
|
|
27
21
|
|
|
28
22
|
let params: BuildParams = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
silent: args.
|
|
32
|
-
watch: args.
|
|
33
|
-
watchServer: args.
|
|
34
|
-
watchClient: args.
|
|
35
|
-
start: args.
|
|
23
|
+
serverDir,
|
|
24
|
+
clientDir,
|
|
25
|
+
silent: args.hasKey("--silent"),
|
|
26
|
+
watch: args.hasKey("--watch"),
|
|
27
|
+
watchServer: args.hasKey("--watch-server"),
|
|
28
|
+
watchClient: args.hasKey("--watch-client"),
|
|
29
|
+
start: args.hasKey("--start"),
|
|
36
30
|
};
|
|
37
31
|
|
|
38
|
-
if (args.
|
|
32
|
+
if (args.hasKey("--no-auto-entries")) params.entriesPath = null;
|
|
39
33
|
|
|
40
|
-
if (args.
|
|
34
|
+
if (args.hasKey("--clean-only")) {
|
|
41
35
|
await clean(params);
|
|
42
36
|
return;
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
if (args.
|
|
39
|
+
if (args.hasKey("--clean")) await clean(params);
|
|
46
40
|
|
|
47
41
|
await build(params);
|
|
48
42
|
}
|
|
@@ -10,7 +10,7 @@ import { getEntryPoints } from "./getEntryPoints.ts";
|
|
|
10
10
|
* rendering.
|
|
11
11
|
*/
|
|
12
12
|
export async function buildClient(
|
|
13
|
-
{
|
|
13
|
+
{ clientDir, watch, watchClient }: BuildParams,
|
|
14
14
|
plugins?: Plugin[],
|
|
15
15
|
) {
|
|
16
16
|
let clientEntries = await getEntryPoints(["ui/index"]);
|
|
@@ -21,7 +21,7 @@ export async function buildClient(
|
|
|
21
21
|
bundle: true,
|
|
22
22
|
splitting: true,
|
|
23
23
|
format: "esm",
|
|
24
|
-
outdir:
|
|
24
|
+
outdir: clientDir,
|
|
25
25
|
outbase: "src/entries",
|
|
26
26
|
minify: process.env.NODE_ENV !== "development",
|
|
27
27
|
plugins,
|
|
@@ -4,7 +4,7 @@ import type { BuildParams } from "../types/BuildParams.ts";
|
|
|
4
4
|
import { populateEntries } from "./populateEntries.ts";
|
|
5
5
|
|
|
6
6
|
export async function buildServer(params: BuildParams, plugins?: Plugin[]) {
|
|
7
|
-
let {
|
|
7
|
+
let { serverDir, watch, watchServer } = params;
|
|
8
8
|
|
|
9
9
|
await populateEntries(params);
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ export async function buildServer(params: BuildParams, plugins?: Plugin[]) {
|
|
|
13
13
|
entryPoints: ["src/server/index.ts"],
|
|
14
14
|
bundle: true,
|
|
15
15
|
splitting: true,
|
|
16
|
-
outdir: `${
|
|
16
|
+
outdir: `${serverDir}/server`,
|
|
17
17
|
platform: "node",
|
|
18
18
|
format: "esm",
|
|
19
19
|
packages: "external",
|
|
@@ -4,7 +4,7 @@ import type { BuildParams } from "../types/BuildParams.ts";
|
|
|
4
4
|
import { getEntryPoints } from "./getEntryPoints.ts";
|
|
5
5
|
|
|
6
6
|
export async function buildServerCSS(
|
|
7
|
-
{
|
|
7
|
+
{ serverDir, watch, watchServer }: BuildParams,
|
|
8
8
|
plugins?: Plugin[],
|
|
9
9
|
) {
|
|
10
10
|
let serverEntries = await getEntryPoints(["server", "server/index"]);
|
|
@@ -17,7 +17,7 @@ export async function buildServerCSS(
|
|
|
17
17
|
})),
|
|
18
18
|
bundle: true,
|
|
19
19
|
splitting: false,
|
|
20
|
-
outdir: `${
|
|
20
|
+
outdir: `${serverDir}/server-css`,
|
|
21
21
|
platform: "node",
|
|
22
22
|
format: "esm",
|
|
23
23
|
packages: "external",
|
|
@@ -3,7 +3,7 @@ import type { Plugin } from "esbuild";
|
|
|
3
3
|
import type { BuildParams } from "../types/BuildParams.ts";
|
|
4
4
|
|
|
5
5
|
export function createPostbuildPlugins(
|
|
6
|
-
{
|
|
6
|
+
{ serverDir, clientDir }: BuildParams,
|
|
7
7
|
onServerRebuild: () => void,
|
|
8
8
|
) {
|
|
9
9
|
let serverPlugins: Plugin[] = [
|
|
@@ -29,7 +29,7 @@ export function createPostbuildPlugins(
|
|
|
29
29
|
name: "postbuild-server-css",
|
|
30
30
|
setup(build) {
|
|
31
31
|
build.onEnd(async () => {
|
|
32
|
-
let dir = `${
|
|
32
|
+
let dir = `${serverDir}/server-css`;
|
|
33
33
|
|
|
34
34
|
try {
|
|
35
35
|
let files = (await readdir(dir)).filter((name) =>
|
|
@@ -38,15 +38,15 @@ export function createPostbuildPlugins(
|
|
|
38
38
|
|
|
39
39
|
if (files.length === 0) return;
|
|
40
40
|
|
|
41
|
-
await mkdir(
|
|
41
|
+
await mkdir(clientDir, { recursive: true });
|
|
42
42
|
|
|
43
43
|
await Promise.all(
|
|
44
44
|
files.map(async (name) => {
|
|
45
|
-
let dir = `${
|
|
45
|
+
let dir = `${clientDir}/${name.slice(0, -4)}`;
|
|
46
46
|
|
|
47
47
|
await mkdir(dir, { recursive: true });
|
|
48
48
|
await rename(
|
|
49
|
-
`${
|
|
49
|
+
`${serverDir}/server-css/${name}`,
|
|
50
50
|
`${dir}/index.css`,
|
|
51
51
|
);
|
|
52
52
|
}),
|