@absolutejs/absolute 0.1.0 → 0.1.2
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/build-s7a2qjm1.js +2 -0
- package/dist/build-sewy0hdv.js +2 -0
- package/dist/src/core/build.js +5 -0
- package/dist/src/core/index.d.ts +2 -0
- package/dist/src/core/index.js +2 -0
- package/dist/src/core/pageHandlers.js +146 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/plugins/index.d.ts +2 -0
- package/dist/src/plugins/index.js +2 -0
- package/dist/src/plugins/networkingPlugin.js +3 -0
- package/dist/src/plugins/pageRouterPlugin.js +2 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.js +2 -0
- package/dist/src/utils/networking.js +3 -0
- package/dist/src/utils/updateScriptTags.js +3 -0
- package/package.json +3 -2
- package/src/core/build.ts +1 -1
- package/src/core/index.ts +2 -0
- package/src/core/pageHandlers.ts +1 -1
- package/src/index.ts +4 -0
- package/src/plugins/index.ts +2 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/updateScriptTags.ts +44 -35
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{h as r}from"../../build-s7a2qjm1.js";import{j as e}from"../utils/networking.js";import"../../build-sewy0hdv.js";import{argv as a}from"node:process";var{env:s}=globalThis.Bun;var t=s.HOST??"localhost",o=s.PORT??r,l,c=a,n=c.includes("--host");if(n)l=e(),t="0.0.0.0";var d=(i)=>i.listen({hostname:t,port:o},()=>{if(n)console.log(`Server started on http://localhost:${o}`),console.log(`Server started on network: http://${l}:${o}`);else console.log(`Server started on http://${t}:${o}`)});export{d as networkingPlugin};
|
|
3
|
+
export{d as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import"../../build-sewy0hdv.js";import q from"node:os";var x=()=>{let m=q.networkInterfaces(),j=Object.values(m).flat().filter((g)=>g!==void 0).find((g)=>g.family==="IPv4"&&!g.internal);if(j)return j.address;return console.warn("No IP address found, falling back to localhost"),"localhost"};export{x as getLocalIPAddress};
|
|
3
|
+
export{x as j};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import"../../build-sewy0hdv.js";import{readFile as K,writeFile as L}from"node:fs/promises";var{Glob:M}=globalThis.Bun;var W=async(y,z)=>{let A=new M("*.html"),q=[];for await(let j of A.scan({cwd:z,absolute:!0}))q.push(j);for(let j of q){let k=await K(j,"utf8");for(let[B,C]of Object.entries(y)){let E=B.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),H=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${E})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");k=k.replace(H,(O,I,Q,T,J)=>{return`${I}${C}${J}`})}await L(j,k,"utf8")}};export{W as updateScriptTags};
|
|
3
|
+
export{W as i};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/absolute",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A fullstack meta-framework for building web applications with TypeScript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/alexkahndev/absolutejs.git"
|
|
8
8
|
},
|
|
9
|
-
"main": "dist/index.js",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
10
11
|
"license": "CC BY-NC 4.0",
|
|
11
12
|
"author": "Alex Kahn",
|
|
12
13
|
"scripts": {
|
package/src/core/build.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
MILLISECONDS_IN_A_SECOND,
|
|
8
8
|
TIME_PRECISION
|
|
9
9
|
} from "../constants";
|
|
10
|
-
import {
|
|
10
|
+
import { updateScriptTags } from "../utils/updateScriptTags";
|
|
11
11
|
|
|
12
12
|
const projectRoot = join(import.meta.dir, "..", "..");
|
|
13
13
|
const buildDir = join(projectRoot, "example/build");
|
package/src/core/pageHandlers.ts
CHANGED
package/src/index.ts
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// TODO : this script seems to only work after building twice maybe due to the async nature of it
|
|
1
|
+
// TODO : this script seems to only work after building twice maybe due to the async nature of it
|
|
2
2
|
|
|
3
3
|
import { readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { Glob } from "bun";
|
|
@@ -11,41 +11,50 @@ import { Glob } from "bun";
|
|
|
11
11
|
* @param manifest - An object mapping script base names to the new file path.
|
|
12
12
|
* @param htmlDir - The directory that contains the HTML files.
|
|
13
13
|
*/
|
|
14
|
-
export const updateScriptTags = async (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
export const updateScriptTags = async (
|
|
15
|
+
manifest: Record<string, string>,
|
|
16
|
+
htmlDir: string
|
|
17
|
+
) => {
|
|
18
|
+
// Use Glob to find all HTML files in the specified directory
|
|
19
|
+
const htmlGlob = new Glob("*.html");
|
|
20
|
+
const htmlFiles: string[] = [];
|
|
21
|
+
for await (const file of htmlGlob.scan({
|
|
22
|
+
cwd: htmlDir,
|
|
23
|
+
absolute: true
|
|
24
|
+
})) {
|
|
25
|
+
htmlFiles.push(file);
|
|
26
|
+
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
// Process each HTML file
|
|
29
|
+
for (const filePath of htmlFiles) {
|
|
30
|
+
let content = await readFile(filePath, "utf8");
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
// For each script in the manifest, update matching <script> tags
|
|
33
|
+
for (const [scriptName, newPath] of Object.entries(manifest)) {
|
|
34
|
+
// Escape special regex characters in the scriptName
|
|
35
|
+
const escapedScriptName = scriptName.replace(
|
|
36
|
+
/[.*+?^${}()|[\]\\]/g,
|
|
37
|
+
"\\$&"
|
|
38
|
+
);
|
|
39
|
+
// The regex explanation:
|
|
40
|
+
// (1) (<script[^>]+src=["']) — capture the opening of the script tag up to the src attribute value
|
|
41
|
+
// (2) (\/?(?:.*\\/)?${escapedScriptName}) — capture any preceding path and the base script name
|
|
42
|
+
// (3) (?:\.[^."'/]+)? — optionally capture a dot and hash (if already hashed)
|
|
43
|
+
// (4) (\.js) — then capture the js extension
|
|
44
|
+
// (5) (["'][^>]*>) — capture the closing quote and remainder of the script tag
|
|
45
|
+
const regex = new RegExp(
|
|
46
|
+
`(<script[^>]+src=["'])(\/?(?:.*\\/)?${escapedScriptName})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,
|
|
47
|
+
"g"
|
|
48
|
+
);
|
|
49
|
+
// Replace the matched src attribute with the new value from the manifest
|
|
50
|
+
content = content.replace(
|
|
51
|
+
regex,
|
|
52
|
+
(_, prefix, _oldBase, _ext, suffix) => {
|
|
53
|
+
return `${prefix}${newPath}${suffix}`;
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
await writeFile(filePath, content, "utf8");
|
|
59
|
+
}
|
|
51
60
|
};
|