elegance-js 2.1.23 → 2.1.26

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.
Files changed (103) hide show
  1. package/dist/client/effect.d.ts +27 -0
  2. package/dist/client/effect.js +37 -0
  3. package/dist/client/eventListener.d.ts +39 -0
  4. package/dist/client/eventListener.js +52 -0
  5. package/dist/client/loadHook.d.ts +34 -0
  6. package/dist/client/loadHook.js +52 -0
  7. package/dist/client/observer.d.ts +36 -0
  8. package/dist/client/observer.js +66 -0
  9. package/dist/client/runtime.d.ts +105 -0
  10. package/dist/client/runtime.js +620 -0
  11. package/dist/client/state.d.ts +40 -0
  12. package/dist/client/state.js +110 -0
  13. package/dist/compilation/compiler.d.ts +155 -0
  14. package/dist/compilation/compiler.js +1153 -0
  15. package/dist/components/ClientComponent.d.ts +22 -0
  16. package/dist/components/ClientComponent.js +55 -0
  17. package/dist/components/Link.d.ts +16 -1
  18. package/dist/components/Link.js +22 -0
  19. package/dist/components/Portal.d.ts +2 -0
  20. package/dist/components/Portal.js +2 -0
  21. package/dist/elements/element.d.ts +87 -0
  22. package/dist/elements/element.js +33 -0
  23. package/dist/elements/element_list.d.ts +7 -0
  24. package/dist/elements/element_list.js +65 -0
  25. package/dist/elements/raw.d.ts +14 -0
  26. package/dist/elements/raw.js +78 -0
  27. package/dist/elements/specific_props.d.ts +750 -0
  28. package/dist/global.d.ts +221 -327
  29. package/dist/index.d.ts +15 -3
  30. package/dist/index.js +11 -0
  31. package/dist/server/layout.d.ts +34 -3
  32. package/dist/server/layout.js +6 -0
  33. package/dist/server/log.d.ts +12 -0
  34. package/dist/server/log.js +64 -0
  35. package/dist/server/page.d.ts +32 -0
  36. package/dist/server/page.js +6 -0
  37. package/dist/server/runtime.d.ts +6 -0
  38. package/dist/server/runtime.js +72 -0
  39. package/dist/server/server.d.ts +103 -11
  40. package/dist/server/server.js +709 -0
  41. package/package.json +13 -13
  42. package/scripts/bootstrap.js +37 -273
  43. package/scripts/bootstrap_files/elegance.txt +40 -0
  44. package/scripts/bootstrap_files/index.txt +3 -0
  45. package/scripts/bootstrap_files/layout.txt +46 -0
  46. package/scripts/bootstrap_files/middleware.txt +18 -0
  47. package/scripts/bootstrap_files/page.txt +123 -0
  48. package/scripts/bootstrap_files/route.txt +6 -0
  49. package/scripts/elegance_dev.ts +40 -0
  50. package/scripts/elegance_prod.ts +40 -0
  51. package/scripts/elegance_static.ts +24 -0
  52. package/scripts/prod.js +9 -26
  53. package/scripts/run.js +13 -0
  54. package/scripts/static.js +13 -0
  55. package/dist/build.d.ts +0 -2
  56. package/dist/build.mjs +0 -202
  57. package/dist/client/client.d.ts +0 -1
  58. package/dist/client/client.mjs +0 -574
  59. package/dist/client/processPageElements.d.ts +0 -1
  60. package/dist/client/processPageElements.mjs +0 -117
  61. package/dist/client/render.d.ts +0 -1
  62. package/dist/client/render.mjs +0 -40
  63. package/dist/client/watcher.d.ts +0 -1
  64. package/dist/client/watcher.mjs +0 -26
  65. package/dist/compilation/compilation.d.ts +0 -139
  66. package/dist/compilation/compilation.mjs +0 -751
  67. package/dist/compilation/compiler_process.d.ts +0 -3
  68. package/dist/compilation/compiler_process.mjs +0 -102
  69. package/dist/compilation/dynamic_compiler.d.ts +0 -10
  70. package/dist/compilation/dynamic_compiler.mjs +0 -93
  71. package/dist/compile_docs.mjs +0 -34
  72. package/dist/components/Link.mjs +0 -65
  73. package/dist/global.mjs +0 -0
  74. package/dist/helpers/ObjectAttributeType.d.ts +0 -7
  75. package/dist/helpers/ObjectAttributeType.mjs +0 -11
  76. package/dist/helpers/camelToKebab.d.ts +0 -1
  77. package/dist/helpers/camelToKebab.mjs +0 -6
  78. package/dist/index.mjs +0 -3
  79. package/dist/internal/deprecate.d.ts +0 -1
  80. package/dist/internal/deprecate.mjs +0 -7
  81. package/dist/log.d.ts +0 -10
  82. package/dist/log.mjs +0 -38
  83. package/dist/server/generateHTMLTemplate.d.ts +0 -12
  84. package/dist/server/generateHTMLTemplate.mjs +0 -41
  85. package/dist/server/layout.mjs +0 -19
  86. package/dist/server/loadHook.d.ts +0 -30
  87. package/dist/server/loadHook.mjs +0 -50
  88. package/dist/server/observe.d.ts +0 -19
  89. package/dist/server/observe.mjs +0 -16
  90. package/dist/server/render.d.ts +0 -5
  91. package/dist/server/render.mjs +0 -61
  92. package/dist/server/server.mjs +0 -429
  93. package/dist/server/state.d.ts +0 -61
  94. package/dist/server/state.mjs +0 -146
  95. package/dist/shared/bindServerElements.mjs +0 -3
  96. package/dist/shared/serverElements.d.ts +0 -11
  97. package/dist/shared/serverElements.mjs +0 -164
  98. package/scripts/dev.js +0 -33
  99. package/scripts/export.js +0 -20
  100. package/scripts/ts-arc-dev.js +0 -9
  101. package/scripts/ts-arc-prod.js +0 -9
  102. /package/dist/{compile_docs.d.ts → elements/specific_props.js} +0 -0
  103. /package/dist/{shared/bindServerElements.d.ts → global.js} +0 -0
@@ -0,0 +1,40 @@
1
+ import { execSync } from "child_process";
2
+ import { serveProject, compileEntireProject, setCompilerOptions, } from "elegance-js";
3
+ import path from "path";
4
+
5
+ async function runtime() {
6
+ const pagesDirectory = path.resolve("./pages");
7
+ const publicDirectory = path.resolve("./public");
8
+ const outputDirectory = path.resolve(".elegance");
9
+
10
+ setCompilerOptions({
11
+ pagesDirectory: pagesDirectory,
12
+ publicDirectory: publicDirectory,
13
+ outputDirectory: outputDirectory,
14
+ environment: "production",
15
+
16
+ doHotReload: true,
17
+ });
18
+
19
+ const { allLayouts, allPages, allStatusCodePages, compiledStaticLayouts, compiledStaticPages, } = await compileEntireProject();
20
+
21
+ execSync(`npx @tailwindcss/cli -i ${path.join(pagesDirectory, "input.css")} -o ${path.join(outputDirectory, "DIST", "index.css")} --minify`);
22
+
23
+ await serveProject({
24
+ port: 3000,
25
+ hostname: "0.0.0.0",
26
+
27
+ allowDynamic: true,
28
+ allowStatusCodePages: true,
29
+ serveAPI: true,
30
+
31
+ allLayouts,
32
+ allStatusCodePages,
33
+ allPages,
34
+
35
+ builtStaticPages: compiledStaticPages,
36
+ builtStaticLayouts: compiledStaticLayouts,
37
+ });
38
+ }
39
+
40
+ runtime();
@@ -0,0 +1,24 @@
1
+ import { execSync } from "child_process";
2
+ import { serveProject, compileEntireProject, setCompilerOptions, } from "elegance-js";
3
+ import path from "path";
4
+
5
+ async function runtime() {
6
+ const pagesDirectory = path.resolve("./pages");
7
+ const publicDirectory = path.resolve("./public");
8
+ const outputDirectory = path.resolve(".elegance");
9
+
10
+ setCompilerOptions({
11
+ pagesDirectory: pagesDirectory,
12
+ publicDirectory: publicDirectory,
13
+ outputDirectory: outputDirectory,
14
+ environment: "production",
15
+
16
+ doHotReload: false,
17
+ });
18
+
19
+ await compileEntireProject();
20
+
21
+ execSync(`npx @tailwindcss/cli -i ${path.join(pagesDirectory, "input.css")} -o ${path.join(outputDirectory, "DIST", "index.css")} --minify`);
22
+ }
23
+
24
+ runtime();
package/scripts/prod.js CHANGED
@@ -1,30 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { compile } from "elegance-js/build"
4
- import { exec, execSync } from "node:child_process";
3
+ import { startEleganceRuntime } from "elegance-js";
4
+ import { join, dirname } from "path";
5
5
 
6
- let child = undefined;
6
+ import { fileURLToPath } from "url";
7
7
 
8
- compile({
9
- environment: "production",
10
- outputDirectory: ".elegance",
11
- pagesDirectory: "./pages",
12
- publicDirectory: {
13
- method: "recursive-copy",
14
- path: "./public",
15
- },
16
- server: {
17
- runServer: true,
18
- port: 3000,
19
- },
20
- hotReload: undefined,
21
- postCompile: () => {
22
- if (child !== undefined) {
23
- child.kill('SIGKILL');
24
- }
25
-
26
- const childProcess = execSync("npx @tailwindcss/cli -i \"./index.css\" -o \"../.elegance/dist/index.css\" --cwd \"./pages\" --minify=true")
27
-
28
- child = childProcess;
29
- },
30
- })
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+
11
+ const runtimePath = join(__dirname, "elegance_prod.ts");
12
+
13
+ startEleganceRuntime(runtimePath);
package/scripts/run.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { startEleganceRuntime } from "elegance-js";
4
+ import { join, dirname } from "path";
5
+
6
+ import { fileURLToPath } from "url";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+
11
+ const runtimePath = join(__dirname, "elegance_dev.ts");
12
+
13
+ startEleganceRuntime(runtimePath);
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { startEleganceRuntime } from "elegance-js";
4
+ import { join, dirname } from "path";
5
+
6
+ import { fileURLToPath } from "url";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+
11
+ const runtimePath = join(__dirname, "elegance_static.ts");
12
+
13
+ startEleganceRuntime(runtimePath);
package/dist/build.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { CompilationOptions } from "./compilation/compilation";
2
- export declare const compile: (props: CompilationOptions) => Promise<void>;
package/dist/build.mjs DELETED
@@ -1,202 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
- import child_process from "node:child_process";
5
- import http from "http";
6
- import { startServer } from "./server/server";
7
- import { log, setQuiet } from "./log";
8
- import { populateServerMaps, setCompilationOptions } from "./compilation/compilation";
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
- const packageDir = path.resolve(__dirname, "..");
12
- const builderPath = path.resolve(packageDir, "dist", "compilation", "compiler_process.mjs");
13
- const yellow = (text) => {
14
- return `\x1B[38;2;238;184;68m${text}`;
15
- };
16
- const bold = (text) => {
17
- return `\x1B[1m${text}`;
18
- };
19
- const white = (text) => {
20
- return `\x1B[38;2;255;247;229m${text}`;
21
- };
22
- const green = (text) => {
23
- return `\x1B[38;2;65;224;108m${text}`;
24
- };
25
- const finishLog = (...text) => {
26
- log.info(text.map((text2) => `${text2}\x1B[0m`).join(""));
27
- };
28
- let options = process.env.OPTIONS;
29
- const getAllSubdirectories = (dir, baseDir = dir) => {
30
- let directories = [];
31
- const items = fs.readdirSync(dir, { withFileTypes: true });
32
- for (const item of items) {
33
- if (item.isDirectory()) {
34
- const fullPath = path.join(dir, item.name);
35
- const relativePath = path.relative(baseDir, fullPath);
36
- directories.push(relativePath);
37
- directories = directories.concat(getAllSubdirectories(fullPath, baseDir));
38
- }
39
- }
40
- return directories;
41
- };
42
- let child = void 0;
43
- let isBuilding = false;
44
- const runBuild = (filepath, DIST_DIR) => {
45
- const optionsString = JSON.stringify(options);
46
- if (isBuilding) {
47
- return;
48
- }
49
- if (child !== void 0) {
50
- child.removeAllListeners();
51
- child.kill("SIGKILL");
52
- }
53
- child = child_process.spawn("node", ["--import", "ts-arc/register", filepath], {
54
- stdio: ["inherit", "inherit", "inherit", "ipc"],
55
- env: {
56
- ...process.env,
57
- DIST_DIR,
58
- OPTIONS: optionsString,
59
- PACKAGE_PATH: packageDir,
60
- DO_BUILD: "true"
61
- }
62
- });
63
- process.env.OPTIONS = optionsString;
64
- process.env.DIST_DIR = DIST_DIR;
65
- child.on("error", () => {
66
- log.error("Failed to start child process.");
67
- });
68
- child.on("exit", () => {
69
- isBuilding = false;
70
- log.info("Builder process complete");
71
- });
72
- child.on("message", (message) => {
73
- const { data } = message;
74
- if (data === "hard-reload") {
75
- httpStream?.write(`data: hard-reload
76
-
77
- `);
78
- } else if (data === "soft-reload") {
79
- httpStream?.write(`data: reload
80
-
81
- `);
82
- } else if (data === "compile-finish") {
83
- isBuilding = false;
84
- if (options.postCompile) {
85
- finishLog(
86
- white("Calling post-compile hook..")
87
- );
88
- options.postCompile();
89
- }
90
- } else if (data === "set-pages-and-layouts") {
91
- const { pageMap, layoutMap } = JSON.parse(message.content);
92
- populateServerMaps(new Map(pageMap), new Map(layoutMap));
93
- }
94
- });
95
- };
96
- const build = (DIST_DIR) => {
97
- runBuild(builderPath, DIST_DIR);
98
- setCompilationOptions(options, DIST_DIR);
99
- };
100
- let isTimedOut = false;
101
- const currentWatchers = [];
102
- let httpStream;
103
- const registerListener = async () => {
104
- const server = http.createServer((req, res) => {
105
- if (req.url === "/events") {
106
- finishLog(white("Client listening for changes.."));
107
- res.writeHead(200, {
108
- "Content-Type": "text/event-stream",
109
- "Cache-Control": "no-cache",
110
- "Connection": "keep-alive",
111
- "Transfer-Encoding": "chunked",
112
- "X-Accel-Buffering": "no",
113
- "Content-Encoding": "none",
114
- "Access-Control-Allow-Origin": "*",
115
- "Access-Control-Allow-Methods": "*",
116
- "Access-Control-Allow-Headers": "*"
117
- });
118
- httpStream = res;
119
- httpStream.write(`data: ping
120
-
121
- `);
122
- } else {
123
- res.writeHead(404, { "Content-Type": "text/plain" });
124
- res.end("Not Found");
125
- }
126
- });
127
- server.listen(options.hotReload.port, () => {
128
- finishLog(bold(green("Hot-Reload server online!")));
129
- });
130
- };
131
- const compile = async (props) => {
132
- options = props;
133
- setQuiet(options.quiet ?? false);
134
- const watch = options.hotReload !== void 0;
135
- const BUILD_FLAG = path.join(options.outputDirectory, "ELEGANCE_BUILD_FLAG");
136
- if (!fs.existsSync(options.outputDirectory)) {
137
- fs.mkdirSync(options.outputDirectory, { recursive: true });
138
- fs.writeFileSync(
139
- path.join(BUILD_FLAG),
140
- "This file marks this directory as one containing an Elegance Build.",
141
- "utf-8"
142
- );
143
- } else {
144
- if (!fs.existsSync(BUILD_FLAG)) {
145
- throw `The output directory already exists, but is not an Elegance Build directory.`;
146
- }
147
- }
148
- const DIST_DIR = path.join(props.outputDirectory, "dist");
149
- if (!fs.existsSync(DIST_DIR)) {
150
- fs.mkdirSync(DIST_DIR, { recursive: true });
151
- }
152
- build(DIST_DIR);
153
- if (options.server != void 0 && options.server.runServer == true) {
154
- startServer({
155
- root: options.server.root ?? DIST_DIR,
156
- environment: options.environment,
157
- port: options.server.port ?? 3e3,
158
- host: options.server.host ?? "localhost",
159
- DIST_DIR,
160
- pagesDirectory: options.pagesDirectory
161
- });
162
- }
163
- if (watch) {
164
- await registerListener();
165
- for (const watcher of currentWatchers) {
166
- watcher.close();
167
- }
168
- let extra = [];
169
- if (options.hotReload?.extraWatchDirectories) {
170
- const dirs = options.hotReload?.extraWatchDirectories ?? [];
171
- if (dirs.length !== 0) {
172
- for (const dir of dirs) {
173
- const subdirs = getAllSubdirectories(dir).map((f) => path.join(dir, f));
174
- extra.push(...subdirs);
175
- }
176
- }
177
- }
178
- const pagesSubDirs = getAllSubdirectories(options.pagesDirectory).map((f) => path.join(options.pagesDirectory, f));
179
- const subdirectories = [...pagesSubDirs, options.pagesDirectory, ...extra];
180
- finishLog(yellow("Hot-Reload Watching Subdirectories: "), ...subdirectories.join(", "));
181
- const watcherFn = async () => {
182
- if (isTimedOut) return;
183
- isTimedOut = true;
184
- process.stdout.write("\x1Bc");
185
- setTimeout(async () => {
186
- build(DIST_DIR);
187
- isTimedOut = false;
188
- }, 100);
189
- };
190
- for (const directory of subdirectories) {
191
- const watcher = fs.watch(
192
- directory,
193
- {},
194
- watcherFn
195
- );
196
- currentWatchers.push(watcher);
197
- }
198
- }
199
- };
200
- export {
201
- compile
202
- };
@@ -1 +0,0 @@
1
- import "../shared/bindServerElements";