@absolutejs/absolute 0.1.3 → 0.1.5
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/LICENSE +24 -0
- package/package.json +1 -1
- package/src/core/build.ts +66 -35
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
```
|
|
2
|
+
# Creative Commons Attribution-NonCommercial 4.0 International License (CC BY-NC 4.0)
|
|
3
|
+
|
|
4
|
+
By using this project, you agree to the following terms under the Creative Commons Attribution-NonCommercial 4.0 International License.
|
|
5
|
+
|
|
6
|
+
## License Summary
|
|
7
|
+
This license allows you to:
|
|
8
|
+
- **Share**: Copy and redistribute the material in any medium or format.
|
|
9
|
+
- **Adapt**: Remix, transform, and build upon the material.
|
|
10
|
+
|
|
11
|
+
**Under the following conditions**:
|
|
12
|
+
- **Attribution**: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
|
13
|
+
- **Non-Commercial**: You may not use the material for commercial purposes.
|
|
14
|
+
|
|
15
|
+
## Full License Text
|
|
16
|
+
The full license text can be found at: https://creativecommons.org/licenses/by-nc/4.0/legalcode
|
|
17
|
+
|
|
18
|
+
## Contact Information for Commercial Use
|
|
19
|
+
For commercial use, licensing inquiries, or additional permissions, please contact:
|
|
20
|
+
Alex Kahn
|
|
21
|
+
alexkahndev@gmail.com
|
|
22
|
+
alexkahndev.github.io
|
|
23
|
+
```
|
|
24
|
+
|
package/package.json
CHANGED
package/src/core/build.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rm, mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join, basename } from "node:path";
|
|
3
|
-
import { exit } from "node:process";
|
|
3
|
+
import { cwd, exit } from "node:process";
|
|
4
4
|
import { $, build as bunBuild, Glob } from "bun";
|
|
5
5
|
import {
|
|
6
6
|
MILLISECONDS_IN_A_MINUTE,
|
|
@@ -9,26 +9,47 @@ import {
|
|
|
9
9
|
} from "../constants";
|
|
10
10
|
import { updateScriptTags } from "../utils/updateScriptTags";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
type BuildConfig = {
|
|
13
|
+
buildDir?: string;
|
|
14
|
+
assetsDir?: string;
|
|
15
|
+
reactIndexDir?: string;
|
|
16
|
+
javascriptDir?: string;
|
|
17
|
+
typeScriptDir?: string;
|
|
18
|
+
reactPagesDir?: string;
|
|
19
|
+
htmlDir?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const build = async ({
|
|
23
|
+
buildDir = "build",
|
|
24
|
+
assetsDir = "src/backend/assets",
|
|
25
|
+
reactIndexDir = "src/frontend/react/indexes",
|
|
26
|
+
javascriptDir = "src/frontend/javascript",
|
|
27
|
+
typeScriptDir = "src/frontend/typescript",
|
|
28
|
+
reactPagesDir = "src/frontend/react/pages",
|
|
29
|
+
htmlDir = "src/frontend/html"
|
|
30
|
+
}:BuildConfig = {}) => {
|
|
22
31
|
const start = performance.now();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
|
|
33
|
+
const projectRoot = cwd();
|
|
34
|
+
const buildDirAbsolute = join(projectRoot, buildDir);
|
|
35
|
+
const assetsDirAbsolute = join(projectRoot, assetsDir);
|
|
36
|
+
const reactIndexDirAbsolute = join(projectRoot, reactIndexDir);
|
|
37
|
+
const javascriptDirAbsolute = join(projectRoot, javascriptDir);
|
|
38
|
+
const typeScriptDirAbsolute = join(projectRoot, typeScriptDir);
|
|
39
|
+
const reactPagesDirAbsolute = join(projectRoot, reactPagesDir);
|
|
40
|
+
const htmlDirAbsolute = join(projectRoot, htmlDir);
|
|
41
|
+
|
|
42
|
+
await rm(buildDirAbsolute, { force: true, recursive: true });
|
|
43
|
+
await generateReactIndexFiles(
|
|
44
|
+
reactPagesDirAbsolute,
|
|
45
|
+
reactIndexDirAbsolute
|
|
46
|
+
);
|
|
26
47
|
|
|
27
48
|
const reactEntryGlob = new Glob("*.{tsx,jsx}");
|
|
28
49
|
const reactEntryPaths: string[] = [];
|
|
29
50
|
for await (const file of reactEntryGlob.scan({
|
|
30
51
|
absolute: true,
|
|
31
|
-
cwd:
|
|
52
|
+
cwd: reactIndexDirAbsolute
|
|
32
53
|
})) {
|
|
33
54
|
reactEntryPaths.push(file);
|
|
34
55
|
}
|
|
@@ -37,7 +58,7 @@ export const build = async () => {
|
|
|
37
58
|
const javascriptEntryPaths: string[] = [];
|
|
38
59
|
for await (const file of javascriptEntryGlob.scan({
|
|
39
60
|
absolute: true,
|
|
40
|
-
cwd:
|
|
61
|
+
cwd: javascriptDirAbsolute
|
|
41
62
|
})) {
|
|
42
63
|
javascriptEntryPaths.push(file);
|
|
43
64
|
}
|
|
@@ -46,7 +67,7 @@ export const build = async () => {
|
|
|
46
67
|
const typeScriptEntryPaths: string[] = [];
|
|
47
68
|
for await (const file of typeScriptEntryGlob.scan({
|
|
48
69
|
absolute: true,
|
|
49
|
-
cwd:
|
|
70
|
+
cwd: typeScriptDirAbsolute
|
|
50
71
|
})) {
|
|
51
72
|
typeScriptEntryPaths.push(file);
|
|
52
73
|
}
|
|
@@ -58,7 +79,7 @@ export const build = async () => {
|
|
|
58
79
|
entrypoints: entryPaths,
|
|
59
80
|
format: "esm",
|
|
60
81
|
naming: `[dir]/[name].[hash].[ext]`,
|
|
61
|
-
outdir:
|
|
82
|
+
outdir: buildDirAbsolute
|
|
62
83
|
}).catch((error) => {
|
|
63
84
|
console.error("Build failed:", error);
|
|
64
85
|
exit(1);
|
|
@@ -71,14 +92,17 @@ export const build = async () => {
|
|
|
71
92
|
console.info(log);
|
|
72
93
|
});
|
|
73
94
|
|
|
74
|
-
await
|
|
95
|
+
await copyAssetsTobuildDirAbsolute(
|
|
96
|
+
assetsDirAbsolute,
|
|
97
|
+
buildDirAbsolute,
|
|
98
|
+
projectRoot
|
|
99
|
+
);
|
|
75
100
|
|
|
76
|
-
// TODO: Find a way to make this type-safe instead of string as the key it should be enumerated with the names of the files
|
|
77
101
|
const manifest = outputs.reduce<Record<string, string>>((acc, artifact) => {
|
|
78
102
|
let relativePath = artifact.path;
|
|
79
103
|
|
|
80
|
-
if (relativePath.startsWith(
|
|
81
|
-
relativePath = relativePath.slice(
|
|
104
|
+
if (relativePath.startsWith(buildDirAbsolute)) {
|
|
105
|
+
relativePath = relativePath.slice(buildDirAbsolute.length);
|
|
82
106
|
}
|
|
83
107
|
|
|
84
108
|
relativePath = relativePath.replace(/^\/+/, "");
|
|
@@ -98,7 +122,7 @@ export const build = async () => {
|
|
|
98
122
|
return acc;
|
|
99
123
|
}, {});
|
|
100
124
|
|
|
101
|
-
await updateScriptTags(manifest,
|
|
125
|
+
await updateScriptTags(manifest, htmlDirAbsolute);
|
|
102
126
|
|
|
103
127
|
const end = performance.now();
|
|
104
128
|
const durationMs = end - start;
|
|
@@ -115,22 +139,29 @@ export const build = async () => {
|
|
|
115
139
|
return manifest;
|
|
116
140
|
};
|
|
117
141
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await $`cp -R ${
|
|
124
|
-
await
|
|
142
|
+
const copyAssetsTobuildDirAbsolute = async (
|
|
143
|
+
assetsDirAbsolute: string,
|
|
144
|
+
buildDirAbsolute: string,
|
|
145
|
+
projectRoot: string
|
|
146
|
+
) => {
|
|
147
|
+
await $`cp -R ${assetsDirAbsolute} ${buildDirAbsolute}`;
|
|
148
|
+
await mkdir(join(buildDirAbsolute, "html"));
|
|
149
|
+
await mkdir(join(buildDirAbsolute, "htmx"));
|
|
150
|
+
|
|
151
|
+
await $`cp -R ${join(projectRoot, "example/html")} ${join(buildDirAbsolute)}`;
|
|
152
|
+
await $`cp -R ${join(projectRoot, "example/htmx")} ${join(buildDirAbsolute)}`;
|
|
125
153
|
};
|
|
126
154
|
|
|
127
|
-
const generateReactIndexFiles = async (
|
|
128
|
-
|
|
129
|
-
|
|
155
|
+
const generateReactIndexFiles = async (
|
|
156
|
+
reactPagesDirAbsolute: string,
|
|
157
|
+
reactIndexDirAbsolute: string
|
|
158
|
+
) => {
|
|
159
|
+
await rm(reactIndexDirAbsolute, { force: true, recursive: true });
|
|
160
|
+
await mkdir(reactIndexDirAbsolute);
|
|
130
161
|
|
|
131
162
|
const pagesGlob = new Glob("*.*");
|
|
132
163
|
const files: string[] = [];
|
|
133
|
-
for await (const file of pagesGlob.scan({ cwd:
|
|
164
|
+
for await (const file of pagesGlob.scan({ cwd: reactPagesDirAbsolute })) {
|
|
134
165
|
files.push(file);
|
|
135
166
|
}
|
|
136
167
|
const promises = files.map(async (file) => {
|
|
@@ -143,7 +174,7 @@ const generateReactIndexFiles = async () => {
|
|
|
143
174
|
].join("\n");
|
|
144
175
|
|
|
145
176
|
return writeFile(
|
|
146
|
-
join(
|
|
177
|
+
join(reactIndexDirAbsolute, `${componentName}Index.tsx`),
|
|
147
178
|
content
|
|
148
179
|
);
|
|
149
180
|
});
|