xpine 0.0.21 → 0.0.24
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/TODO +0 -2
- package/dist/index.js +184 -80
- package/dist/src/build/esbuild/addDotJS.d.ts +5 -0
- package/dist/src/build/esbuild/addDotJS.d.ts.map +1 -0
- package/dist/src/build/esbuild/getDataFiles.d.ts +5 -0
- package/dist/src/build/esbuild/getDataFiles.d.ts.map +1 -0
- package/dist/src/build/esbuild/transformTSXFiles.d.ts +6 -0
- package/dist/src/build/esbuild/transformTSXFiles.d.ts.map +1 -0
- package/dist/src/express.d.ts +3 -0
- package/dist/src/express.d.ts.map +1 -1
- package/dist/src/runDevServer.d.ts.map +1 -1
- package/dist/src/scripts/build.d.ts +5 -1
- package/dist/src/scripts/build.d.ts.map +1 -1
- package/dist/src/scripts/xpine-build.js +110 -65
- package/dist/src/scripts/xpine-dev.js +148 -68
- package/dist/src/static/spa.js +2 -1
- package/dist/src/util/config-file.d.ts +6 -0
- package/dist/src/util/config-file.d.ts.map +1 -0
- package/dist/src/util/constants.d.ts +3 -0
- package/dist/src/util/constants.d.ts.map +1 -0
- package/dist/src/util/get-config.d.ts.map +1 -1
- package/dist/src/util/postcss/remove-layers.d.ts +1 -1
- package/dist/src/util/regex.d.ts +11 -0
- package/dist/src/util/regex.d.ts.map +1 -0
- package/dist/src/util/require.d.ts.map +1 -1
- package/dist/types.d.ts +31 -2
- package/dist/types.d.ts.map +1 -1
- package/eslint.config.mjs +27 -0
- package/package.json +18 -4
- package/tests/e2e/alpine.spec.ts +14 -0
- package/tests/e2e/app-build.spec.ts +73 -0
- package/tests/e2e/spa.spec.ts +23 -0
- package/tests/e2e/tests-examples/demo-todo-app.spec.ts +437 -0
- package/tests/eslint.config.mjs +27 -0
- package/tests/package-lock.json +8941 -0
- package/tests/package.json +89 -0
- package/tests/playwright.config.ts +81 -0
- package/tests/tsconfig.json +46 -0
- package/tests/xpine.config.mjs +1 -0
- package/types.ts +34 -2
package/TODO
CHANGED
package/dist/index.js
CHANGED
|
@@ -128,6 +128,10 @@ var require_default = createRequire(import.meta.url);
|
|
|
128
128
|
function getXPineDistDir() {
|
|
129
129
|
const dir = import.meta.dirname;
|
|
130
130
|
const splitDir = dir.split("/xpine/dist");
|
|
131
|
+
if (splitDir.length === 1) {
|
|
132
|
+
const splitDirSingle = dir.split("/xpine/");
|
|
133
|
+
return splitDirSingle[0] + "/xpine/dist";
|
|
134
|
+
}
|
|
131
135
|
return splitDir[0] + "/xpine/dist";
|
|
132
136
|
}
|
|
133
137
|
|
|
@@ -210,26 +214,55 @@ var remove_layers_default = plugin;
|
|
|
210
214
|
// src/build/esbuild/transformTSXFiles.ts
|
|
211
215
|
import fs2 from "fs-extra";
|
|
212
216
|
import ts2 from "typescript";
|
|
213
|
-
import path3 from "path";
|
|
214
217
|
|
|
215
218
|
// src/util/regex.ts
|
|
216
219
|
var regex_default = {
|
|
217
220
|
dotTsx: /.tsx/,
|
|
218
221
|
hasLetters: /[A-Za-z0-9]/g,
|
|
219
|
-
configFile: /\+config\.[tj]
|
|
222
|
+
configFile: /\+config\.[tj]sx?/g,
|
|
220
223
|
dynamicRoutes: /(\[)(.*?)(\])/g,
|
|
221
224
|
isDynamicRoute: /\[(.*)\]/g,
|
|
222
225
|
endsWithTSX: /\.tsx$/,
|
|
223
226
|
endsWithJSX: /\.jsx$/
|
|
224
227
|
};
|
|
225
228
|
|
|
229
|
+
// src/util/config-file.ts
|
|
230
|
+
import path3 from "path";
|
|
231
|
+
function sourcePathToDistPath(sourcePath) {
|
|
232
|
+
return sourcePath?.replace(config.srcDir, config.distDir)?.replace(/\.ts$/, ".js")?.replace(/\.tsx$/, ".js");
|
|
233
|
+
}
|
|
234
|
+
function getConfigFiles(pathName, pageConfigFiles, returnDistPaths = true) {
|
|
235
|
+
const configs = [];
|
|
236
|
+
for (const configFile of pageConfigFiles) {
|
|
237
|
+
const result = path3.relative(pathName, configFile)?.replace(regex_default.configFile, "");
|
|
238
|
+
const hasLetters = result.match(regex_default.hasLetters);
|
|
239
|
+
if (!hasLetters) {
|
|
240
|
+
configs.push(returnDistPaths ? sourcePathToDistPath(configFile) : configFile);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (!configs.length) return null;
|
|
244
|
+
return configs.sort((a, b) => b.length - a.length);
|
|
245
|
+
}
|
|
246
|
+
async function getCompleteConfig(configFiles, cacheKey) {
|
|
247
|
+
let config2 = {};
|
|
248
|
+
for (const configFile of configFiles) {
|
|
249
|
+
config2 = {
|
|
250
|
+
...(await import(configFile + `?cache=${cacheKey}`)).default,
|
|
251
|
+
...config2
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
return config2;
|
|
255
|
+
}
|
|
256
|
+
function isAConfigFile(pathName) {
|
|
257
|
+
return !!pathName.match(regex_default.configFile);
|
|
258
|
+
}
|
|
259
|
+
|
|
226
260
|
// src/build/esbuild/transformTSXFiles.ts
|
|
227
261
|
function transformTSXFiles(componentData, pageConfigFiles) {
|
|
228
262
|
return {
|
|
229
263
|
name: "transform-tsx-files",
|
|
230
264
|
setup(build2) {
|
|
231
|
-
build2.onLoad({ filter: regex_default.dotTsx }, (args) => {
|
|
232
|
-
const configFile = getConfigFile(args.path, pageConfigFiles);
|
|
265
|
+
build2.onLoad({ filter: regex_default.dotTsx }, async (args) => {
|
|
233
266
|
const content = fs2.readFileSync(args.path, "utf-8");
|
|
234
267
|
const source = ts2.createSourceFile(
|
|
235
268
|
args.path,
|
|
@@ -243,7 +276,7 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
243
276
|
...args,
|
|
244
277
|
contents: `${htmlImportStart}${cleanedContent.fullContent}`,
|
|
245
278
|
clientContent: cleanedContent.clientContent,
|
|
246
|
-
|
|
279
|
+
configFiles: isAConfigFile(args?.path) ? null : getConfigFiles(args.path, pageConfigFiles)
|
|
247
280
|
});
|
|
248
281
|
return {
|
|
249
282
|
contents: newContent,
|
|
@@ -253,16 +286,6 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
253
286
|
}
|
|
254
287
|
};
|
|
255
288
|
}
|
|
256
|
-
function getConfigFile(pathName, pageConfigFiles) {
|
|
257
|
-
const configs = [];
|
|
258
|
-
for (const configFile of pageConfigFiles) {
|
|
259
|
-
const result = path3.relative(pathName, configFile)?.replace(regex_default.configFile, "");
|
|
260
|
-
const hasLetters = result.match(regex_default.hasLetters);
|
|
261
|
-
if (!hasLetters) configs.push(configFile);
|
|
262
|
-
}
|
|
263
|
-
const configToUse = configs.sort((a, b) => b.length - a.length)?.[0];
|
|
264
|
-
return configToUse;
|
|
265
|
-
}
|
|
266
289
|
|
|
267
290
|
// src/build/esbuild/addDotJS.ts
|
|
268
291
|
import fs3 from "fs-extra";
|
|
@@ -314,13 +337,18 @@ function getDataFiles(dataFiles) {
|
|
|
314
337
|
};
|
|
315
338
|
}
|
|
316
339
|
|
|
340
|
+
// src/util/constants.ts
|
|
341
|
+
var doctypeHTML = "<!DOCTYPE html>";
|
|
342
|
+
var staticComment = "<!-- static -->";
|
|
343
|
+
|
|
317
344
|
// src/scripts/build.ts
|
|
318
345
|
var extensions = [".ts", ".tsx"];
|
|
319
346
|
var packageJson = JSON.parse(fs5.readFileSync(config.packageJsonPath, "utf-8"));
|
|
320
347
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
321
348
|
var xpineDistDir = getXPineDistDir();
|
|
322
|
-
async function buildApp(isDev = false) {
|
|
349
|
+
async function buildApp(isDev = false, removePreviousBuild = false) {
|
|
323
350
|
try {
|
|
351
|
+
if (removePreviousBuild) fs5.removeSync(config.distDir);
|
|
324
352
|
const srcDirFiles = globSync(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
325
353
|
const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev);
|
|
326
354
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
@@ -328,7 +356,7 @@ async function buildApp(isDev = false) {
|
|
|
328
356
|
fs5.removeSync(config.distTempFolder);
|
|
329
357
|
await buildCSS();
|
|
330
358
|
await buildPublicFolderSymlinks();
|
|
331
|
-
if (!isDev) await
|
|
359
|
+
if (!isDev) await buildFilesWithConfigs(componentData);
|
|
332
360
|
} catch (err) {
|
|
333
361
|
console.error("Build failed");
|
|
334
362
|
console.error(err);
|
|
@@ -398,14 +426,12 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
|
|
|
398
426
|
function writeDevServerClientSideCode(tempFilePath) {
|
|
399
427
|
const devServerPath = path5.join(xpineDistDir, "./src/static/dev-server.js");
|
|
400
428
|
const content = fs5.readFileSync(devServerPath, "utf-8");
|
|
401
|
-
fs5.appendFileSync(tempFilePath,
|
|
402
|
-
` + content);
|
|
429
|
+
fs5.appendFileSync(tempFilePath, "\n" + content);
|
|
403
430
|
}
|
|
404
431
|
function writeSpaClientSideCode(tempFilePath) {
|
|
405
432
|
const spaPath = path5.join(xpineDistDir, "./src/static/spa.js");
|
|
406
433
|
const content = fs5.readFileSync(spaPath, "utf-8");
|
|
407
|
-
fs5.appendFileSync(tempFilePath,
|
|
408
|
-
` + content);
|
|
434
|
+
fs5.appendFileSync(tempFilePath, "\n" + content);
|
|
409
435
|
}
|
|
410
436
|
async function buildAlpineDataFile(componentData, dataFiles) {
|
|
411
437
|
const output = {
|
|
@@ -494,55 +520,71 @@ async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
|
|
|
494
520
|
}, 0);
|
|
495
521
|
console.info(`[${totalSize.toFixed(3)} MB] Built ${type}`);
|
|
496
522
|
}
|
|
497
|
-
async function
|
|
498
|
-
const
|
|
523
|
+
async function buildFilesWithConfigs(componentData) {
|
|
524
|
+
const now = Date.now();
|
|
525
|
+
const componentsWithConfigs = componentData.filter((item) => item.configFiles);
|
|
499
526
|
for (const component of componentsWithConfigs) {
|
|
500
|
-
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
527
|
+
let config2 = await getCompleteConfig(component.configFiles, now);
|
|
528
|
+
const builtComponentPath = sourcePathToDistPath(component.path);
|
|
529
|
+
const componentImport = await import(builtComponentPath + `?cache=${Date.now()}`);
|
|
530
|
+
if (componentImport?.config) {
|
|
531
|
+
config2 = {
|
|
532
|
+
...config2,
|
|
533
|
+
...componentImport.config
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
if (config2?.staticPaths) buildStaticFiles(config2, component, componentImport, builtComponentPath);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
async function buildStaticFiles(config2, component, componentImport, builtComponentPath) {
|
|
540
|
+
if (!config2?.staticPaths) return;
|
|
541
|
+
let componentFileName = component.path.split("/").pop().replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
|
|
542
|
+
const isDynamicRoute = component.path.match(regex_default.isDynamicRoute);
|
|
543
|
+
if (isDynamicRoute) {
|
|
544
|
+
componentFileName = component.path.split("/").filter((dir) => dir.match(regex_default.isDynamicRoute)).join("/").replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
|
|
545
|
+
}
|
|
546
|
+
const componentDynamicPaths = getComponentDynamicPaths(componentFileName);
|
|
547
|
+
const componentFn = componentImport.default;
|
|
548
|
+
const outputPath = componentDynamicPaths?.length ? componentDynamicPaths.reduce((total, current) => {
|
|
549
|
+
return total.replace(`/[${current}]`, "");
|
|
550
|
+
}, path5.dirname(builtComponentPath)) : path5.dirname(builtComponentPath);
|
|
551
|
+
if (typeof config2?.staticPaths === "boolean") {
|
|
552
|
+
try {
|
|
553
|
+
const req = { params: {} };
|
|
554
|
+
const data = config2?.data ? await config2.data(req) : null;
|
|
555
|
+
const staticComponentOutput = await componentFn({ data });
|
|
556
|
+
fs5.writeFileSync(
|
|
557
|
+
path5.join(outputPath, "./index.html"),
|
|
558
|
+
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data }) : staticComponentOutput) + staticComment
|
|
559
|
+
);
|
|
560
|
+
} catch (err) {
|
|
561
|
+
console.error(err);
|
|
562
|
+
console.log("Could not build static component", component.path);
|
|
563
|
+
}
|
|
564
|
+
} else if (typeof config2?.staticPaths === "function") {
|
|
565
|
+
const dynamicPaths = await config2.staticPaths();
|
|
566
|
+
for (const dynamicPath of dynamicPaths) {
|
|
567
|
+
try {
|
|
568
|
+
const req = {
|
|
569
|
+
params: {
|
|
570
|
+
...componentDynamicPaths?.length ? dynamicPath : {}
|
|
537
571
|
}
|
|
538
|
-
}
|
|
572
|
+
};
|
|
573
|
+
const data = config2?.data ? await config2.data(req) : null;
|
|
574
|
+
const staticComponentOutput = await componentFn({ req, data });
|
|
575
|
+
const updatedOutDir = path5.join(outputPath, `./${componentDynamicPaths.map((key) => dynamicPath[key]).join("/")}`);
|
|
576
|
+
fs5.ensureDirSync(updatedOutDir);
|
|
577
|
+
fs5.writeFileSync(
|
|
578
|
+
path5.join(updatedOutDir, "./index.html"),
|
|
579
|
+
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data }) : staticComponentOutput) + staticComment
|
|
580
|
+
);
|
|
581
|
+
} catch (err) {
|
|
582
|
+
console.log("Could not build static component", component.path);
|
|
583
|
+
console.error(err);
|
|
539
584
|
}
|
|
540
585
|
}
|
|
541
586
|
}
|
|
542
587
|
}
|
|
543
|
-
function sourcePathToDistPath(sourcePath) {
|
|
544
|
-
return sourcePath.replace(config.srcDir, config.distDir).replace(/\.ts$/, ".js").replace(/\.tsx$/, ".js");
|
|
545
|
-
}
|
|
546
588
|
function getComponentDynamicPaths(componentPath) {
|
|
547
589
|
const matches = [...componentPath.matchAll(regex_default.dynamicRoutes)];
|
|
548
590
|
if (!matches?.length) return null;
|
|
@@ -591,6 +633,7 @@ async function loadSecretsManagerSecrets() {
|
|
|
591
633
|
await setupEnv();
|
|
592
634
|
async function runDevServer() {
|
|
593
635
|
process.env.NODE_ENV = "development";
|
|
636
|
+
const rebuildEmitter = createRebuildEmitter();
|
|
594
637
|
await buildApp(true);
|
|
595
638
|
const startServer = (await import(config.serverDistAppPath + `?cache=${Date.now()}`)).default;
|
|
596
639
|
let appServer = await startServer();
|
|
@@ -602,15 +645,21 @@ async function runDevServer() {
|
|
|
602
645
|
watcher.on("all", async (event, path9) => {
|
|
603
646
|
const shouldReloadServer = path9.startsWith(config.serverDir) && !path9.startsWith(config.runDir) || ["add", "unlink"].includes(event) && path9.startsWith(config.pagesDir);
|
|
604
647
|
if (shouldReloadServer) {
|
|
605
|
-
await appServer.server
|
|
606
|
-
|
|
607
|
-
const startServer2 = (await import(config.serverDistAppPath + `?cache=${Date.now()}`)).default;
|
|
608
|
-
appServer = await startServer2();
|
|
648
|
+
await asyncServerClose(appServer.server);
|
|
649
|
+
rebuildEmitter.emit("rebuild-server");
|
|
609
650
|
return;
|
|
610
651
|
}
|
|
611
652
|
await buildApp(true);
|
|
612
653
|
refreshEmitter.emit("refresh");
|
|
613
654
|
});
|
|
655
|
+
rebuildEmitter.on("done", async () => {
|
|
656
|
+
await rebuildServer();
|
|
657
|
+
});
|
|
658
|
+
async function rebuildServer() {
|
|
659
|
+
await buildApp(true);
|
|
660
|
+
const startServer2 = (await import(config.serverDistAppPath + `?cache=${Date.now()}`)).default;
|
|
661
|
+
appServer = await startServer2();
|
|
662
|
+
}
|
|
614
663
|
const wsApp = express();
|
|
615
664
|
const wsServer = http.createServer(wsApp);
|
|
616
665
|
expressWs(wsApp, wsServer);
|
|
@@ -630,6 +679,37 @@ async function runDevServer() {
|
|
|
630
679
|
console.info(`Dev server listening on port ${wsPort}`);
|
|
631
680
|
});
|
|
632
681
|
}
|
|
682
|
+
function asyncServerClose(server) {
|
|
683
|
+
return new Promise((resolve, reject) => {
|
|
684
|
+
server.close();
|
|
685
|
+
resolve(true);
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
function createRebuildEmitter(delay = 500) {
|
|
689
|
+
class RebuildEmitter extends EventEmitter {
|
|
690
|
+
}
|
|
691
|
+
;
|
|
692
|
+
const rebuildEmitter = new RebuildEmitter();
|
|
693
|
+
let start = 0;
|
|
694
|
+
let hasEmitted = false;
|
|
695
|
+
rebuildEmitter.on("rebuild-server", () => {
|
|
696
|
+
hasEmitted = false;
|
|
697
|
+
trigger();
|
|
698
|
+
});
|
|
699
|
+
function trigger() {
|
|
700
|
+
start = Date.now();
|
|
701
|
+
const interval = setInterval(() => {
|
|
702
|
+
if (hasEmitted) return;
|
|
703
|
+
const now = Date.now();
|
|
704
|
+
if (now - start >= delay) {
|
|
705
|
+
rebuildEmitter.emit("done");
|
|
706
|
+
clearInterval(interval);
|
|
707
|
+
hasEmitted = true;
|
|
708
|
+
}
|
|
709
|
+
}, 100);
|
|
710
|
+
}
|
|
711
|
+
return rebuildEmitter;
|
|
712
|
+
}
|
|
633
713
|
|
|
634
714
|
// src/express.ts
|
|
635
715
|
import express2 from "express";
|
|
@@ -676,8 +756,8 @@ function getTokenFromRequest(req) {
|
|
|
676
756
|
import requestIP from "request-ip";
|
|
677
757
|
import fs6 from "fs-extra";
|
|
678
758
|
import path8 from "path";
|
|
679
|
-
var doctypeHTML = "<!DOCTYPE html>";
|
|
680
759
|
async function createRouter() {
|
|
760
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
681
761
|
const methods = ["get", "post", "put", "patch", "delete"];
|
|
682
762
|
const router = express2.Router();
|
|
683
763
|
const routes = globSync2(config.pagesDir + "/**/*.{tsx,ts}");
|
|
@@ -692,10 +772,10 @@ async function createRouter() {
|
|
|
692
772
|
};
|
|
693
773
|
}).filter(Boolean);
|
|
694
774
|
const routeResults = [];
|
|
775
|
+
const configFiles = globSync2(config.pagesDir + "/**/+config.{tsx,ts}");
|
|
695
776
|
for (const route of routeMap) {
|
|
696
777
|
const isJSX = route.originalRoute.endsWith(".tsx") || route.originalRoute.endsWith(".jsx");
|
|
697
|
-
const
|
|
698
|
-
const slugRoute = route.route.toLowerCase().replace(/[ ]/g, "");
|
|
778
|
+
const slugRoute = route.route.replace(/[ ]/g, "");
|
|
699
779
|
const foundMethod = methods.find((method) => slugRoute.endsWith(`.${method}`));
|
|
700
780
|
const isDynamicRoute = slugRoute.match(regex_default.isDynamicRoute);
|
|
701
781
|
let formattedRouteItem = slugRoute;
|
|
@@ -706,6 +786,16 @@ async function createRouter() {
|
|
|
706
786
|
formattedRouteItem = formattedRouteItem.replace(match[0], ":" + match[2]);
|
|
707
787
|
}
|
|
708
788
|
}
|
|
789
|
+
const componentImport = isDev ? null : await import(route.path);
|
|
790
|
+
const componentFn = componentImport?.default;
|
|
791
|
+
const configFilePaths = getConfigFiles(route.originalRoute, configFiles);
|
|
792
|
+
let config2 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
|
|
793
|
+
if (componentImport?.config) {
|
|
794
|
+
config2 = {
|
|
795
|
+
...config2,
|
|
796
|
+
...componentImport.config
|
|
797
|
+
};
|
|
798
|
+
}
|
|
709
799
|
routeResults.push({
|
|
710
800
|
formattedRouteItem,
|
|
711
801
|
foundMethod,
|
|
@@ -714,23 +804,37 @@ async function createRouter() {
|
|
|
714
804
|
router[foundMethod || "get"](formattedRouteItem, async (req, res) => {
|
|
715
805
|
try {
|
|
716
806
|
const staticPath = routeHasStaticPath(formattedRouteItem, req.params);
|
|
717
|
-
if (staticPath &&
|
|
807
|
+
if (staticPath && !isDev) {
|
|
718
808
|
res.sendFile(staticPath);
|
|
719
809
|
return;
|
|
720
810
|
}
|
|
721
|
-
if (
|
|
811
|
+
if (componentFn && !isDev) {
|
|
722
812
|
if (isJSX) {
|
|
723
|
-
|
|
813
|
+
const data = config2?.data ? await config2.data(req) : null;
|
|
814
|
+
const originalResult = await componentFn({ req, res, data });
|
|
815
|
+
const output = config2?.wrapper ? await config2.wrapper({ req, children: originalResult, config: config2, data }) : originalResult;
|
|
816
|
+
res.send(doctypeHTML + output);
|
|
724
817
|
} else {
|
|
725
|
-
await
|
|
818
|
+
await componentFn(req, res);
|
|
726
819
|
}
|
|
727
820
|
return;
|
|
728
821
|
}
|
|
729
|
-
const
|
|
822
|
+
const componentImportDev = await import(route.path + `?cache=${Date.now()}`);
|
|
823
|
+
const componentFnDev = componentImportDev.default;
|
|
730
824
|
if (isJSX) {
|
|
731
|
-
|
|
825
|
+
let config3 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
|
|
826
|
+
if (componentImportDev?.config) {
|
|
827
|
+
config3 = {
|
|
828
|
+
...config3,
|
|
829
|
+
...componentImportDev.config
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
const data = config3?.data ? await config3.data(req) : null;
|
|
833
|
+
const originalResult = await componentFnDev({ req, res, data });
|
|
834
|
+
const output = config3?.wrapper ? await config3.wrapper({ req, children: originalResult, config: config3, data }) : originalResult;
|
|
835
|
+
res.send(doctypeHTML + output);
|
|
732
836
|
} else {
|
|
733
|
-
await
|
|
837
|
+
await componentFnDev(req, res);
|
|
734
838
|
}
|
|
735
839
|
} catch (err) {
|
|
736
840
|
console.error(err);
|
|
@@ -765,7 +869,7 @@ async function createXPineRouter(app, beforeErrorRoute) {
|
|
|
765
869
|
router(req, res, next);
|
|
766
870
|
});
|
|
767
871
|
const found404 = routeResults?.find((item) => item?.formattedRouteItem === "/404");
|
|
768
|
-
const import404 = process.env.NODE_ENV === "development" ? null : (await import(found404.route.path)).default;
|
|
872
|
+
const import404 = process.env.NODE_ENV === "development" || !found404 ? null : (await import(found404.route.path)).default;
|
|
769
873
|
if (beforeErrorRoute) beforeErrorRoute(app);
|
|
770
874
|
app.use(async function(req, res) {
|
|
771
875
|
res.status(404);
|
|
@@ -820,6 +924,7 @@ export {
|
|
|
820
924
|
JSXRuntime,
|
|
821
925
|
buildApp,
|
|
822
926
|
buildCSS,
|
|
927
|
+
buildFilesWithConfigs,
|
|
823
928
|
buildPublicFolderSymlinks,
|
|
824
929
|
buildStaticFiles,
|
|
825
930
|
config,
|
|
@@ -834,6 +939,5 @@ export {
|
|
|
834
939
|
runDevServer,
|
|
835
940
|
setupEnv,
|
|
836
941
|
signUser,
|
|
837
|
-
sourcePathToDistPath,
|
|
838
942
|
verifyUser
|
|
839
943
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addDotJS.d.ts","sourceRoot":"","sources":["../../../../src/build/esbuild/addDotJS.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO;;;EA0B3F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDataFiles.d.ts","sourceRoot":"","sources":["../../../../src/build/esbuild/getDataFiles.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,SAAS,EAAE,GAAG,EAAE;;;EAiBpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformTSXFiles.d.ts","sourceRoot":"","sources":["../../../../src/build/esbuild/transformTSXFiles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE;;;EA2BlG"}
|
package/dist/src/express.d.ts
CHANGED
|
@@ -4,4 +4,7 @@ export declare function createRouter(): Promise<{
|
|
|
4
4
|
routeResults: any[];
|
|
5
5
|
}>;
|
|
6
6
|
export declare function createXPineRouter(app: any, beforeErrorRoute?: (app: Express) => void): Promise<void>;
|
|
7
|
+
export declare function routeHasStaticPath(route: string, params: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
}): string | false;
|
|
7
10
|
//# sourceMappingURL=express.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAgB,OAAO,EAAqB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAgB,OAAO,EAAqB,MAAM,SAAS,CAAC;AAY5E,wBAAsB,YAAY;;;GAqGjC;AAiBD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,iBA6B1F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,KAAK,CAWnG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runDevServer.d.ts","sourceRoot":"","sources":["../../src/runDevServer.ts"],"names":[],"mappings":"AAYA,wBAAsB,YAAY,
|
|
1
|
+
{"version":3,"file":"runDevServer.d.ts","sourceRoot":"","sources":["../../src/runDevServer.ts"],"names":[],"mappings":"AAYA,wBAAsB,YAAY,kBA6DjC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { ConfigFile, ComponentData } from '../../types';
|
|
2
|
+
export declare function buildApp(isDev?: boolean, removePreviousBuild?: boolean): Promise<void>;
|
|
2
3
|
export declare function buildCSS(): Promise<void>;
|
|
3
4
|
export declare function buildPublicFolderSymlinks(): Promise<void>;
|
|
4
5
|
export declare function logSize(pathName: string, type: 'app' | 'client' | 'css', validExtensions?: string[]): Promise<void>;
|
|
6
|
+
export declare function buildFilesWithConfigs(componentData: ComponentData[]): Promise<void>;
|
|
7
|
+
export declare function buildStaticFiles(config: ConfigFile, component: ComponentData, componentImport: any, builtComponentPath: string): Promise<void>;
|
|
8
|
+
export declare function getComponentDynamicPaths(componentPath: string): string[];
|
|
5
9
|
//# sourceMappingURL=build.d.ts.map
|
|
@@ -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;AASjF,wBAAsB,QAAQ,CAAC,KAAK,UAAQ,EAAE,mBAAmB,UAAQ,iBAgBxE;AA2ID,wBAAsB,QAAQ,kBAW7B;AAGD,wBAAsB,yBAAyB,kBAgB9C;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,EAAE,eAAe,WAAkB,iBAahH;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,iBA4DpI;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxE"}
|