elegance-js 2.0.12 → 2.0.14
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/client/client.mjs +10 -18
- package/dist/page_compiler.mjs +33 -38
- package/package.json +1 -1
package/dist/client/client.mjs
CHANGED
|
@@ -177,17 +177,7 @@ var sanitizePathname = (pn) => {
|
|
|
177
177
|
return pn.slice(0, -1);
|
|
178
178
|
};
|
|
179
179
|
var currentPage = sanitizePathname(loc.pathname);
|
|
180
|
-
|
|
181
|
-
const sanitized = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
|
|
182
|
-
const parts = sanitized.split("/").filter(Boolean);
|
|
183
|
-
const subpaths = [
|
|
184
|
-
"/",
|
|
185
|
-
...parts.map((_, i) => "/" + parts.slice(0, i + 1).join("/"))
|
|
186
|
-
];
|
|
187
|
-
if (sanitized === "/") return ["/"];
|
|
188
|
-
return subpaths;
|
|
189
|
-
}
|
|
190
|
-
var createStateManager = (subjects) => {
|
|
180
|
+
var createStateManager = (subjects, bindLevel) => {
|
|
191
181
|
const state = {
|
|
192
182
|
subjects: subjects.map((subject) => {
|
|
193
183
|
const s = {
|
|
@@ -209,14 +199,16 @@ var createStateManager = (subjects) => {
|
|
|
209
199
|
destroy: (s) => {
|
|
210
200
|
state.subjects.splice(state.subjects.indexOf(s), 1);
|
|
211
201
|
},
|
|
212
|
-
|
|
213
|
-
Bind is deprecated, but kept as a paramater to not upset legacy code.
|
|
214
|
-
*/
|
|
215
|
-
get: (id, bind) => {
|
|
202
|
+
get: (id) => {
|
|
216
203
|
const subject = state.subjects.find((s) => s.id === id);
|
|
217
204
|
if (subject) return subject;
|
|
218
|
-
|
|
219
|
-
|
|
205
|
+
if (bindLevel === 2 /* SCOPED */) return void 0;
|
|
206
|
+
const parts = window.location.pathname.split("/").filter(Boolean);
|
|
207
|
+
const paths = [
|
|
208
|
+
...parts.map((_, i) => "/" + parts.slice(0, i + 1).join("/")),
|
|
209
|
+
"/"
|
|
210
|
+
].reverse();
|
|
211
|
+
for (const item of paths) {
|
|
220
212
|
const sanitized = sanitizePathname(item);
|
|
221
213
|
const data = ld[sanitized];
|
|
222
214
|
if (!data) continue;
|
|
@@ -248,7 +240,7 @@ var initPageData = (data, currentPage2, previousPage, bindLevel) => {
|
|
|
248
240
|
}
|
|
249
241
|
let state = data?.stateManager;
|
|
250
242
|
if (!state) {
|
|
251
|
-
state = createStateManager(data.state || []);
|
|
243
|
+
state = createStateManager(data.state || [], bindLevel);
|
|
252
244
|
data.stateManager = state;
|
|
253
245
|
}
|
|
254
246
|
for (const subject of state.subjects) {
|
package/dist/page_compiler.mjs
CHANGED
|
@@ -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,34 @@ 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 (DIST_DIR2) => {
|
|
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 hardReloadForPage = await buildLayout(filePath, directory);
|
|
717
|
+
if (hardReloadForPage) {
|
|
718
|
+
shouldClientHardReload = true;
|
|
719
|
+
}
|
|
720
|
+
} catch (e) {
|
|
721
|
+
console.error(e);
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return { shouldClientHardReload };
|
|
727
|
+
};
|
|
714
728
|
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
729
|
const id = globalThis.__SERVER_CURRENT_STATE_ID__ += 1;
|
|
720
730
|
const childIndicator = `<template layout-id="${id}"></template>`;
|
|
721
731
|
const { pageContentHTML, metadataHTML } = await generateLayout(
|
|
@@ -741,10 +751,6 @@ var buildLayout = async (filePath, directory) => {
|
|
|
741
751
|
};
|
|
742
752
|
};
|
|
743
753
|
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
754
|
return {
|
|
749
755
|
pageContent: splitAt(pageContentHTML, childIndicator),
|
|
750
756
|
metadata: splitAround(metadataHTML, childIndicator),
|
|
@@ -761,10 +767,6 @@ var fetchPageLayoutHTML = async (dirname) => {
|
|
|
761
767
|
const filePath = path.resolve(path.join(options.pagesDirectory, dir, "layout.ts"));
|
|
762
768
|
if (builtLayouts.has(filePath)) {
|
|
763
769
|
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
770
|
}
|
|
769
771
|
}
|
|
770
772
|
const pageContent = {
|
|
@@ -903,8 +905,6 @@ var build = async () => {
|
|
|
903
905
|
try {
|
|
904
906
|
{
|
|
905
907
|
log(bold(yellow(" -- Elegance.JS -- ")));
|
|
906
|
-
log(white(`Beginning build at ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}..`));
|
|
907
|
-
log("");
|
|
908
908
|
if (options.environment === "production") {
|
|
909
909
|
log(
|
|
910
910
|
" - ",
|
|
@@ -918,12 +918,8 @@ var build = async () => {
|
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
920
|
if (options.preCompile) {
|
|
921
|
-
log(
|
|
922
|
-
white("Calling pre-compile hook..")
|
|
923
|
-
);
|
|
924
921
|
options.preCompile();
|
|
925
922
|
}
|
|
926
|
-
const projectFiles = getProjectFiles(options.pagesDirectory);
|
|
927
923
|
const start = performance.now();
|
|
928
924
|
{
|
|
929
925
|
pluginsToShip = [];
|
|
@@ -944,8 +940,11 @@ var build = async () => {
|
|
|
944
940
|
});
|
|
945
941
|
}
|
|
946
942
|
}
|
|
947
|
-
const pagesTranspiled = performance.now();
|
|
948
943
|
let shouldClientHardReload;
|
|
944
|
+
{
|
|
945
|
+
const { shouldClientHardReload: doReload } = await buildLayouts(path.resolve(DIST_DIR));
|
|
946
|
+
if (doReload) shouldClientHardReload = true;
|
|
947
|
+
}
|
|
949
948
|
{
|
|
950
949
|
const { shouldClientHardReload: doReload } = await buildPages(path.resolve(DIST_DIR));
|
|
951
950
|
if (doReload) shouldClientHardReload = true;
|
|
@@ -963,18 +962,14 @@ var build = async () => {
|
|
|
963
962
|
await fs.promises.cp(src, path.join(DIST_DIR), { recursive: true });
|
|
964
963
|
}
|
|
965
964
|
{
|
|
966
|
-
log(
|
|
967
|
-
log(
|
|
968
|
-
log(`${Math.round(end - pagesBuilt)}ms to Build Client`);
|
|
969
|
-
log(green(bold(`Compiled ${projectFiles.length} files in ${Math.ceil(end - start)}ms!`)));
|
|
965
|
+
log(`Took ${Math.round(pagesBuilt - start)}ms to Build Pages.`);
|
|
966
|
+
log(`Took ${Math.round(end - pagesBuilt)}ms to Build Client.`);
|
|
970
967
|
}
|
|
971
968
|
process.send({ event: "message", data: "set-layouts", layouts: JSON.stringify(Array.from(__SERVER_CURRENT_LAYOUTS__)), currentLayouTId: __SERVER_CURRENT_LAYOUT_ID__ });
|
|
972
969
|
process.send({ event: "message", data: "compile-finish" });
|
|
973
970
|
if (shouldClientHardReload) {
|
|
974
|
-
log("Sending hard reload..");
|
|
975
971
|
process.send({ event: "message", data: "hard-reload" });
|
|
976
972
|
} else {
|
|
977
|
-
log("Sending soft reload..");
|
|
978
973
|
process.send({ event: "message", data: "soft-reload" });
|
|
979
974
|
}
|
|
980
975
|
} catch (e) {
|