xpine 0.0.61 → 0.0.62
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/index.js +97 -72
- package/dist/src/runDevServer.d.ts.map +1 -1
- package/dist/src/scripts/build.d.ts.map +1 -1
- package/dist/src/scripts/xpine-build.js +76 -58
- package/dist/src/scripts/xpine-dev.js +92 -67
- package/dist/src/static/dev-server.js +2 -1
- package/dist/src/util/dev-server-port.d.ts +2 -0
- package/dist/src/util/dev-server-port.d.ts.map +1 -0
- package/dist/src/util/paths.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import EventEmitter2 from "events";
|
|
|
6
6
|
import chokidar from "chokidar";
|
|
7
7
|
|
|
8
8
|
// src/scripts/build.ts
|
|
9
|
-
import
|
|
10
|
-
import
|
|
9
|
+
import path7 from "path";
|
|
10
|
+
import fs8 from "fs-extra";
|
|
11
11
|
import { build } from "esbuild";
|
|
12
12
|
import micromatch from "micromatch";
|
|
13
13
|
import minifyXML from "minify-xml";
|
|
@@ -305,18 +305,27 @@ async function triggerXPineOnLoad(noCache = false) {
|
|
|
305
305
|
import { globSync as globSync3 } from "glob";
|
|
306
306
|
|
|
307
307
|
// src/util/paths.ts
|
|
308
|
+
import path3 from "path";
|
|
309
|
+
import fs2 from "fs";
|
|
308
310
|
function getXPineDistDir() {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
311
|
+
let dir = import.meta.dirname;
|
|
312
|
+
while (true) {
|
|
313
|
+
const packageJsonPath = path3.join(dir, "package.json");
|
|
314
|
+
if (fs2.existsSync(packageJsonPath)) {
|
|
315
|
+
try {
|
|
316
|
+
const packageJson2 = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
|
|
317
|
+
if (packageJson2?.name === "xpine") return path3.join(dir, "dist");
|
|
318
|
+
} catch {
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const parent = path3.dirname(dir);
|
|
322
|
+
if (parent === dir) throw new Error(`Could not find the xpine package root from ${import.meta.dirname}`);
|
|
323
|
+
dir = parent;
|
|
314
324
|
}
|
|
315
|
-
return splitDir[0] + "/xpine/dist";
|
|
316
325
|
}
|
|
317
326
|
|
|
318
327
|
// src/build/esbuild/transformTSXFiles.ts
|
|
319
|
-
import
|
|
328
|
+
import fs3 from "fs-extra";
|
|
320
329
|
import ts2 from "typescript";
|
|
321
330
|
|
|
322
331
|
// src/util/regex.ts
|
|
@@ -343,14 +352,14 @@ var regex_default = {
|
|
|
343
352
|
};
|
|
344
353
|
|
|
345
354
|
// src/util/config-file.ts
|
|
346
|
-
import
|
|
355
|
+
import path4 from "path";
|
|
347
356
|
function sourcePathToDistPath(sourcePath) {
|
|
348
357
|
return sourcePath?.replace(config.srcDir, config.distDir)?.replace(/\.ts$/, ".js")?.replace(/\.tsx$/, ".js");
|
|
349
358
|
}
|
|
350
359
|
function getConfigFiles(pathName, pageConfigFiles, returnDistPaths = true) {
|
|
351
360
|
const configs = [];
|
|
352
361
|
for (const configFile of pageConfigFiles) {
|
|
353
|
-
const result =
|
|
362
|
+
const result = path4.relative(pathName, configFile)?.replace(regex_default.configFile, "");
|
|
354
363
|
const hasLetters = result.match(regex_default.hasLetters);
|
|
355
364
|
if (!hasLetters) {
|
|
356
365
|
configs.push(returnDistPaths ? sourcePathToDistPath(configFile) : configFile);
|
|
@@ -379,7 +388,7 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
379
388
|
name: "transform-tsx-files",
|
|
380
389
|
setup(build2) {
|
|
381
390
|
build2.onLoad({ filter: regex_default.dotTsx }, async (args) => {
|
|
382
|
-
const content =
|
|
391
|
+
const content = fs3.readFileSync(args.path, "utf-8");
|
|
383
392
|
const source = ts2.createSourceFile(
|
|
384
393
|
args.path,
|
|
385
394
|
content,
|
|
@@ -407,8 +416,8 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
407
416
|
}
|
|
408
417
|
|
|
409
418
|
// src/build/esbuild/addDotJS.ts
|
|
410
|
-
import
|
|
411
|
-
import
|
|
419
|
+
import fs4 from "fs-extra";
|
|
420
|
+
import path5 from "path";
|
|
412
421
|
import builtinModules from "builtin-modules";
|
|
413
422
|
function addDotJS(allPackages2, extensions2, isDev2) {
|
|
414
423
|
const allPackagesIncludingNode = allPackages2.concat(builtinModules);
|
|
@@ -419,11 +428,11 @@ function addDotJS(allPackages2, extensions2, isDev2) {
|
|
|
419
428
|
const hasAtSign = args.path.startsWith("@");
|
|
420
429
|
const isPackage = hasAtSign ? allPackagesIncludingNode.includes(args.path) : allPackagesIncludingNode.includes(args.path.split("/").shift());
|
|
421
430
|
if (args.importer && !isPackage) {
|
|
422
|
-
const calculatedDir =
|
|
431
|
+
const calculatedDir = path5.join(args.resolveDir, args.path);
|
|
423
432
|
let existsAsFile = false;
|
|
424
433
|
for (const extension of extensions2) {
|
|
425
434
|
const asFile = calculatedDir + extension;
|
|
426
|
-
const exists =
|
|
435
|
+
const exists = fs4.existsSync(asFile);
|
|
427
436
|
if (exists) existsAsFile = true;
|
|
428
437
|
}
|
|
429
438
|
let outputPath = args.path + (existsAsFile ? "" : "/index") + ".js";
|
|
@@ -436,13 +445,13 @@ function addDotJS(allPackages2, extensions2, isDev2) {
|
|
|
436
445
|
}
|
|
437
446
|
|
|
438
447
|
// src/build/esbuild/getDataFiles.ts
|
|
439
|
-
import
|
|
448
|
+
import fs5 from "fs-extra";
|
|
440
449
|
function getDataFiles(dataFiles) {
|
|
441
450
|
return {
|
|
442
451
|
name: "get-data-files",
|
|
443
452
|
setup(build2) {
|
|
444
453
|
build2.onLoad({ filter: /\.data\.(js|mjs|ts)$/ }, (args) => {
|
|
445
|
-
const contents =
|
|
454
|
+
const contents = fs5.readFileSync(args.path, "utf-8");
|
|
446
455
|
dataFiles.push({
|
|
447
456
|
...args,
|
|
448
457
|
contents
|
|
@@ -460,6 +469,15 @@ function getDataFiles(dataFiles) {
|
|
|
460
469
|
var doctypeHTML = "<!DOCTYPE html>";
|
|
461
470
|
var staticComment = "<!-- static -->";
|
|
462
471
|
|
|
472
|
+
// src/util/dev-server-port.ts
|
|
473
|
+
function getDevServerWsPort() {
|
|
474
|
+
const wsPort = Number.parseInt(process.env.WS_PORT || "", 10);
|
|
475
|
+
if (Number.isInteger(wsPort) && wsPort > 0) return wsPort;
|
|
476
|
+
const appPort = Number.parseInt(process.env.PORT || "", 10);
|
|
477
|
+
if (Number.isInteger(appPort) && appPort > 0) return appPort + 1;
|
|
478
|
+
return 3001;
|
|
479
|
+
}
|
|
480
|
+
|
|
463
481
|
// src/scripts/build.ts
|
|
464
482
|
import ts3 from "typescript";
|
|
465
483
|
|
|
@@ -511,8 +529,8 @@ function getTokenFromRequest(req) {
|
|
|
511
529
|
|
|
512
530
|
// src/express.ts
|
|
513
531
|
import requestIP from "request-ip";
|
|
514
|
-
import
|
|
515
|
-
import
|
|
532
|
+
import fs6 from "fs-extra";
|
|
533
|
+
import path6 from "path";
|
|
516
534
|
import EventEmitter from "events";
|
|
517
535
|
|
|
518
536
|
// src/csrf.ts
|
|
@@ -839,10 +857,10 @@ function routeHasStaticPath(route, params) {
|
|
|
839
857
|
if (key === "0") routeToStaticPath = routeToStaticPath.replace(/\/\*/g, () => `/${value}`);
|
|
840
858
|
}
|
|
841
859
|
routeToStaticPath += "/index.html";
|
|
842
|
-
const pagesDir =
|
|
843
|
-
const outputPath =
|
|
844
|
-
if (outputPath !== pagesDir && !outputPath.startsWith(pagesDir +
|
|
845
|
-
if (
|
|
860
|
+
const pagesDir = path6.resolve(config.distPagesDir);
|
|
861
|
+
const outputPath = path6.resolve(pagesDir, "." + path6.posix.normalize("/" + routeToStaticPath));
|
|
862
|
+
if (outputPath !== pagesDir && !outputPath.startsWith(pagesDir + path6.sep)) return false;
|
|
863
|
+
if (fs6.existsSync(outputPath)) return outputPath;
|
|
846
864
|
return false;
|
|
847
865
|
}
|
|
848
866
|
function filePathToURLPath(pathName, isDist = true) {
|
|
@@ -857,7 +875,7 @@ function filePathToURLPath(pathName, isDist = true) {
|
|
|
857
875
|
|
|
858
876
|
// src/build/css.ts
|
|
859
877
|
import { globSync as globSync2 } from "glob";
|
|
860
|
-
import
|
|
878
|
+
import fs7 from "fs-extra";
|
|
861
879
|
import postcss from "postcss";
|
|
862
880
|
|
|
863
881
|
// src/build/postcss/remove-layers.ts
|
|
@@ -926,15 +944,15 @@ async function buildCSS(disableTailwind) {
|
|
|
926
944
|
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
927
945
|
for (const file of cssFiles) {
|
|
928
946
|
try {
|
|
929
|
-
const fileContents =
|
|
947
|
+
const fileContents = fs7.readFileSync(file, "utf-8");
|
|
930
948
|
let result = fileContents;
|
|
931
949
|
if (!disableTailwind) {
|
|
932
950
|
result = await postcss([add_breakpoint_data_default()]).process(fileContents, { from: file });
|
|
933
951
|
result = await postcss([tailwindPostcss(), remove_layers_default()]).process(result.css, { from: file });
|
|
934
952
|
}
|
|
935
953
|
const newPath = file.replace(config.srcDir, config.distDir);
|
|
936
|
-
|
|
937
|
-
|
|
954
|
+
fs7.ensureFileSync(newPath);
|
|
955
|
+
fs7.writeFileSync(newPath, result.css);
|
|
938
956
|
} catch (err) {
|
|
939
957
|
console.error(err);
|
|
940
958
|
}
|
|
@@ -944,7 +962,7 @@ async function buildCSS(disableTailwind) {
|
|
|
944
962
|
|
|
945
963
|
// src/scripts/build.ts
|
|
946
964
|
var extensions = [".ts", ".tsx"];
|
|
947
|
-
var packageJson = JSON.parse(
|
|
965
|
+
var packageJson = JSON.parse(fs8.readFileSync(config.packageJsonPath, "utf-8"));
|
|
948
966
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
949
967
|
var xpineDistDir = getXPineDistDir();
|
|
950
968
|
async function buildApp(args) {
|
|
@@ -952,7 +970,7 @@ async function buildApp(args) {
|
|
|
952
970
|
const removePreviousBuild = args?.removePreviousBuild || false;
|
|
953
971
|
const disableTailwind = args?.disableTailwind || false;
|
|
954
972
|
try {
|
|
955
|
-
if (removePreviousBuild)
|
|
973
|
+
if (removePreviousBuild) fs8.removeSync(config.distDir);
|
|
956
974
|
const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
957
975
|
const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev2);
|
|
958
976
|
const clientSideBundles = [];
|
|
@@ -977,7 +995,7 @@ async function buildApp(args) {
|
|
|
977
995
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
978
996
|
await buildClientSideFiles([alpineDataFile, ...clientSideBundles], isDev2);
|
|
979
997
|
}
|
|
980
|
-
|
|
998
|
+
fs8.removeSync(config.distTempFolder);
|
|
981
999
|
await buildCSS(disableTailwind);
|
|
982
1000
|
await buildPublicFolderSymlinks();
|
|
983
1001
|
await buildOnLoadFile(componentData, isDev2);
|
|
@@ -998,7 +1016,7 @@ async function buildAppFiles(files, isDev2) {
|
|
|
998
1016
|
return fileName === "+config";
|
|
999
1017
|
});
|
|
1000
1018
|
const backendFiles = files.filter((file) => extensions?.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
|
|
1001
|
-
|
|
1019
|
+
fs8.ensureDirSync(config.distDir);
|
|
1002
1020
|
await build({
|
|
1003
1021
|
entryPoints: backendFiles,
|
|
1004
1022
|
format: "esm",
|
|
@@ -1022,8 +1040,8 @@ async function buildAppFiles(files, isDev2) {
|
|
|
1022
1040
|
};
|
|
1023
1041
|
}
|
|
1024
1042
|
async function buildClientSideFiles(alpineDataFiles = [], isDev2, tempClientSidePath, id) {
|
|
1025
|
-
const tempFilePath =
|
|
1026
|
-
|
|
1043
|
+
const tempFilePath = path7.join(config.distTempFolder, tempClientSidePath || "./app.ts");
|
|
1044
|
+
fs8.ensureFileSync(tempFilePath);
|
|
1027
1045
|
const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
|
|
1028
1046
|
const standaloneFolderGlob = config.publicDir + "/standalone/**/*.*";
|
|
1029
1047
|
const clientFiles = globSync3(
|
|
@@ -1056,14 +1074,14 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev2, tempClientSide
|
|
|
1056
1074
|
await logSize(config.distPublicDir, id ? `client bundle: ${id}.js` : "client bundle: app.js");
|
|
1057
1075
|
}
|
|
1058
1076
|
function writeDevServerClientSideCode(tempFilePath) {
|
|
1059
|
-
const devServerPath =
|
|
1060
|
-
const content =
|
|
1061
|
-
|
|
1077
|
+
const devServerPath = path7.join(xpineDistDir, "./src/static/dev-server.js");
|
|
1078
|
+
const content = fs8.readFileSync(devServerPath, "utf-8").replace("__XPINE_WS_PORT__", String(getDevServerWsPort()));
|
|
1079
|
+
fs8.appendFileSync(tempFilePath, "\n" + content);
|
|
1062
1080
|
}
|
|
1063
1081
|
function writeSpaClientSideCode(tempFilePath) {
|
|
1064
|
-
const spaPath =
|
|
1065
|
-
const content =
|
|
1066
|
-
|
|
1082
|
+
const spaPath = path7.join(xpineDistDir, "./src/static/spa.js");
|
|
1083
|
+
const content = fs8.readFileSync(spaPath, "utf-8");
|
|
1084
|
+
fs8.appendFileSync(tempFilePath, "\n" + content);
|
|
1067
1085
|
}
|
|
1068
1086
|
async function buildAlpineDataFile(componentData, dataFiles, bundleID) {
|
|
1069
1087
|
const output = {
|
|
@@ -1110,13 +1128,13 @@ async function buildAlpineDataFile(componentData, dataFiles, bundleID) {
|
|
|
1110
1128
|
}
|
|
1111
1129
|
const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
|
|
1112
1130
|
if (bundleID) {
|
|
1113
|
-
const bundlePath =
|
|
1114
|
-
|
|
1115
|
-
|
|
1131
|
+
const bundlePath = path7.join(config.distTempFolder, `./alpine-data-${bundleID}.ts`);
|
|
1132
|
+
fs8.ensureFileSync(bundlePath);
|
|
1133
|
+
fs8.writeFileSync(bundlePath, result);
|
|
1116
1134
|
return bundlePath;
|
|
1117
1135
|
} else {
|
|
1118
|
-
|
|
1119
|
-
|
|
1136
|
+
fs8.ensureFileSync(config.alpineDataPath);
|
|
1137
|
+
fs8.writeFileSync(config.alpineDataPath, result);
|
|
1120
1138
|
return config.alpineDataPath;
|
|
1121
1139
|
}
|
|
1122
1140
|
}
|
|
@@ -1134,8 +1152,8 @@ async function buildPublicFolderSymlinks() {
|
|
|
1134
1152
|
const splitNewPath = newPath.split("/");
|
|
1135
1153
|
splitNewPath.pop();
|
|
1136
1154
|
const newDir = splitNewPath.join("/");
|
|
1137
|
-
|
|
1138
|
-
|
|
1155
|
+
fs8.ensureDirSync(newDir);
|
|
1156
|
+
fs8.symlinkSync(file, newPath);
|
|
1139
1157
|
} catch {
|
|
1140
1158
|
}
|
|
1141
1159
|
}
|
|
@@ -1146,8 +1164,8 @@ async function buildPublicFolderSymlinks() {
|
|
|
1146
1164
|
const updatedNewPath = splitNewPath.join("/");
|
|
1147
1165
|
splitNewPath.pop();
|
|
1148
1166
|
const newDir = splitNewPath.join("/");
|
|
1149
|
-
|
|
1150
|
-
|
|
1167
|
+
fs8.ensureDirSync(newDir);
|
|
1168
|
+
fs8.symlinkSync(file, updatedNewPath);
|
|
1151
1169
|
} catch {
|
|
1152
1170
|
}
|
|
1153
1171
|
}
|
|
@@ -1158,7 +1176,7 @@ async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
|
|
|
1158
1176
|
if (!validExtensions?.find((ext) => file.endsWith(ext))) return false;
|
|
1159
1177
|
return {
|
|
1160
1178
|
file,
|
|
1161
|
-
size:
|
|
1179
|
+
size: fs8.statSync(file).size / (1024 * 1e3)
|
|
1162
1180
|
};
|
|
1163
1181
|
}).filter(Boolean);
|
|
1164
1182
|
const totalSize = fileSizes.reduce((total, current) => {
|
|
@@ -1216,9 +1234,9 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
1216
1234
|
routePath: urlPath
|
|
1217
1235
|
};
|
|
1218
1236
|
const staticComponentOutput = await componentFn({ data, routePath: urlPath, req });
|
|
1219
|
-
const htmlOutputPath =
|
|
1220
|
-
|
|
1221
|
-
|
|
1237
|
+
const htmlOutputPath = path7.join(outputPath, "./index.html");
|
|
1238
|
+
fs8.ensureFileSync(htmlOutputPath);
|
|
1239
|
+
fs8.writeFileSync(
|
|
1222
1240
|
htmlOutputPath,
|
|
1223
1241
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
1224
1242
|
);
|
|
@@ -1230,7 +1248,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
1230
1248
|
const dynamicPaths = await config2.staticPaths();
|
|
1231
1249
|
for (const dynamicPath of dynamicPaths) {
|
|
1232
1250
|
try {
|
|
1233
|
-
const updatedOutDir =
|
|
1251
|
+
const updatedOutDir = path7.join(outputPath, `./${componentDynamicPaths.map((key) => dynamicPath[key]).join("/")}`);
|
|
1234
1252
|
const urlPath = filePathToURLPath(updatedOutDir);
|
|
1235
1253
|
const req = {
|
|
1236
1254
|
params: {
|
|
@@ -1244,9 +1262,9 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
1244
1262
|
let data = config2?.data ? await config2.data(req) : null;
|
|
1245
1263
|
data = { ...data, routePath: urlPath };
|
|
1246
1264
|
const staticComponentOutput = await componentFn({ req, data, routePath: urlPath });
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1265
|
+
fs8.ensureDirSync(updatedOutDir);
|
|
1266
|
+
fs8.writeFileSync(
|
|
1267
|
+
path7.join(updatedOutDir, "./index.html"),
|
|
1250
1268
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
1251
1269
|
);
|
|
1252
1270
|
} catch (err) {
|
|
@@ -1260,10 +1278,10 @@ function determineOutputPathForStaticPath(builtComponentPath, componentDynamicPa
|
|
|
1260
1278
|
if (componentDynamicPaths?.length) {
|
|
1261
1279
|
return componentDynamicPaths.reduce((total, current) => {
|
|
1262
1280
|
return total.replace(`/[...${current}]`, "").replace(`/[${current}]`, "");
|
|
1263
|
-
},
|
|
1281
|
+
}, path7.dirname(builtComponentPath));
|
|
1264
1282
|
} else {
|
|
1265
1283
|
if (builtComponentPath?.match(regex_default.endsWithIndex)) {
|
|
1266
|
-
return
|
|
1284
|
+
return path7.dirname(builtComponentPath);
|
|
1267
1285
|
} else {
|
|
1268
1286
|
if (!builtComponentPath.match(regex_default.endsWithJs)) return null;
|
|
1269
1287
|
return builtComponentPath.replace(regex_default.endsWithJs, "");
|
|
@@ -1310,8 +1328,8 @@ async function buildOnLoadFile(componentData, isDev2) {
|
|
|
1310
1328
|
context.runArrayQueue();
|
|
1311
1329
|
}
|
|
1312
1330
|
`;
|
|
1313
|
-
const onLoadFilePath =
|
|
1314
|
-
|
|
1331
|
+
const onLoadFilePath = path7.join(config.distDir, "./__xpineOnLoad.ts");
|
|
1332
|
+
fs8.writeFileSync(onLoadFilePath, output);
|
|
1315
1333
|
await build({
|
|
1316
1334
|
entryPoints: [onLoadFilePath],
|
|
1317
1335
|
format: "esm",
|
|
@@ -1366,20 +1384,20 @@ async function buildSitemap() {
|
|
|
1366
1384
|
}).join("\n")}
|
|
1367
1385
|
</urlset>
|
|
1368
1386
|
`;
|
|
1369
|
-
|
|
1370
|
-
|
|
1387
|
+
fs8.ensureFileSync(config.sitemapPath);
|
|
1388
|
+
fs8.writeFileSync(config.sitemapPath, minifyXML(sitemap));
|
|
1371
1389
|
}
|
|
1372
1390
|
|
|
1373
1391
|
// src/runDevServer.ts
|
|
1374
|
-
import
|
|
1392
|
+
import path9 from "path";
|
|
1375
1393
|
|
|
1376
1394
|
// src/util/env.ts
|
|
1377
1395
|
import dotenv from "dotenv";
|
|
1378
|
-
import
|
|
1396
|
+
import path8 from "path";
|
|
1379
1397
|
import { GetSecretValueCommand, SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
|
|
1380
1398
|
async function setupEnv() {
|
|
1381
1399
|
if (process.env.HAS_SETUP_ENV) return;
|
|
1382
|
-
dotenv.config({ path:
|
|
1400
|
+
dotenv.config({ path: path8.join(config.rootDir, `./.env.${process.env.STAGE || "dev"}`) });
|
|
1383
1401
|
await loadSecretsManagerSecrets();
|
|
1384
1402
|
process.env.HAS_SETUP_ENV = "true";
|
|
1385
1403
|
}
|
|
@@ -1416,12 +1434,12 @@ async function runDevServer() {
|
|
|
1416
1434
|
const watcher = chokidar.watch(config.srcDir, {
|
|
1417
1435
|
ignoreInitial: true,
|
|
1418
1436
|
// Ignore map and prisma files
|
|
1419
|
-
ignored: (pathName) => pathName.endsWith(".map") || pathName.startsWith(
|
|
1437
|
+
ignored: (pathName) => pathName.endsWith(".map") || pathName.startsWith(path9.join(config.serverDir, "./prisma"))
|
|
1420
1438
|
});
|
|
1421
|
-
watcher.on("all", async (event,
|
|
1422
|
-
const isRegularExpressRoute =
|
|
1423
|
-
const isServerDir =
|
|
1424
|
-
const shouldReloadServer = isServerDir || isRegularExpressRoute || ["add", "unlink"].includes(event) &&
|
|
1439
|
+
watcher.on("all", async (event, path10) => {
|
|
1440
|
+
const isRegularExpressRoute = path10.startsWith(config.pagesDir) && (path10.endsWith(".ts") || path10.endsWith(".js"));
|
|
1441
|
+
const isServerDir = path10.startsWith(config.serverDir) && !path10.startsWith(config.runDir);
|
|
1442
|
+
const shouldReloadServer = isServerDir || isRegularExpressRoute || ["add", "unlink"].includes(event) && path10.startsWith(config.pagesDir);
|
|
1425
1443
|
if (shouldReloadServer) {
|
|
1426
1444
|
await asyncServerClose(appServer.server);
|
|
1427
1445
|
rebuildEmitter.emit("rebuild-server");
|
|
@@ -1451,11 +1469,18 @@ async function runDevServer() {
|
|
|
1451
1469
|
ws.send("refresh:client");
|
|
1452
1470
|
});
|
|
1453
1471
|
});
|
|
1454
|
-
const wsPort =
|
|
1472
|
+
const wsPort = getDevServerWsPort();
|
|
1455
1473
|
wsServer.listen(wsPort);
|
|
1456
1474
|
wsServer.on("listening", () => {
|
|
1457
1475
|
console.info(`Dev server listening on port ${wsPort}`);
|
|
1458
1476
|
});
|
|
1477
|
+
wsServer.prependListener("error", (err) => {
|
|
1478
|
+
if (err.code === "EADDRINUSE") {
|
|
1479
|
+
console.error(`Live-reload port ${wsPort} is already in use (another dev server?). Set WS_PORT or PORT to use a different port.`);
|
|
1480
|
+
process.exit(1);
|
|
1481
|
+
}
|
|
1482
|
+
throw err;
|
|
1483
|
+
});
|
|
1459
1484
|
}
|
|
1460
1485
|
function asyncServerClose(server) {
|
|
1461
1486
|
return new Promise((resolve) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runDevServer.d.ts","sourceRoot":"","sources":["../../src/runDevServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runDevServer.d.ts","sourceRoot":"","sources":["../../src/runDevServer.ts"],"names":[],"mappings":"AAaA,wBAAsB,YAAY,kBAuEjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,UAAU,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;AAajF,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAA;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,iBAgDhD;AA6JD,wBAAsB,yBAAyB,kBAiC9C;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,WAAkB,iBAa9F;AAED,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,aAAa,EAAE,iBAezE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,iBA2FpI;AAED,wBAAgB,gCAAgC,CAAC,kBAAkB,EAAE,MAAM,EAAE,qBAAqB,CAAC,EAAE,MAAM,EAAE,UAgB5G;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAUxE;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAA;AAGD,wBAAsB,eAAe,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,iBAoDpF;AAED,wBAAsB,YAAY,kBA4CjC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/scripts/build.ts
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import path6 from "path";
|
|
5
|
+
import fs8 from "fs-extra";
|
|
6
6
|
import { build } from "esbuild";
|
|
7
7
|
import micromatch from "micromatch";
|
|
8
8
|
import minifyXML from "minify-xml";
|
|
@@ -300,18 +300,27 @@ async function triggerXPineOnLoad(noCache = false) {
|
|
|
300
300
|
import { globSync as globSync3 } from "glob";
|
|
301
301
|
|
|
302
302
|
// src/util/paths.ts
|
|
303
|
+
import path3 from "path";
|
|
304
|
+
import fs2 from "fs";
|
|
303
305
|
function getXPineDistDir() {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
306
|
+
let dir = import.meta.dirname;
|
|
307
|
+
while (true) {
|
|
308
|
+
const packageJsonPath = path3.join(dir, "package.json");
|
|
309
|
+
if (fs2.existsSync(packageJsonPath)) {
|
|
310
|
+
try {
|
|
311
|
+
const packageJson2 = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
|
|
312
|
+
if (packageJson2?.name === "xpine") return path3.join(dir, "dist");
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const parent = path3.dirname(dir);
|
|
317
|
+
if (parent === dir) throw new Error(`Could not find the xpine package root from ${import.meta.dirname}`);
|
|
318
|
+
dir = parent;
|
|
309
319
|
}
|
|
310
|
-
return splitDir[0] + "/xpine/dist";
|
|
311
320
|
}
|
|
312
321
|
|
|
313
322
|
// src/build/esbuild/transformTSXFiles.ts
|
|
314
|
-
import
|
|
323
|
+
import fs3 from "fs-extra";
|
|
315
324
|
import ts2 from "typescript";
|
|
316
325
|
|
|
317
326
|
// src/util/regex.ts
|
|
@@ -338,14 +347,14 @@ var regex_default = {
|
|
|
338
347
|
};
|
|
339
348
|
|
|
340
349
|
// src/util/config-file.ts
|
|
341
|
-
import
|
|
350
|
+
import path4 from "path";
|
|
342
351
|
function sourcePathToDistPath(sourcePath) {
|
|
343
352
|
return sourcePath?.replace(config.srcDir, config.distDir)?.replace(/\.ts$/, ".js")?.replace(/\.tsx$/, ".js");
|
|
344
353
|
}
|
|
345
354
|
function getConfigFiles(pathName, pageConfigFiles, returnDistPaths = true) {
|
|
346
355
|
const configs = [];
|
|
347
356
|
for (const configFile of pageConfigFiles) {
|
|
348
|
-
const result =
|
|
357
|
+
const result = path4.relative(pathName, configFile)?.replace(regex_default.configFile, "");
|
|
349
358
|
const hasLetters = result.match(regex_default.hasLetters);
|
|
350
359
|
if (!hasLetters) {
|
|
351
360
|
configs.push(returnDistPaths ? sourcePathToDistPath(configFile) : configFile);
|
|
@@ -374,7 +383,7 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
374
383
|
name: "transform-tsx-files",
|
|
375
384
|
setup(build2) {
|
|
376
385
|
build2.onLoad({ filter: regex_default.dotTsx }, async (args) => {
|
|
377
|
-
const content =
|
|
386
|
+
const content = fs3.readFileSync(args.path, "utf-8");
|
|
378
387
|
const source = ts2.createSourceFile(
|
|
379
388
|
args.path,
|
|
380
389
|
content,
|
|
@@ -402,8 +411,8 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
402
411
|
}
|
|
403
412
|
|
|
404
413
|
// src/build/esbuild/addDotJS.ts
|
|
405
|
-
import
|
|
406
|
-
import
|
|
414
|
+
import fs4 from "fs-extra";
|
|
415
|
+
import path5 from "path";
|
|
407
416
|
import builtinModules from "builtin-modules";
|
|
408
417
|
function addDotJS(allPackages2, extensions2, isDev3) {
|
|
409
418
|
const allPackagesIncludingNode = allPackages2.concat(builtinModules);
|
|
@@ -414,11 +423,11 @@ function addDotJS(allPackages2, extensions2, isDev3) {
|
|
|
414
423
|
const hasAtSign = args.path.startsWith("@");
|
|
415
424
|
const isPackage = hasAtSign ? allPackagesIncludingNode.includes(args.path) : allPackagesIncludingNode.includes(args.path.split("/").shift());
|
|
416
425
|
if (args.importer && !isPackage) {
|
|
417
|
-
const calculatedDir =
|
|
426
|
+
const calculatedDir = path5.join(args.resolveDir, args.path);
|
|
418
427
|
let existsAsFile = false;
|
|
419
428
|
for (const extension of extensions2) {
|
|
420
429
|
const asFile = calculatedDir + extension;
|
|
421
|
-
const exists =
|
|
430
|
+
const exists = fs4.existsSync(asFile);
|
|
422
431
|
if (exists) existsAsFile = true;
|
|
423
432
|
}
|
|
424
433
|
let outputPath = args.path + (existsAsFile ? "" : "/index") + ".js";
|
|
@@ -431,13 +440,13 @@ function addDotJS(allPackages2, extensions2, isDev3) {
|
|
|
431
440
|
}
|
|
432
441
|
|
|
433
442
|
// src/build/esbuild/getDataFiles.ts
|
|
434
|
-
import
|
|
443
|
+
import fs5 from "fs-extra";
|
|
435
444
|
function getDataFiles(dataFiles) {
|
|
436
445
|
return {
|
|
437
446
|
name: "get-data-files",
|
|
438
447
|
setup(build2) {
|
|
439
448
|
build2.onLoad({ filter: /\.data\.(js|mjs|ts)$/ }, (args) => {
|
|
440
|
-
const contents =
|
|
449
|
+
const contents = fs5.readFileSync(args.path, "utf-8");
|
|
441
450
|
dataFiles.push({
|
|
442
451
|
...args,
|
|
443
452
|
contents
|
|
@@ -455,6 +464,15 @@ function getDataFiles(dataFiles) {
|
|
|
455
464
|
var doctypeHTML = "<!DOCTYPE html>";
|
|
456
465
|
var staticComment = "<!-- static -->";
|
|
457
466
|
|
|
467
|
+
// src/util/dev-server-port.ts
|
|
468
|
+
function getDevServerWsPort() {
|
|
469
|
+
const wsPort = Number.parseInt(process.env.WS_PORT || "", 10);
|
|
470
|
+
if (Number.isInteger(wsPort) && wsPort > 0) return wsPort;
|
|
471
|
+
const appPort = Number.parseInt(process.env.PORT || "", 10);
|
|
472
|
+
if (Number.isInteger(appPort) && appPort > 0) return appPort + 1;
|
|
473
|
+
return 3001;
|
|
474
|
+
}
|
|
475
|
+
|
|
458
476
|
// src/scripts/build.ts
|
|
459
477
|
import ts3 from "typescript";
|
|
460
478
|
|
|
@@ -468,7 +486,7 @@ var { verify, sign } = jsonwebtoken;
|
|
|
468
486
|
|
|
469
487
|
// src/express.ts
|
|
470
488
|
import requestIP from "request-ip";
|
|
471
|
-
import
|
|
489
|
+
import fs6 from "fs-extra";
|
|
472
490
|
import EventEmitter from "events";
|
|
473
491
|
var isDev = process.env.NODE_ENV === "development";
|
|
474
492
|
var OnInitEmitter = class extends EventEmitter {
|
|
@@ -492,7 +510,7 @@ function filePathToURLPath(pathName, isDist = true) {
|
|
|
492
510
|
|
|
493
511
|
// src/build/css.ts
|
|
494
512
|
import { globSync as globSync2 } from "glob";
|
|
495
|
-
import
|
|
513
|
+
import fs7 from "fs-extra";
|
|
496
514
|
import postcss from "postcss";
|
|
497
515
|
|
|
498
516
|
// src/build/postcss/remove-layers.ts
|
|
@@ -561,15 +579,15 @@ async function buildCSS(disableTailwind2) {
|
|
|
561
579
|
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
562
580
|
for (const file of cssFiles) {
|
|
563
581
|
try {
|
|
564
|
-
const fileContents =
|
|
582
|
+
const fileContents = fs7.readFileSync(file, "utf-8");
|
|
565
583
|
let result = fileContents;
|
|
566
584
|
if (!disableTailwind2) {
|
|
567
585
|
result = await postcss([add_breakpoint_data_default()]).process(fileContents, { from: file });
|
|
568
586
|
result = await postcss([tailwindPostcss(), remove_layers_default()]).process(result.css, { from: file });
|
|
569
587
|
}
|
|
570
588
|
const newPath = file.replace(config.srcDir, config.distDir);
|
|
571
|
-
|
|
572
|
-
|
|
589
|
+
fs7.ensureFileSync(newPath);
|
|
590
|
+
fs7.writeFileSync(newPath, result.css);
|
|
573
591
|
} catch (err) {
|
|
574
592
|
console.error(err);
|
|
575
593
|
}
|
|
@@ -579,7 +597,7 @@ async function buildCSS(disableTailwind2) {
|
|
|
579
597
|
|
|
580
598
|
// src/scripts/build.ts
|
|
581
599
|
var extensions = [".ts", ".tsx"];
|
|
582
|
-
var packageJson = JSON.parse(
|
|
600
|
+
var packageJson = JSON.parse(fs8.readFileSync(config.packageJsonPath, "utf-8"));
|
|
583
601
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
584
602
|
var xpineDistDir = getXPineDistDir();
|
|
585
603
|
async function buildApp(args) {
|
|
@@ -587,7 +605,7 @@ async function buildApp(args) {
|
|
|
587
605
|
const removePreviousBuild2 = args?.removePreviousBuild || false;
|
|
588
606
|
const disableTailwind2 = args?.disableTailwind || false;
|
|
589
607
|
try {
|
|
590
|
-
if (removePreviousBuild2)
|
|
608
|
+
if (removePreviousBuild2) fs8.removeSync(config.distDir);
|
|
591
609
|
const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
592
610
|
const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev3);
|
|
593
611
|
const clientSideBundles = [];
|
|
@@ -612,7 +630,7 @@ async function buildApp(args) {
|
|
|
612
630
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
613
631
|
await buildClientSideFiles([alpineDataFile, ...clientSideBundles], isDev3);
|
|
614
632
|
}
|
|
615
|
-
|
|
633
|
+
fs8.removeSync(config.distTempFolder);
|
|
616
634
|
await buildCSS(disableTailwind2);
|
|
617
635
|
await buildPublicFolderSymlinks();
|
|
618
636
|
await buildOnLoadFile(componentData, isDev3);
|
|
@@ -633,7 +651,7 @@ async function buildAppFiles(files, isDev3) {
|
|
|
633
651
|
return fileName === "+config";
|
|
634
652
|
});
|
|
635
653
|
const backendFiles = files.filter((file) => extensions?.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
|
|
636
|
-
|
|
654
|
+
fs8.ensureDirSync(config.distDir);
|
|
637
655
|
await build({
|
|
638
656
|
entryPoints: backendFiles,
|
|
639
657
|
format: "esm",
|
|
@@ -657,8 +675,8 @@ async function buildAppFiles(files, isDev3) {
|
|
|
657
675
|
};
|
|
658
676
|
}
|
|
659
677
|
async function buildClientSideFiles(alpineDataFiles = [], isDev3, tempClientSidePath, id) {
|
|
660
|
-
const tempFilePath =
|
|
661
|
-
|
|
678
|
+
const tempFilePath = path6.join(config.distTempFolder, tempClientSidePath || "./app.ts");
|
|
679
|
+
fs8.ensureFileSync(tempFilePath);
|
|
662
680
|
const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
|
|
663
681
|
const standaloneFolderGlob = config.publicDir + "/standalone/**/*.*";
|
|
664
682
|
const clientFiles = globSync3(
|
|
@@ -691,14 +709,14 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev3, tempClientSide
|
|
|
691
709
|
await logSize(config.distPublicDir, id ? `client bundle: ${id}.js` : "client bundle: app.js");
|
|
692
710
|
}
|
|
693
711
|
function writeDevServerClientSideCode(tempFilePath) {
|
|
694
|
-
const devServerPath =
|
|
695
|
-
const content =
|
|
696
|
-
|
|
712
|
+
const devServerPath = path6.join(xpineDistDir, "./src/static/dev-server.js");
|
|
713
|
+
const content = fs8.readFileSync(devServerPath, "utf-8").replace("__XPINE_WS_PORT__", String(getDevServerWsPort()));
|
|
714
|
+
fs8.appendFileSync(tempFilePath, "\n" + content);
|
|
697
715
|
}
|
|
698
716
|
function writeSpaClientSideCode(tempFilePath) {
|
|
699
|
-
const spaPath =
|
|
700
|
-
const content =
|
|
701
|
-
|
|
717
|
+
const spaPath = path6.join(xpineDistDir, "./src/static/spa.js");
|
|
718
|
+
const content = fs8.readFileSync(spaPath, "utf-8");
|
|
719
|
+
fs8.appendFileSync(tempFilePath, "\n" + content);
|
|
702
720
|
}
|
|
703
721
|
async function buildAlpineDataFile(componentData, dataFiles, bundleID) {
|
|
704
722
|
const output = {
|
|
@@ -745,13 +763,13 @@ async function buildAlpineDataFile(componentData, dataFiles, bundleID) {
|
|
|
745
763
|
}
|
|
746
764
|
const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
|
|
747
765
|
if (bundleID) {
|
|
748
|
-
const bundlePath =
|
|
749
|
-
|
|
750
|
-
|
|
766
|
+
const bundlePath = path6.join(config.distTempFolder, `./alpine-data-${bundleID}.ts`);
|
|
767
|
+
fs8.ensureFileSync(bundlePath);
|
|
768
|
+
fs8.writeFileSync(bundlePath, result);
|
|
751
769
|
return bundlePath;
|
|
752
770
|
} else {
|
|
753
|
-
|
|
754
|
-
|
|
771
|
+
fs8.ensureFileSync(config.alpineDataPath);
|
|
772
|
+
fs8.writeFileSync(config.alpineDataPath, result);
|
|
755
773
|
return config.alpineDataPath;
|
|
756
774
|
}
|
|
757
775
|
}
|
|
@@ -769,8 +787,8 @@ async function buildPublicFolderSymlinks() {
|
|
|
769
787
|
const splitNewPath = newPath.split("/");
|
|
770
788
|
splitNewPath.pop();
|
|
771
789
|
const newDir = splitNewPath.join("/");
|
|
772
|
-
|
|
773
|
-
|
|
790
|
+
fs8.ensureDirSync(newDir);
|
|
791
|
+
fs8.symlinkSync(file, newPath);
|
|
774
792
|
} catch {
|
|
775
793
|
}
|
|
776
794
|
}
|
|
@@ -781,8 +799,8 @@ async function buildPublicFolderSymlinks() {
|
|
|
781
799
|
const updatedNewPath = splitNewPath.join("/");
|
|
782
800
|
splitNewPath.pop();
|
|
783
801
|
const newDir = splitNewPath.join("/");
|
|
784
|
-
|
|
785
|
-
|
|
802
|
+
fs8.ensureDirSync(newDir);
|
|
803
|
+
fs8.symlinkSync(file, updatedNewPath);
|
|
786
804
|
} catch {
|
|
787
805
|
}
|
|
788
806
|
}
|
|
@@ -793,7 +811,7 @@ async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
|
|
|
793
811
|
if (!validExtensions?.find((ext) => file.endsWith(ext))) return false;
|
|
794
812
|
return {
|
|
795
813
|
file,
|
|
796
|
-
size:
|
|
814
|
+
size: fs8.statSync(file).size / (1024 * 1e3)
|
|
797
815
|
};
|
|
798
816
|
}).filter(Boolean);
|
|
799
817
|
const totalSize = fileSizes.reduce((total, current) => {
|
|
@@ -851,9 +869,9 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
851
869
|
routePath: urlPath
|
|
852
870
|
};
|
|
853
871
|
const staticComponentOutput = await componentFn({ data, routePath: urlPath, req });
|
|
854
|
-
const htmlOutputPath =
|
|
855
|
-
|
|
856
|
-
|
|
872
|
+
const htmlOutputPath = path6.join(outputPath, "./index.html");
|
|
873
|
+
fs8.ensureFileSync(htmlOutputPath);
|
|
874
|
+
fs8.writeFileSync(
|
|
857
875
|
htmlOutputPath,
|
|
858
876
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
859
877
|
);
|
|
@@ -865,7 +883,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
865
883
|
const dynamicPaths = await config2.staticPaths();
|
|
866
884
|
for (const dynamicPath of dynamicPaths) {
|
|
867
885
|
try {
|
|
868
|
-
const updatedOutDir =
|
|
886
|
+
const updatedOutDir = path6.join(outputPath, `./${componentDynamicPaths.map((key) => dynamicPath[key]).join("/")}`);
|
|
869
887
|
const urlPath = filePathToURLPath(updatedOutDir);
|
|
870
888
|
const req = {
|
|
871
889
|
params: {
|
|
@@ -879,9 +897,9 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
879
897
|
let data = config2?.data ? await config2.data(req) : null;
|
|
880
898
|
data = { ...data, routePath: urlPath };
|
|
881
899
|
const staticComponentOutput = await componentFn({ req, data, routePath: urlPath });
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
900
|
+
fs8.ensureDirSync(updatedOutDir);
|
|
901
|
+
fs8.writeFileSync(
|
|
902
|
+
path6.join(updatedOutDir, "./index.html"),
|
|
885
903
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
886
904
|
);
|
|
887
905
|
} catch (err) {
|
|
@@ -895,10 +913,10 @@ function determineOutputPathForStaticPath(builtComponentPath, componentDynamicPa
|
|
|
895
913
|
if (componentDynamicPaths?.length) {
|
|
896
914
|
return componentDynamicPaths.reduce((total, current) => {
|
|
897
915
|
return total.replace(`/[...${current}]`, "").replace(`/[${current}]`, "");
|
|
898
|
-
},
|
|
916
|
+
}, path6.dirname(builtComponentPath));
|
|
899
917
|
} else {
|
|
900
918
|
if (builtComponentPath?.match(regex_default.endsWithIndex)) {
|
|
901
|
-
return
|
|
919
|
+
return path6.dirname(builtComponentPath);
|
|
902
920
|
} else {
|
|
903
921
|
if (!builtComponentPath.match(regex_default.endsWithJs)) return null;
|
|
904
922
|
return builtComponentPath.replace(regex_default.endsWithJs, "");
|
|
@@ -945,8 +963,8 @@ async function buildOnLoadFile(componentData, isDev3) {
|
|
|
945
963
|
context.runArrayQueue();
|
|
946
964
|
}
|
|
947
965
|
`;
|
|
948
|
-
const onLoadFilePath =
|
|
949
|
-
|
|
966
|
+
const onLoadFilePath = path6.join(config.distDir, "./__xpineOnLoad.ts");
|
|
967
|
+
fs8.writeFileSync(onLoadFilePath, output);
|
|
950
968
|
await build({
|
|
951
969
|
entryPoints: [onLoadFilePath],
|
|
952
970
|
format: "esm",
|
|
@@ -1001,8 +1019,8 @@ async function buildSitemap() {
|
|
|
1001
1019
|
}).join("\n")}
|
|
1002
1020
|
</urlset>
|
|
1003
1021
|
`;
|
|
1004
|
-
|
|
1005
|
-
|
|
1022
|
+
fs8.ensureFileSync(config.sitemapPath);
|
|
1023
|
+
fs8.writeFileSync(config.sitemapPath, minifyXML(sitemap));
|
|
1006
1024
|
}
|
|
1007
1025
|
|
|
1008
1026
|
// src/scripts/xpine-build.ts
|
|
@@ -8,8 +8,8 @@ import EventEmitter2 from "events";
|
|
|
8
8
|
import chokidar from "chokidar";
|
|
9
9
|
|
|
10
10
|
// src/scripts/build.ts
|
|
11
|
-
import
|
|
12
|
-
import
|
|
11
|
+
import path6 from "path";
|
|
12
|
+
import fs8 from "fs-extra";
|
|
13
13
|
import { build } from "esbuild";
|
|
14
14
|
import micromatch from "micromatch";
|
|
15
15
|
import minifyXML from "minify-xml";
|
|
@@ -307,18 +307,27 @@ async function triggerXPineOnLoad(noCache = false) {
|
|
|
307
307
|
import { globSync as globSync3 } from "glob";
|
|
308
308
|
|
|
309
309
|
// src/util/paths.ts
|
|
310
|
+
import path3 from "path";
|
|
311
|
+
import fs2 from "fs";
|
|
310
312
|
function getXPineDistDir() {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
313
|
+
let dir = import.meta.dirname;
|
|
314
|
+
while (true) {
|
|
315
|
+
const packageJsonPath = path3.join(dir, "package.json");
|
|
316
|
+
if (fs2.existsSync(packageJsonPath)) {
|
|
317
|
+
try {
|
|
318
|
+
const packageJson2 = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
|
|
319
|
+
if (packageJson2?.name === "xpine") return path3.join(dir, "dist");
|
|
320
|
+
} catch {
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const parent = path3.dirname(dir);
|
|
324
|
+
if (parent === dir) throw new Error(`Could not find the xpine package root from ${import.meta.dirname}`);
|
|
325
|
+
dir = parent;
|
|
316
326
|
}
|
|
317
|
-
return splitDir[0] + "/xpine/dist";
|
|
318
327
|
}
|
|
319
328
|
|
|
320
329
|
// src/build/esbuild/transformTSXFiles.ts
|
|
321
|
-
import
|
|
330
|
+
import fs3 from "fs-extra";
|
|
322
331
|
import ts2 from "typescript";
|
|
323
332
|
|
|
324
333
|
// src/util/regex.ts
|
|
@@ -345,14 +354,14 @@ var regex_default = {
|
|
|
345
354
|
};
|
|
346
355
|
|
|
347
356
|
// src/util/config-file.ts
|
|
348
|
-
import
|
|
357
|
+
import path4 from "path";
|
|
349
358
|
function sourcePathToDistPath(sourcePath) {
|
|
350
359
|
return sourcePath?.replace(config.srcDir, config.distDir)?.replace(/\.ts$/, ".js")?.replace(/\.tsx$/, ".js");
|
|
351
360
|
}
|
|
352
361
|
function getConfigFiles(pathName, pageConfigFiles, returnDistPaths = true) {
|
|
353
362
|
const configs = [];
|
|
354
363
|
for (const configFile of pageConfigFiles) {
|
|
355
|
-
const result =
|
|
364
|
+
const result = path4.relative(pathName, configFile)?.replace(regex_default.configFile, "");
|
|
356
365
|
const hasLetters = result.match(regex_default.hasLetters);
|
|
357
366
|
if (!hasLetters) {
|
|
358
367
|
configs.push(returnDistPaths ? sourcePathToDistPath(configFile) : configFile);
|
|
@@ -381,7 +390,7 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
381
390
|
name: "transform-tsx-files",
|
|
382
391
|
setup(build2) {
|
|
383
392
|
build2.onLoad({ filter: regex_default.dotTsx }, async (args) => {
|
|
384
|
-
const content =
|
|
393
|
+
const content = fs3.readFileSync(args.path, "utf-8");
|
|
385
394
|
const source = ts2.createSourceFile(
|
|
386
395
|
args.path,
|
|
387
396
|
content,
|
|
@@ -409,8 +418,8 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
409
418
|
}
|
|
410
419
|
|
|
411
420
|
// src/build/esbuild/addDotJS.ts
|
|
412
|
-
import
|
|
413
|
-
import
|
|
421
|
+
import fs4 from "fs-extra";
|
|
422
|
+
import path5 from "path";
|
|
414
423
|
import builtinModules from "builtin-modules";
|
|
415
424
|
function addDotJS(allPackages2, extensions2, isDev2) {
|
|
416
425
|
const allPackagesIncludingNode = allPackages2.concat(builtinModules);
|
|
@@ -421,11 +430,11 @@ function addDotJS(allPackages2, extensions2, isDev2) {
|
|
|
421
430
|
const hasAtSign = args.path.startsWith("@");
|
|
422
431
|
const isPackage = hasAtSign ? allPackagesIncludingNode.includes(args.path) : allPackagesIncludingNode.includes(args.path.split("/").shift());
|
|
423
432
|
if (args.importer && !isPackage) {
|
|
424
|
-
const calculatedDir =
|
|
433
|
+
const calculatedDir = path5.join(args.resolveDir, args.path);
|
|
425
434
|
let existsAsFile = false;
|
|
426
435
|
for (const extension of extensions2) {
|
|
427
436
|
const asFile = calculatedDir + extension;
|
|
428
|
-
const exists =
|
|
437
|
+
const exists = fs4.existsSync(asFile);
|
|
429
438
|
if (exists) existsAsFile = true;
|
|
430
439
|
}
|
|
431
440
|
let outputPath = args.path + (existsAsFile ? "" : "/index") + ".js";
|
|
@@ -438,13 +447,13 @@ function addDotJS(allPackages2, extensions2, isDev2) {
|
|
|
438
447
|
}
|
|
439
448
|
|
|
440
449
|
// src/build/esbuild/getDataFiles.ts
|
|
441
|
-
import
|
|
450
|
+
import fs5 from "fs-extra";
|
|
442
451
|
function getDataFiles(dataFiles) {
|
|
443
452
|
return {
|
|
444
453
|
name: "get-data-files",
|
|
445
454
|
setup(build2) {
|
|
446
455
|
build2.onLoad({ filter: /\.data\.(js|mjs|ts)$/ }, (args) => {
|
|
447
|
-
const contents =
|
|
456
|
+
const contents = fs5.readFileSync(args.path, "utf-8");
|
|
448
457
|
dataFiles.push({
|
|
449
458
|
...args,
|
|
450
459
|
contents
|
|
@@ -462,6 +471,15 @@ function getDataFiles(dataFiles) {
|
|
|
462
471
|
var doctypeHTML = "<!DOCTYPE html>";
|
|
463
472
|
var staticComment = "<!-- static -->";
|
|
464
473
|
|
|
474
|
+
// src/util/dev-server-port.ts
|
|
475
|
+
function getDevServerWsPort() {
|
|
476
|
+
const wsPort = Number.parseInt(process.env.WS_PORT || "", 10);
|
|
477
|
+
if (Number.isInteger(wsPort) && wsPort > 0) return wsPort;
|
|
478
|
+
const appPort = Number.parseInt(process.env.PORT || "", 10);
|
|
479
|
+
if (Number.isInteger(appPort) && appPort > 0) return appPort + 1;
|
|
480
|
+
return 3001;
|
|
481
|
+
}
|
|
482
|
+
|
|
465
483
|
// src/scripts/build.ts
|
|
466
484
|
import ts3 from "typescript";
|
|
467
485
|
|
|
@@ -475,7 +493,7 @@ var { verify, sign } = jsonwebtoken;
|
|
|
475
493
|
|
|
476
494
|
// src/express.ts
|
|
477
495
|
import requestIP from "request-ip";
|
|
478
|
-
import
|
|
496
|
+
import fs6 from "fs-extra";
|
|
479
497
|
import EventEmitter from "events";
|
|
480
498
|
var isDev = process.env.NODE_ENV === "development";
|
|
481
499
|
var OnInitEmitter = class extends EventEmitter {
|
|
@@ -499,7 +517,7 @@ function filePathToURLPath(pathName, isDist = true) {
|
|
|
499
517
|
|
|
500
518
|
// src/build/css.ts
|
|
501
519
|
import { globSync as globSync2 } from "glob";
|
|
502
|
-
import
|
|
520
|
+
import fs7 from "fs-extra";
|
|
503
521
|
import postcss from "postcss";
|
|
504
522
|
|
|
505
523
|
// src/build/postcss/remove-layers.ts
|
|
@@ -568,15 +586,15 @@ async function buildCSS(disableTailwind) {
|
|
|
568
586
|
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
569
587
|
for (const file of cssFiles) {
|
|
570
588
|
try {
|
|
571
|
-
const fileContents =
|
|
589
|
+
const fileContents = fs7.readFileSync(file, "utf-8");
|
|
572
590
|
let result = fileContents;
|
|
573
591
|
if (!disableTailwind) {
|
|
574
592
|
result = await postcss([add_breakpoint_data_default()]).process(fileContents, { from: file });
|
|
575
593
|
result = await postcss([tailwindPostcss(), remove_layers_default()]).process(result.css, { from: file });
|
|
576
594
|
}
|
|
577
595
|
const newPath = file.replace(config.srcDir, config.distDir);
|
|
578
|
-
|
|
579
|
-
|
|
596
|
+
fs7.ensureFileSync(newPath);
|
|
597
|
+
fs7.writeFileSync(newPath, result.css);
|
|
580
598
|
} catch (err) {
|
|
581
599
|
console.error(err);
|
|
582
600
|
}
|
|
@@ -586,7 +604,7 @@ async function buildCSS(disableTailwind) {
|
|
|
586
604
|
|
|
587
605
|
// src/scripts/build.ts
|
|
588
606
|
var extensions = [".ts", ".tsx"];
|
|
589
|
-
var packageJson = JSON.parse(
|
|
607
|
+
var packageJson = JSON.parse(fs8.readFileSync(config.packageJsonPath, "utf-8"));
|
|
590
608
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
591
609
|
var xpineDistDir = getXPineDistDir();
|
|
592
610
|
async function buildApp(args) {
|
|
@@ -594,7 +612,7 @@ async function buildApp(args) {
|
|
|
594
612
|
const removePreviousBuild = args?.removePreviousBuild || false;
|
|
595
613
|
const disableTailwind = args?.disableTailwind || false;
|
|
596
614
|
try {
|
|
597
|
-
if (removePreviousBuild)
|
|
615
|
+
if (removePreviousBuild) fs8.removeSync(config.distDir);
|
|
598
616
|
const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
599
617
|
const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev2);
|
|
600
618
|
const clientSideBundles = [];
|
|
@@ -619,7 +637,7 @@ async function buildApp(args) {
|
|
|
619
637
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
620
638
|
await buildClientSideFiles([alpineDataFile, ...clientSideBundles], isDev2);
|
|
621
639
|
}
|
|
622
|
-
|
|
640
|
+
fs8.removeSync(config.distTempFolder);
|
|
623
641
|
await buildCSS(disableTailwind);
|
|
624
642
|
await buildPublicFolderSymlinks();
|
|
625
643
|
await buildOnLoadFile(componentData, isDev2);
|
|
@@ -640,7 +658,7 @@ async function buildAppFiles(files, isDev2) {
|
|
|
640
658
|
return fileName === "+config";
|
|
641
659
|
});
|
|
642
660
|
const backendFiles = files.filter((file) => extensions?.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
|
|
643
|
-
|
|
661
|
+
fs8.ensureDirSync(config.distDir);
|
|
644
662
|
await build({
|
|
645
663
|
entryPoints: backendFiles,
|
|
646
664
|
format: "esm",
|
|
@@ -664,8 +682,8 @@ async function buildAppFiles(files, isDev2) {
|
|
|
664
682
|
};
|
|
665
683
|
}
|
|
666
684
|
async function buildClientSideFiles(alpineDataFiles = [], isDev2, tempClientSidePath, id) {
|
|
667
|
-
const tempFilePath =
|
|
668
|
-
|
|
685
|
+
const tempFilePath = path6.join(config.distTempFolder, tempClientSidePath || "./app.ts");
|
|
686
|
+
fs8.ensureFileSync(tempFilePath);
|
|
669
687
|
const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
|
|
670
688
|
const standaloneFolderGlob = config.publicDir + "/standalone/**/*.*";
|
|
671
689
|
const clientFiles = globSync3(
|
|
@@ -698,14 +716,14 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev2, tempClientSide
|
|
|
698
716
|
await logSize(config.distPublicDir, id ? `client bundle: ${id}.js` : "client bundle: app.js");
|
|
699
717
|
}
|
|
700
718
|
function writeDevServerClientSideCode(tempFilePath) {
|
|
701
|
-
const devServerPath =
|
|
702
|
-
const content =
|
|
703
|
-
|
|
719
|
+
const devServerPath = path6.join(xpineDistDir, "./src/static/dev-server.js");
|
|
720
|
+
const content = fs8.readFileSync(devServerPath, "utf-8").replace("__XPINE_WS_PORT__", String(getDevServerWsPort()));
|
|
721
|
+
fs8.appendFileSync(tempFilePath, "\n" + content);
|
|
704
722
|
}
|
|
705
723
|
function writeSpaClientSideCode(tempFilePath) {
|
|
706
|
-
const spaPath =
|
|
707
|
-
const content =
|
|
708
|
-
|
|
724
|
+
const spaPath = path6.join(xpineDistDir, "./src/static/spa.js");
|
|
725
|
+
const content = fs8.readFileSync(spaPath, "utf-8");
|
|
726
|
+
fs8.appendFileSync(tempFilePath, "\n" + content);
|
|
709
727
|
}
|
|
710
728
|
async function buildAlpineDataFile(componentData, dataFiles, bundleID) {
|
|
711
729
|
const output = {
|
|
@@ -752,13 +770,13 @@ async function buildAlpineDataFile(componentData, dataFiles, bundleID) {
|
|
|
752
770
|
}
|
|
753
771
|
const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
|
|
754
772
|
if (bundleID) {
|
|
755
|
-
const bundlePath =
|
|
756
|
-
|
|
757
|
-
|
|
773
|
+
const bundlePath = path6.join(config.distTempFolder, `./alpine-data-${bundleID}.ts`);
|
|
774
|
+
fs8.ensureFileSync(bundlePath);
|
|
775
|
+
fs8.writeFileSync(bundlePath, result);
|
|
758
776
|
return bundlePath;
|
|
759
777
|
} else {
|
|
760
|
-
|
|
761
|
-
|
|
778
|
+
fs8.ensureFileSync(config.alpineDataPath);
|
|
779
|
+
fs8.writeFileSync(config.alpineDataPath, result);
|
|
762
780
|
return config.alpineDataPath;
|
|
763
781
|
}
|
|
764
782
|
}
|
|
@@ -776,8 +794,8 @@ async function buildPublicFolderSymlinks() {
|
|
|
776
794
|
const splitNewPath = newPath.split("/");
|
|
777
795
|
splitNewPath.pop();
|
|
778
796
|
const newDir = splitNewPath.join("/");
|
|
779
|
-
|
|
780
|
-
|
|
797
|
+
fs8.ensureDirSync(newDir);
|
|
798
|
+
fs8.symlinkSync(file, newPath);
|
|
781
799
|
} catch {
|
|
782
800
|
}
|
|
783
801
|
}
|
|
@@ -788,8 +806,8 @@ async function buildPublicFolderSymlinks() {
|
|
|
788
806
|
const updatedNewPath = splitNewPath.join("/");
|
|
789
807
|
splitNewPath.pop();
|
|
790
808
|
const newDir = splitNewPath.join("/");
|
|
791
|
-
|
|
792
|
-
|
|
809
|
+
fs8.ensureDirSync(newDir);
|
|
810
|
+
fs8.symlinkSync(file, updatedNewPath);
|
|
793
811
|
} catch {
|
|
794
812
|
}
|
|
795
813
|
}
|
|
@@ -800,7 +818,7 @@ async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
|
|
|
800
818
|
if (!validExtensions?.find((ext) => file.endsWith(ext))) return false;
|
|
801
819
|
return {
|
|
802
820
|
file,
|
|
803
|
-
size:
|
|
821
|
+
size: fs8.statSync(file).size / (1024 * 1e3)
|
|
804
822
|
};
|
|
805
823
|
}).filter(Boolean);
|
|
806
824
|
const totalSize = fileSizes.reduce((total, current) => {
|
|
@@ -858,9 +876,9 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
858
876
|
routePath: urlPath
|
|
859
877
|
};
|
|
860
878
|
const staticComponentOutput = await componentFn({ data, routePath: urlPath, req });
|
|
861
|
-
const htmlOutputPath =
|
|
862
|
-
|
|
863
|
-
|
|
879
|
+
const htmlOutputPath = path6.join(outputPath, "./index.html");
|
|
880
|
+
fs8.ensureFileSync(htmlOutputPath);
|
|
881
|
+
fs8.writeFileSync(
|
|
864
882
|
htmlOutputPath,
|
|
865
883
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
866
884
|
);
|
|
@@ -872,7 +890,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
872
890
|
const dynamicPaths = await config2.staticPaths();
|
|
873
891
|
for (const dynamicPath of dynamicPaths) {
|
|
874
892
|
try {
|
|
875
|
-
const updatedOutDir =
|
|
893
|
+
const updatedOutDir = path6.join(outputPath, `./${componentDynamicPaths.map((key) => dynamicPath[key]).join("/")}`);
|
|
876
894
|
const urlPath = filePathToURLPath(updatedOutDir);
|
|
877
895
|
const req = {
|
|
878
896
|
params: {
|
|
@@ -886,9 +904,9 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
886
904
|
let data = config2?.data ? await config2.data(req) : null;
|
|
887
905
|
data = { ...data, routePath: urlPath };
|
|
888
906
|
const staticComponentOutput = await componentFn({ req, data, routePath: urlPath });
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
907
|
+
fs8.ensureDirSync(updatedOutDir);
|
|
908
|
+
fs8.writeFileSync(
|
|
909
|
+
path6.join(updatedOutDir, "./index.html"),
|
|
892
910
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
893
911
|
);
|
|
894
912
|
} catch (err) {
|
|
@@ -902,10 +920,10 @@ function determineOutputPathForStaticPath(builtComponentPath, componentDynamicPa
|
|
|
902
920
|
if (componentDynamicPaths?.length) {
|
|
903
921
|
return componentDynamicPaths.reduce((total, current) => {
|
|
904
922
|
return total.replace(`/[...${current}]`, "").replace(`/[${current}]`, "");
|
|
905
|
-
},
|
|
923
|
+
}, path6.dirname(builtComponentPath));
|
|
906
924
|
} else {
|
|
907
925
|
if (builtComponentPath?.match(regex_default.endsWithIndex)) {
|
|
908
|
-
return
|
|
926
|
+
return path6.dirname(builtComponentPath);
|
|
909
927
|
} else {
|
|
910
928
|
if (!builtComponentPath.match(regex_default.endsWithJs)) return null;
|
|
911
929
|
return builtComponentPath.replace(regex_default.endsWithJs, "");
|
|
@@ -952,8 +970,8 @@ async function buildOnLoadFile(componentData, isDev2) {
|
|
|
952
970
|
context.runArrayQueue();
|
|
953
971
|
}
|
|
954
972
|
`;
|
|
955
|
-
const onLoadFilePath =
|
|
956
|
-
|
|
973
|
+
const onLoadFilePath = path6.join(config.distDir, "./__xpineOnLoad.ts");
|
|
974
|
+
fs8.writeFileSync(onLoadFilePath, output);
|
|
957
975
|
await build({
|
|
958
976
|
entryPoints: [onLoadFilePath],
|
|
959
977
|
format: "esm",
|
|
@@ -1008,20 +1026,20 @@ async function buildSitemap() {
|
|
|
1008
1026
|
}).join("\n")}
|
|
1009
1027
|
</urlset>
|
|
1010
1028
|
`;
|
|
1011
|
-
|
|
1012
|
-
|
|
1029
|
+
fs8.ensureFileSync(config.sitemapPath);
|
|
1030
|
+
fs8.writeFileSync(config.sitemapPath, minifyXML(sitemap));
|
|
1013
1031
|
}
|
|
1014
1032
|
|
|
1015
1033
|
// src/runDevServer.ts
|
|
1016
|
-
import
|
|
1034
|
+
import path8 from "path";
|
|
1017
1035
|
|
|
1018
1036
|
// src/util/env.ts
|
|
1019
1037
|
import dotenv from "dotenv";
|
|
1020
|
-
import
|
|
1038
|
+
import path7 from "path";
|
|
1021
1039
|
import { GetSecretValueCommand, SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
|
|
1022
1040
|
async function setupEnv() {
|
|
1023
1041
|
if (process.env.HAS_SETUP_ENV) return;
|
|
1024
|
-
dotenv.config({ path:
|
|
1042
|
+
dotenv.config({ path: path7.join(config.rootDir, `./.env.${process.env.STAGE || "dev"}`) });
|
|
1025
1043
|
await loadSecretsManagerSecrets();
|
|
1026
1044
|
process.env.HAS_SETUP_ENV = "true";
|
|
1027
1045
|
}
|
|
@@ -1058,12 +1076,12 @@ async function runDevServer() {
|
|
|
1058
1076
|
const watcher = chokidar.watch(config.srcDir, {
|
|
1059
1077
|
ignoreInitial: true,
|
|
1060
1078
|
// Ignore map and prisma files
|
|
1061
|
-
ignored: (pathName) => pathName.endsWith(".map") || pathName.startsWith(
|
|
1079
|
+
ignored: (pathName) => pathName.endsWith(".map") || pathName.startsWith(path8.join(config.serverDir, "./prisma"))
|
|
1062
1080
|
});
|
|
1063
|
-
watcher.on("all", async (event,
|
|
1064
|
-
const isRegularExpressRoute =
|
|
1065
|
-
const isServerDir =
|
|
1066
|
-
const shouldReloadServer = isServerDir || isRegularExpressRoute || ["add", "unlink"].includes(event) &&
|
|
1081
|
+
watcher.on("all", async (event, path9) => {
|
|
1082
|
+
const isRegularExpressRoute = path9.startsWith(config.pagesDir) && (path9.endsWith(".ts") || path9.endsWith(".js"));
|
|
1083
|
+
const isServerDir = path9.startsWith(config.serverDir) && !path9.startsWith(config.runDir);
|
|
1084
|
+
const shouldReloadServer = isServerDir || isRegularExpressRoute || ["add", "unlink"].includes(event) && path9.startsWith(config.pagesDir);
|
|
1067
1085
|
if (shouldReloadServer) {
|
|
1068
1086
|
await asyncServerClose(appServer.server);
|
|
1069
1087
|
rebuildEmitter.emit("rebuild-server");
|
|
@@ -1093,11 +1111,18 @@ async function runDevServer() {
|
|
|
1093
1111
|
ws.send("refresh:client");
|
|
1094
1112
|
});
|
|
1095
1113
|
});
|
|
1096
|
-
const wsPort =
|
|
1114
|
+
const wsPort = getDevServerWsPort();
|
|
1097
1115
|
wsServer.listen(wsPort);
|
|
1098
1116
|
wsServer.on("listening", () => {
|
|
1099
1117
|
console.info(`Dev server listening on port ${wsPort}`);
|
|
1100
1118
|
});
|
|
1119
|
+
wsServer.prependListener("error", (err) => {
|
|
1120
|
+
if (err.code === "EADDRINUSE") {
|
|
1121
|
+
console.error(`Live-reload port ${wsPort} is already in use (another dev server?). Set WS_PORT or PORT to use a different port.`);
|
|
1122
|
+
process.exit(1);
|
|
1123
|
+
}
|
|
1124
|
+
throw err;
|
|
1125
|
+
});
|
|
1101
1126
|
}
|
|
1102
1127
|
function asyncServerClose(server) {
|
|
1103
1128
|
return new Promise((resolve) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/static/dev-server.mjs
|
|
2
2
|
var socketProtocol = "ws:";
|
|
3
|
-
var
|
|
3
|
+
var wsPort = "__XPINE_WS_PORT__";
|
|
4
|
+
var echoSocketUrl = socketProtocol + "//" + window.location.hostname + ":" + wsPort + "/dev-server/";
|
|
4
5
|
var socket = new WebSocket(echoSocketUrl);
|
|
5
6
|
socket.addEventListener("message", async (msg) => {
|
|
6
7
|
if (msg.data === "refresh:client") {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-server-port.d.ts","sourceRoot":"","sources":["../../../src/util/dev-server-port.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,IAAI,MAAM,CAM3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../../src/util/paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../../src/util/paths.ts"],"names":[],"mappings":"AASA,wBAAgB,eAAe,WAgB9B"}
|