@spirobel/mininext 0.6.0 → 0.6.1
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/mininext.js +10 -4
- package/dist/url.d.ts +21 -3
- package/dist/url.js +20 -8
- package/package.json +3 -3
package/dist/mininext.js
CHANGED
|
@@ -85,14 +85,20 @@ async function buildBackend(backendPath = "backend/backend.ts") {
|
|
|
85
85
|
console.log(await $ `bun run build.ts frontend ${frontEndPath}`.text());
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
for (const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
88
|
+
for (const svg of url.getSvgs()) {
|
|
89
|
+
const firstPlaceToLook = path.resolve(path.dirname(svg.callerPath), `svgs/${svg.svgFilePath}`);
|
|
90
|
+
const secondPlaceToLook = path.resolve(projectRoot(), `${svg.svgFilePath}`);
|
|
91
|
+
const svgResolvedFilePath = (await Bun.file(firstPlaceToLook).exists())
|
|
92
|
+
? firstPlaceToLook
|
|
93
|
+
: secondPlaceToLook;
|
|
94
|
+
const parsedSvgPath = path.parse(svgResolvedFilePath);
|
|
95
|
+
const svgContent = Bun.file(svgResolvedFilePath);
|
|
91
96
|
const svgHash = Bun.hash(await svgContent.arrayBuffer());
|
|
92
97
|
const svgUrl = `/${parsedSvgPath.name}-${svgHash}.svg`;
|
|
93
98
|
bundledSVGs[svgUrl] = {
|
|
94
99
|
svgContent: await svgContent.text(),
|
|
95
|
-
|
|
100
|
+
svgFilePath: svg.svgFilePath,
|
|
101
|
+
options: svg.options,
|
|
96
102
|
};
|
|
97
103
|
}
|
|
98
104
|
const res = await Bun.build({
|
package/dist/url.d.ts
CHANGED
|
@@ -78,7 +78,8 @@ declare global {
|
|
|
78
78
|
var FrontendScriptUrls: Array<string>;
|
|
79
79
|
var bundledSVGs: Record<string, {
|
|
80
80
|
svgContent: string;
|
|
81
|
-
|
|
81
|
+
svgFilePath: string;
|
|
82
|
+
options: ResponseInit;
|
|
82
83
|
}>;
|
|
83
84
|
}
|
|
84
85
|
export type ScriptTag = (...params: any[]) => Promise<HtmlString>;
|
|
@@ -91,7 +92,20 @@ export declare class url {
|
|
|
91
92
|
static direct_handlers_html: Map<string, HtmlHandler>;
|
|
92
93
|
private static frontends;
|
|
93
94
|
private static svgs;
|
|
94
|
-
|
|
95
|
+
/**
|
|
96
|
+
* This function takes care of bundling your svg (icons?) into the webapp
|
|
97
|
+
* they will have a hash in the name to break the cache when needed
|
|
98
|
+
* @param svgFilePath first place to look: svgs folder in the same path the calling file, after that path from project root.
|
|
99
|
+
* @param options ResponseInit, default headers for an svg
|
|
100
|
+
* @returns url to the svg
|
|
101
|
+
*/
|
|
102
|
+
static svg(svgFilePath: string, options?: ResponseInit): string | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* this function helps you build frontends with any kind of framework (no framework at all) and get the bundle
|
|
105
|
+
* @param path first place to look: frontend folder in the same path the calling file, after that /frontend path from project root.
|
|
106
|
+
* @param snippet this is handy to pass in a piece of html that often goes along with a certain frontend
|
|
107
|
+
* @returns a html script element with the bundled frontend as the src
|
|
108
|
+
*/
|
|
95
109
|
static frontend<X>(path: string, snippet?: BasedHtml): HtmlString;
|
|
96
110
|
static frontend<X>(path: string, snippet?: HtmlHandler<X>): (mini: Mini<X>) => HtmlString;
|
|
97
111
|
/**
|
|
@@ -101,7 +115,11 @@ export declare class url {
|
|
|
101
115
|
path: string;
|
|
102
116
|
callerPath: string;
|
|
103
117
|
}[];
|
|
104
|
-
static
|
|
118
|
+
static getSvgs(): {
|
|
119
|
+
svgFilePath: string;
|
|
120
|
+
callerPath: string;
|
|
121
|
+
options: ResponseInit;
|
|
122
|
+
}[];
|
|
105
123
|
static serveFrontend(req: Request): Response | undefined;
|
|
106
124
|
static serveSvg(req: Request): Response | undefined;
|
|
107
125
|
/**
|
package/dist/url.js
CHANGED
|
@@ -71,16 +71,28 @@ export class url {
|
|
|
71
71
|
static direct_handlers_html = new Map();
|
|
72
72
|
// An array of the uncompiled frontend files, example frontends[0] = "index.tsx" -> frontend/index.tsx (from the project root)
|
|
73
73
|
static frontends = [];
|
|
74
|
-
static svgs =
|
|
75
|
-
|
|
74
|
+
static svgs = [];
|
|
75
|
+
/**
|
|
76
|
+
* This function takes care of bundling your svg (icons?) into the webapp
|
|
77
|
+
* they will have a hash in the name to break the cache when needed
|
|
78
|
+
* @param svgFilePath first place to look: svgs folder in the same path the calling file, after that path from project root.
|
|
79
|
+
* @param options ResponseInit, default headers for an svg
|
|
80
|
+
* @returns url to the svg
|
|
81
|
+
*/
|
|
82
|
+
static svg(svgFilePath, options = {
|
|
76
83
|
headers: {
|
|
77
84
|
"Content-Type": "image/svg+xml",
|
|
78
85
|
"Content-Disposition": "attachment",
|
|
79
86
|
},
|
|
80
87
|
}) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
const stack = new Error().stack?.split("\n");
|
|
89
|
+
let callerPath = "";
|
|
90
|
+
if (stack) {
|
|
91
|
+
callerPath = stack[2].slice(stack[2].lastIndexOf("(") + 1, stack[2].lastIndexOf(".") + 3);
|
|
92
|
+
}
|
|
93
|
+
url.svgs.push({ svgFilePath, callerPath, options });
|
|
94
|
+
var foundSvg = Object.entries(bundledSVGs).find(([key, value]) => value.svgFilePath === svgFilePath);
|
|
95
|
+
return foundSvg && foundSvg[0];
|
|
84
96
|
}
|
|
85
97
|
static frontend(path, snippet) {
|
|
86
98
|
const stack = new Error().stack?.split("\n");
|
|
@@ -105,8 +117,8 @@ export class url {
|
|
|
105
117
|
static getFrontends() {
|
|
106
118
|
return url.frontends;
|
|
107
119
|
}
|
|
108
|
-
static
|
|
109
|
-
return
|
|
120
|
+
static getSvgs() {
|
|
121
|
+
return url.svgs;
|
|
110
122
|
}
|
|
111
123
|
static serveFrontend(req) {
|
|
112
124
|
const reqPath = new URL(req.url).pathname;
|
|
@@ -123,7 +135,7 @@ export class url {
|
|
|
123
135
|
const reqPath = new URL(req.url).pathname;
|
|
124
136
|
const resolvedSvg = bundledSVGs[reqPath];
|
|
125
137
|
if (resolvedSvg) {
|
|
126
|
-
return new Response(resolvedSvg.svgContent,
|
|
138
|
+
return new Response(resolvedSvg.svgContent, resolvedSvg.options);
|
|
127
139
|
}
|
|
128
140
|
}
|
|
129
141
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spirobel/mininext",
|
|
3
|
-
"license"
|
|
3
|
+
"license": "MIT",
|
|
4
4
|
"module": "dist/mininext/mininext.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/mininext.js",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"publish": "bun run build && npm publish",
|
|
10
10
|
"build": "tsc",
|
|
11
|
-
"clean":"rm -rf ./dist"
|
|
11
|
+
"clean": "rm -rf ./dist"
|
|
12
12
|
},
|
|
13
13
|
"files": ["dist"],
|
|
14
|
-
"version": "0.6.
|
|
14
|
+
"version": "0.6.1",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/bun": "latest"
|
|
17
17
|
},
|