@prozilla-os/dev-tools 1.0.4 → 1.0.5
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 +166 -1
- package/dist/main.js +101 -150
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -1,7 +1,123 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
3
|
+
import { FC } from 'react';
|
|
4
|
+
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
2
5
|
import { Plugin as Plugin_2 } from 'vite';
|
|
3
6
|
import { UserConfig } from 'vite';
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* An application that can be ran by ProzillaOS
|
|
10
|
+
* Applications can be installed by adding them to the `apps` array in {@link AppsConfig}
|
|
11
|
+
*/
|
|
12
|
+
declare class App<AppProps extends WindowProps = WindowProps> {
|
|
13
|
+
/**
|
|
14
|
+
* The display name of this application
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* The unique ID of this application
|
|
19
|
+
*/
|
|
20
|
+
id: string;
|
|
21
|
+
/**
|
|
22
|
+
* Main component that renders this app inside a window
|
|
23
|
+
*/
|
|
24
|
+
windowContent: FC<AppProps>;
|
|
25
|
+
/**
|
|
26
|
+
* Default options that get passed to the {@link this.windowContent} component
|
|
27
|
+
*/
|
|
28
|
+
windowOptions?: {
|
|
29
|
+
size: Vector2;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Description of this application
|
|
34
|
+
*/
|
|
35
|
+
description: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* URL of the icon of this application
|
|
38
|
+
*/
|
|
39
|
+
iconUrl: string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Defines what the app can handle and how it can be used elsewhere in the system
|
|
42
|
+
*/
|
|
43
|
+
role: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* An array of file extensions that this application can interpret
|
|
46
|
+
*/
|
|
47
|
+
associatedExtensions: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Determines whether the app is pinned by default
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
pinnedByDefault: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Determines whether the app is launched at startup
|
|
55
|
+
* @default false
|
|
56
|
+
*/
|
|
57
|
+
launchAtStartup: boolean;
|
|
58
|
+
isActive: boolean;
|
|
59
|
+
isPinned?: boolean;
|
|
60
|
+
constructor(name: App["name"], id: App["id"], windowContent: App<AppProps>["windowContent"], windowOptions?: App["windowOptions"]);
|
|
61
|
+
WindowContent: (props: AppProps) => JSX_2.Element | null;
|
|
62
|
+
/**
|
|
63
|
+
* Set the display name of this application
|
|
64
|
+
*/
|
|
65
|
+
setName(name: string): this;
|
|
66
|
+
/**
|
|
67
|
+
* Set the description of this application
|
|
68
|
+
*/
|
|
69
|
+
setDescription(description: App["description"]): this;
|
|
70
|
+
/**
|
|
71
|
+
* Set the URL of the icon of this application
|
|
72
|
+
*/
|
|
73
|
+
setIconUrl(iconUrl: App["iconUrl"]): this;
|
|
74
|
+
/**
|
|
75
|
+
* Set the role of this application
|
|
76
|
+
*/
|
|
77
|
+
setRole(role: string | null): this;
|
|
78
|
+
/**
|
|
79
|
+
* Set the associated extensions of this application
|
|
80
|
+
*/
|
|
81
|
+
setAssociatedExtensions(extensions: string[] | null): this;
|
|
82
|
+
/**
|
|
83
|
+
* Changes whether this application is pinned by default or not
|
|
84
|
+
*/
|
|
85
|
+
setPinnedByDefault(pinnedByDefault: boolean): this;
|
|
86
|
+
/**
|
|
87
|
+
* Changes whether this application is launched at startup or not
|
|
88
|
+
*/
|
|
89
|
+
setLaunchAtStartup(launchAtStartup: boolean): this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class AppsConfig {
|
|
93
|
+
apps: AppsConfigOptions["apps"];
|
|
94
|
+
static APP_ROLES: {
|
|
95
|
+
FileExplorer: string;
|
|
96
|
+
Terminal: string;
|
|
97
|
+
TextEditor: string;
|
|
98
|
+
Settings: string;
|
|
99
|
+
MediaViewer: string;
|
|
100
|
+
Browser: string;
|
|
101
|
+
};
|
|
102
|
+
constructor(options?: OptionalInterface<AppsConfigOptions>);
|
|
103
|
+
getAppById(id: string): App | null;
|
|
104
|
+
/**
|
|
105
|
+
* Get the app associated with a file extension
|
|
106
|
+
*/
|
|
107
|
+
getAppByFileExtension(fileExtension: string): App | null;
|
|
108
|
+
/**
|
|
109
|
+
* Get the app with a specific role
|
|
110
|
+
*/
|
|
111
|
+
getAppByRole(role: string): App | null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare interface AppsConfigOptions {
|
|
115
|
+
/**
|
|
116
|
+
* An array of applications
|
|
117
|
+
*/
|
|
118
|
+
apps: App<any>[];
|
|
119
|
+
}
|
|
120
|
+
|
|
5
121
|
/**
|
|
6
122
|
* Helper function for creating Vite configurations for ProzillaOS apps
|
|
7
123
|
* @param basePath - Path of base directory
|
|
@@ -11,6 +127,10 @@ import { UserConfig } from 'vite';
|
|
|
11
127
|
*/
|
|
12
128
|
export declare const appViteConfig: (basePath: string, entryPath: string) => UserConfig;
|
|
13
129
|
|
|
130
|
+
declare type OptionalInterface<Interface> = {
|
|
131
|
+
[Property in keyof Interface]?: Interface[Property];
|
|
132
|
+
};
|
|
133
|
+
|
|
14
134
|
declare function print_2(message: string, status?: status_2, newLine?: boolean): void;
|
|
15
135
|
export { print_2 as print }
|
|
16
136
|
|
|
@@ -46,4 +166,49 @@ export declare function stageSitePlugin(options: StageOptions): Plugin_2;
|
|
|
46
166
|
declare type status_2 = "error" | "info" | "file" | "success" | "start";
|
|
47
167
|
export { status_2 as status }
|
|
48
168
|
|
|
169
|
+
declare class Vector2 {
|
|
170
|
+
x: number;
|
|
171
|
+
y: number;
|
|
172
|
+
static get ZERO(): Vector2;
|
|
173
|
+
get clone(): Vector2;
|
|
174
|
+
constructor(x: number, y?: number);
|
|
175
|
+
round(): Vector2;
|
|
176
|
+
getDistance(x: number, y?: number): number;
|
|
177
|
+
getDistance(vector2: Vector2): number;
|
|
178
|
+
static add(vector2A: Vector2, vector2B: Vector2): Vector2;
|
|
179
|
+
static subtract(vector2A: Vector2, vector2B: Vector2): Vector2;
|
|
180
|
+
static scale(vector2: Vector2, scalar: number): Vector2;
|
|
181
|
+
static magnitude(vector2: Vector2): number;
|
|
182
|
+
static normalize(vector2: Vector2): Vector2;
|
|
183
|
+
static sqrDistance(vector2A: Vector2, vector2B: Vector2): number;
|
|
184
|
+
static lerp(vector2A: Vector2, vector2B: Vector2, t: number): Vector2;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare interface WindowOptions {
|
|
188
|
+
id?: string;
|
|
189
|
+
app?: App;
|
|
190
|
+
size?: Vector2;
|
|
191
|
+
position?: Vector2;
|
|
192
|
+
fullscreen?: boolean | string;
|
|
193
|
+
options?: object;
|
|
194
|
+
isFocused?: boolean;
|
|
195
|
+
lastInteraction?: number;
|
|
196
|
+
minimized?: boolean;
|
|
197
|
+
[key: string]: unknown;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare interface WindowProps extends WindowOptions {
|
|
201
|
+
fullscreen?: boolean;
|
|
202
|
+
onInteract?: Function;
|
|
203
|
+
setTitle?: React.Dispatch<React.SetStateAction<string>>;
|
|
204
|
+
setIconUrl?: React.Dispatch<React.SetStateAction<string>>;
|
|
205
|
+
close?: (event?: Event) => void;
|
|
206
|
+
focus?: (event: Event, force?: boolean) => void;
|
|
207
|
+
active?: boolean;
|
|
208
|
+
minimized?: boolean;
|
|
209
|
+
toggleMinimized?: Function;
|
|
210
|
+
index?: number;
|
|
211
|
+
standalone?: boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
49
214
|
export { }
|
package/dist/main.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { resolve as p, sep as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import A from "@vitejs/plugin-react-swc";
|
|
2
|
+
import F from "vite-plugin-dts";
|
|
3
|
+
import U from "vite-plugin-css-injected-by-js";
|
|
4
|
+
import { resolve as p, sep as h, posix as z } from "path";
|
|
5
|
+
import { ANSI as f } from "@prozilla-os/shared";
|
|
6
|
+
const Z = (e, n) => {
|
|
7
|
+
let t = p(e, n);
|
|
8
|
+
return h === "\\" && (t = t.split(h).join(z.sep)), console.log("Using Vite config for app"), console.log("Entry: " + t), {
|
|
8
9
|
plugins: [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
A(),
|
|
11
|
+
U(),
|
|
12
|
+
F({
|
|
12
13
|
outDir: "dist",
|
|
13
14
|
rollupTypes: !0,
|
|
14
15
|
strictOutput: !0,
|
|
@@ -18,7 +19,7 @@ const Y = (e, t) => {
|
|
|
18
19
|
],
|
|
19
20
|
build: {
|
|
20
21
|
lib: {
|
|
21
|
-
entry:
|
|
22
|
+
entry: t,
|
|
22
23
|
formats: ["es"]
|
|
23
24
|
},
|
|
24
25
|
rollupOptions: {
|
|
@@ -32,204 +33,154 @@ const Y = (e, t) => {
|
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, j = (e, t, o) => t in e ? U(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, z = (e, t, o) => j(e, t + "", o), D = (e, t, o) => t.has(e) || v("Cannot " + o), d = (e, t, o) => (D(e, t, "read from private field"), o ? o.call(e) : t.get(e)), R = (e, t, o) => t.has(e) ? v("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, o);
|
|
38
|
-
const x = {
|
|
39
|
-
fg: {
|
|
40
|
-
black: "\x1B[30m",
|
|
41
|
-
red: "\x1B[31m",
|
|
42
|
-
green: "\x1B[32m",
|
|
43
|
-
yellow: "\x1B[33m",
|
|
44
|
-
blue: "\x1B[34m",
|
|
45
|
-
magenta: "\x1B[35m",
|
|
46
|
-
cyan: "\x1B[36m",
|
|
47
|
-
white: "\x1B[37m"
|
|
48
|
-
},
|
|
49
|
-
bg: {},
|
|
50
|
-
decoration: {
|
|
51
|
-
dim: "\x1B[2m",
|
|
52
|
-
bold: "\x1B[1m"
|
|
53
|
-
},
|
|
54
|
-
reset: "\x1B[0m"
|
|
55
|
-
};
|
|
56
|
-
var l;
|
|
57
|
-
class C {
|
|
58
|
-
constructor() {
|
|
59
|
-
R(this, l, {});
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Add event listener for an event
|
|
63
|
-
*/
|
|
64
|
-
on(t, o) {
|
|
65
|
-
d(this, l)[t] || (d(this, l)[t] = []), d(this, l)[t].push(o);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Remove event listener for an event
|
|
69
|
-
*/
|
|
70
|
-
off(t, o) {
|
|
71
|
-
d(this, l)[t] && (d(this, l)[t] = d(this, l)[t].filter(
|
|
72
|
-
(n) => n !== o
|
|
73
|
-
));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Dispatch event
|
|
77
|
-
*/
|
|
78
|
-
emit(t, o) {
|
|
79
|
-
d(this, l)[t] && d(this, l)[t].forEach((n) => {
|
|
80
|
-
n(o);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
l = /* @__PURE__ */ new WeakMap(), z(C, "EVENT_NAMES", {});
|
|
85
|
-
function m(e, t, o) {
|
|
86
|
-
if (o && console.log(""), t == null)
|
|
36
|
+
function c(e, n, t) {
|
|
37
|
+
if (t && console.log(""), n == null)
|
|
87
38
|
return console.log(e);
|
|
88
|
-
switch (
|
|
39
|
+
switch (n) {
|
|
89
40
|
case "start":
|
|
90
|
-
console.log(`${
|
|
41
|
+
console.log(`${f.fg.yellow}${e}...${f.reset}`);
|
|
91
42
|
break;
|
|
92
43
|
case "file":
|
|
93
|
-
console.log(`- ${
|
|
44
|
+
console.log(`- ${f.fg.cyan}${e}${f.reset}`);
|
|
94
45
|
break;
|
|
95
46
|
case "success":
|
|
96
|
-
console.log(`${
|
|
47
|
+
console.log(`${f.fg.green}✓ ${e}${f.reset}`);
|
|
97
48
|
break;
|
|
98
49
|
case "error":
|
|
99
|
-
console.error(`${
|
|
50
|
+
console.error(`${f.fg.red}⚠ ${e}${f.reset}`);
|
|
100
51
|
break;
|
|
101
52
|
default:
|
|
102
53
|
console.log(e);
|
|
103
54
|
break;
|
|
104
55
|
}
|
|
105
56
|
}
|
|
106
|
-
const
|
|
107
|
-
function
|
|
57
|
+
const x = {};
|
|
58
|
+
function b(e) {
|
|
108
59
|
return e.replace(/\r\n/g, `
|
|
109
60
|
`);
|
|
110
61
|
}
|
|
111
|
-
function
|
|
112
|
-
const { imageUrls:
|
|
113
|
-
(
|
|
62
|
+
function D(e) {
|
|
63
|
+
const { imageUrls: n, appsConfig: t, baseUrl: o } = e, a = /* @__PURE__ */ new Date(), d = a.getFullYear(), i = a.getMonth() + 1, r = a.getDate(), g = i >= 10 ? i.toString() : "0" + i, m = r >= 10 ? r.toString() : "0" + r, $ = `${d}-${g}-${m}`, s = n.map(
|
|
64
|
+
(l) => `
|
|
114
65
|
<image:image>
|
|
115
|
-
<image:loc>${
|
|
66
|
+
<image:loc>${o.slice(0, -1) + l}</image:loc>
|
|
116
67
|
</image:image>`
|
|
117
|
-
),
|
|
118
|
-
({ id:
|
|
68
|
+
), u = t.apps.map(
|
|
69
|
+
({ id: l }) => `
|
|
119
70
|
<url>
|
|
120
|
-
<loc>${
|
|
121
|
-
<lastmod>${
|
|
71
|
+
<loc>${o + l}</loc>
|
|
72
|
+
<lastmod>${$}</lastmod>
|
|
122
73
|
</url>`
|
|
123
|
-
),
|
|
74
|
+
), w = `
|
|
124
75
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
125
76
|
<!DOCTYPE xml>
|
|
126
77
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
127
78
|
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
|
|
128
79
|
<url>
|
|
129
|
-
<loc>${
|
|
130
|
-
<lastmod>${
|
|
80
|
+
<loc>${o}</loc>
|
|
81
|
+
<lastmod>${$}</lastmod>
|
|
131
82
|
${s.join("")}
|
|
132
83
|
</url>
|
|
133
|
-
${
|
|
84
|
+
${u.join("")}
|
|
134
85
|
</urlset>`;
|
|
135
|
-
return
|
|
86
|
+
return b(w.trim());
|
|
136
87
|
}
|
|
137
|
-
function
|
|
138
|
-
const { baseUrl:
|
|
139
|
-
return
|
|
88
|
+
function R(e) {
|
|
89
|
+
const { baseUrl: n } = e;
|
|
90
|
+
return b(`# https://www.robotstxt.org/robotstxt.html
|
|
140
91
|
User-agent: *
|
|
141
92
|
Disallow:
|
|
142
|
-
Sitemap: ${
|
|
93
|
+
Sitemap: ${n}sitemap.xml`);
|
|
143
94
|
}
|
|
144
|
-
function
|
|
95
|
+
function T(e) {
|
|
145
96
|
return e.domain;
|
|
146
97
|
}
|
|
147
|
-
function
|
|
148
|
-
const { baseUrl:
|
|
149
|
-
e = e.replaceAll(
|
|
150
|
-
const
|
|
151
|
-
e = e.replaceAll(
|
|
152
|
-
const
|
|
153
|
-
e = e.replaceAll(
|
|
154
|
-
const r = p(
|
|
155
|
-
return
|
|
98
|
+
function j(e, n) {
|
|
99
|
+
const { baseUrl: t, buildPath: o } = n, a = new RegExp('(?<=")https?:\\/\\/[a-z0-9-]+(\\.)([a-zA-Z0-9-]+(\\.))*[a-z]{2,3}\\/(?=.*")', "gi");
|
|
100
|
+
e = e.replaceAll(a, t);
|
|
101
|
+
const d = /<!--.*?-->/g;
|
|
102
|
+
e = e.replaceAll(d, "");
|
|
103
|
+
const i = /^\s*$\n/gm;
|
|
104
|
+
e = e.replaceAll(i, "");
|
|
105
|
+
const r = p(o, "index.html");
|
|
106
|
+
return x.writeFileSync(r, e, { flag: "w+" }), c(r, "file"), b(e);
|
|
156
107
|
}
|
|
157
|
-
function
|
|
158
|
-
const { buildPath:
|
|
159
|
-
|
|
108
|
+
function k(e, n) {
|
|
109
|
+
const { buildPath: t } = n, o = p(t, "404.html");
|
|
110
|
+
x.writeFileSync(o, e, { flag: "w+" }), c(o, "file");
|
|
160
111
|
}
|
|
161
|
-
function
|
|
162
|
-
const { appsConfig:
|
|
163
|
-
for (const r of
|
|
164
|
-
const g = r.id,
|
|
112
|
+
function v(e, n) {
|
|
113
|
+
const { appsConfig: t, siteName: o, siteTagLine: a, baseUrl: d, buildPath: i } = n;
|
|
114
|
+
for (const r of t.apps) {
|
|
115
|
+
const g = r.id, m = r.name, $ = r.description ?? a;
|
|
165
116
|
if (g === "index") {
|
|
166
|
-
|
|
117
|
+
c("Invalid app ID found: " + g, "error");
|
|
167
118
|
return;
|
|
168
119
|
}
|
|
169
120
|
let s = e;
|
|
170
|
-
const
|
|
171
|
-
s = s.replaceAll(
|
|
172
|
-
const
|
|
173
|
-
s = s.replaceAll(
|
|
174
|
-
const
|
|
175
|
-
s = s.replaceAll(
|
|
176
|
-
const
|
|
177
|
-
s = s.replaceAll(
|
|
178
|
-
const
|
|
179
|
-
|
|
121
|
+
const u = new RegExp('(?<=(<title>|<meta property="og:title" content="|<meta name="twitter:title" content="))(([a-zA-Z|-]|\\s)+)(?=(<\\/title>|"\\/?>))', "g");
|
|
122
|
+
s = s.replaceAll(u, `${m} | ${o}`);
|
|
123
|
+
const w = 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(w, $);
|
|
125
|
+
const l = 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(l, d + g);
|
|
127
|
+
const S = /(<!-- FAQ -->.*?)?<script type="application\/ld\+json">.*?<\/script>/gs;
|
|
128
|
+
s = s.replaceAll(S, "");
|
|
129
|
+
const y = p(i, `${g}.html`);
|
|
130
|
+
x.writeFileSync(y, s, { flag: "w+" }), c(y, "file");
|
|
180
131
|
}
|
|
181
132
|
}
|
|
182
|
-
function
|
|
133
|
+
function C({ appsConfig: e, siteName: n, siteTagLine: t, buildPath: o, domain: a, imageUrls: d = [] }) {
|
|
183
134
|
try {
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
sitemapXml: p(
|
|
187
|
-
robotsTxt: p(
|
|
188
|
-
indexHtml: p(
|
|
189
|
-
cname: p(
|
|
135
|
+
c("Staging build...", "start", !0);
|
|
136
|
+
const i = `https://${a}/`, r = {
|
|
137
|
+
sitemapXml: p(o, "sitemap.xml"),
|
|
138
|
+
robotsTxt: p(o, "robots.txt"),
|
|
139
|
+
indexHtml: p(o, "index.html"),
|
|
140
|
+
cname: p(o, "CNAME")
|
|
190
141
|
}, g = [
|
|
191
|
-
[r.sitemapXml,
|
|
192
|
-
[r.robotsTxt,
|
|
193
|
-
[r.cname,
|
|
194
|
-
],
|
|
142
|
+
[r.sitemapXml, D],
|
|
143
|
+
[r.robotsTxt, R],
|
|
144
|
+
[r.cname, T]
|
|
145
|
+
], m = {
|
|
195
146
|
appsConfig: e,
|
|
196
|
-
siteName:
|
|
197
|
-
siteTagLine:
|
|
198
|
-
buildPath:
|
|
199
|
-
domain:
|
|
200
|
-
baseUrl:
|
|
201
|
-
imageUrls:
|
|
147
|
+
siteName: n,
|
|
148
|
+
siteTagLine: t,
|
|
149
|
+
buildPath: o,
|
|
150
|
+
domain: a,
|
|
151
|
+
baseUrl: i,
|
|
152
|
+
imageUrls: d,
|
|
202
153
|
paths: r
|
|
203
154
|
};
|
|
204
|
-
g.forEach(([
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
}),
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
} catch (
|
|
211
|
-
console.error(
|
|
155
|
+
g.forEach(([u, w]) => {
|
|
156
|
+
const l = u.substring(0, u.lastIndexOf("/"));
|
|
157
|
+
l != "" && !x.existsSync(l) && x.mkdirSync(l, { recursive: !0 }), x.writeFileSync(u, w(m), { flag: "w+" }), c(u, "file");
|
|
158
|
+
}), c("Generating pages...", "start", !0);
|
|
159
|
+
const $ = x.readFileSync(r.indexHtml, "utf-8"), s = j($, m);
|
|
160
|
+
k(s, m), v(s, m), c("Staging complete", "success", !0);
|
|
161
|
+
} catch (i) {
|
|
162
|
+
console.error(i), c("Staging failed", "error"), process.exit(1);
|
|
212
163
|
}
|
|
213
164
|
}
|
|
214
|
-
function
|
|
215
|
-
let
|
|
165
|
+
function L(e) {
|
|
166
|
+
let n;
|
|
216
167
|
return {
|
|
217
168
|
name: "vite-plugin-stage-site",
|
|
218
|
-
configResolved(
|
|
219
|
-
|
|
169
|
+
configResolved(t) {
|
|
170
|
+
n = t;
|
|
220
171
|
},
|
|
221
172
|
writeBundle() {
|
|
222
|
-
let
|
|
223
|
-
|
|
173
|
+
let t = e.buildPath ?? n.build.outDir;
|
|
174
|
+
t = p(n.root, t), C({
|
|
224
175
|
...e,
|
|
225
|
-
buildPath:
|
|
176
|
+
buildPath: t
|
|
226
177
|
});
|
|
227
178
|
}
|
|
228
179
|
};
|
|
229
180
|
}
|
|
230
181
|
export {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
182
|
+
Z as appViteConfig,
|
|
183
|
+
c as print,
|
|
184
|
+
L as stageSitePlugin
|
|
234
185
|
};
|
|
235
186
|
//# 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","../../../node_modules/@prozilla-os/shared/dist/main.js","../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};","var g = Object.defineProperty;\nvar m = (t) => {\n throw TypeError(t);\n};\nvar M = (t, n, e) => n in t ? g(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;\nvar d = (t, n, e) => M(t, typeof n != \"symbol\" ? n + \"\" : n, e), b = (t, n, e) => n.has(t) || m(\"Cannot \" + e);\nvar i = (t, n, e) => (b(t, n, \"read from private field\"), e ? e.call(t) : n.get(t)), x = (t, n, e) => n.has(t) ? m(\"Cannot add the same private member more than once\") : n instanceof WeakSet ? n.add(t) : n.set(t, e);\nconst A = {\n fg: {\n black: \"\\x1B[30m\",\n red: \"\\x1B[31m\",\n green: \"\\x1B[32m\",\n yellow: \"\\x1B[33m\",\n blue: \"\\x1B[34m\",\n magenta: \"\\x1B[35m\",\n cyan: \"\\x1B[36m\",\n white: \"\\x1B[37m\"\n },\n bg: {},\n decoration: {\n dim: \"\\x1B[2m\",\n bold: \"\\x1B[1m\"\n },\n reset: \"\\x1B[0m\"\n};\nfunction E(t, n) {\n const e = n.indexOf(t);\n e !== -1 && n.splice(e, 1);\n}\nfunction O(t) {\n return t[Math.floor(Math.random() * t.length)];\n}\nfunction T(t) {\n return t.filter((n, e) => t.indexOf(n) === e);\n}\nconst p = {\n s: 1e3,\n m: 1e3 * 60,\n h: 1e3 * 60 * 60,\n d: 1e3 * 60 * 60 * 24,\n w: 1e3 * 60 * 60 * 24 * 7,\n n: 1e3 * 60 * 60 * 24 * 31,\n y: 1e3 * 60 * 60 * 24 * 365,\n c: 1e3 * 60 * 60 * 24 * 365 * 100\n};\nfunction y(t, n = 3, e) {\n const s = [], a = (o, f) => {\n if (!e)\n return o.join(\", \");\n let u = \"\", h = \"\";\n return f ? h = \"ago\" : u = \"in\", [u, o.join(\", \"), h].join(\" \").trim();\n };\n let c = !1;\n if (t < 0 && (t = -t, c = !0), Math.abs(t) < p.s)\n return a([\"less than a second\"], c);\n const l = [], B = {\n s: \"seconds\",\n m: \"minutes\",\n h: \"hours\",\n d: \"days\",\n n: \"months\",\n y: \"years\"\n };\n for (const [o, f] of Object.entries(p).reverse()) {\n if (o === \"w\" || o === \"c\")\n continue;\n const u = Math.floor(t / f);\n t -= u * f, u > 0 && l.push({ amount: u, label: B[o] });\n }\n for (let o = 0; o < n; o++) {\n const f = l[o];\n f && s.push(`${f.amount} ${f.label}`);\n }\n return s.length === 0 ? a([\"less than a second\"], c) : a(s, c);\n}\nfunction j(t, n = 3, e) {\n const s = t.valueOf() - Date.now();\n return y(s, n, e);\n}\nvar r;\nclass I {\n constructor() {\n x(this, r, {});\n }\n /**\n * Add event listener for an event\n */\n on(n, e) {\n i(this, r)[n] || (i(this, r)[n] = []), i(this, r)[n].push(e);\n }\n /**\n * Remove event listener for an event\n */\n off(n, e) {\n i(this, r)[n] && (i(this, r)[n] = i(this, r)[n].filter(\n (s) => s !== e\n ));\n }\n /**\n * Dispatch event\n */\n emit(n, e) {\n i(this, r)[n] && i(this, r)[n].forEach((s) => {\n s(e);\n });\n }\n}\nr = new WeakMap(), d(I, \"EVENT_NAMES\", {});\nfunction R(t, n, e) {\n return t < n ? n : t > e ? e : t;\n}\nfunction D(t, n) {\n return Math.random() * (n - t) + t;\n}\nfunction F(t, n) {\n const e = Math.pow(10, n || 0);\n return Math.round(t * e) / e;\n}\nfunction S(t) {\n return typeof t == \"number\" || parseInt(t) || parseInt(t) === 0;\n}\nexport {\n A as ANSI,\n I as EventEmitter,\n R as clamp,\n j as formatRelativeTime,\n y as formatTime,\n S as isValidInteger,\n O as randomFromArray,\n D as randomRange,\n T as removeDuplicatesFromArray,\n E as removeFromArray,\n F as round\n};\n//# sourceMappingURL=main.js.map\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","g","m","t","M","n","e","d","b","i","x","A","r","I","s","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;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;AClDA,IAAIO,IAAI,OAAO,gBACXC,IAAI,CAACC,MAAM;AACb,QAAM,UAAUA,CAAC;AACnB,GACIC,IAAI,CAACD,GAAGE,GAAGC,MAAMD,KAAKF,IAAIF,EAAEE,GAAGE,GAAG,EAAE,YAAY,IAAI,cAAc,IAAI,UAAU,IAAI,OAAOC,EAAC,CAAE,IAAIH,EAAEE,CAAC,IAAIC,GACzGC,IAAI,CAACJ,GAAGE,GAAGC,MAAMF,EAAED,GAA0BE,IAAI,IAAQC,CAAC,GAAGE,IAAI,CAACL,GAAGE,GAAGC,MAAMD,EAAE,IAAIF,CAAC,KAAKD,EAAE,YAAYI,CAAC,GACzGG,IAAI,CAACN,GAAGE,GA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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,IAAA7E,EAAQ2E,EAAO,MAAME,CAAQ,GAE9BX,EAAA;AAAA,QACT,GAAGrC;AAAA,QACH,WAAWgD;AAAA,MAAA,CACX;AAAA,IACF;AAAA,EAAA;AAEF;","x_google_ignoreList":[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;AA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