@aerogel/vite 0.0.0-next.0d1cf82f9dfbe1d3e7ec5644f85f97a43c8c2334

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.
@@ -0,0 +1,45 @@
1
+ import { ComponentResolver } from 'unplugin-vue-components';
2
+ import { Plugin as Plugin_2 } from 'vite';
3
+
4
+ declare function Aerogel(options?: Options): Plugin_2[];
5
+ export default Aerogel;
6
+
7
+ export declare function AerogelResolver(): ComponentResolver;
8
+
9
+ export declare interface AppInfo {
10
+ name: string;
11
+ version: string;
12
+ basePath: string;
13
+ themeColor: string;
14
+ sourceHash: string;
15
+ additionalManifestEntries: string[];
16
+ description?: string;
17
+ baseUrl?: string;
18
+ sourceUrl?: string;
19
+ plugins?: string[];
20
+ }
21
+
22
+ export declare interface ClientIDDocument {
23
+ '@context': 'https://www.w3.org/ns/solid/oidc-context.jsonld';
24
+ client_id: string;
25
+ client_name: string;
26
+ redirect_uris: [string, ...string[]];
27
+ client_uri: string;
28
+ logo_uri?: string;
29
+ scope: string;
30
+ grant_types: string[];
31
+ response_types: string[];
32
+ }
33
+
34
+ export declare interface Options {
35
+ lib?: boolean;
36
+ name?: string;
37
+ description?: string;
38
+ themeColor?: string;
39
+ icons?: Record<string, string>;
40
+ baseUrl?: string;
41
+ static404Redirect?: boolean | string;
42
+ solidClientId?: boolean | ClientIDDocument;
43
+ }
44
+
45
+ export { }
@@ -0,0 +1,336 @@
1
+ import { dirname as g, resolve as d } from "node:path";
2
+ import h from "@vitejs/plugin-vue";
3
+ import { objectWithoutEmpty as s, stringMatchAll as y, toString as b, arrayFilter as v, after as S } from "@noeldemartin/utils";
4
+ import { VitePWA as j } from "vite-plugin-pwa";
5
+ import w from "mustache";
6
+ import { execSync as $ } from "node:child_process";
7
+ import { existsSync as P, readFileSync as f } from "node:fs";
8
+ const x = `<!DOCTYPE html>
9
+ <html lang="en">
10
+ <head>
11
+ <meta charset="UTF-8" />
12
+ <link rel="icon" href="/favicon.ico" />
13
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
14
+ <title>{{ app.name }}</title>
15
+ <script>
16
+ (function () {
17
+ const basePath = '{{{ app.basePath }}}';
18
+ const url = new URL(location.href);
19
+
20
+ if (!url.pathname.startsWith(basePath)) {
21
+ const link = document.createElement('link');
22
+
23
+ link.rel = 'stylesheet';
24
+ link.href = 'https://cdn.simplecss.org/simple.min.css';
25
+
26
+ document.head.appendChild(link);
27
+
28
+ return;
29
+ }
30
+
31
+ const queryParameters = {};
32
+
33
+ url.searchParams.forEach((value, key) => (queryParameters[key] = value));
34
+
35
+ localStorage.setItem(
36
+ 'static-404-redirect',
37
+ JSON.stringify({
38
+ path: url.pathname.substring(basePath.length - 1),
39
+ hash: url.hash,
40
+ query: queryParameters,
41
+ })
42
+ );
43
+
44
+ location.href = basePath;
45
+ })();
46
+ <\/script>
47
+
48
+ <style>
49
+ body {
50
+ width: 100vw;
51
+ height: 100vh;
52
+ display: flex;
53
+ flex-direction: column;
54
+ justify-content: center;
55
+ align-items: center;
56
+ }
57
+ </style>
58
+ </head>
59
+ <body>
60
+ <h1>404 | Page not found</h1>
61
+ <a href="/">go home</a>
62
+ </body>
63
+ </html>
64
+ `;
65
+ function U(e, t, i) {
66
+ const r = i.static404Redirect ?? process.env.NODE_ENV === "production";
67
+ i.lib || !r || e.emitFile({
68
+ type: "asset",
69
+ fileName: typeof i.static404Redirect == "string" ? i.static404Redirect : "404.html",
70
+ source: w.render(x, { app: t })
71
+ });
72
+ }
73
+ function c(e, t) {
74
+ if (!e.baseUrl)
75
+ return console.warn(
76
+ "It was not possible to create a Solid ClientID document because the baseUrl was not provided, to remove this warning add a `baseUrl` option in the Aerogel vite plugin options."
77
+ ), null;
78
+ const i = e.baseUrl.endsWith("/") ? e.baseUrl : `${e.baseUrl}/`, r = t.icons && (t.icons["512x512"] ?? Object.values(t.icons).pop()), n = {
79
+ "@context": "https://www.w3.org/ns/solid/oidc-context.jsonld",
80
+ client_id: `${i}clientid.jsonld`,
81
+ client_name: e.name,
82
+ redirect_uris: [i],
83
+ client_uri: i,
84
+ scope: "openid profile offline_access webid",
85
+ grant_types: ["refresh_token", "authorization_code"],
86
+ response_types: ["code"]
87
+ };
88
+ return r && (n.logo_uri = i + r), n;
89
+ }
90
+ function k(e, t, i) {
91
+ var n;
92
+ if (!((n = t.plugins) != null && n.includes("solid")))
93
+ return;
94
+ const r = c(t, i);
95
+ r && (e.emitFile({
96
+ type: "asset",
97
+ fileName: "clientid.jsonld",
98
+ source: JSON.stringify(r)
99
+ }), t.additionalManifestEntries.push("/clientid.jsonld"));
100
+ }
101
+ function C(e, t) {
102
+ const i = t.solidClientId ?? !0, r = typeof i != "boolean" ? i : c(e, t), n = {};
103
+ return i && r && (n.clientID = r), `export default ${JSON.stringify(n)};`;
104
+ }
105
+ function I(e, t) {
106
+ return (i, r, n) => {
107
+ var o;
108
+ if (!((o = i.url) != null && o.endsWith("/clientid.jsonld"))) {
109
+ n();
110
+ return;
111
+ }
112
+ const a = c(e, t);
113
+ if (!a) {
114
+ n();
115
+ return;
116
+ }
117
+ r.statusCode = 200, r.setHeader("Content-Type", "application/ld+json"), r.write(JSON.stringify(a), "utf-8"), r.end();
118
+ };
119
+ }
120
+ function _() {
121
+ try {
122
+ return $("git rev-parse HEAD").toString();
123
+ } catch {
124
+ return "?";
125
+ }
126
+ }
127
+ const A = {
128
+ apng: "image/apng",
129
+ avif: "image/avif",
130
+ bmp: "image/bmp",
131
+ cur: "image/x-icon",
132
+ gif: "image/gif",
133
+ ico: "image/x-icon",
134
+ jfif: "image/jpeg",
135
+ jpeg: "image/jpeg",
136
+ jpg: "image/jpeg",
137
+ pjp: "image/jpeg",
138
+ pjpeg: "image/jpeg",
139
+ png: "image/png",
140
+ svg: "image/svg",
141
+ tif: "image/tiff",
142
+ tiff: "image/tiff",
143
+ webp: "image/webp"
144
+ };
145
+ function D(e) {
146
+ var i;
147
+ const t = (i = e.match(/\.([^.]+)$/)) == null ? void 0 : i[1];
148
+ return (t && A[t]) ?? null;
149
+ }
150
+ function M(e) {
151
+ var t;
152
+ return e.repository ? typeof e.repository == "object" ? e.repository.url.replace(`.${e.repository.type}`, "") : (t = e.repository) == null ? void 0 : t.replace("github:", "https://github.com/") : null;
153
+ }
154
+ function O(e) {
155
+ return Object.keys(e.dependencies ?? {}).filter((t) => t.startsWith("@aerogel/plugin-")).map((t) => t.substring(16));
156
+ }
157
+ function m(e, t) {
158
+ if (!P(t))
159
+ return;
160
+ const i = JSON.parse(f(t).toString()), r = s({
161
+ version: i.version,
162
+ sourceUrl: M(i),
163
+ plugins: O(i)
164
+ });
165
+ Object.assign(e, r);
166
+ }
167
+ function E(e) {
168
+ return `<style>${this.readFile(e)}</style>`;
169
+ }
170
+ function T(e = {}) {
171
+ const t = e.maskIconColor ?? this.app.themeColor;
172
+ return `
173
+ <link rel="apple-touch-icon" sizes="180x180" href="${this.app.basePath}apple-touch-icon.png" />
174
+ <link rel="icon" type="image/png" sizes="32x32" href="${this.app.basePath}favicon-32x32.png" />
175
+ <link rel="icon" type="image/png" sizes="16x16" href="${this.app.basePath}favicon-16x16.png" />
176
+ <link rel="mask-icon" href="${this.app.basePath}safari-pinned-tab.svg" color="${t}" />
177
+ `;
178
+ }
179
+ function F(e) {
180
+ return `<script>${this.readFile(e)}<\/script>`;
181
+ }
182
+ function z(e = {}) {
183
+ const t = this.app.baseUrl && `<meta property="og:url" content="${this.app.baseUrl}" />`, i = this.app.description && `
184
+ <meta property="og:description" content="${this.app.description}" />
185
+ <meta name="description" content="${this.app.description}" />
186
+ `, r = e.image && `
187
+ <meta property="og:image" content="${e.image}" />
188
+
189
+ <!-- TODO calculate real image dimensions (these are hard-coded) -->
190
+ <meta property="og:image:width" content="600" />
191
+ <meta property="og:image:height" content="250" />
192
+ `;
193
+ return `
194
+ <meta name="apple-mobile-web-app-title" content="${this.app.name}" />
195
+ <meta name="application-name" content="${this.app.name}" />
196
+ <meta name="msapplication-TileColor" content="${this.app.themeColor}" />
197
+ <meta name="theme-color" content="${this.app.themeColor}" />
198
+ <meta property="og:title" content="${this.app.name}" />
199
+ <meta property="og:type" content="website" />
200
+ ${t ?? ""}
201
+ ${i ?? ""}
202
+ ${r ?? ""}
203
+ `;
204
+ }
205
+ function N() {
206
+ return `
207
+ <script>
208
+ setTimeout(function() {
209
+ if (!document.querySelector('#app.loading')) {
210
+ return;
211
+ }
212
+
213
+ document.getElementById('splash').style.opacity = 1;
214
+ }, 1000);
215
+ <\/script>
216
+ `;
217
+ }
218
+ function W(e) {
219
+ return this.readFile(e);
220
+ }
221
+ const H = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
222
+ __proto__: null,
223
+ css: E,
224
+ favicons: T,
225
+ js: F,
226
+ socialMeta: z,
227
+ splashJs: N,
228
+ svg: W
229
+ }, Symbol.toStringTag, { value: "Module" }));
230
+ function R(e, t) {
231
+ return Function(`with (this) { return ${e} }`).bind({
232
+ ...H,
233
+ ...t
234
+ })();
235
+ }
236
+ function q(e, t, i) {
237
+ const r = y(e, /{{(.*?)}}/g), n = g(t), a = (o) => f(d(n, o)).toString();
238
+ for (const o of r)
239
+ e = e.replace(
240
+ o[0],
241
+ b(
242
+ R(o[1], {
243
+ app: i,
244
+ readFile: a
245
+ })
246
+ )
247
+ );
248
+ return e;
249
+ }
250
+ function Q() {
251
+ return {
252
+ type: "component",
253
+ resolve: (e) => {
254
+ if (!(!e.startsWith("AG") || e.startsWith("AGStory")))
255
+ return e.startsWith("AGSolid") ? { name: e, as: e, from: "@aerogel/plugin-solid" } : e.startsWith("AGCloud") ? { name: e, as: e, from: "@aerogel/plugin-local-first" } : { name: e, as: e, from: "@aerogel/core" };
256
+ }
257
+ };
258
+ }
259
+ function X(e = {}) {
260
+ const t = {
261
+ name: e.name ?? "App",
262
+ version: "?",
263
+ sourceHash: _(),
264
+ description: e.description,
265
+ basePath: "/",
266
+ baseUrl: e.baseUrl,
267
+ themeColor: e.themeColor ?? "#ffffff",
268
+ additionalManifestEntries: [
269
+ "/apple-touch-icon.png",
270
+ "/favicon-32x32.png",
271
+ "/favicon-16x16.png",
272
+ "/safari-pinned-tab.svg"
273
+ ]
274
+ }, i = {
275
+ "virtual:aerogel"() {
276
+ const n = {
277
+ name: t.name,
278
+ version: t.version,
279
+ sourceHash: t.sourceHash,
280
+ basePath: t.basePath,
281
+ sourceUrl: t.sourceUrl
282
+ };
283
+ return `export default ${JSON.stringify(n)};`;
284
+ },
285
+ "virtual:aerogel-solid": () => C(t, e)
286
+ }, r = {
287
+ name: "vite:aerogel",
288
+ buildStart(n) {
289
+ !Array.isArray(n.input) || !n.input[0] || m(t, d(n.input[0], "../package.json"));
290
+ },
291
+ configureServer(n) {
292
+ var a;
293
+ (a = n.httpServer) == null || a.once("listening", async () => {
294
+ var o, l, p, u;
295
+ await S({ ms: 100 }), t.baseUrl = ((l = (o = n.resolvedUrls) == null ? void 0 : o.network) == null ? void 0 : l[0]) ?? ((u = (p = n.resolvedUrls) == null ? void 0 : p.local) == null ? void 0 : u[0]) ?? t.baseUrl;
296
+ }), n.middlewares.use(I(t, e)), m(t, `${n.config.root}/package.json`);
297
+ },
298
+ config: (n) => (t.basePath = n.base ?? t.basePath, n.optimizeDeps = n.optimizeDeps ?? {}, n.optimizeDeps.exclude = [...n.optimizeDeps.exclude ?? [], ...Object.keys(i)], n),
299
+ generateBundle() {
300
+ U(this, t, e), k(this, t, e);
301
+ },
302
+ load: (n) => {
303
+ var a;
304
+ return (a = i[n]) == null ? void 0 : a.call(i);
305
+ },
306
+ resolveId: (n) => n in i ? n : void 0,
307
+ transformIndexHtml: (n, a) => q(n, a.filename, t)
308
+ };
309
+ return v([
310
+ h(),
311
+ !e.lib && j({
312
+ registerType: "autoUpdate",
313
+ manifest: s({
314
+ name: t.name,
315
+ short_name: t.name,
316
+ description: t.description,
317
+ theme_color: e.themeColor,
318
+ icons: e.icons && Object.entries(e.icons).map(([n, a]) => s({
319
+ src: a,
320
+ sizes: n,
321
+ type: D(a)
322
+ }))
323
+ }),
324
+ workbox: {
325
+ maximumFileSizeToCacheInBytes: 1e7,
326
+ additionalManifestEntries: t.additionalManifestEntries
327
+ }
328
+ }),
329
+ r
330
+ ]).flat();
331
+ }
332
+ export {
333
+ Q as AerogelResolver,
334
+ X as default
335
+ };
336
+ //# sourceMappingURL=aerogel-vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aerogel-vite.js","sources":["../src/templates/404.html?raw","../src/lib/404.ts","../src/lib/solid.ts","../src/lib/git.ts","../src/lib/media-types.ts","../src/lib/package-parser.ts","../src/lib/html-eval.ts","../src/lib/html.ts","../src/index.ts"],"sourcesContent":["export default \"<!DOCTYPE html>\\n<html lang=\\\"en\\\">\\n <head>\\n <meta charset=\\\"UTF-8\\\" />\\n <link rel=\\\"icon\\\" href=\\\"/favicon.ico\\\" />\\n <meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1.0\\\" />\\n <title>{{ app.name }}</title>\\n <script>\\n (function () {\\n const basePath = '{{{ app.basePath }}}';\\n const url = new URL(location.href);\\n\\n if (!url.pathname.startsWith(basePath)) {\\n const link = document.createElement('link');\\n\\n link.rel = 'stylesheet';\\n link.href = 'https://cdn.simplecss.org/simple.min.css';\\n\\n document.head.appendChild(link);\\n\\n return;\\n }\\n\\n const queryParameters = {};\\n\\n url.searchParams.forEach((value, key) => (queryParameters[key] = value));\\n\\n localStorage.setItem(\\n 'static-404-redirect',\\n JSON.stringify({\\n path: url.pathname.substring(basePath.length - 1),\\n hash: url.hash,\\n query: queryParameters,\\n })\\n );\\n\\n location.href = basePath;\\n })();\\n </script>\\n\\n <style>\\n body {\\n width: 100vw;\\n height: 100vh;\\n display: flex;\\n flex-direction: column;\\n justify-content: center;\\n align-items: center;\\n }\\n </style>\\n </head>\\n <body>\\n <h1>404 | Page not found</h1>\\n <a href=\\\"/\\\">go home</a>\\n </body>\\n</html>\\n\"","import Mustache from 'mustache';\nimport type { PluginContext } from 'rollup';\n\nimport type { AppInfo, Options } from '@aerogel/vite/lib/options';\n\nimport static404RedirectHTML from '../templates/404.html?raw';\n\nexport function generate404Assets(context: PluginContext, app: AppInfo, options: Options): void {\n const static404Redirect = options.static404Redirect ?? process.env.NODE_ENV === 'production';\n\n if (options.lib || !static404Redirect) {\n return;\n }\n\n context.emitFile({\n type: 'asset',\n fileName: typeof options.static404Redirect === 'string' ? options.static404Redirect : '404.html',\n source: Mustache.render(static404RedirectHTML, { app }),\n });\n}\n","import type { Connect } from 'vite';\nimport type { PluginContext } from 'rollup';\n\nimport type { AppInfo, Options } from '@aerogel/vite/lib/options';\n\nimport type { VirtualAerogelSolid } from 'virtual:aerogel-solid';\n\nfunction createClientIDDocument(app: AppInfo, options: Options): ClientIDDocument | null {\n if (!app.baseUrl) {\n // eslint-disable-next-line no-console\n console.warn(\n 'It was not possible to create a Solid ClientID document because the baseUrl ' +\n 'was not provided, to remove this warning add a `baseUrl` option in the Aerogel vite plugin options.',\n );\n\n return null;\n }\n\n const baseUrl = app.baseUrl.endsWith('/') ? app.baseUrl : `${app.baseUrl}/`;\n const logoPublicPath = options.icons && (options.icons['512x512'] ?? Object.values(options.icons).pop());\n const clientID: ClientIDDocument = {\n '@context': 'https://www.w3.org/ns/solid/oidc-context.jsonld',\n 'client_id': `${baseUrl}clientid.jsonld`,\n 'client_name': app.name,\n 'redirect_uris': [baseUrl],\n 'client_uri': baseUrl,\n 'scope': 'openid profile offline_access webid',\n 'grant_types': ['refresh_token', 'authorization_code'],\n 'response_types': ['code'],\n };\n\n if (logoPublicPath) {\n clientID.logo_uri = baseUrl + logoPublicPath;\n }\n\n return clientID;\n}\n\nexport interface ClientIDDocument {\n '@context': 'https://www.w3.org/ns/solid/oidc-context.jsonld';\n client_id: string;\n client_name: string;\n redirect_uris: [string, ...string[]];\n client_uri: string;\n logo_uri?: string;\n scope: string;\n grant_types: string[];\n response_types: string[];\n}\n\nexport function generateSolidAssets(context: PluginContext, app: AppInfo, options: Options): void {\n if (!app.plugins?.includes('solid')) {\n return;\n }\n\n const clientID = createClientIDDocument(app, options);\n\n if (!clientID) {\n return;\n }\n\n context.emitFile({\n type: 'asset',\n fileName: 'clientid.jsonld',\n source: JSON.stringify(clientID),\n });\n\n app.additionalManifestEntries.push('/clientid.jsonld');\n}\n\nexport function generateSolidVirtualModule(app: AppInfo, options: Options): string {\n const clientId = options.solidClientId ?? true;\n const clientIdDocument = typeof clientId !== 'boolean' ? clientId : createClientIDDocument(app, options);\n const virtual: VirtualAerogelSolid = {};\n\n if (clientId && clientIdDocument) {\n virtual.clientID = clientIdDocument;\n }\n\n return `export default ${JSON.stringify(virtual)};`;\n}\n\nexport function solidMiddleware(app: AppInfo, options: Options): Connect.NextHandleFunction {\n return (request, response, next) => {\n if (!request.url?.endsWith('/clientid.jsonld')) {\n next();\n\n return;\n }\n\n const clientID = createClientIDDocument(app, options);\n\n if (!clientID) {\n next();\n\n return;\n }\n\n response.statusCode = 200;\n response.setHeader('Content-Type', 'application/ld+json');\n response.write(JSON.stringify(clientID), 'utf-8');\n response.end();\n };\n}\n","import { execSync } from 'node:child_process';\n\nexport function getSourceHash(): string {\n try {\n return execSync('git rev-parse HEAD').toString();\n } catch (e) {\n return '?';\n }\n}\n","// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#common_image_file_types\nconst mediaTypeByExtension: Record<string, string> = {\n apng: 'image/apng',\n avif: 'image/avif',\n bmp: 'image/bmp',\n cur: 'image/x-icon',\n gif: 'image/gif',\n ico: 'image/x-icon',\n jfif: 'image/jpeg',\n jpeg: 'image/jpeg',\n jpg: 'image/jpeg',\n pjp: 'image/jpeg',\n pjpeg: 'image/jpeg',\n png: 'image/png',\n svg: 'image/svg',\n tif: 'image/tiff',\n tiff: 'image/tiff',\n webp: 'image/webp',\n};\n\nexport function guessMediaType(filename: string): string | null {\n const extension = filename.match(/\\.([^.]+)$/)?.[1];\n\n return (extension && mediaTypeByExtension[extension]) ?? null;\n}\n","import { existsSync, readFileSync } from 'node:fs';\n\nimport { objectWithoutEmpty } from '@noeldemartin/utils';\n\nimport type { AppInfo } from '@aerogel/vite/lib/options';\n\ninterface PackageJson {\n version: string;\n repository?: string | { type: string; url: string };\n dependencies?: Record<string, string>;\n}\n\nfunction getSourceUrl(packageJson: PackageJson): string | null {\n if (!packageJson.repository) {\n return null;\n }\n\n if (typeof packageJson.repository === 'object') {\n return packageJson.repository.url.replace(`.${packageJson.repository.type}`, '');\n }\n\n return packageJson.repository?.replace('github:', 'https://github.com/');\n}\n\nfunction getPlugins(packageJson: PackageJson): string[] {\n return Object.keys(packageJson.dependencies ?? {})\n .filter((dependency) => dependency.startsWith('@aerogel/plugin-'))\n .map((plugin) => plugin.substring(16));\n}\n\nexport function loadPackageInfo(app: AppInfo, packageJsonPath: string): void {\n if (!existsSync(packageJsonPath)) {\n return;\n }\n\n const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()) as PackageJson;\n const parsed: Partial<AppInfo> = objectWithoutEmpty({\n version: packageJson.version,\n sourceUrl: getSourceUrl(packageJson),\n plugins: getPlugins(packageJson),\n });\n\n Object.assign(app, parsed);\n}\n","import type { AppInfo } from '@aerogel/vite/lib/options';\n\nexport interface HTMLEvalScope {\n app: AppInfo;\n readFile(path: string): string;\n}\n\nexport function css(this: HTMLEvalScope, path: string): string {\n return `<style>${this.readFile(path)}</style>`;\n}\n\nexport function favicons(this: HTMLEvalScope, options: { maskIconColor?: string } = {}): string {\n const maskIconColor = options.maskIconColor ?? this.app.themeColor;\n\n return `\n <link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"${this.app.basePath}apple-touch-icon.png\" />\n <link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"${this.app.basePath}favicon-32x32.png\" />\n <link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"${this.app.basePath}favicon-16x16.png\" />\n <link rel=\"mask-icon\" href=\"${this.app.basePath}safari-pinned-tab.svg\" color=\"${maskIconColor}\" />\n `;\n}\n\nexport function js(this: HTMLEvalScope, path: string): string {\n return `<script>${this.readFile(path)}</script>`;\n}\n\nexport function socialMeta(this: HTMLEvalScope, options: { image?: string } = {}): string {\n const urlMeta = this.app.baseUrl && `<meta property=\"og:url\" content=\"${this.app.baseUrl}\" />`;\n const descriptionMeta =\n this.app.description &&\n `\n <meta property=\"og:description\" content=\"${this.app.description}\" />\n <meta name=\"description\" content=\"${this.app.description}\" />\n `;\n const imageMeta =\n options.image &&\n `\n <meta property=\"og:image\" content=\"${options.image}\" />\n\n <!-- TODO calculate real image dimensions (these are hard-coded) -->\n <meta property=\"og:image:width\" content=\"600\" />\n <meta property=\"og:image:height\" content=\"250\" />\n `;\n\n return `\n <meta name=\"apple-mobile-web-app-title\" content=\"${this.app.name}\" />\n <meta name=\"application-name\" content=\"${this.app.name}\" />\n <meta name=\"msapplication-TileColor\" content=\"${this.app.themeColor}\" />\n <meta name=\"theme-color\" content=\"${this.app.themeColor}\" />\n <meta property=\"og:title\" content=\"${this.app.name}\" />\n <meta property=\"og:type\" content=\"website\" />\n ${urlMeta ?? ''}\n ${descriptionMeta ?? ''}\n ${imageMeta ?? ''}\n `;\n}\n\nexport function splashJs(): string {\n return `\n <script>\n setTimeout(function() {\n if (!document.querySelector('#app.loading')) {\n return;\n }\n\n document.getElementById('splash').style.opacity = 1;\n }, 1000);\n </script>\n `;\n}\n\nexport function svg(this: HTMLEvalScope, path: string): string {\n return this.readFile(path);\n}\n","import { dirname, resolve } from 'node:path';\nimport { readFileSync } from 'node:fs';\n\nimport { stringMatchAll, toString } from '@noeldemartin/utils';\n\nimport type { AppInfo } from '@aerogel/vite/lib/options';\n\nimport * as globalScope from './html-eval';\nimport type { HTMLEvalScope } from './html-eval';\n\nfunction evalScript(script: string, scope: HTMLEvalScope): unknown {\n return Function(`with (this) { return ${script} }`).bind({\n ...globalScope,\n ...scope,\n })();\n}\n\nexport function renderHTML(html: string, filename: string, app: AppInfo): string {\n const matches = stringMatchAll<2>(html, /{{(.*?)}}/g);\n const directory = dirname(filename);\n const readFile = (path: string) => readFileSync(resolve(directory, path)).toString();\n\n for (const match of matches) {\n html = html.replace(\n match[0],\n toString(\n evalScript(match[1], {\n app,\n readFile,\n }),\n ),\n );\n }\n\n return html;\n}\n","import { resolve } from 'node:path';\n\nimport Vue from '@vitejs/plugin-vue';\nimport { after, arrayFilter, objectWithoutEmpty } from '@noeldemartin/utils';\nimport { VitePWA } from 'vite-plugin-pwa';\nimport type { ComponentResolver } from 'unplugin-vue-components';\nimport type { Plugin } from 'vite';\n\nimport { generate404Assets } from '@aerogel/vite/lib/404';\nimport { generateSolidAssets, generateSolidVirtualModule, solidMiddleware } from '@aerogel/vite/lib/solid';\nimport { getSourceHash } from '@aerogel/vite/lib/git';\nimport { guessMediaType } from '@aerogel/vite/lib/media-types';\nimport { loadPackageInfo } from '@aerogel/vite/lib/package-parser';\nimport { renderHTML } from '@aerogel/vite/lib/html';\nimport type { AppInfo, Options } from '@aerogel/vite/lib/options';\nimport type { ClientIDDocument } from '@aerogel/vite/lib/solid';\n\nimport type { VirtualAerogel } from 'virtual:aerogel';\n\nexport type { Options, AppInfo, ClientIDDocument };\n\nexport function AerogelResolver(): ComponentResolver {\n return {\n type: 'component',\n resolve: (name) => {\n if (!name.startsWith('AG') || name.startsWith('AGStory')) {\n return;\n }\n\n if (name.startsWith('AGSolid')) {\n return { name, as: name, from: '@aerogel/plugin-solid' };\n }\n\n if (name.startsWith('AGCloud')) {\n return { name, as: name, from: '@aerogel/plugin-local-first' };\n }\n\n return { name, as: name, from: '@aerogel/core' };\n },\n };\n}\n\nexport default function Aerogel(options: Options = {}): Plugin[] {\n const app: AppInfo = {\n name: options.name ?? 'App',\n version: '?',\n sourceHash: getSourceHash(),\n description: options.description,\n basePath: '/',\n baseUrl: options.baseUrl,\n themeColor: options.themeColor ?? '#ffffff',\n additionalManifestEntries: [\n '/apple-touch-icon.png',\n '/favicon-32x32.png',\n '/favicon-16x16.png',\n '/safari-pinned-tab.svg',\n ],\n };\n const virtualHandlers: Record<string, () => string> = {\n 'virtual:aerogel'() {\n const virtual: VirtualAerogel = {\n name: app.name,\n version: app.version,\n sourceHash: app.sourceHash,\n basePath: app.basePath,\n sourceUrl: app.sourceUrl,\n };\n\n return `export default ${JSON.stringify(virtual)};`;\n },\n 'virtual:aerogel-solid': () => generateSolidVirtualModule(app, options),\n };\n const AerogelPlugin: Plugin = {\n name: 'vite:aerogel',\n buildStart(buildOptions) {\n if (!Array.isArray(buildOptions.input) || !buildOptions.input[0]) {\n return;\n }\n\n loadPackageInfo(app, resolve(buildOptions.input[0], '../package.json'));\n },\n configureServer(server) {\n server.httpServer?.once('listening', async () => {\n await after({ ms: 100 });\n\n app.baseUrl = server.resolvedUrls?.network?.[0] ?? server.resolvedUrls?.local?.[0] ?? app.baseUrl;\n });\n\n server.middlewares.use(solidMiddleware(app, options));\n\n loadPackageInfo(app, `${server.config.root}/package.json`);\n },\n config: (config) => {\n app.basePath = config.base ?? app.basePath;\n config.optimizeDeps = config.optimizeDeps ?? {};\n config.optimizeDeps.exclude = [...(config.optimizeDeps.exclude ?? []), ...Object.keys(virtualHandlers)];\n\n return config;\n },\n generateBundle() {\n generate404Assets(this, app, options);\n generateSolidAssets(this, app, options);\n },\n load: (id) => virtualHandlers[id]?.(),\n resolveId: (id) => (id in virtualHandlers ? id : undefined),\n transformIndexHtml: (html, context) => renderHTML(html, context.filename, app),\n };\n\n return arrayFilter([\n Vue(),\n !options.lib &&\n VitePWA({\n registerType: 'autoUpdate',\n manifest: objectWithoutEmpty({\n name: app.name,\n short_name: app.name,\n description: app.description,\n theme_color: options.themeColor,\n icons:\n options.icons &&\n Object.entries(options.icons).map(([sizes, src]) =>\n objectWithoutEmpty({\n src,\n sizes,\n type: guessMediaType(src),\n })),\n }),\n workbox: {\n maximumFileSizeToCacheInBytes: 10000000,\n additionalManifestEntries: app.additionalManifestEntries,\n },\n }),\n AerogelPlugin,\n ]).flat();\n}\n"],"names":["static404RedirectHTML","generate404Assets","context","app","options","static404Redirect","Mustache","createClientIDDocument","baseUrl","logoPublicPath","clientID","generateSolidAssets","_a","generateSolidVirtualModule","clientId","clientIdDocument","virtual","solidMiddleware","request","response","next","getSourceHash","execSync","mediaTypeByExtension","guessMediaType","filename","extension","getSourceUrl","packageJson","getPlugins","dependency","plugin","loadPackageInfo","packageJsonPath","existsSync","readFileSync","parsed","objectWithoutEmpty","css","path","favicons","maskIconColor","js","socialMeta","urlMeta","descriptionMeta","imageMeta","splashJs","svg","evalScript","script","scope","globalScope","renderHTML","html","matches","stringMatchAll","directory","dirname","readFile","resolve","match","toString","AerogelResolver","name","Aerogel","virtualHandlers","AerogelPlugin","buildOptions","server","after","_b","_d","_c","config","id","arrayFilter","Vue","VitePWA","sizes","src"],"mappings":";;;;;;;AAAA,MAAeA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACOC,SAAAC,EAAkBC,GAAwBC,GAAcC,GAAwB;AAC5F,QAAMC,IAAoBD,EAAQ,qBAAqB,QAAQ,IAAI,aAAa;AAE5E,EAAAA,EAAQ,OAAO,CAACC,KAIpBH,EAAQ,SAAS;AAAA,IACb,MAAM;AAAA,IACN,UAAU,OAAOE,EAAQ,qBAAsB,WAAWA,EAAQ,oBAAoB;AAAA,IACtF,QAAQE,EAAS,OAAON,GAAuB,EAAE,KAAAG,EAAK,CAAA;AAAA,EAAA,CACzD;AACL;ACZA,SAASI,EAAuBJ,GAAcC,GAA2C;AACjF,MAAA,CAACD,EAAI;AAEG,mBAAA;AAAA,MACJ;AAAA,IAEJ,GAE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ogel {
3
+ name: string;
4
+ version: string;
5
+ basePath: string;
6
+ sourceHash: string;
7
+ sourceUrl?: string;
8
+ }
9
+
10
+ const virtual: VirtualAerogel;
11
+
12
+ export default virtual;
13
+ }
14
+
15
+ declare module 'virtual:aerogel-solid' {
16
+ import type { ClientIDDocument } from '@aerogel/vite';
17
+
18
+ export interface VirtualAerogelSolid {
19
+ clientID?: ClientIDDocument;
20
+ }
21
+
22
+ const virtual: VirtualAerogelSolid;
23
+
24
+ export default virtual;
25
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@aerogel/vite",
3
+ "version": "0.0.0-next.0d1cf82f9dfbe1d3e7ec5644f85f97a43c8c2334",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/aerogel-vite.d.ts",
9
+ "default": "./dist/aerogel-vite.js"
10
+ },
11
+ "./virtual": {
12
+ "types": "./dist/virtual.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "src",
17
+ "dist"
18
+ ],
19
+ "license": "MIT",
20
+ "author": "Noel De Martin",
21
+ "repository": "github:NoelDeMartin/aerogel",
22
+ "scripts": {
23
+ "build": "vite build && cp src/types/virtual.d.ts dist/virtual.d.ts",
24
+ "lint": "noeldemartin-lint src",
25
+ "test": "vitest --run",
26
+ "test:ci": "vitest --run --reporter verbose",
27
+ "verify": "noeldemartin-verify"
28
+ },
29
+ "dependencies": {
30
+ "@noeldemartin/utils": "0.7.0-next.26f0bbb6596310f174e1ea368f158997a01c3081",
31
+ "@vitejs/plugin-vue": "^5.2.3",
32
+ "mustache": "^4.2.0",
33
+ "unplugin-vue-components": "^28.4.1",
34
+ "vite-plugin-pwa": "^0.21.2"
35
+ },
36
+ "eslintConfig": {
37
+ "extends": [
38
+ "@noeldemartin/eslint-config-typescript"
39
+ ]
40
+ }
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,135 @@
1
+ import { resolve } from 'node:path';
2
+
3
+ import Vue from '@vitejs/plugin-vue';
4
+ import { after, arrayFilter, objectWithoutEmpty } from '@noeldemartin/utils';
5
+ import { VitePWA } from 'vite-plugin-pwa';
6
+ import type { ComponentResolver } from 'unplugin-vue-components';
7
+ import type { Plugin } from 'vite';
8
+
9
+ import { generate404Assets } from '@aerogel/vite/lib/404';
10
+ import { generateSolidAssets, generateSolidVirtualModule, solidMiddleware } from '@aerogel/vite/lib/solid';
11
+ import { getSourceHash } from '@aerogel/vite/lib/git';
12
+ import { guessMediaType } from '@aerogel/vite/lib/media-types';
13
+ import { loadPackageInfo } from '@aerogel/vite/lib/package-parser';
14
+ import { renderHTML } from '@aerogel/vite/lib/html';
15
+ import type { AppInfo, Options } from '@aerogel/vite/lib/options';
16
+ import type { ClientIDDocument } from '@aerogel/vite/lib/solid';
17
+
18
+ import type { VirtualAerogel } from 'virtual:aerogel';
19
+
20
+ export type { Options, AppInfo, ClientIDDocument };
21
+
22
+ export function AerogelResolver(): ComponentResolver {
23
+ return {
24
+ type: 'component',
25
+ resolve: (name) => {
26
+ if (!name.startsWith('AG') || name.startsWith('AGStory')) {
27
+ return;
28
+ }
29
+
30
+ if (name.startsWith('AGSolid')) {
31
+ return { name, as: name, from: '@aerogel/plugin-solid' };
32
+ }
33
+
34
+ if (name.startsWith('AGCloud')) {
35
+ return { name, as: name, from: '@aerogel/plugin-local-first' };
36
+ }
37
+
38
+ return { name, as: name, from: '@aerogel/core' };
39
+ },
40
+ };
41
+ }
42
+
43
+ export default function Aerogel(options: Options = {}): Plugin[] {
44
+ const app: AppInfo = {
45
+ name: options.name ?? 'App',
46
+ version: '?',
47
+ sourceHash: getSourceHash(),
48
+ description: options.description,
49
+ basePath: '/',
50
+ baseUrl: options.baseUrl,
51
+ themeColor: options.themeColor ?? '#ffffff',
52
+ additionalManifestEntries: [
53
+ '/apple-touch-icon.png',
54
+ '/favicon-32x32.png',
55
+ '/favicon-16x16.png',
56
+ '/safari-pinned-tab.svg',
57
+ ],
58
+ };
59
+ const virtualHandlers: Record<string, () => string> = {
60
+ 'virtual:aerogel'() {
61
+ const virtual: VirtualAerogel = {
62
+ name: app.name,
63
+ version: app.version,
64
+ sourceHash: app.sourceHash,
65
+ basePath: app.basePath,
66
+ sourceUrl: app.sourceUrl,
67
+ };
68
+
69
+ return `export default ${JSON.stringify(virtual)};`;
70
+ },
71
+ 'virtual:aerogel-solid': () => generateSolidVirtualModule(app, options),
72
+ };
73
+ const AerogelPlugin: Plugin = {
74
+ name: 'vite:aerogel',
75
+ buildStart(buildOptions) {
76
+ if (!Array.isArray(buildOptions.input) || !buildOptions.input[0]) {
77
+ return;
78
+ }
79
+
80
+ loadPackageInfo(app, resolve(buildOptions.input[0], '../package.json'));
81
+ },
82
+ configureServer(server) {
83
+ server.httpServer?.once('listening', async () => {
84
+ await after({ ms: 100 });
85
+
86
+ app.baseUrl = server.resolvedUrls?.network?.[0] ?? server.resolvedUrls?.local?.[0] ?? app.baseUrl;
87
+ });
88
+
89
+ server.middlewares.use(solidMiddleware(app, options));
90
+
91
+ loadPackageInfo(app, `${server.config.root}/package.json`);
92
+ },
93
+ config: (config) => {
94
+ app.basePath = config.base ?? app.basePath;
95
+ config.optimizeDeps = config.optimizeDeps ?? {};
96
+ config.optimizeDeps.exclude = [...(config.optimizeDeps.exclude ?? []), ...Object.keys(virtualHandlers)];
97
+
98
+ return config;
99
+ },
100
+ generateBundle() {
101
+ generate404Assets(this, app, options);
102
+ generateSolidAssets(this, app, options);
103
+ },
104
+ load: (id) => virtualHandlers[id]?.(),
105
+ resolveId: (id) => (id in virtualHandlers ? id : undefined),
106
+ transformIndexHtml: (html, context) => renderHTML(html, context.filename, app),
107
+ };
108
+
109
+ return arrayFilter([
110
+ Vue(),
111
+ !options.lib &&
112
+ VitePWA({
113
+ registerType: 'autoUpdate',
114
+ manifest: objectWithoutEmpty({
115
+ name: app.name,
116
+ short_name: app.name,
117
+ description: app.description,
118
+ theme_color: options.themeColor,
119
+ icons:
120
+ options.icons &&
121
+ Object.entries(options.icons).map(([sizes, src]) =>
122
+ objectWithoutEmpty({
123
+ src,
124
+ sizes,
125
+ type: guessMediaType(src),
126
+ })),
127
+ }),
128
+ workbox: {
129
+ maximumFileSizeToCacheInBytes: 10000000,
130
+ additionalManifestEntries: app.additionalManifestEntries,
131
+ },
132
+ }),
133
+ AerogelPlugin,
134
+ ]).flat();
135
+ }
package/src/lib/404.ts ADDED
@@ -0,0 +1,20 @@
1
+ import Mustache from 'mustache';
2
+ import type { PluginContext } from 'rollup';
3
+
4
+ import type { AppInfo, Options } from '@aerogel/vite/lib/options';
5
+
6
+ import static404RedirectHTML from '../templates/404.html?raw';
7
+
8
+ export function generate404Assets(context: PluginContext, app: AppInfo, options: Options): void {
9
+ const static404Redirect = options.static404Redirect ?? process.env.NODE_ENV === 'production';
10
+
11
+ if (options.lib || !static404Redirect) {
12
+ return;
13
+ }
14
+
15
+ context.emitFile({
16
+ type: 'asset',
17
+ fileName: typeof options.static404Redirect === 'string' ? options.static404Redirect : '404.html',
18
+ source: Mustache.render(static404RedirectHTML, { app }),
19
+ });
20
+ }
package/src/lib/git.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { execSync } from 'node:child_process';
2
+
3
+ export function getSourceHash(): string {
4
+ try {
5
+ return execSync('git rev-parse HEAD').toString();
6
+ } catch (e) {
7
+ return '?';
8
+ }
9
+ }
@@ -0,0 +1,74 @@
1
+ import type { AppInfo } from '@aerogel/vite/lib/options';
2
+
3
+ export interface HTMLEvalScope {
4
+ app: AppInfo;
5
+ readFile(path: string): string;
6
+ }
7
+
8
+ export function css(this: HTMLEvalScope, path: string): string {
9
+ return `<style>${this.readFile(path)}</style>`;
10
+ }
11
+
12
+ export function favicons(this: HTMLEvalScope, options: { maskIconColor?: string } = {}): string {
13
+ const maskIconColor = options.maskIconColor ?? this.app.themeColor;
14
+
15
+ return `
16
+ <link rel="apple-touch-icon" sizes="180x180" href="${this.app.basePath}apple-touch-icon.png" />
17
+ <link rel="icon" type="image/png" sizes="32x32" href="${this.app.basePath}favicon-32x32.png" />
18
+ <link rel="icon" type="image/png" sizes="16x16" href="${this.app.basePath}favicon-16x16.png" />
19
+ <link rel="mask-icon" href="${this.app.basePath}safari-pinned-tab.svg" color="${maskIconColor}" />
20
+ `;
21
+ }
22
+
23
+ export function js(this: HTMLEvalScope, path: string): string {
24
+ return `<script>${this.readFile(path)}</script>`;
25
+ }
26
+
27
+ export function socialMeta(this: HTMLEvalScope, options: { image?: string } = {}): string {
28
+ const urlMeta = this.app.baseUrl && `<meta property="og:url" content="${this.app.baseUrl}" />`;
29
+ const descriptionMeta =
30
+ this.app.description &&
31
+ `
32
+ <meta property="og:description" content="${this.app.description}" />
33
+ <meta name="description" content="${this.app.description}" />
34
+ `;
35
+ const imageMeta =
36
+ options.image &&
37
+ `
38
+ <meta property="og:image" content="${options.image}" />
39
+
40
+ <!-- TODO calculate real image dimensions (these are hard-coded) -->
41
+ <meta property="og:image:width" content="600" />
42
+ <meta property="og:image:height" content="250" />
43
+ `;
44
+
45
+ return `
46
+ <meta name="apple-mobile-web-app-title" content="${this.app.name}" />
47
+ <meta name="application-name" content="${this.app.name}" />
48
+ <meta name="msapplication-TileColor" content="${this.app.themeColor}" />
49
+ <meta name="theme-color" content="${this.app.themeColor}" />
50
+ <meta property="og:title" content="${this.app.name}" />
51
+ <meta property="og:type" content="website" />
52
+ ${urlMeta ?? ''}
53
+ ${descriptionMeta ?? ''}
54
+ ${imageMeta ?? ''}
55
+ `;
56
+ }
57
+
58
+ export function splashJs(): string {
59
+ return `
60
+ <script>
61
+ setTimeout(function() {
62
+ if (!document.querySelector('#app.loading')) {
63
+ return;
64
+ }
65
+
66
+ document.getElementById('splash').style.opacity = 1;
67
+ }, 1000);
68
+ </script>
69
+ `;
70
+ }
71
+
72
+ export function svg(this: HTMLEvalScope, path: string): string {
73
+ return this.readFile(path);
74
+ }
@@ -0,0 +1,79 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { formatCodeBlock } from '@noeldemartin/utils';
3
+
4
+ import type { AppInfo } from '@aerogel/vite/lib/options';
5
+
6
+ import { renderHTML } from './html';
7
+
8
+ describe('HTML helpers', () => {
9
+
10
+ const app: AppInfo = {
11
+ name: 'My App',
12
+ version: '0.1.0',
13
+ basePath: '/site/',
14
+ themeColor: '#654321',
15
+ sourceHash: '123456',
16
+ additionalManifestEntries: [],
17
+ };
18
+
19
+ it('Evaluates app info', () => {
20
+ // Arrange
21
+ const html = '<title>{{ app.name }}</title>';
22
+ const expected = '<title>My App</title>';
23
+
24
+ // Act
25
+ const actual = renderHTML(html, '/var/www/index.html', app);
26
+
27
+ // Assert
28
+ expect(actual).toEqual(expected);
29
+ });
30
+
31
+ it('Evaluates asset helpers', () => {
32
+ // Arrange
33
+ const html = `
34
+ {{ css('./inline-styles.css') }}
35
+ {{ js('./inline-script.js') }}
36
+ {{ svg('./inline-svg.svg') }}
37
+ `;
38
+ const expected = `
39
+ <style>file-source[/var/www/inline-styles.css]</style>
40
+ <script>file-source[/var/www/inline-script.js]</script>
41
+ file-source[/var/www/inline-svg.svg]
42
+ `;
43
+
44
+ // Act
45
+ const actual = renderHTML(html, '/var/www/index.html', app);
46
+
47
+ // Assert
48
+ expect(actual).toEqual(expected);
49
+ });
50
+
51
+ it('Evaluates meta helpers', () => {
52
+ // Arrange
53
+ const html = `
54
+ {{ favicons({ maskIconColor: '#123456' }) }}
55
+ {{ socialMeta() }}
56
+ `;
57
+ const expected = formatCodeBlock(`
58
+ <link rel="apple-touch-icon" sizes="180x180" href="/site/apple-touch-icon.png" />
59
+ <link rel="icon" type="image/png" sizes="32x32" href="/site/favicon-32x32.png" />
60
+ <link rel="icon" type="image/png" sizes="16x16" href="/site/favicon-16x16.png" />
61
+ <link rel="mask-icon" href="/site/safari-pinned-tab.svg" color="#123456" />
62
+
63
+
64
+ <meta name="apple-mobile-web-app-title" content="My App" />
65
+ <meta name="application-name" content="My App" />
66
+ <meta name="msapplication-TileColor" content="#654321" />
67
+ <meta name="theme-color" content="#654321" />
68
+ <meta property="og:title" content="My App" />
69
+ <meta property="og:type" content="website" />
70
+ `);
71
+
72
+ // Act
73
+ const actual = renderHTML(html, '/var/www/index.html', app);
74
+
75
+ // Assert
76
+ expect(formatCodeBlock(actual)).toEqual(expected);
77
+ });
78
+
79
+ });
@@ -0,0 +1,36 @@
1
+ import { dirname, resolve } from 'node:path';
2
+ import { readFileSync } from 'node:fs';
3
+
4
+ import { stringMatchAll, toString } from '@noeldemartin/utils';
5
+
6
+ import type { AppInfo } from '@aerogel/vite/lib/options';
7
+
8
+ import * as globalScope from './html-eval';
9
+ import type { HTMLEvalScope } from './html-eval';
10
+
11
+ function evalScript(script: string, scope: HTMLEvalScope): unknown {
12
+ return Function(`with (this) { return ${script} }`).bind({
13
+ ...globalScope,
14
+ ...scope,
15
+ })();
16
+ }
17
+
18
+ export function renderHTML(html: string, filename: string, app: AppInfo): string {
19
+ const matches = stringMatchAll<2>(html, /{{(.*?)}}/g);
20
+ const directory = dirname(filename);
21
+ const readFile = (path: string) => readFileSync(resolve(directory, path)).toString();
22
+
23
+ for (const match of matches) {
24
+ html = html.replace(
25
+ match[0],
26
+ toString(
27
+ evalScript(match[1], {
28
+ app,
29
+ readFile,
30
+ }),
31
+ ),
32
+ );
33
+ }
34
+
35
+ return html;
36
+ }
@@ -0,0 +1,14 @@
1
+ import { guessMediaType } from '@aerogel/vite/lib/media-types';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ describe('Media Types helpers', () => {
5
+
6
+ it('guesses media types from filenames', () => {
7
+ expect(guessMediaType('foo.png')).toBe('image/png');
8
+ expect(guessMediaType('foo.bar.png')).toBe('image/png');
9
+ expect(guessMediaType('foo.jpg')).toBe('image/jpeg');
10
+ expect(guessMediaType('foo.jpeg')).toBe('image/jpeg');
11
+ expect(guessMediaType('foo')).toBeNull();
12
+ });
13
+
14
+ });
@@ -0,0 +1,25 @@
1
+ // https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#common_image_file_types
2
+ const mediaTypeByExtension: Record<string, string> = {
3
+ apng: 'image/apng',
4
+ avif: 'image/avif',
5
+ bmp: 'image/bmp',
6
+ cur: 'image/x-icon',
7
+ gif: 'image/gif',
8
+ ico: 'image/x-icon',
9
+ jfif: 'image/jpeg',
10
+ jpeg: 'image/jpeg',
11
+ jpg: 'image/jpeg',
12
+ pjp: 'image/jpeg',
13
+ pjpeg: 'image/jpeg',
14
+ png: 'image/png',
15
+ svg: 'image/svg',
16
+ tif: 'image/tiff',
17
+ tiff: 'image/tiff',
18
+ webp: 'image/webp',
19
+ };
20
+
21
+ export function guessMediaType(filename: string): string | null {
22
+ const extension = filename.match(/\.([^.]+)$/)?.[1];
23
+
24
+ return (extension && mediaTypeByExtension[extension]) ?? null;
25
+ }
@@ -0,0 +1,25 @@
1
+ import type { ClientIDDocument } from '@aerogel/vite/lib/solid';
2
+
3
+ export interface Options {
4
+ lib?: boolean;
5
+ name?: string;
6
+ description?: string;
7
+ themeColor?: string;
8
+ icons?: Record<string, string>;
9
+ baseUrl?: string;
10
+ static404Redirect?: boolean | string;
11
+ solidClientId?: boolean | ClientIDDocument;
12
+ }
13
+
14
+ export interface AppInfo {
15
+ name: string;
16
+ version: string;
17
+ basePath: string;
18
+ themeColor: string;
19
+ sourceHash: string;
20
+ additionalManifestEntries: string[];
21
+ description?: string;
22
+ baseUrl?: string;
23
+ sourceUrl?: string;
24
+ plugins?: string[];
25
+ }
@@ -0,0 +1,44 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+
3
+ import { objectWithoutEmpty } from '@noeldemartin/utils';
4
+
5
+ import type { AppInfo } from '@aerogel/vite/lib/options';
6
+
7
+ interface PackageJson {
8
+ version: string;
9
+ repository?: string | { type: string; url: string };
10
+ dependencies?: Record<string, string>;
11
+ }
12
+
13
+ function getSourceUrl(packageJson: PackageJson): string | null {
14
+ if (!packageJson.repository) {
15
+ return null;
16
+ }
17
+
18
+ if (typeof packageJson.repository === 'object') {
19
+ return packageJson.repository.url.replace(`.${packageJson.repository.type}`, '');
20
+ }
21
+
22
+ return packageJson.repository?.replace('github:', 'https://github.com/');
23
+ }
24
+
25
+ function getPlugins(packageJson: PackageJson): string[] {
26
+ return Object.keys(packageJson.dependencies ?? {})
27
+ .filter((dependency) => dependency.startsWith('@aerogel/plugin-'))
28
+ .map((plugin) => plugin.substring(16));
29
+ }
30
+
31
+ export function loadPackageInfo(app: AppInfo, packageJsonPath: string): void {
32
+ if (!existsSync(packageJsonPath)) {
33
+ return;
34
+ }
35
+
36
+ const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()) as PackageJson;
37
+ const parsed: Partial<AppInfo> = objectWithoutEmpty({
38
+ version: packageJson.version,
39
+ sourceUrl: getSourceUrl(packageJson),
40
+ plugins: getPlugins(packageJson),
41
+ });
42
+
43
+ Object.assign(app, parsed);
44
+ }
@@ -0,0 +1,104 @@
1
+ import type { Connect } from 'vite';
2
+ import type { PluginContext } from 'rollup';
3
+
4
+ import type { AppInfo, Options } from '@aerogel/vite/lib/options';
5
+
6
+ import type { VirtualAerogelSolid } from 'virtual:aerogel-solid';
7
+
8
+ function createClientIDDocument(app: AppInfo, options: Options): ClientIDDocument | null {
9
+ if (!app.baseUrl) {
10
+ // eslint-disable-next-line no-console
11
+ console.warn(
12
+ 'It was not possible to create a Solid ClientID document because the baseUrl ' +
13
+ 'was not provided, to remove this warning add a `baseUrl` option in the Aerogel vite plugin options.',
14
+ );
15
+
16
+ return null;
17
+ }
18
+
19
+ const baseUrl = app.baseUrl.endsWith('/') ? app.baseUrl : `${app.baseUrl}/`;
20
+ const logoPublicPath = options.icons && (options.icons['512x512'] ?? Object.values(options.icons).pop());
21
+ const clientID: ClientIDDocument = {
22
+ '@context': 'https://www.w3.org/ns/solid/oidc-context.jsonld',
23
+ 'client_id': `${baseUrl}clientid.jsonld`,
24
+ 'client_name': app.name,
25
+ 'redirect_uris': [baseUrl],
26
+ 'client_uri': baseUrl,
27
+ 'scope': 'openid profile offline_access webid',
28
+ 'grant_types': ['refresh_token', 'authorization_code'],
29
+ 'response_types': ['code'],
30
+ };
31
+
32
+ if (logoPublicPath) {
33
+ clientID.logo_uri = baseUrl + logoPublicPath;
34
+ }
35
+
36
+ return clientID;
37
+ }
38
+
39
+ export interface ClientIDDocument {
40
+ '@context': 'https://www.w3.org/ns/solid/oidc-context.jsonld';
41
+ client_id: string;
42
+ client_name: string;
43
+ redirect_uris: [string, ...string[]];
44
+ client_uri: string;
45
+ logo_uri?: string;
46
+ scope: string;
47
+ grant_types: string[];
48
+ response_types: string[];
49
+ }
50
+
51
+ export function generateSolidAssets(context: PluginContext, app: AppInfo, options: Options): void {
52
+ if (!app.plugins?.includes('solid')) {
53
+ return;
54
+ }
55
+
56
+ const clientID = createClientIDDocument(app, options);
57
+
58
+ if (!clientID) {
59
+ return;
60
+ }
61
+
62
+ context.emitFile({
63
+ type: 'asset',
64
+ fileName: 'clientid.jsonld',
65
+ source: JSON.stringify(clientID),
66
+ });
67
+
68
+ app.additionalManifestEntries.push('/clientid.jsonld');
69
+ }
70
+
71
+ export function generateSolidVirtualModule(app: AppInfo, options: Options): string {
72
+ const clientId = options.solidClientId ?? true;
73
+ const clientIdDocument = typeof clientId !== 'boolean' ? clientId : createClientIDDocument(app, options);
74
+ const virtual: VirtualAerogelSolid = {};
75
+
76
+ if (clientId && clientIdDocument) {
77
+ virtual.clientID = clientIdDocument;
78
+ }
79
+
80
+ return `export default ${JSON.stringify(virtual)};`;
81
+ }
82
+
83
+ export function solidMiddleware(app: AppInfo, options: Options): Connect.NextHandleFunction {
84
+ return (request, response, next) => {
85
+ if (!request.url?.endsWith('/clientid.jsonld')) {
86
+ next();
87
+
88
+ return;
89
+ }
90
+
91
+ const clientID = createClientIDDocument(app, options);
92
+
93
+ if (!clientID) {
94
+ next();
95
+
96
+ return;
97
+ }
98
+
99
+ response.statusCode = 200;
100
+ response.setHeader('Content-Type', 'application/ld+json');
101
+ response.write(JSON.stringify(clientID), 'utf-8');
102
+ response.end();
103
+ };
104
+ }
@@ -0,0 +1,56 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" href="/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>{{ app.name }}</title>
8
+ <script>
9
+ (function () {
10
+ const basePath = '{{{ app.basePath }}}';
11
+ const url = new URL(location.href);
12
+
13
+ if (!url.pathname.startsWith(basePath)) {
14
+ const link = document.createElement('link');
15
+
16
+ link.rel = 'stylesheet';
17
+ link.href = 'https://cdn.simplecss.org/simple.min.css';
18
+
19
+ document.head.appendChild(link);
20
+
21
+ return;
22
+ }
23
+
24
+ const queryParameters = {};
25
+
26
+ url.searchParams.forEach((value, key) => (queryParameters[key] = value));
27
+
28
+ localStorage.setItem(
29
+ 'static-404-redirect',
30
+ JSON.stringify({
31
+ path: url.pathname.substring(basePath.length - 1),
32
+ hash: url.hash,
33
+ query: queryParameters,
34
+ })
35
+ );
36
+
37
+ location.href = basePath;
38
+ })();
39
+ </script>
40
+
41
+ <style>
42
+ body {
43
+ width: 100vw;
44
+ height: 100vh;
45
+ display: flex;
46
+ flex-direction: column;
47
+ justify-content: center;
48
+ align-items: center;
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <h1>404 | Page not found</h1>
54
+ <a href="/">go home</a>
55
+ </body>
56
+ </html>
@@ -0,0 +1,12 @@
1
+ import { vi } from 'vitest';
2
+
3
+ vi.mock('fs', async () => {
4
+ const fs = (await vi.importActual('fs')) as Object;
5
+
6
+ return {
7
+ ...fs,
8
+ readFileSync(path: string): string {
9
+ return `file-source[${path}]`;
10
+ },
11
+ };
12
+ });
@@ -0,0 +1,4 @@
1
+ declare module '*.html?raw' {
2
+ declare const html: string;
3
+ export default html;
4
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="@total-typescript/ts-reset" />
@@ -0,0 +1,25 @@
1
+ declare module 'virtual:aerogel' {
2
+ export interface VirtualAerogel {
3
+ name: string;
4
+ version: string;
5
+ basePath: string;
6
+ sourceHash: string;
7
+ sourceUrl?: string;
8
+ }
9
+
10
+ const virtual: VirtualAerogel;
11
+
12
+ export default virtual;
13
+ }
14
+
15
+ declare module 'virtual:aerogel-solid' {
16
+ import type { ClientIDDocument } from '@aerogel/vite';
17
+
18
+ export interface VirtualAerogelSolid {
19
+ clientID?: ClientIDDocument;
20
+ }
21
+
22
+ const virtual: VirtualAerogelSolid;
23
+
24
+ export default virtual;
25
+ }