elegance-js 2.0.13 → 2.0.15

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.
@@ -299,9 +299,6 @@ var underline = (text) => {
299
299
  var white = (text) => {
300
300
  return `\x1B[38;2;255;247;229m${text}`;
301
301
  };
302
- var green = (text) => {
303
- return `\x1B[38;2;65;224;108m${text}`;
304
- };
305
302
  var log = (...text) => {
306
303
  if (options.quiet) return;
307
304
  return console.log(text.map((text2) => `${text2}\x1B[0m`).join(""));
@@ -321,16 +318,6 @@ var getAllSubdirectories = (dir, baseDir = dir) => {
321
318
  }
322
319
  return directories;
323
320
  };
324
- var getProjectFiles = (pagesDirectory) => {
325
- const files = [];
326
- const subdirectories = [...getAllSubdirectories(pagesDirectory), ""];
327
- for (const subdirectory of subdirectories) {
328
- const absoluteDirectoryPath = path.join(pagesDirectory, subdirectory);
329
- const subdirectoryFiles = fs.readdirSync(absoluteDirectoryPath, { withFileTypes: true }).filter((f) => f.name.endsWith(".ts"));
330
- files.push(...subdirectoryFiles);
331
- }
332
- return files;
333
- };
334
321
  var buildClient = async (DIST_DIR2) => {
335
322
  let clientString = "window.__name = (func) => func; ";
336
323
  clientString += fs.readFileSync(clientPath, "utf-8");
@@ -711,11 +698,32 @@ var generateLayout = async (DIST_DIR2, filePath, directory, childIndicator) => {
711
698
  return { pageContentHTML: renderedPage.bodyHTML, metadataHTML };
712
699
  };
713
700
  var builtLayouts = /* @__PURE__ */ new Map();
701
+ var buildLayouts = async () => {
702
+ const pagesDirectory = path.resolve(options.pagesDirectory);
703
+ const subdirectories = [...getAllSubdirectories(pagesDirectory), ""];
704
+ let shouldClientHardReload = false;
705
+ for (const directory of subdirectories) {
706
+ const abs = path.resolve(path.join(pagesDirectory, directory));
707
+ const files = fs.readdirSync(abs, { withFileTypes: true }).filter((f) => f.name.endsWith(".ts"));
708
+ for (const file of files) {
709
+ const filePath = path.join(file.parentPath, file.name);
710
+ const name = file.name.slice(0, file.name.length - 3);
711
+ const isLayout = name === "layout";
712
+ if (isLayout == false) {
713
+ continue;
714
+ }
715
+ try {
716
+ const builtLayout = await buildLayout(filePath, directory);
717
+ builtLayouts.set(directory, builtLayout);
718
+ } catch (e) {
719
+ console.error(e);
720
+ continue;
721
+ }
722
+ }
723
+ }
724
+ return { shouldClientHardReload };
725
+ };
714
726
  var buildLayout = async (filePath, directory) => {
715
- const storedState = globalThis.__SERVER_CURRENT_STATE__;
716
- const storedObjectAttributes = globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__;
717
- const storedLoadHooks = globalThis.__SERVER_CURRENT_LOADHOOKS__;
718
- const storedPageDataBanner = globalThis.__SERVER_PAGE_DATA_BANNER__;
719
727
  const id = globalThis.__SERVER_CURRENT_STATE_ID__ += 1;
720
728
  const childIndicator = `<template layout-id="${id}"></template>`;
721
729
  const { pageContentHTML, metadataHTML } = await generateLayout(
@@ -741,10 +749,6 @@ var buildLayout = async (filePath, directory) => {
741
749
  };
742
750
  };
743
751
  const pageURL = directory;
744
- globalThis.__SERVER_CURRENT_STATE__ = storedState;
745
- globalThis.__SERVER_CURRENT_OBJECT_ATTRIBUTES__ = storedObjectAttributes;
746
- globalThis.__SERVER_CURRENT_LOADHOOKS__ = storedLoadHooks;
747
- globalThis.__SERVER_PAGE_DATA_BANNER__ = storedPageDataBanner;
748
752
  return {
749
753
  pageContent: splitAt(pageContentHTML, childIndicator),
750
754
  metadata: splitAround(metadataHTML, childIndicator),
@@ -761,10 +765,6 @@ var fetchPageLayoutHTML = async (dirname) => {
761
765
  const filePath = path.resolve(path.join(options.pagesDirectory, dir, "layout.ts"));
762
766
  if (builtLayouts.has(filePath)) {
763
767
  layouts.push(builtLayouts.get(filePath));
764
- } else if (fs.existsSync(filePath)) {
765
- const built = await buildLayout(filePath, dir);
766
- builtLayouts.set(filePath, built);
767
- layouts.push(built);
768
768
  }
769
769
  }
770
770
  const pageContent = {
@@ -903,8 +903,6 @@ var build = async () => {
903
903
  try {
904
904
  {
905
905
  log(bold(yellow(" -- Elegance.JS -- ")));
906
- log(white(`Beginning build at ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}..`));
907
- log("");
908
906
  if (options.environment === "production") {
909
907
  log(
910
908
  " - ",
@@ -918,12 +916,8 @@ var build = async () => {
918
916
  }
919
917
  }
920
918
  if (options.preCompile) {
921
- log(
922
- white("Calling pre-compile hook..")
923
- );
924
919
  options.preCompile();
925
920
  }
926
- const projectFiles = getProjectFiles(options.pagesDirectory);
927
921
  const start = performance.now();
928
922
  {
929
923
  pluginsToShip = [];
@@ -944,8 +938,11 @@ var build = async () => {
944
938
  });
945
939
  }
946
940
  }
947
- const pagesTranspiled = performance.now();
948
941
  let shouldClientHardReload;
942
+ {
943
+ const { shouldClientHardReload: doReload } = await buildLayouts();
944
+ if (doReload) shouldClientHardReload = true;
945
+ }
949
946
  {
950
947
  const { shouldClientHardReload: doReload } = await buildPages(path.resolve(DIST_DIR));
951
948
  if (doReload) shouldClientHardReload = true;
@@ -963,18 +960,14 @@ var build = async () => {
963
960
  await fs.promises.cp(src, path.join(DIST_DIR), { recursive: true });
964
961
  }
965
962
  {
966
- log(`${Math.round(pagesTranspiled - start)}ms to Transpile Fales`);
967
- log(`${Math.round(pagesBuilt - pagesTranspiled)}ms to Build Pages`);
968
- log(`${Math.round(end - pagesBuilt)}ms to Build Client`);
969
- log(green(bold(`Compiled ${projectFiles.length} files in ${Math.ceil(end - start)}ms!`)));
963
+ log(`Took ${Math.round(pagesBuilt - start)}ms to Build Pages.`);
964
+ log(`Took ${Math.round(end - pagesBuilt)}ms to Build Client.`);
970
965
  }
971
966
  process.send({ event: "message", data: "set-layouts", layouts: JSON.stringify(Array.from(__SERVER_CURRENT_LAYOUTS__)), currentLayouTId: __SERVER_CURRENT_LAYOUT_ID__ });
972
967
  process.send({ event: "message", data: "compile-finish" });
973
968
  if (shouldClientHardReload) {
974
- log("Sending hard reload..");
975
969
  process.send({ event: "message", data: "hard-reload" });
976
970
  } else {
977
- log("Sending soft reload..");
978
971
  process.send({ event: "message", data: "soft-reload" });
979
972
  }
980
973
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elegance-js",
3
- "version": "2.0.13",
3
+ "version": "2.0.15",
4
4
  "description": "Web-Framework",
5
5
  "type": "module",
6
6
  "bin": {