xpine 0.0.29 → 0.0.31

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.
@@ -4,7 +4,7 @@ export type State<StateProps> = {
4
4
  set: (id: string, callback: SetContext<StateProps>, defaultValue?: any) => void;
5
5
  clear: () => void;
6
6
  getAll: () => any;
7
- addToArray: (id: string, value: any, position?: number) => void;
7
+ addToArray: (id: string, value: any, position?: number | Date) => void;
8
8
  getArrayQueue: () => any;
9
9
  runArrayQueue: () => void;
10
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,KAAK,IAAI,CAAC;AAE9D,MAAM,MAAM,KAAK,CAAC,UAAU,IAAI;IAC9B,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,UAAU,CAAC;IAChC,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAChF,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,CAAC;IAClB,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,aAAa,EAAE,MAAM,GAAG,CAAC;IACzB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAA;AAED,KAAK,WAAW,CAAC,IAAI,IAAI;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CA8CjE;AAED,eAAO,MAAM,OAAO,YAAoB,CAAC;AAEzC,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,kBACjC,GAAG,SAYnC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,KAAK,IAAI,CAAC;AAE9D,MAAM,MAAM,KAAK,CAAC,UAAU,IAAI;IAC9B,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,UAAU,CAAC;IAChC,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAChF,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,CAAC;IAClB,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACvE,aAAa,EAAE,MAAM,GAAG,CAAC;IACzB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAA;AAED,KAAK,WAAW,CAAC,IAAI,IAAI;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAA;AAQD,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAmDjE;AAED,eAAO,MAAM,OAAO,YAAoB,CAAC;AAEzC,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,kBACjC,GAAG,SAYnC"}
@@ -7,4 +7,5 @@ export declare function createXPineRouter(app: any, beforeErrorRoute?: (app: Exp
7
7
  export declare function routeHasStaticPath(route: string, params: {
8
8
  [key: string]: string;
9
9
  }): string | false;
10
+ export declare function filePathToURLPath(pathName: string, isDist?: boolean): string;
10
11
  //# 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;AAyC5E,wBAAsB,YAAY;;;GA8GjC;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
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAgB,OAAO,EAAqB,MAAM,SAAS,CAAC;AAyC5E,wBAAsB,YAAY;;;GA+GjC;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;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,OAAc,UAQzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,UAAU,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;AAWjF,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CA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BAAyB,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,iBAmEpI;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxE;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"}
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/scripts/build.ts
4
4
  import path5 from "path";
5
- import fs5 from "fs-extra";
5
+ import fs6 from "fs-extra";
6
6
  import { build } from "esbuild";
7
7
 
8
8
  // src/build/typescript-builder.ts
@@ -116,10 +116,12 @@ function createContext(value) {
116
116
  },
117
117
  runArrayQueue() {
118
118
  Object.keys(arrayQueue).forEach((key) => {
119
- arrayQueue[key].sort((a, b) => {
120
- return (a?.position ?? Infinity) - (b.position ?? Infinity);
121
- });
122
- for (const item of arrayQueue[key]) {
119
+ const dates = arrayQueue[key].filter((item) => item?.position instanceof Date);
120
+ const numbers = arrayQueue[key].filter((item) => typeof item?.position === "number" || !item?.position);
121
+ const sortedDates = dates.toSorted((a, b) => b?.position.getTime() - a?.position.getTime());
122
+ const sortedNumbers = numbers.toSorted((a, b) => (a?.position ?? Infinity) - (b.position ?? Infinity));
123
+ const output = sortedNumbers.concat(sortedDates);
124
+ for (const item of output) {
123
125
  this.set(key, item.value, []);
124
126
  }
125
127
  });
@@ -278,7 +280,7 @@ async function triggerXPineOnLoad(noCache = false) {
278
280
  }
279
281
 
280
282
  // src/scripts/build.ts
281
- import { globSync } from "glob";
283
+ import { globSync as globSync2 } from "glob";
282
284
  import postcss from "postcss";
283
285
  import tailwindPostcss from "@tailwindcss/postcss";
284
286
 
@@ -319,7 +321,9 @@ var regex_default = {
319
321
  dynamicRoutes: /(\[)(.*?)(\])/g,
320
322
  isDynamicRoute: /\[(.*)\]/g,
321
323
  endsWithTSX: /\.tsx$/,
322
- endsWithJSX: /\.jsx$/
324
+ endsWithJSX: /\.jsx$/,
325
+ endsWithFileName: /\.(html|tsx|jsx|js|ts)$/,
326
+ indexFile: /index\.(html|tsx|jsx|js|ts)$/g
323
327
  };
324
328
 
325
329
  // src/util/config-file.ts
@@ -442,8 +446,41 @@ var staticComment = "<!-- static -->";
442
446
 
443
447
  // src/scripts/build.ts
444
448
  import ts3 from "typescript";
449
+
450
+ // src/express.ts
451
+ import express from "express";
452
+ import { globSync } from "glob";
453
+
454
+ // src/auth.ts
455
+ import jsonwebtoken from "jsonwebtoken";
456
+ var { verify, sign } = jsonwebtoken;
457
+
458
+ // src/express.ts
459
+ import requestIP from "request-ip";
460
+ import fs5 from "fs-extra";
461
+ import EventEmitter from "events";
462
+ var OnInitEmitter = class extends EventEmitter {
463
+ };
464
+ var onInitEmitter = new OnInitEmitter();
465
+ onInitEmitter.on("triggerOnInit", async (paths) => {
466
+ for (const routePath of paths) {
467
+ const pathImport = await import(routePath.path + `?cache=${Date.now()}`);
468
+ if (pathImport?.config?.onInit) await pathImport.config.onInit();
469
+ }
470
+ });
471
+ function filePathToURLPath(pathName, isDist = true) {
472
+ const result = pathName.split(isDist ? config.distPagesDir : config.pagesDir).pop().replace(regex_default.indexFile, "").replace(regex_default.endsWithFileName, "");
473
+ if (result.endsWith("/")) {
474
+ const cleanedResult = result.slice(0, -1);
475
+ if (!cleanedResult) return "/";
476
+ return cleanedResult;
477
+ }
478
+ return result;
479
+ }
480
+
481
+ // src/scripts/build.ts
445
482
  var extensions = [".ts", ".tsx"];
446
- var packageJson = JSON.parse(fs5.readFileSync(config.packageJsonPath, "utf-8"));
483
+ var packageJson = JSON.parse(fs6.readFileSync(config.packageJsonPath, "utf-8"));
447
484
  var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
448
485
  var xpineDistDir = getXPineDistDir();
449
486
  async function buildApp(args) {
@@ -451,12 +488,12 @@ async function buildApp(args) {
451
488
  const removePreviousBuild2 = args?.removePreviousBuild || false;
452
489
  const disableTailwind2 = args?.disableTailwind || false;
453
490
  try {
454
- if (removePreviousBuild2) fs5.removeSync(config.distDir);
455
- const srcDirFiles = globSync(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
491
+ if (removePreviousBuild2) fs6.removeSync(config.distDir);
492
+ const srcDirFiles = globSync2(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
456
493
  const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev2);
457
494
  const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
458
495
  await buildClientSideFiles([alpineDataFile], isDev2);
459
- fs5.removeSync(config.distTempFolder);
496
+ fs6.removeSync(config.distTempFolder);
460
497
  await buildCSS(disableTailwind2);
461
498
  await buildPublicFolderSymlinks();
462
499
  await buildOnLoadFile(componentData, isDev2);
@@ -476,7 +513,7 @@ async function buildAppFiles(files, isDev2) {
476
513
  return fileName === "+config";
477
514
  });
478
515
  const backendFiles = files.filter((file) => extensions.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
479
- fs5.ensureDirSync(config.distDir);
516
+ fs6.ensureDirSync(config.distDir);
480
517
  await build({
481
518
  entryPoints: backendFiles,
482
519
  format: "esm",
@@ -501,9 +538,9 @@ async function buildAppFiles(files, isDev2) {
501
538
  }
502
539
  async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
503
540
  const tempFilePath = path5.join(config.distTempFolder, "./app.ts");
504
- fs5.ensureFileSync(tempFilePath);
541
+ fs6.ensureFileSync(tempFilePath);
505
542
  const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
506
- const clientFiles = globSync(
543
+ const clientFiles = globSync2(
507
544
  config.publicDir + "/**/*.{js,ts}",
508
545
  {
509
546
  ignore: pagesScriptsGlob
@@ -519,7 +556,7 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
519
556
  minify: !isDev2,
520
557
  sourcemap: isDev2 ? "inline" : false
521
558
  });
522
- const pagesFiles = globSync(pagesScriptsGlob);
559
+ const pagesFiles = globSync2(pagesScriptsGlob);
523
560
  await build({
524
561
  entryPoints: pagesFiles || [],
525
562
  bundle: true,
@@ -531,13 +568,13 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
531
568
  }
532
569
  function writeDevServerClientSideCode(tempFilePath) {
533
570
  const devServerPath = path5.join(xpineDistDir, "./src/static/dev-server.js");
534
- const content = fs5.readFileSync(devServerPath, "utf-8");
535
- fs5.appendFileSync(tempFilePath, "\n" + content);
571
+ const content = fs6.readFileSync(devServerPath, "utf-8");
572
+ fs6.appendFileSync(tempFilePath, "\n" + content);
536
573
  }
537
574
  function writeSpaClientSideCode(tempFilePath) {
538
575
  const spaPath = path5.join(xpineDistDir, "./src/static/spa.js");
539
- const content = fs5.readFileSync(spaPath, "utf-8");
540
- fs5.appendFileSync(tempFilePath, "\n" + content);
576
+ const content = fs6.readFileSync(spaPath, "utf-8");
577
+ fs6.appendFileSync(tempFilePath, "\n" + content);
541
578
  }
542
579
  async function buildAlpineDataFile(componentData, dataFiles) {
543
580
  const output = {
@@ -583,23 +620,23 @@ async function buildAlpineDataFile(componentData, dataFiles) {
583
620
  output.code.push(`Alpine.data('${dataFunction.name}', ${dataFunction.name});`);
584
621
  }
585
622
  const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
586
- fs5.ensureFileSync(config.alpineDataPath);
587
- fs5.writeFileSync(config.alpineDataPath, result);
623
+ fs6.ensureFileSync(config.alpineDataPath);
624
+ fs6.writeFileSync(config.alpineDataPath, result);
588
625
  return config.alpineDataPath;
589
626
  }
590
627
  async function buildCSS(disableTailwind2) {
591
- const cssFiles = globSync(config.srcDir + "/**/*.css");
628
+ const cssFiles = globSync2(config.srcDir + "/**/*.css");
592
629
  for (const file of cssFiles) {
593
- const fileContents = fs5.readFileSync(file, "utf-8");
630
+ const fileContents = fs6.readFileSync(file, "utf-8");
594
631
  const result = disableTailwind2 ? fileContents : await postcss([tailwindPostcss(), remove_layers_default()]).process(fileContents, { from: file });
595
632
  const newPath = file.replace(config.srcDir, config.distDir);
596
- fs5.ensureFileSync(newPath);
597
- fs5.writeFileSync(newPath, result.css);
633
+ fs6.ensureFileSync(newPath);
634
+ fs6.writeFileSync(newPath, result.css);
598
635
  }
599
636
  logSize(config.distPublicDir, "css");
600
637
  }
601
638
  async function buildPublicFolderSymlinks() {
602
- const files = globSync(config.publicDir + "/**/*.*", {
639
+ const files = globSync2(config.publicDir + "/**/*.*", {
603
640
  ignore: "/**/*.{css,js,ts,tsx,jsx}"
604
641
  });
605
642
  for (const file of files) {
@@ -608,19 +645,19 @@ async function buildPublicFolderSymlinks() {
608
645
  const splitNewPath = newPath.split("/");
609
646
  splitNewPath.pop();
610
647
  const newDir = splitNewPath.join("/");
611
- fs5.ensureDirSync(newDir);
612
- fs5.symlinkSync(file, newPath);
648
+ fs6.ensureDirSync(newDir);
649
+ fs6.symlinkSync(file, newPath);
613
650
  } catch {
614
651
  }
615
652
  }
616
653
  }
617
654
  async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
618
- const files = globSync(pathName + "/**/*" + (type === "css" ? ".css" : ""));
655
+ const files = globSync2(pathName + "/**/*" + (type === "css" ? ".css" : ""));
619
656
  const fileSizes = files.map((file) => {
620
657
  if (!validExtensions.find((ext) => file.endsWith(ext))) return false;
621
658
  return {
622
659
  file,
623
- size: fs5.statSync(file).size / (1024 * 1e3)
660
+ size: fs6.statSync(file).size / (1024 * 1e3)
624
661
  };
625
662
  }).filter(Boolean);
626
663
  const totalSize = fileSizes.reduce((total, current) => {
@@ -658,13 +695,14 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
658
695
  return total.replace(`/[${current}]`, "");
659
696
  }, path5.dirname(builtComponentPath)) : path5.dirname(builtComponentPath);
660
697
  if (typeof config2?.staticPaths === "boolean") {
698
+ const urlPath = filePathToURLPath(outputPath);
661
699
  try {
662
700
  const req = { params: {} };
663
701
  const data = config2?.data ? await config2.data(req) : null;
664
- const staticComponentOutput = await componentFn({ data });
665
- fs5.writeFileSync(
702
+ const staticComponentOutput = await componentFn({ data, path: urlPath });
703
+ fs6.writeFileSync(
666
704
  path5.join(outputPath, "./index.html"),
667
- doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data }) : staticComponentOutput) + staticComment
705
+ doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, path: urlPath }) : staticComponentOutput) + staticComment
668
706
  );
669
707
  } catch (err) {
670
708
  console.error(err);
@@ -679,13 +717,14 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
679
717
  ...componentDynamicPaths?.length ? dynamicPath : {}
680
718
  }
681
719
  };
682
- const data = config2?.data ? await config2.data(req) : null;
683
- const staticComponentOutput = await componentFn({ req, data });
684
720
  const updatedOutDir = path5.join(outputPath, `./${componentDynamicPaths.map((key) => dynamicPath[key]).join("/")}`);
685
- fs5.ensureDirSync(updatedOutDir);
686
- fs5.writeFileSync(
721
+ const urlPath = filePathToURLPath(updatedOutDir);
722
+ const data = config2?.data ? await config2.data(req) : null;
723
+ const staticComponentOutput = await componentFn({ req, data, path: urlPath });
724
+ fs6.ensureDirSync(updatedOutDir);
725
+ fs6.writeFileSync(
687
726
  path5.join(updatedOutDir, "./index.html"),
688
- doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data }) : staticComponentOutput) + staticComment
727
+ doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, path: urlPath }) : staticComponentOutput) + staticComment
689
728
  );
690
729
  } catch (err) {
691
730
  console.log("Could not build static component", component.path);
@@ -734,7 +773,7 @@ async function buildOnLoadFile(componentData, isDev2) {
734
773
  }
735
774
  `;
736
775
  const onLoadFilePath = path5.join(config.distDir, "./__xpineOnLoad.ts");
737
- fs5.writeFileSync(onLoadFilePath, output);
776
+ fs6.writeFileSync(onLoadFilePath, output);
738
777
  await build({
739
778
  entryPoints: [onLoadFilePath],
740
779
  format: "esm",
@@ -3,13 +3,13 @@
3
3
  // src/runDevServer.ts
4
4
  import expressWs from "express-ws";
5
5
  import http from "http";
6
- import express from "express";
7
- import EventEmitter from "events";
6
+ import express2 from "express";
7
+ import EventEmitter2 from "events";
8
8
  import chokidar from "chokidar";
9
9
 
10
10
  // src/scripts/build.ts
11
11
  import path5 from "path";
12
- import fs5 from "fs-extra";
12
+ import fs6 from "fs-extra";
13
13
  import { build } from "esbuild";
14
14
 
15
15
  // src/build/typescript-builder.ts
@@ -123,10 +123,12 @@ function createContext(value) {
123
123
  },
124
124
  runArrayQueue() {
125
125
  Object.keys(arrayQueue).forEach((key) => {
126
- arrayQueue[key].sort((a, b) => {
127
- return (a?.position ?? Infinity) - (b.position ?? Infinity);
128
- });
129
- for (const item of arrayQueue[key]) {
126
+ const dates = arrayQueue[key].filter((item) => item?.position instanceof Date);
127
+ const numbers = arrayQueue[key].filter((item) => typeof item?.position === "number" || !item?.position);
128
+ const sortedDates = dates.toSorted((a, b) => b?.position.getTime() - a?.position.getTime());
129
+ const sortedNumbers = numbers.toSorted((a, b) => (a?.position ?? Infinity) - (b.position ?? Infinity));
130
+ const output = sortedNumbers.concat(sortedDates);
131
+ for (const item of output) {
130
132
  this.set(key, item.value, []);
131
133
  }
132
134
  });
@@ -285,7 +287,7 @@ async function triggerXPineOnLoad(noCache = false) {
285
287
  }
286
288
 
287
289
  // src/scripts/build.ts
288
- import { globSync } from "glob";
290
+ import { globSync as globSync2 } from "glob";
289
291
  import postcss from "postcss";
290
292
  import tailwindPostcss from "@tailwindcss/postcss";
291
293
 
@@ -326,7 +328,9 @@ var regex_default = {
326
328
  dynamicRoutes: /(\[)(.*?)(\])/g,
327
329
  isDynamicRoute: /\[(.*)\]/g,
328
330
  endsWithTSX: /\.tsx$/,
329
- endsWithJSX: /\.jsx$/
331
+ endsWithJSX: /\.jsx$/,
332
+ endsWithFileName: /\.(html|tsx|jsx|js|ts)$/,
333
+ indexFile: /index\.(html|tsx|jsx|js|ts)$/g
330
334
  };
331
335
 
332
336
  // src/util/config-file.ts
@@ -449,8 +453,41 @@ var staticComment = "<!-- static -->";
449
453
 
450
454
  // src/scripts/build.ts
451
455
  import ts3 from "typescript";
456
+
457
+ // src/express.ts
458
+ import express from "express";
459
+ import { globSync } from "glob";
460
+
461
+ // src/auth.ts
462
+ import jsonwebtoken from "jsonwebtoken";
463
+ var { verify, sign } = jsonwebtoken;
464
+
465
+ // src/express.ts
466
+ import requestIP from "request-ip";
467
+ import fs5 from "fs-extra";
468
+ import EventEmitter from "events";
469
+ var OnInitEmitter = class extends EventEmitter {
470
+ };
471
+ var onInitEmitter = new OnInitEmitter();
472
+ onInitEmitter.on("triggerOnInit", async (paths) => {
473
+ for (const routePath of paths) {
474
+ const pathImport = await import(routePath.path + `?cache=${Date.now()}`);
475
+ if (pathImport?.config?.onInit) await pathImport.config.onInit();
476
+ }
477
+ });
478
+ function filePathToURLPath(pathName, isDist = true) {
479
+ const result = pathName.split(isDist ? config.distPagesDir : config.pagesDir).pop().replace(regex_default.indexFile, "").replace(regex_default.endsWithFileName, "");
480
+ if (result.endsWith("/")) {
481
+ const cleanedResult = result.slice(0, -1);
482
+ if (!cleanedResult) return "/";
483
+ return cleanedResult;
484
+ }
485
+ return result;
486
+ }
487
+
488
+ // src/scripts/build.ts
452
489
  var extensions = [".ts", ".tsx"];
453
- var packageJson = JSON.parse(fs5.readFileSync(config.packageJsonPath, "utf-8"));
490
+ var packageJson = JSON.parse(fs6.readFileSync(config.packageJsonPath, "utf-8"));
454
491
  var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
455
492
  var xpineDistDir = getXPineDistDir();
456
493
  async function buildApp(args) {
@@ -458,12 +495,12 @@ async function buildApp(args) {
458
495
  const removePreviousBuild = args?.removePreviousBuild || false;
459
496
  const disableTailwind = args?.disableTailwind || false;
460
497
  try {
461
- if (removePreviousBuild) fs5.removeSync(config.distDir);
462
- const srcDirFiles = globSync(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
498
+ if (removePreviousBuild) fs6.removeSync(config.distDir);
499
+ const srcDirFiles = globSync2(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
463
500
  const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev);
464
501
  const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
465
502
  await buildClientSideFiles([alpineDataFile], isDev);
466
- fs5.removeSync(config.distTempFolder);
503
+ fs6.removeSync(config.distTempFolder);
467
504
  await buildCSS(disableTailwind);
468
505
  await buildPublicFolderSymlinks();
469
506
  await buildOnLoadFile(componentData, isDev);
@@ -483,7 +520,7 @@ async function buildAppFiles(files, isDev) {
483
520
  return fileName === "+config";
484
521
  });
485
522
  const backendFiles = files.filter((file) => extensions.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
486
- fs5.ensureDirSync(config.distDir);
523
+ fs6.ensureDirSync(config.distDir);
487
524
  await build({
488
525
  entryPoints: backendFiles,
489
526
  format: "esm",
@@ -508,9 +545,9 @@ async function buildAppFiles(files, isDev) {
508
545
  }
509
546
  async function buildClientSideFiles(alpineDataFiles = [], isDev) {
510
547
  const tempFilePath = path5.join(config.distTempFolder, "./app.ts");
511
- fs5.ensureFileSync(tempFilePath);
548
+ fs6.ensureFileSync(tempFilePath);
512
549
  const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
513
- const clientFiles = globSync(
550
+ const clientFiles = globSync2(
514
551
  config.publicDir + "/**/*.{js,ts}",
515
552
  {
516
553
  ignore: pagesScriptsGlob
@@ -526,7 +563,7 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
526
563
  minify: !isDev,
527
564
  sourcemap: isDev ? "inline" : false
528
565
  });
529
- const pagesFiles = globSync(pagesScriptsGlob);
566
+ const pagesFiles = globSync2(pagesScriptsGlob);
530
567
  await build({
531
568
  entryPoints: pagesFiles || [],
532
569
  bundle: true,
@@ -538,13 +575,13 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
538
575
  }
539
576
  function writeDevServerClientSideCode(tempFilePath) {
540
577
  const devServerPath = path5.join(xpineDistDir, "./src/static/dev-server.js");
541
- const content = fs5.readFileSync(devServerPath, "utf-8");
542
- fs5.appendFileSync(tempFilePath, "\n" + content);
578
+ const content = fs6.readFileSync(devServerPath, "utf-8");
579
+ fs6.appendFileSync(tempFilePath, "\n" + content);
543
580
  }
544
581
  function writeSpaClientSideCode(tempFilePath) {
545
582
  const spaPath = path5.join(xpineDistDir, "./src/static/spa.js");
546
- const content = fs5.readFileSync(spaPath, "utf-8");
547
- fs5.appendFileSync(tempFilePath, "\n" + content);
583
+ const content = fs6.readFileSync(spaPath, "utf-8");
584
+ fs6.appendFileSync(tempFilePath, "\n" + content);
548
585
  }
549
586
  async function buildAlpineDataFile(componentData, dataFiles) {
550
587
  const output = {
@@ -590,23 +627,23 @@ async function buildAlpineDataFile(componentData, dataFiles) {
590
627
  output.code.push(`Alpine.data('${dataFunction.name}', ${dataFunction.name});`);
591
628
  }
592
629
  const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
593
- fs5.ensureFileSync(config.alpineDataPath);
594
- fs5.writeFileSync(config.alpineDataPath, result);
630
+ fs6.ensureFileSync(config.alpineDataPath);
631
+ fs6.writeFileSync(config.alpineDataPath, result);
595
632
  return config.alpineDataPath;
596
633
  }
597
634
  async function buildCSS(disableTailwind) {
598
- const cssFiles = globSync(config.srcDir + "/**/*.css");
635
+ const cssFiles = globSync2(config.srcDir + "/**/*.css");
599
636
  for (const file of cssFiles) {
600
- const fileContents = fs5.readFileSync(file, "utf-8");
637
+ const fileContents = fs6.readFileSync(file, "utf-8");
601
638
  const result = disableTailwind ? fileContents : await postcss([tailwindPostcss(), remove_layers_default()]).process(fileContents, { from: file });
602
639
  const newPath = file.replace(config.srcDir, config.distDir);
603
- fs5.ensureFileSync(newPath);
604
- fs5.writeFileSync(newPath, result.css);
640
+ fs6.ensureFileSync(newPath);
641
+ fs6.writeFileSync(newPath, result.css);
605
642
  }
606
643
  logSize(config.distPublicDir, "css");
607
644
  }
608
645
  async function buildPublicFolderSymlinks() {
609
- const files = globSync(config.publicDir + "/**/*.*", {
646
+ const files = globSync2(config.publicDir + "/**/*.*", {
610
647
  ignore: "/**/*.{css,js,ts,tsx,jsx}"
611
648
  });
612
649
  for (const file of files) {
@@ -615,19 +652,19 @@ async function buildPublicFolderSymlinks() {
615
652
  const splitNewPath = newPath.split("/");
616
653
  splitNewPath.pop();
617
654
  const newDir = splitNewPath.join("/");
618
- fs5.ensureDirSync(newDir);
619
- fs5.symlinkSync(file, newPath);
655
+ fs6.ensureDirSync(newDir);
656
+ fs6.symlinkSync(file, newPath);
620
657
  } catch {
621
658
  }
622
659
  }
623
660
  }
624
661
  async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
625
- const files = globSync(pathName + "/**/*" + (type === "css" ? ".css" : ""));
662
+ const files = globSync2(pathName + "/**/*" + (type === "css" ? ".css" : ""));
626
663
  const fileSizes = files.map((file) => {
627
664
  if (!validExtensions.find((ext) => file.endsWith(ext))) return false;
628
665
  return {
629
666
  file,
630
- size: fs5.statSync(file).size / (1024 * 1e3)
667
+ size: fs6.statSync(file).size / (1024 * 1e3)
631
668
  };
632
669
  }).filter(Boolean);
633
670
  const totalSize = fileSizes.reduce((total, current) => {
@@ -665,13 +702,14 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
665
702
  return total.replace(`/[${current}]`, "");
666
703
  }, path5.dirname(builtComponentPath)) : path5.dirname(builtComponentPath);
667
704
  if (typeof config2?.staticPaths === "boolean") {
705
+ const urlPath = filePathToURLPath(outputPath);
668
706
  try {
669
707
  const req = { params: {} };
670
708
  const data = config2?.data ? await config2.data(req) : null;
671
- const staticComponentOutput = await componentFn({ data });
672
- fs5.writeFileSync(
709
+ const staticComponentOutput = await componentFn({ data, path: urlPath });
710
+ fs6.writeFileSync(
673
711
  path5.join(outputPath, "./index.html"),
674
- doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data }) : staticComponentOutput) + staticComment
712
+ doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, path: urlPath }) : staticComponentOutput) + staticComment
675
713
  );
676
714
  } catch (err) {
677
715
  console.error(err);
@@ -686,13 +724,14 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
686
724
  ...componentDynamicPaths?.length ? dynamicPath : {}
687
725
  }
688
726
  };
689
- const data = config2?.data ? await config2.data(req) : null;
690
- const staticComponentOutput = await componentFn({ req, data });
691
727
  const updatedOutDir = path5.join(outputPath, `./${componentDynamicPaths.map((key) => dynamicPath[key]).join("/")}`);
692
- fs5.ensureDirSync(updatedOutDir);
693
- fs5.writeFileSync(
728
+ const urlPath = filePathToURLPath(updatedOutDir);
729
+ const data = config2?.data ? await config2.data(req) : null;
730
+ const staticComponentOutput = await componentFn({ req, data, path: urlPath });
731
+ fs6.ensureDirSync(updatedOutDir);
732
+ fs6.writeFileSync(
694
733
  path5.join(updatedOutDir, "./index.html"),
695
- doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data }) : staticComponentOutput) + staticComment
734
+ doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, path: urlPath }) : staticComponentOutput) + staticComment
696
735
  );
697
736
  } catch (err) {
698
737
  console.log("Could not build static component", component.path);
@@ -741,7 +780,7 @@ async function buildOnLoadFile(componentData, isDev) {
741
780
  }
742
781
  `;
743
782
  const onLoadFilePath = path5.join(config.distDir, "./__xpineOnLoad.ts");
744
- fs5.writeFileSync(onLoadFilePath, output);
783
+ fs6.writeFileSync(onLoadFilePath, output);
745
784
  await build({
746
785
  entryPoints: [onLoadFilePath],
747
786
  format: "esm",
@@ -823,10 +862,10 @@ async function runDevServer() {
823
862
  const startServer2 = (await import(config.serverDistAppPath + `?cache=${Date.now()}`)).default;
824
863
  appServer = await startServer2();
825
864
  }
826
- const wsApp = express();
865
+ const wsApp = express2();
827
866
  const wsServer = http.createServer(wsApp);
828
867
  expressWs(wsApp, wsServer);
829
- class RefreshEmitter extends EventEmitter {
868
+ class RefreshEmitter extends EventEmitter2 {
830
869
  }
831
870
  ;
832
871
  const refreshEmitter = new RefreshEmitter();
@@ -849,7 +888,7 @@ function asyncServerClose(server) {
849
888
  });
850
889
  }
851
890
  function createRebuildEmitter(delay = 500) {
852
- class RebuildEmitter extends EventEmitter {
891
+ class RebuildEmitter extends EventEmitter2 {
853
892
  }
854
893
  ;
855
894
  const rebuildEmitter = new RebuildEmitter();
@@ -6,6 +6,8 @@ declare const _default: {
6
6
  isDynamicRoute: RegExp;
7
7
  endsWithTSX: RegExp;
8
8
  endsWithJSX: RegExp;
9
+ endsWithFileName: RegExp;
10
+ indexFile: RegExp;
9
11
  };
10
12
  export default _default;
11
13
  //# sourceMappingURL=regex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../../src/util/regex.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wBAQE"}
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../../src/util/regex.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,wBAUE"}
package/dist/types.d.ts CHANGED
@@ -16,6 +16,7 @@ export type WrapperProps = {
16
16
  children: any;
17
17
  config: ConfigFile;
18
18
  data?: any;
19
+ path?: string;
19
20
  };
20
21
  export type ConfigFile = {
21
22
  staticPaths?: boolean | (() => Promise<{
@@ -28,6 +29,7 @@ export type PageProps = {
28
29
  req: ServerRequest;
29
30
  res: Response;
30
31
  data: any;
32
+ path: string;
31
33
  };
32
34
  export type FileItem = {
33
35
  file: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,aAAa,CAAC;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC,CAAC;IACrE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC7C,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,aA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AE,CAAC,CAAC,CAAC;IACrE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC7C,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,aAAa,CAAC;IACnB,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC;CACvB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpine",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "main": "dist/index.js",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-secrets-manager": "^3.758.0",
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "failed",
3
+ "failedTests": []
4
+ }
package/types.ts CHANGED
@@ -20,6 +20,7 @@ export type WrapperProps = {
20
20
  children: any;
21
21
  config: ConfigFile;
22
22
  data?: any;
23
+ path?: string;
23
24
  }
24
25
 
25
26
  export type ConfigFile = {
@@ -32,6 +33,7 @@ export type PageProps = {
32
33
  req: ServerRequest;
33
34
  res: Response;
34
35
  data: any;
36
+ path: string;
35
37
  }
36
38
 
37
39
  export type FileItem = {