okno 1.0.0-beta.18 → 1.0.0-beta.19
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/index.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { extname as Y, join as h, dirname as
|
|
2
|
-
import { existsSync as O, readFileSync as U, mkdirSync as
|
|
1
|
+
import { extname as Y, join as h, dirname as P, relative as N, sep as G, resolve as g } from "node:path";
|
|
2
|
+
import { existsSync as O, readFileSync as U, mkdirSync as R, writeFileSync as T, cpSync as Q } from "node:fs";
|
|
3
3
|
import { execSync as K } from "node:child_process";
|
|
4
4
|
import { fileURLToPath as Z } from "node:url";
|
|
5
|
-
import { i as x, g as q, s as
|
|
6
|
-
import { simpleGit as
|
|
5
|
+
import { i as x, g as q, s as v, b as tt, a as et, c as ot, e as nt, d as rt, f as it, h as M, j as $, k as st } from "./dispatch-DKZB5I61.js";
|
|
6
|
+
import { simpleGit as H } from "simple-git";
|
|
7
7
|
import "./acorn-CZBJD705.js";
|
|
8
|
-
function F(n,
|
|
9
|
-
n.statusCode =
|
|
8
|
+
function F(n, i, e) {
|
|
9
|
+
n.statusCode = i, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(e));
|
|
10
10
|
}
|
|
11
11
|
function at(n) {
|
|
12
|
-
return new Promise((
|
|
12
|
+
return new Promise((i) => {
|
|
13
13
|
let e = "";
|
|
14
14
|
n.on("data", (t) => e += t), n.on("end", () => {
|
|
15
15
|
try {
|
|
16
|
-
|
|
16
|
+
i(e ? JSON.parse(e) : {});
|
|
17
17
|
} catch {
|
|
18
|
-
|
|
18
|
+
i({});
|
|
19
19
|
}
|
|
20
|
-
}), n.on("error", () =>
|
|
20
|
+
}), n.on("error", () => i({}));
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
function lt(n) {
|
|
24
|
-
return new Promise((
|
|
24
|
+
return new Promise((i, e) => {
|
|
25
25
|
const t = [];
|
|
26
|
-
n.on("data", (
|
|
26
|
+
n.on("data", (c) => t.push(c)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
function ct(n,
|
|
30
|
-
if (
|
|
31
|
-
for (const e of new Set(
|
|
29
|
+
function ct(n, i) {
|
|
30
|
+
if (i) {
|
|
31
|
+
for (const e of new Set(i.modules)) {
|
|
32
32
|
const t = n.moduleGraph.getModuleById("\0okno:" + e);
|
|
33
33
|
t && n.moduleGraph.invalidateModule(t);
|
|
34
34
|
}
|
|
35
|
-
for (const e of new Set(
|
|
35
|
+
for (const e of new Set(i.files))
|
|
36
36
|
n.moduleGraph.getModulesByFile(e)?.forEach((t) => n.moduleGraph.invalidateModule(t));
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
function ut(n,
|
|
40
|
-
n.middlewares.use(async (e, t,
|
|
41
|
-
if (!e.url?.startsWith("/__okno/api/")) return
|
|
39
|
+
function ut(n, i) {
|
|
40
|
+
n.middlewares.use(async (e, t, c) => {
|
|
41
|
+
if (!e.url?.startsWith("/__okno/api/")) return c();
|
|
42
42
|
const y = e.url.slice(12).split("?")[0], o = {
|
|
43
43
|
method: e.method || "GET",
|
|
44
44
|
route: y,
|
|
45
45
|
json: () => at(e),
|
|
46
46
|
binary: () => lt(e),
|
|
47
|
-
header: (
|
|
48
|
-
const s = e.headers[
|
|
47
|
+
header: (r) => {
|
|
48
|
+
const s = e.headers[r];
|
|
49
49
|
return Array.isArray(s) ? s[0] : s;
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
try {
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
55
|
-
ct(n,
|
|
56
|
-
} catch (
|
|
57
|
-
F(t, 500, { error:
|
|
53
|
+
const r = await x(i, o);
|
|
54
|
+
if (!r) return c();
|
|
55
|
+
ct(n, r.invalidation), F(t, r.status, r.body);
|
|
56
|
+
} catch (r) {
|
|
57
|
+
F(t, 500, { error: r instanceof Error ? r.message : String(r) });
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
function dt(n,
|
|
61
|
+
function dt(n, i) {
|
|
62
62
|
let e;
|
|
63
63
|
try {
|
|
64
|
-
e = decodeURIComponent(
|
|
64
|
+
e = decodeURIComponent(i);
|
|
65
65
|
} catch {
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
68
|
if (!e || e.includes("\0")) return null;
|
|
69
|
-
const t = g(n, "files"),
|
|
70
|
-
return
|
|
69
|
+
const t = g(n, "files"), c = g(t, e);
|
|
70
|
+
return c === t || !c.startsWith(t + G) ? null : c;
|
|
71
71
|
}
|
|
72
|
-
const
|
|
72
|
+
const B = "okno", ft = {
|
|
73
73
|
".webp": "image/webp",
|
|
74
74
|
".png": "image/png",
|
|
75
75
|
".jpg": "image/jpeg",
|
|
@@ -90,80 +90,80 @@ const H = "okno", ft = {
|
|
|
90
90
|
".ttf": "font/ttf",
|
|
91
91
|
".otf": "font/otf"
|
|
92
92
|
};
|
|
93
|
-
function pt(n,
|
|
94
|
-
ut(n,
|
|
95
|
-
if (e.method !== "GET" || !e.url?.startsWith("/okno/files/")) return
|
|
93
|
+
function pt(n, i) {
|
|
94
|
+
ut(n, i), n.middlewares.use((e, t, c) => {
|
|
95
|
+
if (e.method !== "GET" || !e.url?.startsWith("/okno/files/")) return c();
|
|
96
96
|
const y = e.url.slice(12).split("?")[0];
|
|
97
|
-
if (!y) return
|
|
98
|
-
const o = dt(
|
|
97
|
+
if (!y) return c();
|
|
98
|
+
const o = dt(i, y);
|
|
99
99
|
if (!o)
|
|
100
100
|
return t.statusCode = 403, t.end("Forbidden");
|
|
101
101
|
if (!O(o))
|
|
102
102
|
return t.statusCode = 404, t.end("Not found");
|
|
103
|
-
const
|
|
104
|
-
t.setHeader("Content-Type", ft[
|
|
105
|
-
}), n.middlewares.use(async (e, t,
|
|
106
|
-
if (!e.url?.startsWith("/__okno/")) return
|
|
103
|
+
const r = Y(o).toLowerCase();
|
|
104
|
+
t.setHeader("Content-Type", ft[r] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(o));
|
|
105
|
+
}), n.middlewares.use(async (e, t, c) => {
|
|
106
|
+
if (!e.url?.startsWith("/__okno/")) return c();
|
|
107
107
|
const y = e.url.slice(8);
|
|
108
108
|
t.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate"), t.setHeader("Pragma", "no-cache"), t.setHeader("Expires", "0");
|
|
109
109
|
try {
|
|
110
110
|
if (e.method === "GET" && y === "repo") {
|
|
111
111
|
t.setHeader("Content-Type", "application/json");
|
|
112
112
|
try {
|
|
113
|
-
const o =
|
|
113
|
+
const o = H(n.config.root), r = (await o.remote(["get-url", "origin"]))?.toString().trim(), s = (await o.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: f, repo: a } = gt(r);
|
|
114
114
|
return t.end(
|
|
115
|
-
JSON.stringify({ ok: !0, owner: f, repo:
|
|
115
|
+
JSON.stringify({ ok: !0, owner: f, repo: a, branch: s || null, remote: r || null })
|
|
116
116
|
);
|
|
117
117
|
} catch (o) {
|
|
118
118
|
return t.end(JSON.stringify({ ok: !1, error: String(o) }));
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
if (e.method === "POST" && y.startsWith("mirror")) {
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
122
|
+
const r = new URL(e.url, "http://localhost").searchParams.get("path");
|
|
123
|
+
if (!r || r.includes("..") || !r.startsWith("files/"))
|
|
124
124
|
return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
|
|
125
|
-
const s = h(
|
|
125
|
+
const s = h(i, r);
|
|
126
126
|
if (O(s))
|
|
127
127
|
return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, skipped: !0 }));
|
|
128
128
|
const f = await mt(e);
|
|
129
|
-
return
|
|
129
|
+
return R(P(s), { recursive: !0 }), T(s, f), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: r, bytes: f.length }));
|
|
130
130
|
}
|
|
131
131
|
if (e.method === "POST" && y === "sync") {
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
134
|
-
if (
|
|
132
|
+
const r = (await ht(e))?.path;
|
|
133
|
+
if (r) {
|
|
134
|
+
if (r.includes("..") || r.includes("\0"))
|
|
135
135
|
return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
|
|
136
|
-
const u = h(
|
|
136
|
+
const u = h(i, r);
|
|
137
137
|
try {
|
|
138
|
-
const
|
|
139
|
-
await
|
|
140
|
-
const m = (await
|
|
141
|
-
|
|
142
|
-
} catch (
|
|
143
|
-
const m =
|
|
138
|
+
const l = H(i);
|
|
139
|
+
await l.fetch("origin", B);
|
|
140
|
+
const m = (await l.revparse(["--show-toplevel"])).trim(), p = N(m, u).split(G).join("/"), w = await l.show([`origin/${B}:${p}`]);
|
|
141
|
+
R(P(u), { recursive: !0 }), T(u, w);
|
|
142
|
+
} catch (l) {
|
|
143
|
+
const m = l instanceof Error ? l.message : String(l);
|
|
144
144
|
console.warn(
|
|
145
|
-
`[okno] sync: could not materialize ${
|
|
145
|
+
`[okno] sync: could not materialize ${r} from origin/${B} — ${m.split(`
|
|
146
146
|
`)[0]}`
|
|
147
147
|
);
|
|
148
148
|
}
|
|
149
|
-
return D(n,
|
|
149
|
+
return D(n, r, u), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: r }));
|
|
150
150
|
}
|
|
151
|
-
const s =
|
|
151
|
+
const s = H(i), f = await s.revparse(["--show-toplevel"]), a = N(f.trim(), i);
|
|
152
152
|
try {
|
|
153
153
|
const u = await s.pull();
|
|
154
|
-
for (const
|
|
155
|
-
if (
|
|
156
|
-
const m =
|
|
154
|
+
for (const l of u.files)
|
|
155
|
+
if (l.startsWith(`${a}/`)) {
|
|
156
|
+
const m = l.slice(`${a}/`.length), p = h(i, m);
|
|
157
157
|
D(n, m, p);
|
|
158
158
|
}
|
|
159
159
|
return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, files: u.files }));
|
|
160
160
|
} catch (u) {
|
|
161
|
-
const
|
|
162
|
-
return console.warn(`[okno] sync: git pull skipped — ${
|
|
163
|
-
`)[0]}`), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, pullSkipped: !0, reason:
|
|
161
|
+
const l = u instanceof Error ? u.message : String(u);
|
|
162
|
+
return console.warn(`[okno] sync: git pull skipped — ${l.split(`
|
|
163
|
+
`)[0]}`), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, pullSkipped: !0, reason: l }));
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
c();
|
|
167
167
|
} catch (o) {
|
|
168
168
|
t.statusCode = 500, t.end(JSON.stringify({ error: String(o) }));
|
|
169
169
|
}
|
|
@@ -171,53 +171,53 @@ function pt(n, r) {
|
|
|
171
171
|
}
|
|
172
172
|
function gt(n) {
|
|
173
173
|
if (!n) return { owner: null, repo: null };
|
|
174
|
-
const
|
|
175
|
-
return
|
|
174
|
+
const i = n.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
|
|
175
|
+
return i ? { owner: i[1], repo: i[2] } : { owner: null, repo: null };
|
|
176
176
|
}
|
|
177
177
|
function mt(n) {
|
|
178
|
-
return new Promise((
|
|
178
|
+
return new Promise((i, e) => {
|
|
179
179
|
const t = [];
|
|
180
|
-
n.on("data", (
|
|
180
|
+
n.on("data", (c) => t.push(c)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
function ht(n) {
|
|
184
|
-
return new Promise((
|
|
184
|
+
return new Promise((i) => {
|
|
185
185
|
let e = "";
|
|
186
186
|
n.on("data", (t) => {
|
|
187
187
|
e += t;
|
|
188
188
|
}), n.on("end", () => {
|
|
189
189
|
try {
|
|
190
|
-
|
|
190
|
+
i(e ? JSON.parse(e) : null);
|
|
191
191
|
} catch {
|
|
192
|
-
|
|
192
|
+
i(null);
|
|
193
193
|
}
|
|
194
|
-
}), n.on("error", () =>
|
|
194
|
+
}), n.on("error", () => i(null));
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
function D(n,
|
|
197
|
+
function D(n, i, e) {
|
|
198
198
|
const t = "\0okno:";
|
|
199
|
-
let
|
|
200
|
-
if (
|
|
201
|
-
const y = n.moduleGraph.getModuleById(
|
|
199
|
+
let c;
|
|
200
|
+
if (i.startsWith("pages/") ? c = t + "pages" : i.startsWith("collections/") ? c = t + "collections" : i.startsWith("globals/") && (c = t + "globals"), c) {
|
|
201
|
+
const y = n.moduleGraph.getModuleById(c);
|
|
202
202
|
y && n.moduleGraph.invalidateModule(y);
|
|
203
203
|
const o = n.moduleGraph.getModulesByFile(e);
|
|
204
|
-
o && o.forEach((
|
|
205
|
-
n.moduleGraph.invalidateModule(
|
|
204
|
+
o && o.forEach((r) => {
|
|
205
|
+
n.moduleGraph.invalidateModule(r);
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
function yt(n,
|
|
210
|
-
const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t =
|
|
209
|
+
function yt(n, i) {
|
|
210
|
+
const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = i.replace(/\\/g, "/");
|
|
211
211
|
return e === t || e.startsWith(t + "/");
|
|
212
212
|
}
|
|
213
|
-
function wt(n,
|
|
214
|
-
for (const [e, t] of Object.entries(
|
|
213
|
+
function wt(n, i) {
|
|
214
|
+
for (const [e, t] of Object.entries(i)) {
|
|
215
215
|
if (n === e) return t;
|
|
216
216
|
if (n.startsWith(e + "/")) return t + n.slice(e.length);
|
|
217
217
|
}
|
|
218
218
|
return null;
|
|
219
219
|
}
|
|
220
|
-
const bt = "okno:",
|
|
220
|
+
const bt = "okno:", S = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), V = P(Z(import.meta.url)), St = JSON.parse(U(g(V, "../package.json"), "utf-8")).version, L = q(), b = g(V, "../editor"), I = g(b, "index.ts"), Ot = O(I), kt = {
|
|
221
221
|
"@modules": g(b, "modules"),
|
|
222
222
|
"@lib": g(b, "lib"),
|
|
223
223
|
"@logger": g(b, "lib/logger.svelte.ts"),
|
|
@@ -229,39 +229,51 @@ const bt = "okno:", _ = "\0okno:", St = /* @__PURE__ */ new Set(["pages", "colle
|
|
|
229
229
|
"@pages": g(b, "pages"),
|
|
230
230
|
"@controllers": g(b, "controllers")
|
|
231
231
|
};
|
|
232
|
-
function
|
|
232
|
+
function Et() {
|
|
233
233
|
try {
|
|
234
|
-
const n = (
|
|
235
|
-
|
|
236
|
-
const t = n("git rev-parse --abbrev-ref HEAD") || "main";
|
|
237
|
-
return `${e[1]}/${e[2]}@${t}`;
|
|
234
|
+
const n = (t) => K(t, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim(), e = n("git remote get-url origin").match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
|
|
235
|
+
return e ? `${e[1]}/${e[2]}@${vt(n)}` : null;
|
|
238
236
|
} catch {
|
|
239
237
|
return null;
|
|
240
238
|
}
|
|
241
239
|
}
|
|
242
|
-
function
|
|
240
|
+
function vt(n) {
|
|
241
|
+
let i = "";
|
|
242
|
+
try {
|
|
243
|
+
i = n("git rev-parse --abbrev-ref HEAD");
|
|
244
|
+
} catch {
|
|
245
|
+
}
|
|
246
|
+
if (i && i !== "HEAD") return i;
|
|
247
|
+
const e = process.env;
|
|
248
|
+
return e.CF_PAGES_BRANCH || // Cloudflare Pages
|
|
249
|
+
e.VERCEL_GIT_COMMIT_REF || // Vercel
|
|
250
|
+
e.BRANCH || // Netlify
|
|
251
|
+
e.GITHUB_REF_NAME || // GitHub Actions
|
|
252
|
+
"main";
|
|
253
|
+
}
|
|
254
|
+
function Nt() {
|
|
243
255
|
try {
|
|
244
256
|
const n = K("git rev-parse --show-toplevel", {
|
|
245
257
|
encoding: "utf-8",
|
|
246
258
|
stdio: ["ignore", "pipe", "ignore"]
|
|
247
259
|
}).trim();
|
|
248
|
-
return N(n, process.cwd()).split(
|
|
260
|
+
return N(n, process.cwd()).split(G).join("/");
|
|
249
261
|
} catch {
|
|
250
262
|
return "";
|
|
251
263
|
}
|
|
252
264
|
}
|
|
253
|
-
function
|
|
254
|
-
const
|
|
255
|
-
let e, t,
|
|
265
|
+
function It(n = {}) {
|
|
266
|
+
const i = n.dir ?? "okno";
|
|
267
|
+
let e, t, c = !1, y = !1;
|
|
256
268
|
return n.isEditor, {
|
|
257
269
|
name: "okno",
|
|
258
270
|
enforce: "pre",
|
|
259
|
-
config(o,
|
|
260
|
-
const s =
|
|
261
|
-
return y =
|
|
271
|
+
config(o, r) {
|
|
272
|
+
const s = r.command === "serve";
|
|
273
|
+
return y = r.command === "build", c = s && Ot, {
|
|
262
274
|
define: {
|
|
263
275
|
__OKNO_API_URL__: JSON.stringify(n.apiUrl ?? "https://api.okno.build"),
|
|
264
|
-
__OKNO_VERSION__: JSON.stringify(
|
|
276
|
+
__OKNO_VERSION__: JSON.stringify(St),
|
|
265
277
|
// True when the consumer is running `vite dev` / `astro dev` /
|
|
266
278
|
// `sveltekit dev` — anything that serves locally. Replaced at
|
|
267
279
|
// consumer build time so the prebuilt editor bundle can honor
|
|
@@ -275,12 +287,12 @@ function jt(n = {}) {
|
|
|
275
287
|
// auto-targets its repo with no picker. null outside a git
|
|
276
288
|
// checkout → editor falls back to the picker. Dev ignores it
|
|
277
289
|
// (runtime /__okno/repo derivation is more current).
|
|
278
|
-
__OKNO_REPO__: JSON.stringify(
|
|
290
|
+
__OKNO_REPO__: JSON.stringify(Et()),
|
|
279
291
|
// Monorepo root path: the build dir relative to the git root (e.g.
|
|
280
292
|
// "apps/site", or "" at the repo root). Sent as X-Okno-Path so the
|
|
281
293
|
// hosted backend reads/writes content under `<root>/okno` instead of
|
|
282
294
|
// the repo-root `okno` — one repo, many okno projects keyed (repo, path).
|
|
283
|
-
__OKNO_ROOT__: JSON.stringify(
|
|
295
|
+
__OKNO_ROOT__: JSON.stringify(Nt())
|
|
284
296
|
},
|
|
285
297
|
// Source mode (monorepo dev only): skip prebundling so saves to
|
|
286
298
|
// `package/editor/**` propagate via HMR instead of needing
|
|
@@ -289,7 +301,7 @@ function jt(n = {}) {
|
|
|
289
301
|
// identically-named tsconfig aliases (`@components`, `@lib`, …). They
|
|
290
302
|
// are instead resolved per-importer in `resolveId`, scoped to imports
|
|
291
303
|
// originating inside the editor source tree. See editor-aliases.ts.
|
|
292
|
-
...
|
|
304
|
+
...c && {
|
|
293
305
|
optimizeDeps: { exclude: ["okno", "okno/editor"] }
|
|
294
306
|
},
|
|
295
307
|
server: {
|
|
@@ -302,7 +314,7 @@ function jt(n = {}) {
|
|
|
302
314
|
// the backend mirrored saves to disk, causing spurious full
|
|
303
315
|
// reloads. In production-mode the backend never touches local
|
|
304
316
|
// FS so blocking those is pure harm — pulls go unseen.)
|
|
305
|
-
ignored: [`**/${
|
|
317
|
+
ignored: [`**/${i}/files/**`, `**/${i}/.okno-tree.json`]
|
|
306
318
|
},
|
|
307
319
|
// Source mode: the editor loads via a dynamic `import("okno/editor")`
|
|
308
320
|
// from a separate package over `@fs`, so Vite's startup dep scan
|
|
@@ -311,22 +323,22 @@ function jt(n = {}) {
|
|
|
311
323
|
// re-optimize that 404s the now-stale prebundled chunks. Warming the
|
|
312
324
|
// editor entry forces that crawl at startup, so those deps land in
|
|
313
325
|
// the first optimize pass and never re-bundle under the user.
|
|
314
|
-
...
|
|
315
|
-
warmup: { clientFiles: [
|
|
326
|
+
...c && {
|
|
327
|
+
warmup: { clientFiles: [I] }
|
|
316
328
|
}
|
|
317
329
|
}
|
|
318
330
|
};
|
|
319
331
|
},
|
|
320
332
|
configResolved(o) {
|
|
321
|
-
e = o.root, t = g(e,
|
|
333
|
+
e = o.root, t = g(e, i);
|
|
322
334
|
},
|
|
323
335
|
async buildStart() {
|
|
324
336
|
if (O(t)) {
|
|
325
|
-
if (await
|
|
337
|
+
if (await M(t, e), y) {
|
|
326
338
|
const o = h(t, "files");
|
|
327
339
|
if (O(o)) {
|
|
328
|
-
const
|
|
329
|
-
g(s) !== g(o) && (
|
|
340
|
+
const r = O(h(e, "static")) ? h(e, "static") : h(e, "public"), s = h(r, "okno", "files");
|
|
341
|
+
g(s) !== g(o) && (R(s, { recursive: !0 }), Q(o, s, {
|
|
330
342
|
recursive: !0,
|
|
331
343
|
filter: (f) => !f.endsWith(".okno-tree.json")
|
|
332
344
|
}));
|
|
@@ -334,7 +346,7 @@ function jt(n = {}) {
|
|
|
334
346
|
}
|
|
335
347
|
if (n.demo) {
|
|
336
348
|
const o = h(e, "public");
|
|
337
|
-
O(o) ||
|
|
349
|
+
O(o) || R(o, { recursive: !0 }), T(
|
|
338
350
|
h(o, "okno-demo.json"),
|
|
339
351
|
JSON.stringify(st(t))
|
|
340
352
|
);
|
|
@@ -343,140 +355,140 @@ function jt(n = {}) {
|
|
|
343
355
|
},
|
|
344
356
|
configureServer(o) {
|
|
345
357
|
pt(o, t);
|
|
346
|
-
const
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
349
|
-
const u =
|
|
358
|
+
const r = (f) => {
|
|
359
|
+
const a = N(t, f);
|
|
360
|
+
if (a.startsWith("..") || !a.endsWith(".ts")) return;
|
|
361
|
+
const u = a.split(/[\\/]/)[0];
|
|
350
362
|
if (u !== "pages" && u !== "collections" && u !== "globals") return;
|
|
351
|
-
const
|
|
352
|
-
|
|
363
|
+
const l = o.moduleGraph.getModuleById(S + u);
|
|
364
|
+
l && o.moduleGraph.invalidateModule(l), o.moduleGraph.getModulesByFile(f)?.forEach((m) => o.moduleGraph.invalidateModule(m)), !$(f) && o.ws.send({ type: "full-reload" });
|
|
353
365
|
};
|
|
354
|
-
o.watcher.on("add",
|
|
366
|
+
o.watcher.on("add", r), o.watcher.on("unlink", r), o.middlewares.use("/__okno/imports", async (f, a, u) => {
|
|
355
367
|
if (f.method !== "GET") return u();
|
|
356
368
|
try {
|
|
357
|
-
const [
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
369
|
+
const [l, m, p] = await Promise.all([
|
|
370
|
+
v(e, "pages"),
|
|
371
|
+
v(e, "globals"),
|
|
372
|
+
v(e, "collections")
|
|
361
373
|
]);
|
|
362
|
-
|
|
363
|
-
pages: Array.from(
|
|
374
|
+
a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(JSON.stringify({
|
|
375
|
+
pages: Array.from(l),
|
|
364
376
|
globals: Array.from(m),
|
|
365
377
|
collections: Array.from(p)
|
|
366
378
|
}));
|
|
367
|
-
} catch (
|
|
368
|
-
u(
|
|
379
|
+
} catch (l) {
|
|
380
|
+
u(l);
|
|
369
381
|
}
|
|
370
382
|
});
|
|
371
383
|
const s = "/__okno_bootstrap.js";
|
|
372
|
-
o.middlewares.use(s, async (f,
|
|
384
|
+
o.middlewares.use(s, async (f, a, u) => {
|
|
373
385
|
try {
|
|
374
|
-
const
|
|
375
|
-
if (!
|
|
376
|
-
|
|
386
|
+
const l = await o.transformRequest("\0okno:bootstrap");
|
|
387
|
+
if (!l) {
|
|
388
|
+
a.statusCode = 500, a.end("okno bootstrap transform failed");
|
|
377
389
|
return;
|
|
378
390
|
}
|
|
379
|
-
|
|
380
|
-
} catch (
|
|
381
|
-
u(
|
|
391
|
+
a.setHeader("content-type", "text/javascript"), a.end(l.code);
|
|
392
|
+
} catch (l) {
|
|
393
|
+
u(l);
|
|
382
394
|
}
|
|
383
|
-
}), o.middlewares.use((f,
|
|
384
|
-
const
|
|
395
|
+
}), o.middlewares.use((f, a, u) => {
|
|
396
|
+
const l = "<script>window.__oknoDev=true<\/script>", m = n.demo ? "<script>window.__oknoDemo=true<\/script>" : "", p = `${l}${m}<script type="module" src="${s}"><\/script>`, w = [];
|
|
385
397
|
let k = null;
|
|
386
|
-
const X =
|
|
387
|
-
const d =
|
|
398
|
+
const X = a.write.bind(a), j = a.end.bind(a), z = a.setHeader.bind(a), W = () => {
|
|
399
|
+
const d = a.getHeader("content-type");
|
|
388
400
|
return typeof d == "string" && d.includes("text/html");
|
|
389
|
-
}, J = (d,
|
|
390
|
-
|
|
391
|
-
if (k === null && (k = W()), !k) return
|
|
392
|
-
d && w.push(J(d, typeof
|
|
393
|
-
let
|
|
394
|
-
|
|
395
|
-
const
|
|
396
|
-
if (!
|
|
401
|
+
}, J = (d, _) => Buffer.isBuffer(d) ? d : d instanceof Uint8Array ? Buffer.from(d.buffer, d.byteOffset, d.byteLength) : typeof d == "string" ? Buffer.from(d, _ || "utf-8") : Buffer.from(String(d));
|
|
402
|
+
a.write = (d, _, ...C) => (k === null && (k = W()), k ? (d && w.push(J(d, typeof _ == "string" ? _ : void 0)), !0) : X(d, _, ...C)), a.end = (d, _, ...C) => {
|
|
403
|
+
if (k === null && (k = W()), !k) return j(d, _, ...C);
|
|
404
|
+
d && w.push(J(d, typeof _ == "string" ? _ : void 0));
|
|
405
|
+
let E = Buffer.concat(w).toString("utf-8");
|
|
406
|
+
E.includes(p) || (E = E.includes("</body>") ? E.replace("</body>", `${p}</body>`) : E + p);
|
|
407
|
+
const A = Buffer.from(E, "utf-8");
|
|
408
|
+
if (!a.headersSent)
|
|
397
409
|
try {
|
|
398
|
-
z("content-length", String(
|
|
410
|
+
z("content-length", String(A.length));
|
|
399
411
|
} catch {
|
|
400
412
|
}
|
|
401
|
-
return
|
|
413
|
+
return j(A, ...C);
|
|
402
414
|
}, u();
|
|
403
415
|
});
|
|
404
416
|
},
|
|
405
417
|
async handleHotUpdate(o) {
|
|
406
|
-
const
|
|
407
|
-
if (o.file ===
|
|
408
|
-
await
|
|
418
|
+
const r = h(t, "schema.ts"), s = h(t, "users.json"), f = h(t, "permissions.ts"), a = h(t, "modules.d.ts");
|
|
419
|
+
if (o.file === r) {
|
|
420
|
+
await M(t, e);
|
|
409
421
|
for (const p of ["pages", "collections", "globals", "locales", "content", "strings"]) {
|
|
410
|
-
const w = o.server.moduleGraph.getModuleById(
|
|
422
|
+
const w = o.server.moduleGraph.getModuleById(S + p);
|
|
411
423
|
w && o.server.moduleGraph.invalidateModule(w);
|
|
412
424
|
}
|
|
413
425
|
return [];
|
|
414
426
|
}
|
|
415
|
-
if (o.file === s || o.file === f || o.file ===
|
|
427
|
+
if (o.file === s || o.file === f || o.file === a)
|
|
416
428
|
return [];
|
|
417
|
-
const u = h(t, "strings.ts"),
|
|
418
|
-
if (o.file === u || !
|
|
419
|
-
await
|
|
429
|
+
const u = h(t, "strings.ts"), l = N(h(t, "strings"), o.file);
|
|
430
|
+
if (o.file === u || !l.startsWith("..") && l.endsWith(".ts")) {
|
|
431
|
+
await M(t, e);
|
|
420
432
|
for (const p of ["strings", "content"]) {
|
|
421
|
-
const w = o.server.moduleGraph.getModuleById(
|
|
433
|
+
const w = o.server.moduleGraph.getModuleById(S + p);
|
|
422
434
|
w && o.server.moduleGraph.invalidateModule(w);
|
|
423
435
|
}
|
|
424
436
|
}
|
|
425
437
|
const m = N(t, o.file);
|
|
426
438
|
if (!m.startsWith("..") && m.endsWith(".ts")) {
|
|
427
439
|
const p = m.split(/[\\/]/)[0];
|
|
428
|
-
if ((p === "pages" || p === "collections" || p === "globals") &&
|
|
429
|
-
const w = o.server.moduleGraph.getModuleById(
|
|
440
|
+
if ((p === "pages" || p === "collections" || p === "globals") && $(o.file)) {
|
|
441
|
+
const w = o.server.moduleGraph.getModuleById(S + p);
|
|
430
442
|
return w && o.server.moduleGraph.invalidateModule(w), [];
|
|
431
443
|
}
|
|
432
444
|
}
|
|
433
445
|
},
|
|
434
|
-
async resolveId(o,
|
|
446
|
+
async resolveId(o, r) {
|
|
435
447
|
if (o.startsWith(bt))
|
|
436
448
|
return "\0" + o;
|
|
437
449
|
if (o.startsWith("okno/")) {
|
|
438
450
|
const s = o.slice(5);
|
|
439
|
-
if (
|
|
451
|
+
if (_t.has(s)) return S + s;
|
|
440
452
|
}
|
|
441
|
-
if (
|
|
442
|
-
return
|
|
443
|
-
if (
|
|
453
|
+
if (c && o === "okno/editor")
|
|
454
|
+
return I;
|
|
455
|
+
if (c && r && yt(r, b)) {
|
|
444
456
|
const s = wt(o, kt);
|
|
445
457
|
if (s)
|
|
446
|
-
return (await this.resolve(s,
|
|
458
|
+
return (await this.resolve(s, r, { skipSelf: !0 }))?.id;
|
|
447
459
|
}
|
|
448
460
|
},
|
|
449
461
|
async load(o) {
|
|
450
|
-
if (!o.startsWith(
|
|
451
|
-
const
|
|
452
|
-
if (
|
|
462
|
+
if (!o.startsWith(S)) return;
|
|
463
|
+
const r = o.slice(S.length);
|
|
464
|
+
if (r === "runtime") {
|
|
453
465
|
if (!L)
|
|
454
466
|
throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
|
|
455
467
|
return L;
|
|
456
468
|
}
|
|
457
|
-
if (
|
|
469
|
+
if (r === "bootstrap")
|
|
458
470
|
return 'import("okno/editor")';
|
|
459
|
-
if (
|
|
460
|
-
const s = await
|
|
471
|
+
if (r === "pages") {
|
|
472
|
+
const s = await v(e, "pages");
|
|
461
473
|
return await tt(t, s);
|
|
462
474
|
}
|
|
463
|
-
if (
|
|
464
|
-
const s = await
|
|
475
|
+
if (r === "collections") {
|
|
476
|
+
const s = await v(e, "collections");
|
|
465
477
|
return await et(t, s, y);
|
|
466
478
|
}
|
|
467
|
-
if (
|
|
468
|
-
const s = await
|
|
479
|
+
if (r === "globals") {
|
|
480
|
+
const s = await v(e, "globals");
|
|
469
481
|
return await ot(t, s);
|
|
470
482
|
}
|
|
471
|
-
if (
|
|
483
|
+
if (r === "locales")
|
|
472
484
|
return nt(t);
|
|
473
|
-
if (
|
|
474
|
-
return await
|
|
475
|
-
if (
|
|
476
|
-
return
|
|
485
|
+
if (r === "strings")
|
|
486
|
+
return await rt(t);
|
|
487
|
+
if (r === "content")
|
|
488
|
+
return it();
|
|
477
489
|
}
|
|
478
490
|
};
|
|
479
491
|
}
|
|
480
492
|
export {
|
|
481
|
-
|
|
493
|
+
It as o
|
|
482
494
|
};
|
package/dist/vite/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAoHpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAsZpD"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "okno",
|
|
3
3
|
"description": "Git-backed CMS with live editing for any Vite framework",
|
|
4
4
|
"author": "Gabriel Uhlíř",
|
|
5
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.19",
|
|
6
6
|
"homepage": "https://okno.build",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"types": "./dist/index.d.ts",
|