@unbase-app/cli 0.0.0-stage → 0.2.0
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/AGENTS.md +37 -0
- package/LICENSE +21 -0
- package/README.md +211 -2
- package/agents/astro.md +162 -0
- package/agents/next.md +109 -0
- package/agents/vite-react.md +108 -0
- package/bin/unbase.mjs +147 -0
- package/lib/args.mjs +49 -0
- package/lib/build.mjs +71 -0
- package/lib/compare.mjs +96 -0
- package/lib/config-edit.mjs +629 -0
- package/lib/doctor.mjs +37 -0
- package/lib/errors.mjs +15 -0
- package/lib/feature.mjs +23 -0
- package/lib/frameworks/astro.mjs +485 -0
- package/lib/frameworks/index.mjs +50 -0
- package/lib/frameworks/next.mjs +321 -0
- package/lib/frameworks/vite-react.mjs +299 -0
- package/lib/init.mjs +165 -0
- package/lib/next-config.mjs +131 -0
- package/lib/pm.mjs +109 -0
- package/lib/readers.mjs +1918 -0
- package/lib/site.mjs +153 -0
- package/lib/uninstall.mjs +136 -0
- package/lib/versions.mjs +71 -0
- package/lib/vite-config.mjs +294 -0
- package/package.json +43 -4
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Next.js: what the CLI does that is Next.js's (frameworks/index.mjs has the
|
|
3
|
+
// shape). init adds @unbase-app/next and wraps next.config in withUnbase(…)
|
|
4
|
+
// (next-config.mjs, through the syntax tree), writes comment-modus.json, and
|
|
5
|
+
// on a Next.js before 16.3 imports the comments' loader in
|
|
6
|
+
// instrumentation-client; uninstall takes them out with unbase.pages.json;
|
|
7
|
+
// doctor reads three features with Unbase's own readers (lib/readers.mjs:
|
|
8
|
+
// detect, read_settings on the pages' metadata, list_pages and the kit's
|
|
9
|
+
// core) on the working tree and one production build (`next build`, into the
|
|
10
|
+
// site's own .next). The steps init leaves: agents/next.md.
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { tailOf } from "../build.mjs";
|
|
16
|
+
import { CouldNotRun } from "../errors.mjs";
|
|
17
|
+
import { check, featureState } from "../feature.mjs";
|
|
18
|
+
import { inspectNextConfig, unwrapNextConfig, wrapNextConfig } from "../next-config.mjs";
|
|
19
|
+
import { core, readSettings, registryFiles, registryOf } from "../readers.mjs";
|
|
20
|
+
import { depsOf, installedVersion } from "../site.mjs";
|
|
21
|
+
import { compareVersions, NEXT, SELF } from "../versions.mjs";
|
|
22
|
+
|
|
23
|
+
/** The file with the steps init leaves, in this package. */
|
|
24
|
+
const AGENTS = "agents/next.md";
|
|
25
|
+
/** comment-modus.json: the link to the Unbase project, the same file as on Astro. */
|
|
26
|
+
export const LINK_FILE = "comment-modus.json";
|
|
27
|
+
const STEPS = {
|
|
28
|
+
install: `${AGENTS} step 1: Install`,
|
|
29
|
+
comments: `${AGENTS} step 2: Comments on the site`,
|
|
30
|
+
pageSettings: `${AGENTS} step 3: Page settings`,
|
|
31
|
+
drafts: `${AGENTS} step 4: Draft pages`,
|
|
32
|
+
};
|
|
33
|
+
/** Next.js injects a package's client module from this version on (instrumentationClientInject); before, instrumentation-client imports it. */
|
|
34
|
+
const INJECTS_FROM = "16.3.0";
|
|
35
|
+
/** instrumentation-client exists from this version on. */
|
|
36
|
+
const INSTRUMENTATION_FROM = "15.3.0";
|
|
37
|
+
const LOADER_IMPORT = `import "${NEXT.name}/comments";`;
|
|
38
|
+
/** What the loader leaves in the client's chunks, minified or not. */
|
|
39
|
+
const LOADER_MARK = "[unbase] comments:";
|
|
40
|
+
const DIST = ".next";
|
|
41
|
+
|
|
42
|
+
/** The project comment-modus.json names, or null; undefined when there is no such file. */
|
|
43
|
+
export function readLink(site) {
|
|
44
|
+
const text = site.text(LINK_FILE);
|
|
45
|
+
if (text === null) return undefined;
|
|
46
|
+
try {
|
|
47
|
+
const data = JSON.parse(text);
|
|
48
|
+
return typeof data?.project === "string" && data.project ? data.project : null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const nextVersion = (site) => installedVersion(site, "next") ?? (String(depsOf(site.pkg).next ?? "").match(/\d+\.\d+\.\d+/)?.[0] ?? null);
|
|
55
|
+
|
|
56
|
+
/** Where instrumentation-client goes: beside the app folder (src/ when the app is in src/app). */
|
|
57
|
+
function instrumentationFile(site) {
|
|
58
|
+
const there = ["src/instrumentation-client.ts", "src/instrumentation-client.js", "instrumentation-client.ts", "instrumentation-client.js"].find((f) => site.exists(f));
|
|
59
|
+
if (there) return there;
|
|
60
|
+
const dir = site.exists("src/app") ? "src/" : "";
|
|
61
|
+
return `${dir}instrumentation-client.${site.exists("tsconfig.json") ? "ts" : "js"}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const importsLoader = (text) => !!text && text.split("\n").some((l) => l.trim().replace(/;$/, "") === LOADER_IMPORT.replace(/;$/, "") || l.trim().replace(/'/g, '"') === LOADER_IMPORT);
|
|
65
|
+
|
|
66
|
+
// ── init ───────────────────────────────────────────────────────────────────
|
|
67
|
+
|
|
68
|
+
/** init's plan for next.config, comment-modus.json and (before Next.js 16.3) instrumentation-client. */
|
|
69
|
+
function planInit(site, { comments, project }) {
|
|
70
|
+
if (!site.configFile) throw new CouldNotRun("no_config", "No next.config.(ts|mjs|js) in the site's folder.");
|
|
71
|
+
const config = wrapNextConfig(site.text(site.configFile), site.configFile);
|
|
72
|
+
const plan = config.changes.length ? [{ file: site.configFile, action: "changed", changes: config.changes, text: config.code }] : [];
|
|
73
|
+
if (!comments) return plan;
|
|
74
|
+
|
|
75
|
+
const text = site.text(LINK_FILE);
|
|
76
|
+
if (text === null) {
|
|
77
|
+
plan.push({ file: LINK_FILE, action: "created", changes: [project ? `project: "${project}"` : "project: null (Unbase fills it in when the site is connected)"], text: `${JSON.stringify({ project }, null, 2)}\n` });
|
|
78
|
+
} else {
|
|
79
|
+
let data;
|
|
80
|
+
try {
|
|
81
|
+
data = JSON.parse(text);
|
|
82
|
+
} catch {
|
|
83
|
+
throw new CouldNotRun("link_file", `${LINK_FILE} is not valid JSON.`, { file: LINK_FILE });
|
|
84
|
+
}
|
|
85
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) throw new CouldNotRun("link_file", `${LINK_FILE} is not a JSON object.`, { file: LINK_FILE });
|
|
86
|
+
const indent = /^[ \t]+(?=")/m.exec(text)?.[0] ?? " ";
|
|
87
|
+
if (project && data.project !== project) plan.push({ file: LINK_FILE, action: "changed", changes: [`project: ${JSON.stringify(data.project ?? null)} → "${project}"`], text: `${JSON.stringify({ ...data, project }, null, indent)}\n` });
|
|
88
|
+
else if (!("project" in data)) plan.push({ file: LINK_FILE, action: "changed", changes: ["project: null"], text: `${JSON.stringify({ project: null, ...data }, null, indent)}\n` });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Before 16.3 Next.js cannot inject the loader; from 15.3 instrumentation-client imports it.
|
|
92
|
+
const version = nextVersion(site);
|
|
93
|
+
if (version && compareVersions(version, INJECTS_FROM) < 0 && compareVersions(version, INSTRUMENTATION_FROM) >= 0) {
|
|
94
|
+
const file = instrumentationFile(site);
|
|
95
|
+
const now = site.text(file);
|
|
96
|
+
if (now === null) plan.push({ file, action: "created", changes: [LOADER_IMPORT], text: `${LOADER_IMPORT}\n` });
|
|
97
|
+
else if (!importsLoader(now)) plan.push({ file, action: "changed", changes: [LOADER_IMPORT], text: `${LOADER_IMPORT}\n${now}` });
|
|
98
|
+
}
|
|
99
|
+
return plan;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── uninstall ──────────────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
/** uninstall's plan: next.config unwrapped, the loader's import out of instrumentation-client, the package and its files. */
|
|
105
|
+
function planUninstall(site) {
|
|
106
|
+
const files = [];
|
|
107
|
+
const remove = [LINK_FILE, core.PAGE_FILE];
|
|
108
|
+
if (site.configFile) {
|
|
109
|
+
const config = unwrapNextConfig(site.text(site.configFile), site.configFile);
|
|
110
|
+
if (config.changes.length) files.push({ file: site.configFile, action: "changed", changes: config.changes, text: config.code });
|
|
111
|
+
}
|
|
112
|
+
for (const file of ["src/instrumentation-client.ts", "src/instrumentation-client.js", "instrumentation-client.ts", "instrumentation-client.js"]) {
|
|
113
|
+
const text = site.text(file);
|
|
114
|
+
if (!importsLoader(text)) continue;
|
|
115
|
+
const rest = text
|
|
116
|
+
.split("\n")
|
|
117
|
+
.filter((l) => !importsLoader(l))
|
|
118
|
+
.join("\n");
|
|
119
|
+
if (!rest.trim()) remove.push(file);
|
|
120
|
+
else files.push({ file, action: "changed", changes: [`removed: ${LOADER_IMPORT}`], text: rest });
|
|
121
|
+
}
|
|
122
|
+
return { packages: [NEXT.name, SELF.name], files, remove };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ── doctor ─────────────────────────────────────────────────────────────────
|
|
126
|
+
|
|
127
|
+
/** The client's compiled chunks of the last build, as text. */
|
|
128
|
+
function clientChunks(site) {
|
|
129
|
+
const dir = join(site.root, DIST, "static");
|
|
130
|
+
const out = [];
|
|
131
|
+
const walk = (d) => {
|
|
132
|
+
for (const e of readdirSync(d, { withFileTypes: true })) {
|
|
133
|
+
if (e.isDirectory()) walk(join(d, e.name));
|
|
134
|
+
else if (e.name.endsWith(".js")) out.push(readFileSync(join(d, e.name), "utf8"));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
if (existsSync(dir)) walk(dir);
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function envHas(site, names) {
|
|
142
|
+
return names.some((name) => process.env[name] || [".env", ".env.production", ".env.local", ".env.production.local"].some((f) => new RegExp(`^\\s*(export\\s+)?${name}\\s*=\\s*\\S`, "m").test(site.text(f) ?? "")));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const listOf = (list, n = 3) => `${list.slice(0, n).join(", ")}${list.length > n ? ", …" : ""}`;
|
|
146
|
+
|
|
147
|
+
/** doctor's three features on a Next.js site, from the production build doctor made (null: --no-build). */
|
|
148
|
+
async function doctorFeatures(site, { build }) {
|
|
149
|
+
const built = !!build?.ok;
|
|
150
|
+
const deps = depsOf(site.pkg);
|
|
151
|
+
const version = nextVersion(site);
|
|
152
|
+
const features = [];
|
|
153
|
+
const text = (p) => site.text(p);
|
|
154
|
+
|
|
155
|
+
let config = null;
|
|
156
|
+
let configError = null;
|
|
157
|
+
if (site.configFile) {
|
|
158
|
+
try {
|
|
159
|
+
config = inspectNextConfig(site.text(site.configFile), site.configFile);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
if (!(e instanceof CouldNotRun)) throw e;
|
|
162
|
+
configError = e.message;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const listed = !!deps[NEXT.name];
|
|
166
|
+
const have = installedVersion(site, NEXT.name);
|
|
167
|
+
const wrapped = !!config?.wrapped;
|
|
168
|
+
/** The package and its line in next.config: one check, shared by comments and page management. */
|
|
169
|
+
const packageCheck = () => {
|
|
170
|
+
if (!listed)
|
|
171
|
+
return check("package", "missing", have ? `${NEXT.name} is in node_modules (${have}) but not listed in package.json.` : `${NEXT.name} is not a dependency.`, { missing: `${NEXT.name} in dependencies, pinned`, file: "package.json", step: STEPS.install });
|
|
172
|
+
if (configError) return check("config", "missing", configError, { file: site.configFile, step: STEPS.install });
|
|
173
|
+
if (!site.configFile) return check("config", "missing", "No next.config: withUnbase wraps the site's config.", { missing: "next.config.ts with withUnbase(…)", file: "next.config.ts", step: STEPS.install });
|
|
174
|
+
if (!wrapped) return check("config", "missing", `${site.configFile} does not hand Next.js withUnbase(…).`, { missing: "export default withUnbase(nextConfig)", file: site.configFile, step: STEPS.install });
|
|
175
|
+
return check("package", "ok", `${NEXT.name} ${have ?? deps[NEXT.name]} is a dependency, and ${site.configFile} hands Next.js withUnbase(…).`);
|
|
176
|
+
};
|
|
177
|
+
const ranProduction = built && /\[unbase\] production build \(UNBASE_DEPLOY_CONTEXT\)/.test(build.output);
|
|
178
|
+
|
|
179
|
+
// ── Visual editing ────────────────────────────────────────────────────────
|
|
180
|
+
{
|
|
181
|
+
const checks = [check("next", "ok", `Next.js ${version ?? ""}: Unbase edits a text where it is written, found by matching it and proven by a probe that changes it once; nothing installed, no markers.`)];
|
|
182
|
+
if (!build) checks.push(check("build", "skipped", "Not built (--no-build)."));
|
|
183
|
+
else if (built) checks.push(check("build", "ok", `A production build works (${build.html.size} prerendered pages).`));
|
|
184
|
+
else checks.push(check("build", "missing", "The production build fails, so Unbase cannot start or check the site.", { missing: "a site that builds", file: site.configFile, detail: tailOf(build.output) }));
|
|
185
|
+
const names = site.detection.settings.map((s) => s.name);
|
|
186
|
+
if (names.length) checks.push(check("settings", "info", `The code reads ${names.length} setting(s) (${listOf(names, 6)}). If the site needs them to start or build, give them development values in Unbase.`));
|
|
187
|
+
features.push({ id: "visual-editing", name: "Visual editing", state: featureState(checks), checks });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ── Comments on the site ──────────────────────────────────────────────────
|
|
191
|
+
{
|
|
192
|
+
const checks = [packageCheck()];
|
|
193
|
+
const project = readLink(site);
|
|
194
|
+
let notInstalled = false;
|
|
195
|
+
if (project === undefined) {
|
|
196
|
+
notInstalled = true;
|
|
197
|
+
checks.push(check("link", "info", `No ${LINK_FILE}: comments on the live site are off. \`unbase init --comments\` adds it. Comments on the canvas in Unbase work without it.`));
|
|
198
|
+
} else {
|
|
199
|
+
if (project) checks.push(check("link", "ok", `Linked to the Unbase project "${project}".`, { file: LINK_FILE }));
|
|
200
|
+
else
|
|
201
|
+
checks.push(
|
|
202
|
+
check("link", "waiting", `Not linked to an Unbase project yet, so comments stay off. Unbase fills in \`project\` in ${LINK_FILE} when the site is connected; or run \`unbase init --project <id or slug>\`.`, { missing: `project in ${LINK_FILE}`, file: LINK_FILE }),
|
|
203
|
+
);
|
|
204
|
+
// The loader on the page: injected by withUnbase, or imported in instrumentation-client.
|
|
205
|
+
const injects = version && compareVersions(version, INJECTS_FROM) >= 0;
|
|
206
|
+
const file = instrumentationFile(site);
|
|
207
|
+
if (injects) checks.push(check("loader", "ok", `Next.js ${version} runs the ?comment loader on every page (withUnbase injects it): nothing to add.`));
|
|
208
|
+
else if (importsLoader(text(file))) checks.push(check("loader", "ok", `${file} imports the ?comment loader.`));
|
|
209
|
+
else if (version && compareVersions(version, INSTRUMENTATION_FROM) >= 0)
|
|
210
|
+
checks.push(check("loader", "missing", `Next.js ${version} cannot inject the loader: ${file} has to import it.`, { missing: LOADER_IMPORT, file, step: STEPS.comments }));
|
|
211
|
+
else checks.push(check("loader", "missing", `Next.js ${version ?? "?"} has no instrumentation-client: the root layout has to render the loader.`, { missing: "the loader in the root layout", file: "src/app/layout.tsx", step: STEPS.comments }));
|
|
212
|
+
if (project && build) {
|
|
213
|
+
if (!built) checks.push(check("built-loader", "skipped", "The build failed."));
|
|
214
|
+
else {
|
|
215
|
+
const chunks = clientChunks(site);
|
|
216
|
+
const inBundle = chunks.some((c) => c.includes(LOADER_MARK));
|
|
217
|
+
const configured = chunks.some((c) => c.includes(`\\"project\\":\\"${project}\\"`) || c.includes(`"project":"${project}"`));
|
|
218
|
+
checks.push(
|
|
219
|
+
inBundle && configured
|
|
220
|
+
? check("built-loader", "ok", "The production build carries the ?comment loader and the project's configuration; a visitor loads nothing unless they open ?comment.")
|
|
221
|
+
: check("built-loader", "missing", inBundle ? "The loader is in the build, but not the project's configuration." : "The ?comment loader is not in the production build.", { missing: "the loader in the build", file: site.configFile, step: STEPS.comments }),
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (!envHas(site, ["PUBLIC_SUPABASE_URL", "NEXT_PUBLIC_SUPABASE_URL"]) || !envHas(site, ["PUBLIC_SUPABASE_ANON_KEY", "NEXT_PUBLIC_SUPABASE_ANON_KEY"]))
|
|
226
|
+
checks.push(check("backend", "info", "Comments find Unbase's backend through PUBLIC_SUPABASE_URL and PUBLIC_SUPABASE_ANON_KEY where the site is built; they are not set here, and doctor cannot see your host's (Unbase's Vercel integration sets them)."));
|
|
227
|
+
}
|
|
228
|
+
features.push({ id: "comments", name: "Comments on the site", state: featureState(checks, notInstalled), checks });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ── Page management: draft pages and page settings ─────────────────────────
|
|
232
|
+
{
|
|
233
|
+
const checks = [packageCheck()];
|
|
234
|
+
const kit = core.kitInstalled({ framework: "next", text }) && wrapped;
|
|
235
|
+
const files = site.appPaths.filter(registryFiles).map((p) => ({ path: p, text: text(p) ?? "" }));
|
|
236
|
+
const byPath = new Map(files.map((f) => [f.path, f.text]));
|
|
237
|
+
const pageFile = core.parsePageFile(text(core.PAGE_FILE));
|
|
238
|
+
let drafts = 0;
|
|
239
|
+
if (!pageFile.ok) checks.push(check("drafts", "missing", `${core.PAGE_FILE} is invalid: ${pageFile.error}.`, { missing: `a valid ${core.PAGE_FILE}`, file: core.PAGE_FILE, step: STEPS.drafts }));
|
|
240
|
+
else {
|
|
241
|
+
const plan = core.draftPlan({ framework: "next", paths: [...byPath.keys()].sort(), text: (p) => byPath.get(p) ?? null, pageFile });
|
|
242
|
+
drafts = plan.checks.length;
|
|
243
|
+
if (plan.failed.length)
|
|
244
|
+
checks.push(
|
|
245
|
+
check("drafts", "missing", `A production build would stop: ${plan.failed.map((f) => `${f.path} (${f.reason}${f.detail ? `: ${f.detail}` : ""})`).join(", ")}.`, { missing: "drafts the package can keep out", file: core.PAGE_FILE, step: STEPS.drafts }),
|
|
246
|
+
);
|
|
247
|
+
else checks.push(check("drafts", "ok", drafts ? `${drafts} draft(s) in ${core.PAGE_FILE}, each kept out of production builds.` : "No drafts now."));
|
|
248
|
+
}
|
|
249
|
+
if (kit && build) {
|
|
250
|
+
if (!built) checks.push(check("fails-closed", "skipped", "The build failed."));
|
|
251
|
+
else if (!ranProduction) checks.push(check("fails-closed", "missing", "withUnbase did not plan the production build.", { missing: "withUnbase(…) running in next build", file: site.configFile, step: STEPS.install }));
|
|
252
|
+
else if (drafts && !/\[unbase\] kept out:/.test(build.output)) checks.push(check("fails-closed", "missing", "The build did not prove the drafts were kept out.", { missing: "the check after the compile", file: site.configFile, step: STEPS.drafts }));
|
|
253
|
+
else checks.push(check("fails-closed", "ok", drafts ? "withUnbase kept the drafts out of the production build and checked its output." : "withUnbase ran in the production build: a draft it cannot keep out stops the build."));
|
|
254
|
+
}
|
|
255
|
+
const registry = registryOf({ files, framework: "next", appPath: site.appPath, staged: true, truncated: false });
|
|
256
|
+
const pages = registry.pages.filter((p) => p.kind !== "template");
|
|
257
|
+
if (kit) {
|
|
258
|
+
const ok = pages.filter((p) => p.capabilities.draft.ok).length;
|
|
259
|
+
const why = {};
|
|
260
|
+
for (const p of pages) if (!p.capabilities.draft.ok) (why[p.capabilities.draft.reason] ??= []).push(p.path);
|
|
261
|
+
const rest = Object.entries(why).map(([r, list]) => `${r}: ${listOf(list)}`);
|
|
262
|
+
checks.push(check("draftable", "info", `${ok} of ${pages.length} pages can be drafts${rest.length ? ` (not: ${rest.join("; ")})` : ""}. In Unbase, draft pages also need Publishing with a Live branch.`));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Page settings: read_settings on the pages' metadata, nothing installed.
|
|
266
|
+
const settings = await readSettings(site.repo, site.appPath, "next");
|
|
267
|
+
if (!settings) checks.push(check("page-settings", "info", "No app router: page settings live in the pages router's <Head>, which Unbase does not set."));
|
|
268
|
+
else {
|
|
269
|
+
const settable = pages.filter((p) => settings.pages[p.path]).length;
|
|
270
|
+
const fresh = pages.filter((p) => settings.pages[p.path] && !Object.values(settings.pages[p.path]).some((f) => f.exists)).length;
|
|
271
|
+
const refused = {};
|
|
272
|
+
for (const [route, r] of Object.entries(settings.refused ?? {})) if (route !== "site" && !settings.pages[route]) (refused[r.reason] ??= []).push(route);
|
|
273
|
+
const not = Object.entries(refused).map(([r, list]) => `${list.length} ${r === "cms" ? "from a CMS (set there)" : r === "computed" ? "built in code" : "where Next.js takes none (a client component, the pages router)"}: ${listOf(list)}`);
|
|
274
|
+
checks.push(
|
|
275
|
+
check(
|
|
276
|
+
"page-settings",
|
|
277
|
+
settable ? "ok" : "info",
|
|
278
|
+
`Page settings in each page's metadata: ${settable} of ${pages.length} pages can be set in Unbase${settable < pages.length && not.length ? `; not ${not.join("; ")}` : ""}.${fresh ? ` ${fresh} without metadata yet get it when their settings are first published.` : ""}`,
|
|
279
|
+
settable < pages.length ? { step: STEPS.pageSettings } : {},
|
|
280
|
+
),
|
|
281
|
+
);
|
|
282
|
+
const site_ = settings.site ? Object.keys(settings.site) : [];
|
|
283
|
+
const layoutWhy = settings.refused?.site;
|
|
284
|
+
checks.push(
|
|
285
|
+
site_.length
|
|
286
|
+
? check("site-settings", "ok", `Site settings in ${Object.values(settings.site)[0].file}: ${site_.join(", ")}.${layoutWhy?.fields ? ` Built in code: ${Object.keys(layoutWhy.fields).join(", ")}.` : ""}`)
|
|
287
|
+
: check("site-settings", "info", `No site settings Unbase can set in the root layout${layoutWhy ? ` (${layoutWhy.reason})` : ""}.`),
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
features.push({ id: "page-management", name: "Page management", state: featureState(checks), checks });
|
|
291
|
+
}
|
|
292
|
+
return features;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* A built page as a visitor sees it, for comparing two builds: Next.js's scripts (the RSC payload,
|
|
297
|
+
* chunk references, the comments' loader) and its hashed asset names say nothing about what renders.
|
|
298
|
+
*/
|
|
299
|
+
export const normaliseNext = (html) =>
|
|
300
|
+
html
|
|
301
|
+
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g, "")
|
|
302
|
+
.replace(/<link\b[^>]*\bas="script"[^>]*>/g, "")
|
|
303
|
+
.replace(/\/_next\/static\/[^"'\s)]+/g, "/_next/static/…")
|
|
304
|
+
.replace(/\s(nonce|data-dpl-id)="[^"]*"/g, "");
|
|
305
|
+
|
|
306
|
+
export default {
|
|
307
|
+
id: "next",
|
|
308
|
+
name: "Next.js",
|
|
309
|
+
/** In the order the kit looks for them (kitFiles). */
|
|
310
|
+
configFiles: core.kitFiles("next").filter((f) => f !== "package.json"),
|
|
311
|
+
agents: AGENTS,
|
|
312
|
+
comments: true,
|
|
313
|
+
// next build has no output folder of its own: it writes the site's .next, where its pages are read.
|
|
314
|
+
build: { bin: "next", args: () => ["build"], env: { NEXT_TELEMETRY_DISABLED: "1" }, output: [`${DIST}/server/app`, `${DIST}/server/pages`] },
|
|
315
|
+
packages: () => [NEXT, SELF],
|
|
316
|
+
init: planInit,
|
|
317
|
+
linked: (site) => readLink(site) ?? null,
|
|
318
|
+
uninstall: planUninstall,
|
|
319
|
+
doctor: doctorFeatures,
|
|
320
|
+
normalise: normaliseNext,
|
|
321
|
+
};
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Vite + React (React Router as a library: what Lovable makes): what the CLI
|
|
3
|
+
// does that is this framework's (frameworks/index.mjs has the shape). One
|
|
4
|
+
// package, @unbase-app/vite (kit/vite): the draft-pages kit and comment
|
|
5
|
+
// mode's loader in one plugin. init adds it, its line in vite.config
|
|
6
|
+
// (vite-config.mjs, through the syntax tree) and comment-modus.json;
|
|
7
|
+
// uninstall takes them out with unbase.pages.json; doctor reads three
|
|
8
|
+
// features with Unbase's own readers (lib/readers.mjs: detect, read_settings,
|
|
9
|
+
// list_pages and the kit's core) on the working tree and one production
|
|
10
|
+
// build. The steps init leaves: agents/vite-react.md.
|
|
11
|
+
//
|
|
12
|
+
// React Router's framework mode (@react-router/dev, detection's
|
|
13
|
+
// "react-router") is not this: it renders its own document and reads its
|
|
14
|
+
// routes from app/routes.ts, neither of which the plugin or the readers read.
|
|
15
|
+
// ============================================================================
|
|
16
|
+
|
|
17
|
+
import { readFileSync } from "node:fs";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { tailOf } from "../build.mjs";
|
|
20
|
+
import { hasOurScript } from "../compare.mjs";
|
|
21
|
+
import { CouldNotRun } from "../errors.mjs";
|
|
22
|
+
import { check, featureState } from "../feature.mjs";
|
|
23
|
+
import { core, readSettings, registryFiles, registryOf } from "../readers.mjs";
|
|
24
|
+
import { depsOf, installedVersion } from "../site.mjs";
|
|
25
|
+
import { addToViteConfig, inspectViteConfig, removeFromViteConfig } from "../vite-config.mjs";
|
|
26
|
+
import { BEFORE, PAGES, SELF, VITE } from "../versions.mjs";
|
|
27
|
+
|
|
28
|
+
const AGENTS = "agents/vite-react.md";
|
|
29
|
+
export const LINK_FILE = "comment-modus.json";
|
|
30
|
+
const STEPS = {
|
|
31
|
+
install: `${AGENTS} step 1: Install`,
|
|
32
|
+
settings: `${AGENTS} step 2: Site settings`,
|
|
33
|
+
drafts: `${AGENTS} step 3: Draft pages`,
|
|
34
|
+
comments: `${AGENTS} step 4: Comments on the site`,
|
|
35
|
+
};
|
|
36
|
+
/** The settings index.html can hold, as read_settings names them. */
|
|
37
|
+
const SITE_SETTINGS = { name: "<title>", description: "meta description", language: "<html lang>", faviconLight: "icon", faviconDark: "dark icon", socialImage: "og:image" };
|
|
38
|
+
|
|
39
|
+
/** The project comment-modus.json names, or the one unbase() names in the config; null without. */
|
|
40
|
+
export function readLink(site) {
|
|
41
|
+
try {
|
|
42
|
+
const data = JSON.parse(readFileSync(join(site.root, LINK_FILE), "utf8"));
|
|
43
|
+
if (typeof data?.project === "string" && data.project.trim()) return data.project.trim();
|
|
44
|
+
} catch {}
|
|
45
|
+
try {
|
|
46
|
+
return site.configFile ? (inspectViteConfig(site.text(site.configFile), site.configFile).options?.project ?? null) : null;
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── init ───────────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
/** init's plan for vite.config and comment-modus.json. */
|
|
55
|
+
function planInit(site, { comments, project }) {
|
|
56
|
+
if (!site.configFile) throw new CouldNotRun("no_config", "No vite.config.(ts|js|mjs|mts) in the site's folder.");
|
|
57
|
+
const config = addToViteConfig(site.text(site.configFile), site.configFile, { comments });
|
|
58
|
+
let link = null;
|
|
59
|
+
if (comments) {
|
|
60
|
+
const text = site.text(LINK_FILE);
|
|
61
|
+
if (text === null) link = { action: "created", data: { project }, indent: " ", changes: [project ? `project: "${project}"` : "project: null (Unbase fills it in when the site is connected)"] };
|
|
62
|
+
else {
|
|
63
|
+
let data;
|
|
64
|
+
try {
|
|
65
|
+
data = JSON.parse(text);
|
|
66
|
+
} catch {
|
|
67
|
+
throw new CouldNotRun("link_file", `${LINK_FILE} is not valid JSON.`, { file: LINK_FILE });
|
|
68
|
+
}
|
|
69
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) throw new CouldNotRun("link_file", `${LINK_FILE} is not a JSON object.`, { file: LINK_FILE });
|
|
70
|
+
const indent = /^[ \t]+(?=")/m.exec(text)?.[0] ?? " ";
|
|
71
|
+
if (project && data.project !== project) link = { action: "changed", data: { ...data, project }, indent, changes: [`project: ${JSON.stringify(data.project ?? null)} → "${project}"`] };
|
|
72
|
+
else if (!("project" in data)) link = { action: "changed", data: { project: null, ...data }, indent, changes: ["project: null"] };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
...(config.changes.length ? [{ file: site.configFile, action: "changed", changes: config.changes, text: config.code }] : []),
|
|
77
|
+
...(link ? [{ file: LINK_FILE, action: link.action, changes: link.changes, text: `${JSON.stringify(link.data, null, link.indent)}\n` }] : []),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ── The move (K5) ──────────────────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* What init takes out once @unbase-app/vite is in: the kit's own Vite plugin under either name
|
|
85
|
+
* (unbase() takes its place in the config), unless the planned config still names it, and the CLI
|
|
86
|
+
* under its name before K5.
|
|
87
|
+
*/
|
|
88
|
+
function planReplaced(site, planned) {
|
|
89
|
+
const deps = depsOf(site.pkg);
|
|
90
|
+
const config = planned.find((f) => f.file === site.configFile)?.text ?? site.text(site.configFile) ?? "";
|
|
91
|
+
const remove = [PAGES.name, BEFORE.pages].filter((n) => deps[n] !== undefined && !config.includes(n));
|
|
92
|
+
if (deps[BEFORE.cli] !== undefined) remove.push(BEFORE.cli);
|
|
93
|
+
return { remove, keep: [], by: VITE.name };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** What of Unbase the site has now, for init's defaults: null without any of it; else whether comment mode is on. */
|
|
97
|
+
function currentOf(site) {
|
|
98
|
+
const deps = depsOf(site.pkg);
|
|
99
|
+
if (![VITE.name, PAGES.name, BEFORE.pages].some((n) => deps[n] !== undefined) || !site.configFile) return null;
|
|
100
|
+
try {
|
|
101
|
+
const config = inspectViteConfig(site.text(site.configFile), site.configFile);
|
|
102
|
+
return { comments: config.has.unbase && config.options?.comments !== false };
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ── uninstall ──────────────────────────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
/** uninstall's plan: vite.config without our lines, the packages (the old kit's too), and the files they read. */
|
|
111
|
+
function planUninstall(site) {
|
|
112
|
+
const config = site.configFile ? removeFromViteConfig(site.text(site.configFile), site.configFile) : { code: null, changes: [] };
|
|
113
|
+
return {
|
|
114
|
+
packages: [VITE.name, PAGES.name, BEFORE.pages, SELF.name, BEFORE.cli],
|
|
115
|
+
files: config.changes.length ? [{ file: site.configFile, action: "changed", changes: config.changes, text: config.code }] : [],
|
|
116
|
+
remove: [LINK_FILE, core.PAGE_FILE],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ── doctor ─────────────────────────────────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
function envHas(site, name) {
|
|
123
|
+
if (process.env[name]) return true;
|
|
124
|
+
return [".env", ".env.production", ".env.local", ".env.production.local"].some((f) => new RegExp(`^\\s*(export\\s+)?${name}\\s*=\\s*\\S`, "m").test(site.text(f) ?? ""));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** doctor's three features on a Vite + React site, from the production build doctor made (null: --no-build). */
|
|
128
|
+
async function doctorFeatures(site, { build }) {
|
|
129
|
+
const built = !!build?.ok;
|
|
130
|
+
const deps = depsOf(site.pkg);
|
|
131
|
+
const detection = site.detection;
|
|
132
|
+
const file = site.configFile ?? "vite.config.ts";
|
|
133
|
+
let config = null;
|
|
134
|
+
let configError = null;
|
|
135
|
+
if (site.configFile) {
|
|
136
|
+
try {
|
|
137
|
+
config = inspectViteConfig(site.text(site.configFile), site.configFile);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
if (!(e instanceof CouldNotRun)) throw e;
|
|
140
|
+
configError = e.message;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const version = installedVersion(site, VITE.name) ?? deps[VITE.name];
|
|
144
|
+
const listed = !!deps[VITE.name];
|
|
145
|
+
const features = [];
|
|
146
|
+
|
|
147
|
+
// ── Visual editing ────────────────────────────────────────────────────────
|
|
148
|
+
{
|
|
149
|
+
const checks = [check("react", "ok", "A Vite + React app: Unbase finds its texts by matching them to where they are written, proven by a probe; nothing to install.")];
|
|
150
|
+
if (!build) checks.push(check("build", "skipped", "Not built (--no-build)."));
|
|
151
|
+
else if (built) checks.push(check("build", "ok", "A production build works."));
|
|
152
|
+
else checks.push(check("build", "missing", "The production build fails, so Unbase cannot start or check the site.", { missing: "a site that builds", file, detail: tailOf(build.output) }));
|
|
153
|
+
const names = detection.settings.map((s) => s.name);
|
|
154
|
+
if (names.length) checks.push(check("settings", "info", `The code reads ${names.length} setting(s) (${names.slice(0, 6).join(", ")}${names.length > 6 ? ", …" : ""}). If the site needs them to start, give them development values in Unbase.`));
|
|
155
|
+
features.push({ id: "visual-editing", name: "Visual editing", state: featureState(checks), checks });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// The package, as both other features need it.
|
|
159
|
+
const packageCheck = () =>
|
|
160
|
+
!listed && (installedVersion(site, VITE.name) || config?.has.unbase)
|
|
161
|
+
? check("listed", "missing", `${VITE.name} is ${installedVersion(site, VITE.name) ? "in node_modules" : "used in the config"} but not listed in package.json.`, { missing: `${VITE.name} in devDependencies, pinned`, file: "package.json", step: STEPS.install })
|
|
162
|
+
: null;
|
|
163
|
+
|
|
164
|
+
// ── Comments on the site ──────────────────────────────────────────────────
|
|
165
|
+
{
|
|
166
|
+
const checks = [];
|
|
167
|
+
const unlisted = packageCheck();
|
|
168
|
+
const off = config?.options && !config.options.comments;
|
|
169
|
+
if (unlisted) checks.push(unlisted);
|
|
170
|
+
else if (!listed || (config && !config.has.unbase)) {
|
|
171
|
+
checks.push(check("package", "info", `Not in the code: \`unbase init --comments\` adds ${VITE.name}. Comments on the canvas in Unbase work without it.`));
|
|
172
|
+
} else if (configError) checks.push(check("config", "missing", configError, { file, step: STEPS.install }));
|
|
173
|
+
else if (off) checks.push(check("config", "info", `${file} calls unbase({ comments: false }): comments on the site are left out. \`unbase init --comments\` turns them on.`));
|
|
174
|
+
else {
|
|
175
|
+
checks.push(check("package", "ok", `${VITE.name} ${version} is a dependency, and unbase() is in ${file}'s plugins.`));
|
|
176
|
+
if (config && config.has.unbase && !config.options) checks.push(check("options", "info", "unbase()'s options are not literal; doctor reads the project from comment-modus.json."));
|
|
177
|
+
const project = readLink(site);
|
|
178
|
+
if (project) checks.push(check("link", "ok", `Linked to the Unbase project "${project}".`, { file: LINK_FILE }));
|
|
179
|
+
else
|
|
180
|
+
checks.push(
|
|
181
|
+
check("link", "waiting", "Not linked to an Unbase project yet, so comment mode stays off. Unbase fills in `project` in comment-modus.json when the site is connected; or run `unbase init --project <id or slug>`.", {
|
|
182
|
+
missing: "project in comment-modus.json",
|
|
183
|
+
file: LINK_FILE,
|
|
184
|
+
step: STEPS.comments,
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
if (built && project) {
|
|
188
|
+
const page = build.html.get("index.html") ?? "";
|
|
189
|
+
const files = ["version.json", "comment-modus/pages.json"].filter((f) => build.file(f) === null);
|
|
190
|
+
checks.push(
|
|
191
|
+
hasOurScript(page, build.file)
|
|
192
|
+
? check("loader", "ok", "The ?comment loader is in the built index.html; it loads nothing unless someone opens ?comment.")
|
|
193
|
+
: check("loader", "missing", "The ?comment loader is not in the built index.html.", { missing: "unbase() running in vite build", file, step: STEPS.install }),
|
|
194
|
+
);
|
|
195
|
+
checks.push(
|
|
196
|
+
files.length
|
|
197
|
+
? check("files", "missing", `The build has no ${files.join(" and ")}.`, { missing: files.join(", "), file, step: STEPS.install })
|
|
198
|
+
: check("files", "ok", "The build has version.json and comment-modus/pages.json (the pages for comment mode's page tree)."),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
if (!envHas(site, "PUBLIC_SUPABASE_URL") || !envHas(site, "PUBLIC_SUPABASE_ANON_KEY"))
|
|
202
|
+
checks.push(check("backend", "info", "comment mode finds Unbase's backend through PUBLIC_SUPABASE_URL and PUBLIC_SUPABASE_ANON_KEY where the site is built; they are not set here, and doctor cannot see your host's."));
|
|
203
|
+
}
|
|
204
|
+
const chose = !unlisted && (!listed || (config && !config.has.unbase) || off);
|
|
205
|
+
features.push({ id: "comments", name: "Comments on the site", state: featureState(checks, !!chose), checks });
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ── Page management: draft pages, and the site settings in index.html ─────
|
|
209
|
+
{
|
|
210
|
+
const checks = [];
|
|
211
|
+
const text = (p) => site.text(p);
|
|
212
|
+
const kit = core.kitInstalled({ framework: "vite-react", text });
|
|
213
|
+
const unlisted = packageCheck();
|
|
214
|
+
if (unlisted) checks.push(unlisted);
|
|
215
|
+
else if (config?.has.unbase && config?.has.kit)
|
|
216
|
+
checks.push(check("kit", "missing", `${file} calls unbase() and ${PAGES.name}'s plugin: two kits would each remove the same routes, and the build stops.`, { missing: `${PAGES.name}'s plugin out of plugins`, file, step: STEPS.install }));
|
|
217
|
+
else if (kit && config?.has.unbase) checks.push(check("kit", "ok", `The draft-pages kit runs in ${VITE.name}'s unbase().`));
|
|
218
|
+
else if (kit) checks.push(check("kit", "ok", `${PAGES.name}'s Vite plugin is in ${file}. \`unbase init\` moves it to ${VITE.name}, which also brings comments on the site.`));
|
|
219
|
+
else
|
|
220
|
+
checks.push(
|
|
221
|
+
check("kit", "missing", listed ? `${file} does not call unbase() in plugins.` : `${VITE.name} is not a dependency.`, {
|
|
222
|
+
missing: listed ? "unbase() in plugins" : VITE.name,
|
|
223
|
+
file: listed ? file : "package.json",
|
|
224
|
+
step: STEPS.install,
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
// The drafts unbase.pages.json holds now, as a production build will treat them.
|
|
229
|
+
const files = site.appPaths.filter(registryFiles).map((p) => ({ path: p, text: text(p) ?? "" }));
|
|
230
|
+
const byPath = new Map(files.map((f) => [f.path, f.text]));
|
|
231
|
+
const pageFile = core.parsePageFile(text(core.PAGE_FILE));
|
|
232
|
+
if (!pageFile.ok) checks.push(check("drafts", "missing", `${core.PAGE_FILE} is invalid: ${pageFile.error}.`, { missing: `a valid ${core.PAGE_FILE}`, file: core.PAGE_FILE, step: STEPS.drafts }));
|
|
233
|
+
else {
|
|
234
|
+
const plan = core.draftPlan({ framework: "vite-react", paths: [...byPath.keys()].sort(), text: (p) => byPath.get(p) ?? null, pageFile });
|
|
235
|
+
if (plan.failed.length)
|
|
236
|
+
checks.push(
|
|
237
|
+
check("drafts", "missing", `A production build would stop: ${plan.failed.map((f) => `${f.path} (${f.reason}${f.detail ? `: ${f.detail}` : ""})`).join(", ")}.`, {
|
|
238
|
+
missing: "drafts the kit can keep out",
|
|
239
|
+
file: core.PAGE_FILE,
|
|
240
|
+
step: STEPS.drafts,
|
|
241
|
+
}),
|
|
242
|
+
);
|
|
243
|
+
else checks.push(check("drafts", "ok", plan.checks.length ? `${plan.checks.length} draft(s) in ${core.PAGE_FILE}, each kept out of production builds.` : "No drafts now."));
|
|
244
|
+
}
|
|
245
|
+
if (kit && build) {
|
|
246
|
+
if (!built) checks.push(check("fails-closed", "skipped", "The build failed."));
|
|
247
|
+
else if (/production build \(UNBASE_DEPLOY_CONTEXT\)/.test(build.output)) checks.push(check("fails-closed", "ok", "The kit ran in the production build: a draft it cannot keep out stops the build."));
|
|
248
|
+
else checks.push(check("fails-closed", "missing", "The kit did not run in the production build.", { missing: "unbase() running in vite build", file, step: STEPS.install }));
|
|
249
|
+
}
|
|
250
|
+
// Which pages can be drafts, as Unbase's page tree will say (staged: Publishing with a Live branch, set in Unbase).
|
|
251
|
+
const registry = registryOf({ files, framework: "vite-react", appPath: site.appPath, staged: true, truncated: false });
|
|
252
|
+
const pages = registry.pages.filter((p) => p.kind !== "template");
|
|
253
|
+
if (!pages.length)
|
|
254
|
+
checks.push(check("routes", "missing", "Unbase finds no route in the code: it reads JSX <Route path element> in a file that imports react-router(-dom).", { missing: "<Route path element> routes", file: "src/App.tsx", step: STEPS.drafts }));
|
|
255
|
+
else if (kit) {
|
|
256
|
+
const ok = pages.filter((p) => p.capabilities.draft.ok).length;
|
|
257
|
+
const why = {};
|
|
258
|
+
for (const p of pages) if (!p.capabilities.draft.ok) (why[p.capabilities.draft.reason] ??= []).push(p.path);
|
|
259
|
+
const rest = Object.entries(why).map(([r, list]) => `${r}: ${list.slice(0, 3).join(", ")}${list.length > 3 ? ", …" : ""}`);
|
|
260
|
+
checks.push(check("draftable", "info", `${ok} of ${pages.length} pages can be drafts${rest.length ? ` (not: ${rest.join("; ")})` : ""}. In Unbase, draft pages also need Publishing with a Live branch.`));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Site settings: read_settings, on index.html. Page settings: none on a single-page app.
|
|
264
|
+
const settings = await readSettings(site.repo, site.appPath, "vite-react");
|
|
265
|
+
const found = Object.keys(settings?.site ?? {});
|
|
266
|
+
const absent = Object.keys(SITE_SETTINGS).filter((k) => !found.includes(k) && k !== "faviconDark");
|
|
267
|
+
if (!site.exists("index.html")) checks.push(check("site-settings", "missing", "No index.html in the site's folder.", { missing: "index.html", file: "index.html", step: STEPS.settings }));
|
|
268
|
+
else if (!found.length)
|
|
269
|
+
checks.push(check("site-settings", "missing", "index.html has none of the settings Unbase reads (a <title>, a meta description, <html lang>, one icon, og:image) as a plain value.", { missing: "<title> in index.html", file: "index.html", step: STEPS.settings }));
|
|
270
|
+
else
|
|
271
|
+
checks.push(
|
|
272
|
+
check(
|
|
273
|
+
"site-settings",
|
|
274
|
+
"ok",
|
|
275
|
+
`Site settings in index.html: ${found.map((k) => SITE_SETTINGS[k]).join(", ")}.${absent.length ? ` Not there, so not offered: ${absent.map((k) => SITE_SETTINGS[k]).join(", ")}.` : ""}`,
|
|
276
|
+
),
|
|
277
|
+
);
|
|
278
|
+
checks.push(check("page-settings", "info", "No page settings: every route of a single-page app is index.html, so a route has no <head> of its own to set."));
|
|
279
|
+
features.push({ id: "page-management", name: "Page management", state: featureState(checks), checks });
|
|
280
|
+
}
|
|
281
|
+
return features;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export default {
|
|
285
|
+
id: "vite-react",
|
|
286
|
+
name: "Vite + React",
|
|
287
|
+
/** In the order the kit looks for them (kitFiles). */
|
|
288
|
+
configFiles: core.kitFiles("vite-react").filter((f) => f !== "package.json"),
|
|
289
|
+
agents: AGENTS,
|
|
290
|
+
comments: true,
|
|
291
|
+
build: { bin: "vite", args: (outDir) => ["build", "--outDir", outDir, "--emptyOutDir"], env: {}, output: [] },
|
|
292
|
+
packages: () => [VITE, SELF],
|
|
293
|
+
init: planInit,
|
|
294
|
+
replaced: planReplaced,
|
|
295
|
+
current: currentOf,
|
|
296
|
+
linked: readLink,
|
|
297
|
+
uninstall: planUninstall,
|
|
298
|
+
doctor: doctorFeatures,
|
|
299
|
+
};
|