@prozilla-os/dev-tools 1.0.5 → 1.0.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/dist/main.d.ts +1 -3
- package/dist/main.js +111 -107
- package/dist/main.js.map +1 -1
- package/package.json +5 -4
package/dist/main.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { FC } from 'react';
|
|
4
4
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
5
|
-
import { Plugin as Plugin_2 } from '
|
|
5
|
+
import { Plugin as Plugin_2 } from 'rollup';
|
|
6
6
|
import { UserConfig } from 'vite';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -146,8 +146,6 @@ export declare interface StageOptions {
|
|
|
146
146
|
* @example "Web-based Operating System"
|
|
147
147
|
*/
|
|
148
148
|
siteTagLine: string;
|
|
149
|
-
/** Path to the build directory */
|
|
150
|
-
buildPath: string;
|
|
151
149
|
/**
|
|
152
150
|
* Domain of the live website
|
|
153
151
|
*
|
package/dist/main.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { resolve as
|
|
5
|
-
import { ANSI as
|
|
6
|
-
const
|
|
7
|
-
let
|
|
8
|
-
return h === "\\" && (
|
|
1
|
+
import b from "@vitejs/plugin-react-swc";
|
|
2
|
+
import w from "vite-plugin-dts";
|
|
3
|
+
import A from "vite-plugin-css-injected-by-js";
|
|
4
|
+
import { resolve as S, sep as h, posix as F } from "path";
|
|
5
|
+
import { ANSI as m } from "@prozilla-os/shared";
|
|
6
|
+
const P = (e, t) => {
|
|
7
|
+
let o = S(e, t);
|
|
8
|
+
return h === "\\" && (o = o.split(h).join(F.sep)), console.log("Using Vite config for app"), console.log("Entry: " + o), {
|
|
9
9
|
plugins: [
|
|
10
|
+
b(),
|
|
10
11
|
A(),
|
|
11
|
-
|
|
12
|
-
F({
|
|
12
|
+
w({
|
|
13
13
|
outDir: "dist",
|
|
14
14
|
rollupTypes: !0,
|
|
15
15
|
strictOutput: !0,
|
|
@@ -19,7 +19,7 @@ const Z = (e, n) => {
|
|
|
19
19
|
],
|
|
20
20
|
build: {
|
|
21
21
|
lib: {
|
|
22
|
-
entry:
|
|
22
|
+
entry: o,
|
|
23
23
|
formats: ["es"]
|
|
24
24
|
},
|
|
25
25
|
rollupOptions: {
|
|
@@ -33,154 +33,158 @@ const Z = (e, n) => {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
function
|
|
37
|
-
if (
|
|
36
|
+
function x(e, t, o) {
|
|
37
|
+
if (o && console.log(""), t == null)
|
|
38
38
|
return console.log(e);
|
|
39
|
-
switch (
|
|
39
|
+
switch (t) {
|
|
40
40
|
case "start":
|
|
41
|
-
console.log(`${
|
|
41
|
+
console.log(`${m.fg.yellow}${e}...${m.reset}`);
|
|
42
42
|
break;
|
|
43
43
|
case "file":
|
|
44
|
-
console.log(`- ${
|
|
44
|
+
console.log(`- ${m.fg.cyan}${e}${m.reset}`);
|
|
45
45
|
break;
|
|
46
46
|
case "success":
|
|
47
|
-
console.log(`${
|
|
47
|
+
console.log(`${m.fg.green}✓ ${e}${m.reset}`);
|
|
48
48
|
break;
|
|
49
49
|
case "error":
|
|
50
|
-
console.error(`${
|
|
50
|
+
console.error(`${m.fg.red}⚠ ${e}${m.reset}`);
|
|
51
51
|
break;
|
|
52
52
|
default:
|
|
53
53
|
console.log(e);
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
function b(e) {
|
|
57
|
+
function $(e) {
|
|
59
58
|
return e.replace(/\r\n/g, `
|
|
60
59
|
`);
|
|
61
60
|
}
|
|
62
|
-
function
|
|
63
|
-
const { imageUrls:
|
|
64
|
-
(
|
|
61
|
+
function N(e) {
|
|
62
|
+
const { imageUrls: t, appsConfig: o, baseUrl: a } = e, i = /* @__PURE__ */ new Date(), c = i.getFullYear(), g = i.getMonth() + 1, n = i.getDate(), r = g >= 10 ? g.toString() : "0" + g, u = n >= 10 ? n.toString() : "0" + n, p = `${c}-${r}-${u}`, s = t.map(
|
|
63
|
+
(d) => `
|
|
65
64
|
<image:image>
|
|
66
|
-
<image:loc>${
|
|
65
|
+
<image:loc>${a.slice(0, -1) + d}</image:loc>
|
|
67
66
|
</image:image>`
|
|
68
|
-
),
|
|
69
|
-
({ id:
|
|
67
|
+
), l = o.apps.map(
|
|
68
|
+
({ id: d }) => `
|
|
70
69
|
<url>
|
|
71
|
-
<loc>${
|
|
72
|
-
<lastmod>${
|
|
70
|
+
<loc>${a + d}</loc>
|
|
71
|
+
<lastmod>${p}</lastmod>
|
|
73
72
|
</url>`
|
|
74
|
-
),
|
|
73
|
+
), f = `
|
|
75
74
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
76
75
|
<!DOCTYPE xml>
|
|
77
76
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
78
77
|
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
|
|
79
78
|
<url>
|
|
80
|
-
<loc>${
|
|
81
|
-
<lastmod>${
|
|
79
|
+
<loc>${a}</loc>
|
|
80
|
+
<lastmod>${p}</lastmod>
|
|
82
81
|
${s.join("")}
|
|
83
82
|
</url>
|
|
84
|
-
${
|
|
83
|
+
${l.join("")}
|
|
85
84
|
</urlset>`;
|
|
86
|
-
return
|
|
85
|
+
return $(f.trim());
|
|
87
86
|
}
|
|
88
|
-
function
|
|
89
|
-
const { baseUrl:
|
|
90
|
-
return
|
|
87
|
+
function U(e) {
|
|
88
|
+
const { baseUrl: t } = e;
|
|
89
|
+
return $(`# https://www.robotstxt.org/robotstxt.html
|
|
91
90
|
User-agent: *
|
|
92
91
|
Disallow:
|
|
93
|
-
Sitemap: ${
|
|
92
|
+
Sitemap: ${t}sitemap.xml`);
|
|
94
93
|
}
|
|
95
|
-
function
|
|
94
|
+
function z(e) {
|
|
96
95
|
return e.domain;
|
|
97
96
|
}
|
|
98
|
-
function
|
|
99
|
-
const { baseUrl:
|
|
100
|
-
e = e.replaceAll(a,
|
|
101
|
-
const
|
|
102
|
-
e = e.replaceAll(d, "");
|
|
103
|
-
const i = /^\s*$\n/gm;
|
|
97
|
+
function T(e, t) {
|
|
98
|
+
const { baseUrl: o } = t, a = new RegExp('(?<=")https?:\\/\\/[a-z0-9-]+(\\.)([a-zA-Z0-9-]+(\\.))*[a-z]{2,3}\\/(?=.*")', "gi");
|
|
99
|
+
e = e.replaceAll(a, o);
|
|
100
|
+
const i = /<!--.*?-->/g;
|
|
104
101
|
e = e.replaceAll(i, "");
|
|
105
|
-
const
|
|
106
|
-
return
|
|
102
|
+
const c = /^\s*$\n/gm;
|
|
103
|
+
return e = e.replaceAll(c, ""), $(e);
|
|
107
104
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
function j(e, t) {
|
|
106
|
+
e.emitFile({
|
|
107
|
+
type: "asset",
|
|
108
|
+
fileName: "404.html",
|
|
109
|
+
source: t
|
|
110
|
+
});
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
const { appsConfig:
|
|
114
|
-
for (const
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
|
|
112
|
+
function R(e, t, o) {
|
|
113
|
+
const { appsConfig: a, siteName: i, siteTagLine: c, baseUrl: g } = o;
|
|
114
|
+
for (const n of a.apps) {
|
|
115
|
+
const r = n.id, u = n.name, p = n.description ?? c;
|
|
116
|
+
if (r === "index") {
|
|
117
|
+
x("Invalid app ID found: " + r, "error");
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
-
let s =
|
|
121
|
-
const
|
|
122
|
-
s = s.replaceAll(
|
|
123
|
-
const
|
|
124
|
-
s = s.replaceAll(
|
|
125
|
-
const
|
|
126
|
-
s = s.replaceAll(
|
|
127
|
-
const
|
|
128
|
-
s = s.replaceAll(
|
|
129
|
-
|
|
130
|
-
|
|
120
|
+
let s = t;
|
|
121
|
+
const l = new RegExp('(?<=(<title>|<meta property="og:title" content="|<meta name="twitter:title" content="))(([a-zA-Z|-]|\\s)+)(?=(<\\/title>|"\\/?>))', "g");
|
|
122
|
+
s = s.replaceAll(l, `${u} | ${i}`);
|
|
123
|
+
const f = new RegExp('(?<=(<meta name="description" content="|<meta property="og:description" content="|<meta name="twitter:description" content="))(([a-zA-Z-.]|\\s)+)(?=("\\/?>))', "g");
|
|
124
|
+
s = s.replaceAll(f, p);
|
|
125
|
+
const d = new RegExp('(?<=(<link rel="canonical" href="|<meta name="twitter:url" content="|<meta property="og:url" content="))(http(s)?:\\/\\/[a-zA-Z-.]+\\/)(?=("\\/?>))', "g");
|
|
126
|
+
s = s.replaceAll(d, g + r);
|
|
127
|
+
const y = /(<!-- FAQ -->.*?)?<script type="application\/ld\+json">.*?<\/script>/gs;
|
|
128
|
+
s = s.replaceAll(y, ""), e.emitFile({
|
|
129
|
+
type: "asset",
|
|
130
|
+
fileName: `${r}.html`,
|
|
131
|
+
source: s
|
|
132
|
+
});
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
|
-
function
|
|
135
|
+
function D(e, t, { appsConfig: o, siteName: a, siteTagLine: i, domain: c, imageUrls: g = [] }) {
|
|
134
136
|
try {
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
sitemapXml:
|
|
138
|
-
robotsTxt:
|
|
139
|
-
indexHtml:
|
|
140
|
-
cname:
|
|
141
|
-
},
|
|
142
|
-
[r.sitemapXml,
|
|
143
|
-
[r.robotsTxt,
|
|
144
|
-
[r.cname,
|
|
145
|
-
],
|
|
146
|
-
appsConfig:
|
|
147
|
-
siteName:
|
|
148
|
-
siteTagLine:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
imageUrls: d,
|
|
137
|
+
x("Staging build...", "start", !0);
|
|
138
|
+
const n = `https://${c}/`, r = {
|
|
139
|
+
sitemapXml: "sitemap.xml",
|
|
140
|
+
robotsTxt: "robots.txt",
|
|
141
|
+
indexHtml: "index.html",
|
|
142
|
+
cname: "CNAME"
|
|
143
|
+
}, u = [
|
|
144
|
+
[r.sitemapXml, N],
|
|
145
|
+
[r.robotsTxt, U],
|
|
146
|
+
[r.cname, z]
|
|
147
|
+
], p = {
|
|
148
|
+
appsConfig: o,
|
|
149
|
+
siteName: a,
|
|
150
|
+
siteTagLine: i,
|
|
151
|
+
domain: c,
|
|
152
|
+
baseUrl: n,
|
|
153
|
+
imageUrls: g,
|
|
153
154
|
paths: r
|
|
154
155
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
u.forEach(([l, f]) => {
|
|
157
|
+
e.emitFile({
|
|
158
|
+
type: "asset",
|
|
159
|
+
fileName: l,
|
|
160
|
+
source: f(p)
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
const s = t["index.html"];
|
|
164
|
+
if (s && s.type == "asset") {
|
|
165
|
+
const l = T(s.source, p);
|
|
166
|
+
e.emitFile({
|
|
167
|
+
type: "asset",
|
|
168
|
+
fileName: "index.html",
|
|
169
|
+
source: l
|
|
170
|
+
}), j(e, l), R(e, l, p);
|
|
171
|
+
}
|
|
172
|
+
x("Staging complete", "success", !0);
|
|
173
|
+
} catch (n) {
|
|
174
|
+
console.error(n), x("Staging failed", "error"), process.exit(1);
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
|
-
function
|
|
166
|
-
let n;
|
|
177
|
+
function v(e) {
|
|
167
178
|
return {
|
|
168
179
|
name: "vite-plugin-stage-site",
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
},
|
|
172
|
-
writeBundle() {
|
|
173
|
-
let t = e.buildPath ?? n.build.outDir;
|
|
174
|
-
t = p(n.root, t), C({
|
|
175
|
-
...e,
|
|
176
|
-
buildPath: t
|
|
177
|
-
});
|
|
180
|
+
generateBundle(t, o) {
|
|
181
|
+
D(this, o, e);
|
|
178
182
|
}
|
|
179
183
|
};
|
|
180
184
|
}
|
|
181
185
|
export {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
186
|
+
P as appViteConfig,
|
|
187
|
+
x as print,
|
|
188
|
+
v as stageSitePlugin
|
|
185
189
|
};
|
|
186
190
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sources":["../src/configs/app.vite.config.ts","../src/features/console.ts","../__vite-browser-external","../src/plugins/stageSite.ts"],"sourcesContent":["import { UserConfig } from \"vite\";\r\nimport react from \"@vitejs/plugin-react-swc\";\r\nimport dts from \"vite-plugin-dts\";\r\nimport cssInjectedByJs from \"vite-plugin-css-injected-by-js\";\r\nimport { posix, resolve, sep } from \"path\";\r\n\r\n/**\r\n * Helper function for creating Vite configurations for ProzillaOS apps\r\n * @param basePath - Path of base directory\r\n * @param entryPath - Path of library entry\r\n * @returns Vite configuration\r\n * @see https://vitejs.dev/config/\r\n */\r\nexport const appViteConfig = (basePath: string, entryPath: string): UserConfig => {\r\n\tlet entryFile = resolve(basePath, entryPath);\r\n\r\n\t// Normalize paths for Windows compatibility\r\n\tif (sep === \"\\\\\")\r\n\t\tentryFile = entryFile.split(sep).join(posix.sep);\r\n\r\n\tconsole.log(\"Using Vite config for app\");\r\n\tconsole.log(\"Entry: \" + entryFile);\r\n\r\n\treturn {\r\n\t\tplugins: [\r\n\t\t\treact(),\r\n\t\t\tcssInjectedByJs(),\r\n\t\t\tdts({\r\n\t\t\t\toutDir: \"dist\",\r\n\t\t\t\trollupTypes: true,\r\n\t\t\t\tstrictOutput: true,\r\n\t\t\t\tpathsToAliases: false,\r\n\t\t\t\ttsconfigPath: \"tsconfig.build.json\"\r\n\t\t\t})\r\n\t\t],\r\n\t\tbuild: {\r\n\t\t\tlib: {\r\n\t\t\t\tentry: entryFile,\r\n\t\t\t\tformats: [\"es\"],\r\n\t\t\t},\r\n\t\t\trollupOptions: {\r\n\t\t\t\texternal: [\"react\", \"react/jsx-runtime\", \"@prozilla-os/core\", \"@prozilla-os/shared\", /@fortawesome\\/*/g],\r\n\t\t\t\toutput: {\r\n\t\t\t\t\tassetFileNames: \"assets/[name][extname]\",\r\n\t\t\t\t\tentryFileNames: \"[name].js\",\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\tsourcemap: true\r\n\t\t}\r\n\t};\r\n};","import { ANSI } from \"@prozilla-os/shared\";\r\n\r\nexport type status = \"error\" | \"info\" | \"file\" | \"success\" | \"start\";\r\n\r\nexport function print(message: string, status?: status, newLine?: boolean) {\r\n\tif (newLine)\r\n\t\tconsole.log(\"\");\r\n\r\n\tif (status == null)\r\n\t\treturn console.log(message);\r\n\r\n\tswitch (status) {\r\n\t\tcase \"start\":\r\n\t\t\tconsole.log(`${ANSI.fg.yellow}${message}...${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tcase \"file\":\r\n\t\t\tconsole.log(`- ${ANSI.fg.cyan}${message}${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tcase \"success\":\r\n\t\t\tconsole.log(`${ANSI.fg.green}✓ ${message}${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tcase \"error\":\r\n\t\t\tconsole.error(`${ANSI.fg.red}⚠ ${message}${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tconsole.log(message);\r\n\t\t\tbreak;\r\n\t}\r\n}","export default {}","import fs from \"fs\";\r\nimport type { AppsConfig } from \"@prozilla-os/core\";\r\nimport { resolve } from \"path\";\r\nimport { print } from \"../features/console\";\r\nimport { Plugin, ResolvedConfig } from \"vite\";\r\n\r\nexport interface StageOptions {\r\n\tappsConfig: AppsConfig;\r\n\r\n\t/**\r\n\t * Name of the website \r\n\t * @example \"ProzillaOS\"\r\n\t */\r\n\tsiteName: string;\r\n\r\n\t/**\r\n\t * Tag line of the website\r\n\t * @example \"Web-based Operating System\"\r\n\t*/\r\n\tsiteTagLine: string;\r\n\r\n\t/** Path to the build directory */\r\n\tbuildPath: string;\r\n\r\n\t/**\r\n\t * Domain of the live website\r\n\t * \r\n\t * A CNAME file will be generated with this value\r\n\t * @example \"os.prozilla.dev\"\r\n\t */\r\n\tdomain: string;\r\n\r\n\t/**\r\n\t * Array of image URLs that will be added to the sitemap\r\n\t */\r\n\timageUrls?: string[];\r\n}\r\n\r\ninterface StageOptionsExtended extends StageOptions {\r\n\timageUrls: string[];\r\n\tbaseUrl: string;\r\n\tpaths: FilePaths;\r\n}\r\n\r\ninterface FilePaths {\r\n\tsitemapXml: string;\r\n\trobotsTxt: string;\r\n\tindexHtml: string;\r\n\tcname: string;\r\n}\r\n\r\nfunction normalizeLineEndings(text: string) {\r\n\treturn text.replace(/\\r\\n/g, \"\\n\");\r\n}\r\n\r\nfunction generateSitemapXml(options: StageOptionsExtended) {\r\n\tconst { imageUrls, appsConfig, baseUrl } = options;\r\n\r\n\tconst date = new Date();\r\n\r\n\tconst year = date.getFullYear();\r\n\tconst month = date.getMonth() + 1;\r\n\tconst day = date.getDate();\r\n\r\n\tconst monthString = month >= 10 ? month.toString() : \"0\" + month;\r\n\tconst dayString = day >= 10 ? day.toString() : \"0\" + day;\r\n\r\n\tconst lastModified = `${year}-${monthString}-${dayString}`;\r\n\r\n\tconst images = imageUrls.map((path) => `\r\n\t\t<image:image>\r\n\t\t\t<image:loc>${baseUrl.slice(0, -1) + path}</image:loc>\r\n\t\t</image:image>`\r\n\t);\r\n\r\n\tconst pages = appsConfig.apps.map(({ id }) => `\r\n\t<url>\r\n\t\t<loc>${baseUrl + id}</loc>\r\n\t\t<lastmod>${lastModified}</lastmod>\r\n\t</url>`\r\n\t);\r\n\r\n\tconst sitemap = `\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE xml>\r\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\r\n\txmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\">\r\n\t<url>\r\n\t\t<loc>${baseUrl}</loc>\r\n\t\t<lastmod>${lastModified}</lastmod>\r\n\t\t${images.join(\"\")}\r\n\t</url>\r\n\t${pages.join(\"\")}\r\n</urlset>`;\r\n\r\n\treturn normalizeLineEndings(sitemap.trim());\r\n}\r\n\r\nfunction generateRobotsTxt(options: StageOptionsExtended) {\r\n\tconst { baseUrl } = options;\r\n\r\n\treturn normalizeLineEndings(`# https://www.robotstxt.org/robotstxt.html\r\nUser-agent: *\r\nDisallow:\r\nSitemap: ${baseUrl}sitemap.xml`);\r\n}\r\n\r\nfunction generateCname(options: StageOptionsExtended) {\r\n\treturn options.domain;\r\n}\r\n\r\nfunction generateTemplate(html: string, options: StageOptionsExtended) {\r\n\tconst { baseUrl, buildPath } = options;\r\n\r\n\tconst baseUrlRegex = /(?<=\")https?:\\/\\/[a-z0-9-]+(\\.)([a-zA-Z0-9-]+(\\.))*[a-z]{2,3}\\/(?=.*\")/gi;\r\n\thtml = html.replaceAll(baseUrlRegex, baseUrl);\r\n\r\n\tconst commentsRegex = /<!--.*?-->/g;\r\n\thtml = html.replaceAll(commentsRegex, \"\");\r\n\r\n\tconst emptyLinesRegex = /^\\s*$\\n/gm;\r\n\thtml = html.replaceAll(emptyLinesRegex, \"\");\r\n\r\n\tconst path = resolve(buildPath, \"index.html\");\r\n\tfs.writeFileSync(path, html, { flag: \"w+\" });\r\n\tprint(path, \"file\");\r\n\r\n\treturn normalizeLineEndings(html);\r\n}\r\n\r\n/**\r\n * To avoid GitHub pages rendering certain pages that are only defined by React router as a 404 page,\r\n * we copy the content of our index file to the 404 page, letting React router properly handle routing on every page \r\n */\r\nfunction generate404Page(template: string, options: StageOptionsExtended) {\r\n\tconst { buildPath } = options;\r\n\r\n\tconst path = resolve(buildPath, \"404.html\");\r\n\tfs.writeFileSync(path, template, { flag: \"w+\" });\r\n\tprint(path, \"file\");\r\n}\r\n\r\n/**\r\n * Add an HTML file for every app page so they can be properly crawled and indexed\r\n */\r\nfunction generateAppPages(template: string, options: StageOptionsExtended) {\r\n\tconst { appsConfig, siteName, siteTagLine, baseUrl, buildPath } = options;\r\n\r\n\tfor (const app of appsConfig.apps) {\r\n\t\tconst appId = app.id;\r\n\t\tconst appName = app.name;\r\n\t\tconst appDescription = app.description ?? siteTagLine;\r\n\r\n\t\tif (appId === \"index\") {\r\n\t\t\tprint(\"Invalid app ID found: \" + appId, \"error\");\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tlet html = template;\r\n\t\t\r\n\t\tconst titleRegex = /(?<=(<title>|<meta property=\"og:title\" content=\"|<meta name=\"twitter:title\" content=\"))(([a-zA-Z|-]|\\s)+)(?=(<\\/title>|\"\\/?>))/g;\r\n\t\thtml = html.replaceAll(titleRegex, `${appName} | ${siteName}`);\r\n\r\n\t\tconst descriptionRegex = /(?<=(<meta name=\"description\" content=\"|<meta property=\"og:description\" content=\"|<meta name=\"twitter:description\" content=\"))(([a-zA-Z-.]|\\s)+)(?=(\"\\/?>))/g;\r\n\t\thtml = html.replaceAll(descriptionRegex, appDescription);\r\n\r\n\t\tconst canonicalRegex = /(?<=(<link rel=\"canonical\" href=\"|<meta name=\"twitter:url\" content=\"|<meta property=\"og:url\" content=\"))(http(s)?:\\/\\/[a-zA-Z-.]+\\/)(?=(\"\\/?>))/g;\r\n\t\thtml = html.replaceAll(canonicalRegex, baseUrl + appId);\r\n\r\n\t\tconst faqRegex = /(<!-- FAQ -->.*?)?<script type=\"application\\/ld\\+json\">.*?<\\/script>/gs;\r\n\t\thtml = html.replaceAll(faqRegex, \"\");\r\n\r\n\t\tconst path = resolve(buildPath, `${appId}.html`);\r\n\t\tfs.writeFileSync(path, html, { flag: \"w+\" });\r\n\t\tprint(path, \"file\");\r\n\t}\r\n}\r\n\r\nfunction stageSite({ appsConfig, siteName, siteTagLine, buildPath, domain, imageUrls = [] }: StageOptions) {\r\n\ttry {\r\n\t\tprint(\"Staging build...\", \"start\", true);\r\n\r\n\t\tconst baseUrl = `https://${domain}/`;\r\n\r\n\t\tconst paths: FilePaths = {\r\n\t\t\tsitemapXml: resolve(buildPath, \"sitemap.xml\"),\r\n\t\t\trobotsTxt: resolve(buildPath, \"robots.txt\"),\r\n\t\t\tindexHtml: resolve(buildPath, \"index.html\"),\r\n\t\t\tcname: resolve(buildPath, \"CNAME\"),\r\n\t\t};\r\n\t\r\n\t\tconst files: [string, (options: StageOptionsExtended) => string][] = [\r\n\t\t\t[paths.sitemapXml, generateSitemapXml],\r\n\t\t\t[paths.robotsTxt, generateRobotsTxt],\r\n\t\t\t[paths.cname, generateCname],\r\n\t\t];\r\n\r\n\t\tconst extendedOptions = {\r\n\t\t\tappsConfig,\r\n\t\t\tsiteName,\r\n\t\t\tsiteTagLine,\r\n\t\t\tbuildPath,\r\n\t\t\tdomain,\r\n\t\t\tbaseUrl,\r\n\t\t\timageUrls,\r\n\t\t\tpaths\r\n\t\t};\r\n\t\r\n\t\tfiles.forEach(([path, generateContent]) => {\r\n\t\t\tconst directory = path.substring(0, path.lastIndexOf(\"/\"));\r\n\t\t\tif (directory != \"\" && !fs.existsSync(directory))\r\n\t\t\t\tfs.mkdirSync(directory, { recursive: true });\r\n\t\r\n\t\t\tfs.writeFileSync(path, generateContent(extendedOptions), { flag: \"w+\" });\r\n\t\t\tprint(path, \"file\");\r\n\t\t});\r\n\r\n\t\tprint(\"Generating pages...\", \"start\", true);\r\n\t\r\n\t\tconst html = fs.readFileSync(paths.indexHtml, \"utf-8\");\r\n\t\tconst template = generateTemplate(html, extendedOptions);\r\n\t\r\n\t\tgenerate404Page(template, extendedOptions);\r\n\t\tgenerateAppPages(template, extendedOptions);\r\n\t\r\n\t\tprint(\"Staging complete\", \"success\", true);\r\n\t} catch (error) {\r\n\t\tconsole.error(error);\r\n\t\tprint(\"Staging failed\", \"error\");\r\n\t\tprocess.exit(1);\r\n\t}\r\n}\r\n\r\nexport function stageSitePlugin(options: StageOptions): Plugin {\r\n\tlet config: ResolvedConfig;\r\n\t\r\n\treturn {\r\n\t\tname: \"vite-plugin-stage-site\",\r\n\t\tconfigResolved(resolvedConfig) {\r\n\t\t\tconfig = resolvedConfig;\r\n\t\t},\r\n\t\twriteBundle() {\r\n\t\t\tlet buildDir = options.buildPath ?? config.build.outDir;\r\n\t\t\tbuildDir = resolve(config.root, buildDir);\r\n\t\t\t\r\n\t\t\tstageSite({\r\n\t\t\t\t...options,\r\n\t\t\t\tbuildPath: buildDir\r\n\t\t\t});\r\n\t\t},\r\n\t};\r\n}"],"names":["appViteConfig","basePath","entryPath","entryFile","resolve","sep","posix","react","cssInjectedByJs","dts","print","message","status","newLine","ANSI","fs","normalizeLineEndings","text","generateSitemapXml","options","imageUrls","appsConfig","baseUrl","date","year","month","day","monthString","dayString","lastModified","images","path","pages","id","sitemap","generateRobotsTxt","generateCname","generateTemplate","html","buildPath","baseUrlRegex","commentsRegex","emptyLinesRegex","generate404Page","template","generateAppPages","siteName","siteTagLine","app","appId","appName","appDescription","titleRegex","descriptionRegex","canonicalRegex","faqRegex","stageSite","domain","paths","files","extendedOptions","generateContent","directory","error","stageSitePlugin","config","resolvedConfig","buildDir"],"mappings":";;;;;AAaa,MAAAA,IAAgB,CAACC,GAAkBC,MAAkC;AAC7E,MAAAC,IAAYC,EAAQH,GAAUC,CAAS;AAG3C,SAAIG,MAAQ,SACXF,IAAYA,EAAU,MAAME,CAAG,EAAE,KAAKC,EAAM,GAAG,IAEhD,QAAQ,IAAI,2BAA2B,GAC/B,QAAA,IAAI,YAAYH,CAAS,GAE1B;AAAA,IACN,SAAS;AAAA,MACRI,EAAM;AAAA,MACNC,EAAgB;AAAA,MAChBC,EAAI;AAAA,QACH,QAAQ;AAAA,QACR,aAAa;AAAA,QACb,cAAc;AAAA,QACd,gBAAgB;AAAA,QAChB,cAAc;AAAA,MAAA,CACd;AAAA,IACF;AAAA,IACA,OAAO;AAAA,MACN,KAAK;AAAA,QACJ,OAAON;AAAA,QACP,SAAS,CAAC,IAAI;AAAA,MACf;AAAA,MACA,eAAe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ACD;AAEO,SAASsD,EAAgB7C,GAA+B;AAC1D,MAAA8C;AAEG,SAAA;AAAA,IACN,MAAM;AAAA,IACN,eAAeC,GAAgB;AACrB,MAAAD,IAAAC;AAAA,IACV;AAAA,IACA,cAAc;AACb,UAAIC,IAAWhD,EAAQ,aAAa8C,EAAO,MAAM;AACtC,MAAAE,IAAA/D,EAAQ6D,EAAO,MAAME,CAAQ,GAE9BX,EAAA;AAAA,QACT,GAAGrC;AAAA,QACH,WAAWgD;AAAA,MAAA,CACX;AAAA,IACF;AAAA,EAAA;AAEF;"}
|
|
1
|
+
{"version":3,"file":"main.js","sources":["../src/configs/app.vite.config.ts","../src/features/console.ts","../src/plugins/stageSite.ts"],"sourcesContent":["import { UserConfig } from \"vite\";\r\nimport react from \"@vitejs/plugin-react-swc\";\r\nimport dts from \"vite-plugin-dts\";\r\nimport cssInjectedByJs from \"vite-plugin-css-injected-by-js\";\r\nimport { posix, resolve, sep } from \"path\";\r\n\r\n/**\r\n * Helper function for creating Vite configurations for ProzillaOS apps\r\n * @param basePath - Path of base directory\r\n * @param entryPath - Path of library entry\r\n * @returns Vite configuration\r\n * @see https://vitejs.dev/config/\r\n */\r\nexport const appViteConfig = (basePath: string, entryPath: string): UserConfig => {\r\n\tlet entryFile = resolve(basePath, entryPath);\r\n\r\n\t// Normalize paths for Windows compatibility\r\n\tif (sep === \"\\\\\")\r\n\t\tentryFile = entryFile.split(sep).join(posix.sep);\r\n\r\n\tconsole.log(\"Using Vite config for app\");\r\n\tconsole.log(\"Entry: \" + entryFile);\r\n\r\n\treturn {\r\n\t\tplugins: [\r\n\t\t\treact(),\r\n\t\t\tcssInjectedByJs(),\r\n\t\t\tdts({\r\n\t\t\t\toutDir: \"dist\",\r\n\t\t\t\trollupTypes: true,\r\n\t\t\t\tstrictOutput: true,\r\n\t\t\t\tpathsToAliases: false,\r\n\t\t\t\ttsconfigPath: \"tsconfig.build.json\"\r\n\t\t\t})\r\n\t\t],\r\n\t\tbuild: {\r\n\t\t\tlib: {\r\n\t\t\t\tentry: entryFile,\r\n\t\t\t\tformats: [\"es\"],\r\n\t\t\t},\r\n\t\t\trollupOptions: {\r\n\t\t\t\texternal: [\"react\", \"react/jsx-runtime\", \"@prozilla-os/core\", \"@prozilla-os/shared\", /@fortawesome\\/*/g],\r\n\t\t\t\toutput: {\r\n\t\t\t\t\tassetFileNames: \"assets/[name][extname]\",\r\n\t\t\t\t\tentryFileNames: \"[name].js\",\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\tsourcemap: true\r\n\t\t}\r\n\t};\r\n};","import { ANSI } from \"@prozilla-os/shared\";\r\n\r\nexport type status = \"error\" | \"info\" | \"file\" | \"success\" | \"start\";\r\n\r\nexport function print(message: string, status?: status, newLine?: boolean) {\r\n\tif (newLine)\r\n\t\tconsole.log(\"\");\r\n\r\n\tif (status == null)\r\n\t\treturn console.log(message);\r\n\r\n\tswitch (status) {\r\n\t\tcase \"start\":\r\n\t\t\tconsole.log(`${ANSI.fg.yellow}${message}...${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tcase \"file\":\r\n\t\t\tconsole.log(`- ${ANSI.fg.cyan}${message}${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tcase \"success\":\r\n\t\t\tconsole.log(`${ANSI.fg.green}✓ ${message}${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tcase \"error\":\r\n\t\t\tconsole.error(`${ANSI.fg.red}⚠ ${message}${ANSI.reset}`);\r\n\t\t\tbreak;\r\n\t\tdefault:\r\n\t\t\tconsole.log(message);\r\n\t\t\tbreak;\r\n\t}\r\n}","import type { AppsConfig } from \"@prozilla-os/core\";\r\nimport { print } from \"../features/console\";\r\nimport type { OutputBundle, PluginContext, Plugin } from \"rollup\";\r\n\r\nexport interface StageOptions {\r\n\tappsConfig: AppsConfig;\r\n\r\n\t/**\r\n\t * Name of the website \r\n\t * @example \"ProzillaOS\"\r\n\t */\r\n\tsiteName: string;\r\n\r\n\t/**\r\n\t * Tag line of the website\r\n\t * @example \"Web-based Operating System\"\r\n\t*/\r\n\tsiteTagLine: string;\r\n\r\n\t/**\r\n\t * Domain of the live website\r\n\t * \r\n\t * A CNAME file will be generated with this value\r\n\t * @example \"os.prozilla.dev\"\r\n\t */\r\n\tdomain: string;\r\n\r\n\t/**\r\n\t * Array of image URLs that will be added to the sitemap\r\n\t */\r\n\timageUrls?: string[];\r\n}\r\n\r\ninterface StageOptionsExtended extends StageOptions {\r\n\timageUrls: string[];\r\n\tbaseUrl: string;\r\n\tpaths: FilePaths;\r\n}\r\n\r\ninterface FilePaths {\r\n\tsitemapXml: string;\r\n\trobotsTxt: string;\r\n\tindexHtml: string;\r\n\tcname: string;\r\n}\r\n\r\nfunction normalizeLineEndings(text: string) {\r\n\treturn text.replace(/\\r\\n/g, \"\\n\");\r\n}\r\n\r\nfunction generateSitemapXml(options: StageOptionsExtended) {\r\n\tconst { imageUrls, appsConfig, baseUrl } = options;\r\n\r\n\tconst date = new Date();\r\n\r\n\tconst year = date.getFullYear();\r\n\tconst month = date.getMonth() + 1;\r\n\tconst day = date.getDate();\r\n\r\n\tconst monthString = month >= 10 ? month.toString() : \"0\" + month;\r\n\tconst dayString = day >= 10 ? day.toString() : \"0\" + day;\r\n\r\n\tconst lastModified = `${year}-${monthString}-${dayString}`;\r\n\r\n\tconst images = imageUrls.map((path) => `\r\n\t\t<image:image>\r\n\t\t\t<image:loc>${baseUrl.slice(0, -1) + path}</image:loc>\r\n\t\t</image:image>`\r\n\t);\r\n\r\n\tconst pages = appsConfig.apps.map(({ id }) => `\r\n\t<url>\r\n\t\t<loc>${baseUrl + id}</loc>\r\n\t\t<lastmod>${lastModified}</lastmod>\r\n\t</url>`\r\n\t);\r\n\r\n\tconst sitemap = `\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE xml>\r\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\r\n\txmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\">\r\n\t<url>\r\n\t\t<loc>${baseUrl}</loc>\r\n\t\t<lastmod>${lastModified}</lastmod>\r\n\t\t${images.join(\"\")}\r\n\t</url>\r\n\t${pages.join(\"\")}\r\n</urlset>`;\r\n\r\n\treturn normalizeLineEndings(sitemap.trim());\r\n}\r\n\r\nfunction generateRobotsTxt(options: StageOptionsExtended) {\r\n\tconst { baseUrl } = options;\r\n\r\n\treturn normalizeLineEndings(`# https://www.robotstxt.org/robotstxt.html\r\nUser-agent: *\r\nDisallow:\r\nSitemap: ${baseUrl}sitemap.xml`);\r\n}\r\n\r\nfunction generateCname(options: StageOptionsExtended) {\r\n\treturn options.domain;\r\n}\r\n\r\nfunction generateTemplate(html: string, options: StageOptionsExtended) {\r\n\tconst { baseUrl } = options;\r\n\r\n\tconst baseUrlRegex = /(?<=\")https?:\\/\\/[a-z0-9-]+(\\.)([a-zA-Z0-9-]+(\\.))*[a-z]{2,3}\\/(?=.*\")/gi;\r\n\thtml = html.replaceAll(baseUrlRegex, baseUrl);\r\n\r\n\tconst commentsRegex = /<!--.*?-->/g;\r\n\thtml = html.replaceAll(commentsRegex, \"\");\r\n\r\n\tconst emptyLinesRegex = /^\\s*$\\n/gm;\r\n\thtml = html.replaceAll(emptyLinesRegex, \"\");\r\n\r\n\treturn normalizeLineEndings(html);\r\n}\r\n\r\n/**\r\n * To avoid GitHub pages rendering certain pages that are only defined by React router as a 404 page,\r\n * we copy the content of our index file to the 404 page, letting React router properly handle routing on every page \r\n */\r\nfunction generate404Page(context: PluginContext, template: string) {\r\n\tcontext.emitFile({\r\n\t\ttype: \"asset\",\r\n\t\tfileName: \"404.html\",\r\n\t\tsource: template\r\n\t});\r\n}\r\n\r\n/**\r\n * Add an HTML file for every app page so they can be properly crawled and indexed\r\n */\r\nfunction generateAppPages(context: PluginContext, template: string, options: StageOptionsExtended) {\r\n\tconst { appsConfig, siteName, siteTagLine, baseUrl } = options;\r\n\r\n\tfor (const app of appsConfig.apps) {\r\n\t\tconst appId = app.id;\r\n\t\tconst appName = app.name;\r\n\t\tconst appDescription = app.description ?? siteTagLine;\r\n\r\n\t\tif (appId === \"index\") {\r\n\t\t\tprint(\"Invalid app ID found: \" + appId, \"error\");\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tlet html = template;\r\n\t\t\r\n\t\tconst titleRegex = /(?<=(<title>|<meta property=\"og:title\" content=\"|<meta name=\"twitter:title\" content=\"))(([a-zA-Z|-]|\\s)+)(?=(<\\/title>|\"\\/?>))/g;\r\n\t\thtml = html.replaceAll(titleRegex, `${appName} | ${siteName}`);\r\n\r\n\t\tconst descriptionRegex = /(?<=(<meta name=\"description\" content=\"|<meta property=\"og:description\" content=\"|<meta name=\"twitter:description\" content=\"))(([a-zA-Z-.]|\\s)+)(?=(\"\\/?>))/g;\r\n\t\thtml = html.replaceAll(descriptionRegex, appDescription);\r\n\r\n\t\tconst canonicalRegex = /(?<=(<link rel=\"canonical\" href=\"|<meta name=\"twitter:url\" content=\"|<meta property=\"og:url\" content=\"))(http(s)?:\\/\\/[a-zA-Z-.]+\\/)(?=(\"\\/?>))/g;\r\n\t\thtml = html.replaceAll(canonicalRegex, baseUrl + appId);\r\n\r\n\t\tconst faqRegex = /(<!-- FAQ -->.*?)?<script type=\"application\\/ld\\+json\">.*?<\\/script>/gs;\r\n\t\thtml = html.replaceAll(faqRegex, \"\");\r\n\r\n\t\tcontext.emitFile({\r\n\t\t\ttype: \"asset\",\r\n\t\t\tfileName: `${appId}.html`,\r\n\t\t\tsource: html\r\n\t\t});\r\n\t}\r\n}\r\n\r\nfunction stageSite(context: PluginContext, bundle: OutputBundle, { appsConfig, siteName, siteTagLine, domain, imageUrls = [] }: StageOptions) {\r\n\ttry {\r\n\t\tprint(\"Staging build...\", \"start\", true);\r\n\r\n\t\tconst baseUrl = `https://${domain}/`;\r\n\r\n\t\tconst paths: FilePaths = {\r\n\t\t\tsitemapXml: \"sitemap.xml\",\r\n\t\t\trobotsTxt: \"robots.txt\",\r\n\t\t\tindexHtml: \"index.html\",\r\n\t\t\tcname: \"CNAME\",\r\n\t\t};\r\n\t\r\n\t\tconst files: [string, (options: StageOptionsExtended) => string][] = [\r\n\t\t\t[paths.sitemapXml, generateSitemapXml],\r\n\t\t\t[paths.robotsTxt, generateRobotsTxt],\r\n\t\t\t[paths.cname, generateCname],\r\n\t\t];\r\n\r\n\t\tconst extendedOptions = {\r\n\t\t\tappsConfig,\r\n\t\t\tsiteName,\r\n\t\t\tsiteTagLine,\r\n\t\t\tdomain,\r\n\t\t\tbaseUrl,\r\n\t\t\timageUrls,\r\n\t\t\tpaths\r\n\t\t};\r\n\t\r\n\t\tfiles.forEach(([path, generateContent]) => {\r\n\t\t\tcontext.emitFile({\r\n\t\t\t\ttype: \"asset\",\r\n\t\t\t\tfileName: path,\r\n\t\t\t\tsource: generateContent(extendedOptions)\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\tconst html = bundle[\"index.html\"];\r\n\t\tif (html && html.type == \"asset\") {\r\n\t\t\tconst template = generateTemplate(html.source as string, extendedOptions);\r\n\r\n\t\t\tcontext.emitFile({\r\n\t\t\t\ttype: \"asset\",\r\n\t\t\t\tfileName: \"index.html\",\r\n\t\t\t\tsource: template \r\n\t\t\t});\r\n\t\r\n\t\t\tgenerate404Page(context, template);\r\n\t\t\tgenerateAppPages(context, template, extendedOptions);\r\n\t\t}\r\n\t\r\n\t\tprint(\"Staging complete\", \"success\", true);\r\n\t} catch (error) {\r\n\t\tconsole.error(error);\r\n\t\tprint(\"Staging failed\", \"error\");\r\n\t\tprocess.exit(1);\r\n\t}\r\n}\r\n\r\nexport function stageSitePlugin(options: StageOptions): Plugin {\r\n\treturn {\r\n\t\tname: \"vite-plugin-stage-site\",\r\n\t\tgenerateBundle(_outputOptions, bundle) {\r\n\t\t\tstageSite(this, bundle, options);\r\n\t\t},\r\n\t};\r\n}"],"names":["appViteConfig","basePath","entryPath","entryFile","resolve","sep","posix","react","cssInjectedByJs","dts","print","message","status","newLine","ANSI","normalizeLineEndings","text","generateSitemapXml","options","imageUrls","appsConfig","baseUrl","date","year","month","day","monthString","dayString","lastModified","images","path","pages","id","sitemap","generateRobotsTxt","generateCname","generateTemplate","html","baseUrlRegex","commentsRegex","emptyLinesRegex","generate404Page","context","template","generateAppPages","siteName","siteTagLine","app","appId","appName","appDescription","titleRegex","descriptionRegex","canonicalRegex","faqRegex","stageSite","bundle","domain","paths","files","extendedOptions","generateContent","error","stageSitePlugin","_outputOptions"],"mappings":";;;;;AAaa,MAAAA,IAAgB,CAACC,GAAkBC,MAAkC;AAC7E,MAAAC,IAAYC,EAAQH,GAAUC,CAAS;AAG3C,SAAIG,MAAQ,SACXF,IAAYA,EAAU,MAAME,CAAG,EAAE,KAAKC,EAAM,GAAG,IAEhD,QAAQ,IAAI,2BAA2B,GAC/B,QAAA,IAAI,YAAYH,CAAS,GAE1B;AAAA,IACN,SAAS;AAAA,MACRI,EAAM;AAAA,MACNC,EAAgB;AAAA,MAChBC,EAAI;AAAA,QACH,QAAQ;AAAA,QACR,aAAa;AAAA,QACb,cAAc;AAAA,QACd,gBAAgB;AAAA,QAChB,cAAc;AAAA,MAAA,CACd;AAAA,IACF;AAAA,IACA,OAAO;AAAA,MACN,KAAK;AAAA,QACJ,OAAON;AAAA,QACP,SAAS,CAAC,IAAI;AAAA,MACf;AAAA,MACA,eAAe;AAAA,QACd,UAAU,CAAC,SAAS,qBAAqB,qBAAqB,uBAAuB,kBAAkB;AAAA,QACvG,QAAQ;AAAA,UACP,gBAAgB;AAAA,UAChB,gBAAgB;AAAA,QACjB;AAAA,MACD;AAAA,MACA,WAAW;AAAA,IACZ;AAAA,EAAA;AAEF;AC9CgB,SAAAO,EAAMC,GAAiBC,GAAiBC,GAAmB;AAI1E,MAHIA,KACH,QAAQ,IAAI,EAAE,GAEXD,KAAU;AACN,WAAA,QAAQ,IAAID,CAAO;AAE3B,UAAQC,GAAQ;AAAA,IACf,KAAK;AACI,cAAA,IAAI,GAAGE,EAAK,GAAG,MAAM,GA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iBC,EAAK,QAAkBuB,CAAe;AAExE,MAAAlB,EAAQ,SAAS;AAAA,QAChB,MAAM;AAAA,QACN,UAAU;AAAA,QACV,QAAQC;AAAA,MAAA,CACR,GAEDF,EAAgBC,GAASC,CAAQ,GAChBC,EAAAF,GAASC,GAAUiB,CAAe;AAAA,IACpD;AAEM,IAAAlD,EAAA,oBAAoB,WAAW,EAAI;AAAA,WACjCoD,GAAO;AACf,YAAQ,MAAMA,CAAK,GACnBpD,EAAM,kBAAkB,OAAO,GAC/B,QAAQ,KAAK,CAAC;AAAA,EACf;AACD;AAEO,SAASqD,EAAgB7C,GAA+B;AACvD,SAAA;AAAA,IACN,MAAM;AAAA,IACN,eAAe8C,GAAgBR,GAAQ;AAC5B,MAAAD,EAAA,MAAMC,GAAQtC,CAAO;AAAA,IAChC;AAAA,EAAA;AAEF;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prozilla-os/dev-tools",
|
|
3
3
|
"description": "A library of tools for the development of ProzillaOS packages.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"homepage": "https://os.prozilla.dev",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Prozilla",
|
|
@@ -21,14 +21,15 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@prozilla-os/core": "1.3.2",
|
|
23
23
|
"@prozilla-os/shared": "^1.2.0",
|
|
24
|
-
"
|
|
24
|
+
"@vitejs/plugin-react-swc": "^3.7.0",
|
|
25
25
|
"vite": "^5.4.8",
|
|
26
|
-
"vite-plugin-
|
|
27
|
-
"
|
|
26
|
+
"vite-plugin-css-injected-by-js": "^3.5.1",
|
|
27
|
+
"vite-plugin-dts": "^3.9.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^20.14.5",
|
|
31
31
|
"@types/react": "^18.3.3",
|
|
32
|
+
"rollup": "^4.24.0",
|
|
32
33
|
"typescript": "^5.4.5"
|
|
33
34
|
},
|
|
34
35
|
"files": [
|