@absolutejs/absolute 0.1.3 → 0.1.6
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/dist/index.js +88 -88
- package/dist/src/core/build.d.ts +11 -1
- package/package.json +3 -2
- package/src/core/build.ts +66 -35
package/dist/src/core/build.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
type BuildConfig = {
|
|
2
|
+
buildDir?: string;
|
|
3
|
+
assetsDir?: string;
|
|
4
|
+
reactIndexDir?: string;
|
|
5
|
+
javascriptDir?: string;
|
|
6
|
+
typeScriptDir?: string;
|
|
7
|
+
reactPagesDir?: string;
|
|
8
|
+
htmlDir?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const build: ({ buildDir, assetsDir, reactIndexDir, javascriptDir, typeScriptDir, reactPagesDir, htmlDir }?: BuildConfig) => Promise<Record<string, string>>;
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/absolute",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "A fullstack meta-framework for building web applications with TypeScript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"build": "rm -rf dist && bun build src/index.ts --outdir dist --minify --splitting --target=bun && tsc --emitDeclarationOnly --project tsconfig.json",
|
|
15
15
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
16
16
|
"format": "prettier --write \"./**/*.{js,jsx,ts,tsx,css,json}\"",
|
|
17
|
-
"dev": "bun run --watch example/server.ts"
|
|
17
|
+
"dev": "bun run --watch example/server.ts",
|
|
18
|
+
"release": "bun run build && bun publish"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"@elysiajs/static": "1.0.2",
|
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
|
});
|