@marktiderman/genesis-cli 1.6.0 → 1.7.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/README.md +156 -1
- package/dist/cli.js +2769 -567
- package/dist/cli.js.map +1 -1
- package/dist/{config-CUdwT-nY.d.ts → config-CrZbM3jD.d.ts} +45 -2
- package/dist/doctor.d.ts +2 -2
- package/dist/doctor.js +133 -5
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +91 -8
- package/dist/expo.js +207 -14
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +502 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +140 -9
- package/dist/index.js.map +1 -1
- package/dist/scaffolder.d.ts +1 -1
- package/dist/scaffolder.js +7 -4
- package/dist/scaffolder.js.map +1 -1
- package/dist/starter/.eas/scripts/rollout-health.mjs +85 -0
- package/dist/starter/.eas/workflows/deploy-production.yml +149 -0
- package/dist/starter/.eas/workflows/e2e.yml +77 -0
- package/dist/starter/.eas/workflows/pr-preview.yml +117 -0
- package/dist/starter/.eas/workflows/rollout.yml +120 -0
- package/dist/starter/.env.example +11 -0
- package/dist/starter/.fingerprintignore +7 -0
- package/dist/starter/.maestro/README.md +38 -0
- package/dist/starter/.maestro/config.yaml +5 -0
- package/dist/starter/.maestro/flows/deep-link.yaml +22 -0
- package/dist/starter/.maestro/flows/launch.yaml +17 -0
- package/dist/starter/.maestro/flows/settings-version.yaml +28 -0
- package/dist/starter/.maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/starter/.maestro/subflows/sign-in.yaml +20 -0
- package/dist/starter/README.md +314 -0
- package/dist/starter/__tests__/app-config.test.ts +51 -0
- package/dist/starter/__tests__/check-in-photos.test.ts +57 -0
- package/dist/starter/__tests__/components/css-stub.js +2 -0
- package/dist/starter/__tests__/components/fake-supabase.ts +136 -0
- package/dist/starter/__tests__/components/links.test.ts +25 -0
- package/dist/starter/__tests__/components/render-app.ts +22 -0
- package/dist/starter/__tests__/components/reports.ts +10 -0
- package/dist/starter/__tests__/components/resolver.js +12 -0
- package/dist/starter/__tests__/components/root-layout.test.tsx +55 -0
- package/dist/starter/__tests__/components/session-storage.test.tsx +81 -0
- package/dist/starter/__tests__/components/settings.test.tsx +134 -0
- package/dist/starter/__tests__/components/setup.ts +69 -0
- package/dist/starter/__tests__/components/sign-in.test.tsx +90 -0
- package/dist/starter/__tests__/components/tabs-feature-off.test.tsx +19 -0
- package/dist/starter/__tests__/components/tabs.test.tsx +43 -0
- package/dist/starter/__tests__/components/tabs.ts +12 -0
- package/dist/starter/__tests__/entry.test.ts +28 -0
- package/dist/starter/__tests__/inline-copy.ts +59 -0
- package/dist/starter/__tests__/starter.test.ts +319 -0
- package/dist/starter/_gitignore +13 -0
- package/dist/starter/app.config.ts +44 -0
- package/dist/starter/babel.config.js +9 -0
- package/dist/starter/eas.json +47 -0
- package/dist/starter/eslint.config.js +5 -0
- package/dist/starter/genesis.config.json +12 -0
- package/dist/starter/global.css +3 -0
- package/dist/starter/index.ts +14 -0
- package/dist/starter/jest.config.js +36 -0
- package/dist/starter/metro.config.js +38 -0
- package/dist/starter/package.json +93 -0
- package/dist/starter/pnpm-workspace.yaml +73 -0
- package/dist/starter/src/app/(app)/(home)/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/(home)/check-in.tsx +41 -0
- package/dist/starter/src/app/(app)/(home)/index.tsx +34 -0
- package/dist/starter/src/app/(app)/_layout.tsx +27 -0
- package/dist/starter/src/app/(app)/notifications/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/notifications/index.tsx +36 -0
- package/dist/starter/src/app/(app)/settings/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/settings/index.tsx +96 -0
- package/dist/starter/src/app/(app)/settings/notifications.tsx +16 -0
- package/dist/starter/src/app/(app)/settings/support/[id].tsx +23 -0
- package/dist/starter/src/app/(app)/settings/support/ideas.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/index.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/new.tsx +35 -0
- package/dist/starter/src/app/(app)/settings/support/shipped.tsx +20 -0
- package/dist/starter/src/app/+native-intent.ts +11 -0
- package/dist/starter/src/app/_layout.tsx +20 -0
- package/dist/starter/src/app/sign-in.tsx +69 -0
- package/dist/starter/src/copy.ts +118 -0
- package/dist/starter/src/forms/check-in.json +121 -0
- package/dist/starter/src/lib/account.ts +42 -0
- package/dist/starter/src/lib/app.ts +52 -0
- package/dist/starter/src/lib/auth.ts +80 -0
- package/dist/starter/src/lib/check-in-photos.ts +66 -0
- package/dist/starter/src/lib/check-in.ts +85 -0
- package/dist/starter/src/lib/define-starter.ts +148 -0
- package/dist/starter/src/lib/devtools-overlay.ts +34 -0
- package/dist/starter/src/lib/devtools.ts +23 -0
- package/dist/starter/src/lib/env.ts +33 -0
- package/dist/starter/src/lib/google-signin.ts +23 -0
- package/dist/starter/src/lib/links.ts +40 -0
- package/dist/starter/src/lib/native-modules.ts +27 -0
- package/dist/starter/src/lib/notifications.ts +15 -0
- package/dist/starter/src/lib/observability.ts +45 -0
- package/dist/starter/src/lib/push.ts +49 -0
- package/dist/starter/src/lib/supabase.ts +65 -0
- package/dist/starter/src/lib/support.ts +44 -0
- package/dist/starter/src/lib/updates.ts +61 -0
- package/dist/starter/starter.config.ts +37 -0
- package/dist/starter/supabase/config.toml +26 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +237 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/handler.ts +227 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/index.ts +55 -0
- package/dist/starter/supabase/functions/genesis-push-send/expo.ts +117 -0
- package/dist/starter/supabase/functions/genesis-push-send/handler.ts +462 -0
- package/dist/starter/supabase/functions/genesis-push-send/index.ts +54 -0
- package/dist/starter/supabase/migrations/20261024000000_genesis_account_deletion.sql +133 -0
- package/dist/starter/supabase/migrations/20261024000100_genesis_app_release_policy.sql +82 -0
- package/dist/starter/supabase/migrations/20261024000200_genesis_apple_token_revocation.sql +205 -0
- package/dist/starter/supabase/migrations/20261024000400_genesis_push.sql +524 -0
- package/dist/starter/supabase/migrations/20261024000600_genesis_support.sql +846 -0
- package/dist/starter/supabase/tests/database/genesis_account_deletion.test.sql +138 -0
- package/dist/starter/supabase/tests/database/genesis_app_release_policy.test.sql +148 -0
- package/dist/starter/supabase/tests/database/genesis_apple_token_revocation.test.sql +230 -0
- package/dist/starter/supabase/tests/database/genesis_push.test.sql +407 -0
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +552 -0
- package/dist/starter/tailwind.config.mjs +15 -0
- package/dist/starter/tsconfig.json +14 -0
- package/dist/starter/vitest.config.mts +7 -0
- package/dist/templates/ci/app-ci.yml +17 -0
- package/dist/templates/ci/genesis-upgrade.yml +21 -0
- package/dist/templates/ci/supabase-ci.yml +20 -0
- package/dist/templates/eas/eas.json +47 -0
- package/dist/templates/eas/scripts/rollout-health.mjs +85 -0
- package/dist/templates/eas/workflows/deploy-production.yml +149 -0
- package/dist/templates/eas/workflows/e2e.yml +77 -0
- package/dist/templates/eas/workflows/pr-preview.yml +117 -0
- package/dist/templates/eas/workflows/rollout.yml +120 -0
- package/dist/templates/maestro/config.yaml +5 -0
- package/dist/templates/maestro/flows/deep-link.yaml +22 -0
- package/dist/templates/maestro/flows/launch.yaml +17 -0
- package/dist/templates/maestro/flows/settings-version.yaml +28 -0
- package/dist/templates/maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/templates/maestro/subflows/sign-in.yaml +20 -0
- package/dist/vite.js +133 -5
- package/dist/vite.js.map +1 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -1,25 +1,1545 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { pathToFileURL } from 'url';
|
|
2
|
+
import { readFileSync, existsSync, readdirSync, mkdirSync, writeFileSync, mkdtempSync, rmSync, realpathSync, statSync, lstatSync } from 'fs';
|
|
3
|
+
import * as path28 from 'path';
|
|
4
|
+
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
5
|
+
import { createHash } from 'crypto';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
7
7
|
import { createJiti } from 'jiti';
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
import { execFileSync, spawnSync } from 'child_process';
|
|
8
10
|
import { buildFeatureOutputs, checkFeatureOutputs, summarizeCheck } from '@marktiderman/genesis-features/node';
|
|
9
11
|
import { findFeatures } from '@marktiderman/genesis-features';
|
|
10
12
|
import { studioSetupSql } from '@marktiderman/genesis-studio-server';
|
|
13
|
+
import { tmpdir } from 'os';
|
|
11
14
|
import { Command } from 'commander';
|
|
12
15
|
import * as fs from 'fs/promises';
|
|
13
16
|
|
|
14
|
-
var __defProp = Object.defineProperty;
|
|
15
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
-
var __esm = (fn, res) => function __init() {
|
|
17
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
18
|
-
};
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
-
};
|
|
17
|
+
var __defProp = Object.defineProperty;
|
|
18
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
19
|
+
var __esm = (fn, res) => function __init() {
|
|
20
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
21
|
+
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
function buildCatalog(packagesDir) {
|
|
27
|
+
const packages = {};
|
|
28
|
+
for (const dir of readdirSync(packagesDir).sort()) {
|
|
29
|
+
const file = path28.join(packagesDir, dir, "package.json");
|
|
30
|
+
if (!existsSync(file)) continue;
|
|
31
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
32
|
+
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
33
|
+
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
34
|
+
}
|
|
35
|
+
return { packages };
|
|
36
|
+
}
|
|
37
|
+
var init_catalog = __esm({
|
|
38
|
+
"src/blocks/catalog.ts"() {
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
function safeRelative(value) {
|
|
42
|
+
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
43
|
+
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
44
|
+
const segments = value.split("/");
|
|
45
|
+
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
function parseManifest(home, id, raw, version) {
|
|
49
|
+
const problems = [];
|
|
50
|
+
const at = `${home} genesis.blocks.${id}`;
|
|
51
|
+
if (!GENESIS_PACKAGE.test(home)) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) declare blocks`);
|
|
52
|
+
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
53
|
+
if (!isObject(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
54
|
+
const pkgOf = (value, where) => {
|
|
55
|
+
if (value === void 0) return home;
|
|
56
|
+
if (typeof value !== "string" || !GENESIS_PACKAGE.test(value)) {
|
|
57
|
+
problems.push(`${where}: package must be a Genesis package, not ${JSON.stringify(value)}`);
|
|
58
|
+
return home;
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
};
|
|
62
|
+
const pathOf = (value, where) => {
|
|
63
|
+
const safe = safeRelative(value);
|
|
64
|
+
if (!safe) problems.push(`${where}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
65
|
+
return safe ?? "";
|
|
66
|
+
};
|
|
67
|
+
const list = (key) => {
|
|
68
|
+
const v = raw[key];
|
|
69
|
+
if (v === void 0) return [];
|
|
70
|
+
if (!Array.isArray(v)) {
|
|
71
|
+
problems.push(`${at}.${key}: must be a list`);
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
return v;
|
|
75
|
+
};
|
|
76
|
+
const requires = list("requires").filter((r) => {
|
|
77
|
+
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
78
|
+
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
79
|
+
return ok;
|
|
80
|
+
});
|
|
81
|
+
let platforms;
|
|
82
|
+
if (raw["platforms"] !== void 0) {
|
|
83
|
+
platforms = list("platforms").filter((p) => {
|
|
84
|
+
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
85
|
+
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
86
|
+
return ok;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
90
|
+
const install = list("install").filter((s) => {
|
|
91
|
+
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
92
|
+
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
93
|
+
return ok;
|
|
94
|
+
});
|
|
95
|
+
const migrations = list("migrations").map((m, i) => {
|
|
96
|
+
const where = `${at}.migrations[${i}]`;
|
|
97
|
+
if (!isObject(m)) {
|
|
98
|
+
problems.push(`${where}: must be an object`);
|
|
99
|
+
return { package: home, file: "" };
|
|
100
|
+
}
|
|
101
|
+
const file = pathOf(m["file"], `${where}.file`);
|
|
102
|
+
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
103
|
+
const out = { package: pkgOf(m["package"], where), file };
|
|
104
|
+
if (m["test"] !== void 0) {
|
|
105
|
+
out.test = pathOf(m["test"], `${where}.test`);
|
|
106
|
+
if (out.test && !/^[a-z0-9_]+\.test\.sql$/.test(out.test.split("/").pop().replace(/^\d{4}_/, ""))) problems.push(`${where}.test: "${out.test}" must be named [NNNN_]name.test.sql`);
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
});
|
|
110
|
+
const functions = list("functions").map((f, i) => {
|
|
111
|
+
const where = `${at}.functions[${i}]`;
|
|
112
|
+
if (!isObject(f)) {
|
|
113
|
+
problems.push(`${where}: must be an object`);
|
|
114
|
+
return { package: home, dir: "" };
|
|
115
|
+
}
|
|
116
|
+
const dir = pathOf(f["dir"], `${where}.dir`);
|
|
117
|
+
if (dir && !FUNCTION_NAME.test(dir.split("/").pop())) problems.push(`${where}.dir: the folder's name "${dir.split("/").pop()}" is not a function name`);
|
|
118
|
+
const out = { package: pkgOf(f["package"], where), dir };
|
|
119
|
+
if (f["verifyJwt"] !== void 0) {
|
|
120
|
+
if (typeof f["verifyJwt"] !== "boolean") problems.push(`${where}.verifyJwt: must be true or false`);
|
|
121
|
+
else out.verifyJwt = f["verifyJwt"];
|
|
122
|
+
}
|
|
123
|
+
if (f["secrets"] !== void 0) {
|
|
124
|
+
if (!strings(f["secrets"]) || f["secrets"].some((s) => !SECRET.test(s))) problems.push(`${where}.secrets: must be a list of UPPER_CASE names`);
|
|
125
|
+
else out.secrets = f["secrets"];
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
});
|
|
129
|
+
const routes = list("routes").map((r, i) => {
|
|
130
|
+
const where = `${at}.routes[${i}]`;
|
|
131
|
+
if (!isObject(r) || typeof r["path"] !== "string" || !ROUTE.test(r["path"]) || r["path"].split("/").includes("..")) {
|
|
132
|
+
problems.push(`${where}: needs a path like /settings/notifications`);
|
|
133
|
+
return { path: "/" };
|
|
134
|
+
}
|
|
135
|
+
const out = { path: r["path"] };
|
|
136
|
+
if (typeof r["description"] === "string") out.description = r["description"];
|
|
137
|
+
if (typeof r["signedIn"] === "boolean") out.signedIn = r["signedIn"];
|
|
138
|
+
return out;
|
|
139
|
+
});
|
|
140
|
+
const skills = list("skills").map((s, i) => {
|
|
141
|
+
if (isObject(s)) return { package: pkgOf(s["package"], `${at}.skills[${i}]`), path: pathOf(s["path"], `${at}.skills[${i}].path`) };
|
|
142
|
+
return { package: home, path: pathOf(s, `${at}.skills[${i}]`) };
|
|
143
|
+
});
|
|
144
|
+
for (const s of skills) if (s.path && !s.path.endsWith("SKILL.md")) problems.push(`${at}.skills: "${s.path}" must point at a SKILL.md`);
|
|
145
|
+
let agents;
|
|
146
|
+
if (raw["agents"] !== void 0) {
|
|
147
|
+
const a = raw["agents"];
|
|
148
|
+
agents = isObject(a) ? { package: pkgOf(a["package"], `${at}.agents`), path: pathOf(a["path"], `${at}.agents.path`) } : { package: home, path: pathOf(a, `${at}.agents`) };
|
|
149
|
+
if (agents.path && !agents.path.endsWith(".md")) problems.push(`${at}.agents: "${agents.path}" must be a Markdown file`);
|
|
150
|
+
}
|
|
151
|
+
let feature;
|
|
152
|
+
if (raw["feature"] !== void 0) {
|
|
153
|
+
const f = raw["feature"];
|
|
154
|
+
if (!isObject(f) || typeof f["name"] !== "string" || typeof f["summary"] !== "string") problems.push(`${at}.feature: needs a name and a summary`);
|
|
155
|
+
else {
|
|
156
|
+
feature = { name: f["name"], summary: f["summary"] };
|
|
157
|
+
if (typeof f["layer"] === "string") feature.layer = f["layer"];
|
|
158
|
+
if (strings(f["keywords"])) feature.keywords = f["keywords"];
|
|
159
|
+
if (strings(f["audience"])) feature.audience = f["audience"];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const steps = list("steps").filter((s) => {
|
|
163
|
+
if (typeof s !== "string") problems.push(`${at}.steps: every step is a sentence`);
|
|
164
|
+
return typeof s === "string";
|
|
165
|
+
});
|
|
166
|
+
const privacy = isObject(raw["privacy"]) ? raw["privacy"] : void 0;
|
|
167
|
+
try {
|
|
168
|
+
const def = { id, requires, contributes: { routes, migrations: migrations.filter((m) => m.file), skills: skills.map((s) => s.path).filter(Boolean), ...privacy ? { privacy } : {} } };
|
|
169
|
+
if (platforms) def.platforms = platforms;
|
|
170
|
+
defineBlock(def);
|
|
171
|
+
} catch (err) {
|
|
172
|
+
if (err instanceof BlockError) problems.push(...err.problems.map((p) => `${at}: ${p}`));
|
|
173
|
+
else throw err;
|
|
174
|
+
}
|
|
175
|
+
if (problems.length) throw new ManifestError(problems);
|
|
176
|
+
return {
|
|
177
|
+
id,
|
|
178
|
+
package: home,
|
|
179
|
+
...version ? { version } : {},
|
|
180
|
+
requires,
|
|
181
|
+
...platforms ? { platforms } : {},
|
|
182
|
+
packages: packages.length ? [...new Set(packages)] : [home],
|
|
183
|
+
install,
|
|
184
|
+
migrations,
|
|
185
|
+
functions,
|
|
186
|
+
routes,
|
|
187
|
+
skills,
|
|
188
|
+
...agents ? { agents } : {},
|
|
189
|
+
...feature ? { feature } : {},
|
|
190
|
+
steps,
|
|
191
|
+
...privacy ? { privacy } : {}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function rawBlocksOf(packageJson) {
|
|
195
|
+
if (!isObject(packageJson) || !isObject(packageJson["genesis"])) return {};
|
|
196
|
+
const blocks = packageJson["genesis"]["blocks"];
|
|
197
|
+
return isObject(blocks) ? blocks : {};
|
|
198
|
+
}
|
|
199
|
+
function declarationFields(block) {
|
|
200
|
+
const c = block.contributes ?? {};
|
|
201
|
+
return {
|
|
202
|
+
...block.requires ? { requires: [...block.requires] } : {},
|
|
203
|
+
...block.platforms ? { platforms: [...block.platforms] } : {},
|
|
204
|
+
...c.migrations ? { migrations: c.migrations.map((m) => ({ ...m })) } : {},
|
|
205
|
+
...c.routes ? { routes: c.routes.map((r) => ({ ...r })) } : {},
|
|
206
|
+
...c.skills ? { skills: [...c.skills] } : {},
|
|
207
|
+
...c.privacy ? { privacy: c.privacy } : {}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function isBlockDef(value) {
|
|
211
|
+
return isObject(value) && typeof value["id"] === "string" && BLOCK_ID.test(value["id"]) && (value["contributes"] === void 0 || isObject(value["contributes"])) && (isObject(value["contributes"]) || Array.isArray(value["requires"]));
|
|
212
|
+
}
|
|
213
|
+
var GENESIS_PACKAGE, BLOCK_ID, MIGRATION_FILE, FUNCTION_NAME, ROUTE, INSTALL_SPEC, SECRET, ManifestError, isObject, strings;
|
|
214
|
+
var init_manifest = __esm({
|
|
215
|
+
"src/blocks/manifest.ts"() {
|
|
216
|
+
GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
217
|
+
BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
218
|
+
MIGRATION_FILE = /^(\d{4})_([a-z0-9_]+)\.sql$/;
|
|
219
|
+
FUNCTION_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
220
|
+
ROUTE = /^\/(?:[A-Za-z0-9_\-[\]().]+\/?)*$/;
|
|
221
|
+
INSTALL_SPEC = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9.^~<>=|* -]+)?$/;
|
|
222
|
+
SECRET = /^[A-Z][A-Z0-9_]*$/;
|
|
223
|
+
ManifestError = class extends Error {
|
|
224
|
+
constructor(problems) {
|
|
225
|
+
super(`Invalid block manifest:
|
|
226
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
227
|
+
this.problems = problems;
|
|
228
|
+
this.name = "ManifestError";
|
|
229
|
+
}
|
|
230
|
+
problems;
|
|
231
|
+
};
|
|
232
|
+
isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
233
|
+
strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
function inside(parent, child) {
|
|
237
|
+
const rel = path28.relative(parent, child);
|
|
238
|
+
return rel === "" || !rel.startsWith("..") && !path28.isAbsolute(rel);
|
|
239
|
+
}
|
|
240
|
+
function readPackageFile(packageDir2, rel) {
|
|
241
|
+
const safe = safeRelative(rel);
|
|
242
|
+
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
243
|
+
const root = realpathSync(packageDir2);
|
|
244
|
+
const file = path28.join(root, ...safe.split("/"));
|
|
245
|
+
if (!existsSync(file)) return null;
|
|
246
|
+
const real = realpathSync(file);
|
|
247
|
+
if (!inside(root, real)) throw new Error(`${rel} in ${packageDir2} points outside the package`);
|
|
248
|
+
if (!statSync(real).isFile()) return null;
|
|
249
|
+
return readFileSync(real, "utf8");
|
|
250
|
+
}
|
|
251
|
+
function readPackageDir(packageDir2, rel, skipped = []) {
|
|
252
|
+
const safe = safeRelative(rel);
|
|
253
|
+
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
254
|
+
const root = realpathSync(packageDir2);
|
|
255
|
+
const dir = path28.join(root, ...safe.split("/"));
|
|
256
|
+
if (!existsSync(dir)) return null;
|
|
257
|
+
const real = realpathSync(dir);
|
|
258
|
+
if (!inside(root, real) || !statSync(real).isDirectory()) throw new Error(`${rel} in ${packageDir2} is not a folder inside the package`);
|
|
259
|
+
const out = [];
|
|
260
|
+
for (const entry of readdirSync(real, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
261
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(entry.name) || entry.isDirectory()) {
|
|
262
|
+
skipped.push(`${safe}/${entry.name}`);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const content = readPackageFile(packageDir2, `${safe}/${entry.name}`);
|
|
266
|
+
if (content !== null && entry.isFile()) out.push({ name: entry.name, content });
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
function appPath(root, rel) {
|
|
271
|
+
const safe = safeRelative(rel.replace(/^\.\//, ""));
|
|
272
|
+
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
273
|
+
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
274
|
+
const realRoot = realpathSync(root);
|
|
275
|
+
const target = path28.join(realRoot, ...safe.split("/"));
|
|
276
|
+
const there = (p) => {
|
|
277
|
+
try {
|
|
278
|
+
lstatSync(p);
|
|
279
|
+
return true;
|
|
280
|
+
} catch {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
let probe = path28.dirname(target);
|
|
285
|
+
while (!there(probe)) probe = path28.dirname(probe);
|
|
286
|
+
let real;
|
|
287
|
+
try {
|
|
288
|
+
real = realpathSync(probe);
|
|
289
|
+
} catch {
|
|
290
|
+
throw new Error(`${rel} goes through a broken symlink (${path28.relative(realRoot, probe)}); refused`);
|
|
291
|
+
}
|
|
292
|
+
if (!inside(realRoot, real)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
293
|
+
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
294
|
+
return target;
|
|
295
|
+
}
|
|
296
|
+
function readApp(root, rel) {
|
|
297
|
+
const file = appPath(root, rel);
|
|
298
|
+
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
299
|
+
}
|
|
300
|
+
function createApp(root, rel, content) {
|
|
301
|
+
const file = appPath(root, rel);
|
|
302
|
+
mkdirSync(path28.dirname(file), { recursive: true });
|
|
303
|
+
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
304
|
+
}
|
|
305
|
+
function replaceApp(root, rel, content) {
|
|
306
|
+
const file = appPath(root, rel);
|
|
307
|
+
mkdirSync(path28.dirname(file), { recursive: true });
|
|
308
|
+
writeFileSync(file, content, "utf8");
|
|
309
|
+
}
|
|
310
|
+
function listApp(root, rel, options = {}) {
|
|
311
|
+
const dir = path28.join(root, rel);
|
|
312
|
+
if (!existsSync(dir)) return [];
|
|
313
|
+
const out = [];
|
|
314
|
+
const walk2 = (r) => {
|
|
315
|
+
for (const entry of readdirSync(path28.join(root, r), { withFileTypes: true })) {
|
|
316
|
+
const child = `${r}/${entry.name}`;
|
|
317
|
+
if (entry.isDirectory()) walk2(child);
|
|
318
|
+
else if (entry.isFile() || options.symlinks && entry.isSymbolicLink()) out.push(child);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
walk2(rel);
|
|
322
|
+
return out.sort();
|
|
323
|
+
}
|
|
324
|
+
var sha256;
|
|
325
|
+
var init_files = __esm({
|
|
326
|
+
"src/blocks/files.ts"() {
|
|
327
|
+
init_manifest();
|
|
328
|
+
sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// src/blocks/discover.ts
|
|
333
|
+
var discover_exports = {};
|
|
334
|
+
__export(discover_exports, {
|
|
335
|
+
CLI_PACKAGE: () => CLI_PACKAGE,
|
|
336
|
+
allBlocks: () => allBlocks,
|
|
337
|
+
blocksOfInstalled: () => blocksOfInstalled,
|
|
338
|
+
catalogBlocks: () => catalogBlocks,
|
|
339
|
+
cliPackageDir: () => cliPackageDir,
|
|
340
|
+
findBlock: () => findBlock,
|
|
341
|
+
installedGenesis: () => installedGenesis,
|
|
342
|
+
packageDir: () => packageDir,
|
|
343
|
+
packageVersion: () => packageVersion,
|
|
344
|
+
readCatalog: () => readCatalog,
|
|
345
|
+
workspacePackagesDir: () => workspacePackagesDir
|
|
346
|
+
});
|
|
347
|
+
function cliPackageDir() {
|
|
348
|
+
let dir = path28.dirname(fileURLToPath(import.meta.url));
|
|
349
|
+
for (; ; ) {
|
|
350
|
+
const file = path28.join(dir, "package.json");
|
|
351
|
+
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
352
|
+
const parent = path28.dirname(dir);
|
|
353
|
+
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
354
|
+
dir = parent;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function workspacePackagesDir() {
|
|
358
|
+
const dir = path28.resolve(cliPackageDir(), "..");
|
|
359
|
+
return existsSync(path28.join(dir, "features", "package.json")) && existsSync(path28.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
360
|
+
}
|
|
361
|
+
function readCatalog() {
|
|
362
|
+
if (catalogCache) return catalogCache;
|
|
363
|
+
const workspace = workspacePackagesDir();
|
|
364
|
+
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
365
|
+
const file = path28.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
366
|
+
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
367
|
+
return catalogCache;
|
|
368
|
+
}
|
|
369
|
+
function installedGenesis(root) {
|
|
370
|
+
const found = /* @__PURE__ */ new Map();
|
|
371
|
+
let dir = path28.resolve(root);
|
|
372
|
+
for (; ; ) {
|
|
373
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path28.join(dir, m)));
|
|
374
|
+
const scope = path28.join(dir, "node_modules", "@marktiderman");
|
|
375
|
+
if (existsSync(scope)) {
|
|
376
|
+
for (const entry of readdirSync(scope)) {
|
|
377
|
+
const name = `@marktiderman/${entry}`;
|
|
378
|
+
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
379
|
+
if (existsSync(path28.join(scope, entry, "package.json"))) found.set(name, path28.join(scope, entry));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const parent = path28.dirname(dir);
|
|
383
|
+
if (atInstallRoot || parent === dir) return found;
|
|
384
|
+
dir = parent;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function packageDir(root, name) {
|
|
388
|
+
const installed = installedGenesis(root).get(name);
|
|
389
|
+
if (installed) return installed;
|
|
390
|
+
if (name === CLI_PACKAGE) return cliPackageDir();
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
function packageVersion(dir) {
|
|
394
|
+
return JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8")).version;
|
|
395
|
+
}
|
|
396
|
+
function declarationsOf(dir, warnings) {
|
|
397
|
+
const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
398
|
+
const key = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
399
|
+
let cached = declarationCache.get(key);
|
|
400
|
+
if (!cached) {
|
|
401
|
+
cached = loadDeclarations(dir, warnings);
|
|
402
|
+
declarationCache.set(key, cached);
|
|
403
|
+
}
|
|
404
|
+
return cached;
|
|
405
|
+
}
|
|
406
|
+
async function loadDeclarations(dir, warnings) {
|
|
407
|
+
const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
408
|
+
const entry = pkg.exports?.["./blocks"];
|
|
409
|
+
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
410
|
+
if (typeof target !== "string") return {};
|
|
411
|
+
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
412
|
+
const file = rel && path28.join(dir, ...rel.split("/"));
|
|
413
|
+
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
414
|
+
try {
|
|
415
|
+
const jiti = createJiti(path28.join(dir, "package.json"), { moduleCache: false });
|
|
416
|
+
const mod = await jiti.import(file);
|
|
417
|
+
const out = {};
|
|
418
|
+
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
419
|
+
return out;
|
|
420
|
+
} catch (err) {
|
|
421
|
+
warnings.push(`${pkg.name}/blocks didn't load in Node (${err instanceof Error ? err.message.split("\n")[0] : String(err)}); using its package.json manifest only.`);
|
|
422
|
+
return {};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async function blocksOfInstalled(dir, warnings = []) {
|
|
426
|
+
const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
427
|
+
const raw = rawBlocksOf(pkg);
|
|
428
|
+
const declared = await declarationsOf(dir, warnings);
|
|
429
|
+
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
430
|
+
const out = [];
|
|
431
|
+
for (const id of [...ids].sort()) {
|
|
432
|
+
const fromJson = raw[id] ?? {};
|
|
433
|
+
const manifest = tryParse(() => parseManifest(pkg.name, id, { ...fromJson, ...declared[id] }, pkg.version), warnings);
|
|
434
|
+
if (manifest) out.push(manifest);
|
|
435
|
+
}
|
|
436
|
+
return out;
|
|
437
|
+
}
|
|
438
|
+
async function allBlocks(root, warnings = []) {
|
|
439
|
+
const out = [];
|
|
440
|
+
const installed = installedGenesis(root);
|
|
441
|
+
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
442
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
443
|
+
if (installed.has(name)) continue;
|
|
444
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
445
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
446
|
+
if (manifest) out.push({ manifest, from: "catalog" });
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return out;
|
|
450
|
+
}
|
|
451
|
+
function tryParse(parse2, warnings) {
|
|
452
|
+
try {
|
|
453
|
+
return parse2();
|
|
454
|
+
} catch (err) {
|
|
455
|
+
if (!(err instanceof ManifestError)) throw err;
|
|
456
|
+
warnings.push(err.message);
|
|
457
|
+
return null;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
function catalogBlocks(warnings = []) {
|
|
461
|
+
const out = [];
|
|
462
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
463
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
464
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
465
|
+
if (manifest) out.push(manifest);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return out;
|
|
469
|
+
}
|
|
470
|
+
async function findBlock(root, id, options = {}) {
|
|
471
|
+
const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
|
|
472
|
+
if (all.length === 0) {
|
|
473
|
+
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
474
|
+
throw new Error(`No Genesis package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
475
|
+
}
|
|
476
|
+
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
477
|
+
return all[0];
|
|
478
|
+
}
|
|
479
|
+
var CLI_PACKAGE, catalogCache, INSTALL_ROOT_MARKERS, declarationCache;
|
|
480
|
+
var init_discover = __esm({
|
|
481
|
+
"src/blocks/discover.ts"() {
|
|
482
|
+
init_catalog();
|
|
483
|
+
init_files();
|
|
484
|
+
init_manifest();
|
|
485
|
+
CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
486
|
+
INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
487
|
+
declarationCache = /* @__PURE__ */ new Map();
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
// src/blocks/lock.ts
|
|
492
|
+
var lock_exports = {};
|
|
493
|
+
__export(lock_exports, {
|
|
494
|
+
LOCK_FILE: () => LOCK_FILE,
|
|
495
|
+
emptyLock: () => emptyLock,
|
|
496
|
+
parseSource: () => parseSource,
|
|
497
|
+
readLock: () => readLock,
|
|
498
|
+
substitute: () => substitute,
|
|
499
|
+
writeLock: () => writeLock
|
|
500
|
+
});
|
|
501
|
+
function emptyLock() {
|
|
502
|
+
return { version: 1, blocks: {}, files: {} };
|
|
503
|
+
}
|
|
504
|
+
function readLock(root) {
|
|
505
|
+
const file = path28.join(root, LOCK_FILE);
|
|
506
|
+
if (!existsSync(file)) return emptyLock();
|
|
507
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
508
|
+
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
509
|
+
return { version: 1, ...raw.substitutions ? { substitutions: raw.substitutions } : {}, blocks: raw.blocks ?? {}, files: raw.files ?? {} };
|
|
510
|
+
}
|
|
511
|
+
function writeLock(root, lock) {
|
|
512
|
+
const sorted = (o) => Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b)));
|
|
513
|
+
const out = { version: 1, ...lock.substitutions ? { substitutions: lock.substitutions } : {}, blocks: sorted(lock.blocks), files: sorted(lock.files) };
|
|
514
|
+
replaceApp(root, LOCK_FILE, `${JSON.stringify(out, null, 2)}
|
|
515
|
+
`);
|
|
516
|
+
}
|
|
517
|
+
function parseSource(source) {
|
|
518
|
+
const at = source.indexOf(":");
|
|
519
|
+
if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
|
|
520
|
+
return { package: source.slice(0, at), path: source.slice(at + 1) };
|
|
521
|
+
}
|
|
522
|
+
function substitute(text, substitutions) {
|
|
523
|
+
let out = text;
|
|
524
|
+
for (const [from, to] of Object.entries(substitutions ?? {}).sort(([a], [b]) => b.length - a.length)) if (from) out = out.split(from).join(to);
|
|
525
|
+
return out;
|
|
526
|
+
}
|
|
527
|
+
var LOCK_FILE;
|
|
528
|
+
var init_lock = __esm({
|
|
529
|
+
"src/blocks/lock.ts"() {
|
|
530
|
+
init_files();
|
|
531
|
+
LOCK_FILE = "genesis.lock.json";
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// src/blocks/migrations.ts
|
|
536
|
+
var migrations_exports = {};
|
|
537
|
+
__export(migrations_exports, {
|
|
538
|
+
MIGRATIONS_DIR: () => MIGRATIONS_DIR,
|
|
539
|
+
TESTS_DIR: () => TESTS_DIR,
|
|
540
|
+
applyMigrationPlan: () => applyMigrationPlan,
|
|
541
|
+
formatMigrationRows: () => formatMigrationRows,
|
|
542
|
+
migrationHeader: () => migrationHeader,
|
|
543
|
+
needsAttention: () => needsAttention,
|
|
544
|
+
nextStamp: () => nextStamp,
|
|
545
|
+
nextTimestamps: () => nextTimestamps,
|
|
546
|
+
planMigrations: () => planMigrations,
|
|
547
|
+
readAppMigrations: () => readAppMigrations,
|
|
548
|
+
stemOf: () => stemOf,
|
|
549
|
+
stemOrNull: () => stemOrNull,
|
|
550
|
+
textSha: () => textSha,
|
|
551
|
+
timestampOf: () => timestampOf,
|
|
552
|
+
validHeaderFile: () => validHeaderFile
|
|
553
|
+
});
|
|
554
|
+
function migrationHeader(pkg, file, source) {
|
|
555
|
+
return `-- genesis-migration: ${pkg} ${file} sha256:${textSha(source)}
|
|
556
|
+
-- Copied by the Genesis CLI. Never edit it once applied: write a new migration instead.
|
|
557
|
+
`;
|
|
558
|
+
}
|
|
559
|
+
function stemOrNull(file) {
|
|
560
|
+
return MIGRATION_FILE.exec(path28.posix.basename(file))?.[2] ?? null;
|
|
561
|
+
}
|
|
562
|
+
function stemOf(file) {
|
|
563
|
+
const stem = stemOrNull(file);
|
|
564
|
+
if (!stem) throw new Error(`${file} is not named NNNN_name.sql`);
|
|
565
|
+
return stem;
|
|
566
|
+
}
|
|
567
|
+
function readAppMigrations(root, dir = MIGRATIONS_DIR) {
|
|
568
|
+
return listApp(root, dir, { symlinks: true }).filter((p) => p.endsWith(".sql")).map((p) => {
|
|
569
|
+
const content = readApp(root, p) ?? "";
|
|
570
|
+
const name = path28.posix.basename(p);
|
|
571
|
+
const m = HEADER.exec(content);
|
|
572
|
+
if (m) return { path: p, name, content, tracked: { package: m[1], file: m[2], sha256: m[3], body: content.slice(m[0].length) } };
|
|
573
|
+
const f = FORWARD.exec(content);
|
|
574
|
+
if (f) return { path: p, name, content, forward: { package: f[1], file: f[2], sha256: f[3], copySha256: f[4] } };
|
|
575
|
+
return { path: p, name, content };
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
function needsAttention(row) {
|
|
579
|
+
return row.state !== "current" && row.state !== "new" && !row.forward;
|
|
580
|
+
}
|
|
581
|
+
function timestampOf(date) {
|
|
582
|
+
return date.toISOString().replace(/\D/g, "").slice(0, 14);
|
|
583
|
+
}
|
|
584
|
+
function nextStamp(ts) {
|
|
585
|
+
const d = new Date(Date.UTC(+ts.slice(0, 4), +ts.slice(4, 6) - 1, +ts.slice(6, 8), +ts.slice(8, 10), +ts.slice(10, 12), +ts.slice(12, 14)));
|
|
586
|
+
const real = !Number.isNaN(d.getTime()) && d.getUTCFullYear() >= 1e3 && timestampOf(d) === ts;
|
|
587
|
+
const next = real ? timestampOf(new Date(d.getTime() + 1e3)) : (BigInt(ts) + 1n).toString().padStart(14, "0");
|
|
588
|
+
if (next.length !== 14 || next <= ts) throw new Error(`No 14-digit timestamp follows ${ts}.`);
|
|
589
|
+
return next;
|
|
590
|
+
}
|
|
591
|
+
function nextTimestamps(existing, now, count) {
|
|
592
|
+
let latest = "";
|
|
593
|
+
for (const name of existing) {
|
|
594
|
+
const prefix = /^(\d+)_/.exec(name)?.[1];
|
|
595
|
+
if (prefix && prefix.length === 14 && prefix > latest) latest = prefix;
|
|
596
|
+
}
|
|
597
|
+
let ts = timestampOf(now);
|
|
598
|
+
if (latest && ts <= latest) ts = nextStamp(latest);
|
|
599
|
+
const after = existing.filter((n) => !/^\d{14}_/.test(n) && n > `${ts}_`);
|
|
600
|
+
if (after.length) throw new Error(`${after.join(", ")} sort after a ${ts} timestamp; rename them to the <14-digit timestamp>_name.sql form first.`);
|
|
601
|
+
const out = [];
|
|
602
|
+
for (let i = 0; i < count; i++) {
|
|
603
|
+
out.push(ts);
|
|
604
|
+
if (i < count - 1) ts = nextStamp(ts);
|
|
605
|
+
}
|
|
606
|
+
for (const t of out) if (latest && t <= latest) throw new Error(`A new migration's timestamp ${t} would sort before ${latest}; refusing.`);
|
|
607
|
+
return out;
|
|
608
|
+
}
|
|
609
|
+
function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date() }) {
|
|
610
|
+
const app = readAppMigrations(root);
|
|
611
|
+
const rows = [];
|
|
612
|
+
const pending = [];
|
|
613
|
+
const seen = /* @__PURE__ */ new Set();
|
|
614
|
+
for (const src of sources) {
|
|
615
|
+
const key = `${src.package} ${src.file}`;
|
|
616
|
+
if (seen.has(key)) continue;
|
|
617
|
+
seen.add(key);
|
|
618
|
+
const stem = stemOf(src.file);
|
|
619
|
+
const base = { ...src.block ? { block: src.block } : {}, package: src.package, file: src.file, state: "current" };
|
|
620
|
+
const sourceSha = src.source === null ? null : textSha(src.source);
|
|
621
|
+
const sameName = (m) => m.name.replace(/^\d+_/, "") === `${stem}.sql`;
|
|
622
|
+
const sameText = (m) => sourceSha !== null && textSha(m.tracked ? m.tracked.body : m.content) === sourceSha;
|
|
623
|
+
const copies = app.filter((m) => !m.forward && (m.tracked && m.tracked.package === src.package && m.tracked.file === src.file || sameName(m) || sameText(m)));
|
|
624
|
+
if (copies.length > 1) {
|
|
625
|
+
rows.push({ ...base, state: "differs", copy: copies[0].path, detail: `${copies.length} files hold it (${copies.map((m) => m.name).join(", ")}); left alone` });
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
const copy = copies[0];
|
|
629
|
+
if (src.source === null || sourceSha === null) {
|
|
630
|
+
rows.push({ ...base, state: "unavailable", ...copy ? { copy: copy.path } : {}, detail: `${src.package} isn't installed, or doesn't ship ${src.file}` });
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
if (!copy) {
|
|
634
|
+
const row2 = { ...base, state: "new" };
|
|
635
|
+
rows.push(row2);
|
|
636
|
+
pending.push({ row: row2, src, kind: "migration" });
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
const copyBody = copy.tracked ? copy.tracked.body : copy.content;
|
|
640
|
+
const copySha = textSha(copyBody);
|
|
641
|
+
const renamed = copy.tracked && (copy.tracked.package !== src.package || copy.tracked.file !== src.file) ? ` (its header names ${copy.tracked.package} ${copy.tracked.file}: renamed or moved upstream)` : "";
|
|
642
|
+
let state;
|
|
643
|
+
let detail;
|
|
644
|
+
if (copy.tracked && copySha !== copy.tracked.sha256) {
|
|
645
|
+
state = "edited";
|
|
646
|
+
detail = "edited after it was copied; it is never rewritten";
|
|
647
|
+
} else if (copySha === sourceSha) {
|
|
648
|
+
state = "current";
|
|
649
|
+
detail = copy.tracked ? renamed.trim() : "copied before headers; matches the package";
|
|
650
|
+
} else if (copy.tracked) {
|
|
651
|
+
state = "changed-upstream";
|
|
652
|
+
detail = `${src.package} now ships a different ${path28.posix.basename(src.file)}; the applied copy is never rewritten`;
|
|
653
|
+
} else {
|
|
654
|
+
state = "differs";
|
|
655
|
+
detail = "has the package migration's name but other text and no header; treated as the app's own";
|
|
656
|
+
}
|
|
657
|
+
const row = { ...base, state, copy: copy.path, ...detail ? { detail: `${detail}${state === "current" ? "" : renamed}` } : {} };
|
|
658
|
+
if (state !== "current") {
|
|
659
|
+
const done = app.find((m) => m.forward && m.forward.package === src.package && m.forward.file === src.file && m.forward.sha256 === sourceSha && m.forward.copySha256 === copySha);
|
|
660
|
+
if (done) row.forward = done.path;
|
|
661
|
+
else if (options.forward) pending.push({ row, src, kind: "forward", copySha });
|
|
662
|
+
}
|
|
663
|
+
rows.push(row);
|
|
664
|
+
}
|
|
665
|
+
const creates = [];
|
|
666
|
+
const stamps = nextTimestamps(app.map((m) => m.name), options.now, pending.length);
|
|
667
|
+
pending.forEach(({ row, src, kind, copySha }, i) => {
|
|
668
|
+
const stem = stemOf(src.file);
|
|
669
|
+
if (kind === "migration") {
|
|
670
|
+
const target2 = `${MIGRATIONS_DIR}/${stamps[i]}_${stem}.sql`;
|
|
671
|
+
row.target = target2;
|
|
672
|
+
creates.push({ path: target2, content: migrationHeader(src.package, src.file, src.source) + src.source, kind, source: { package: src.package, file: src.file } });
|
|
673
|
+
if (options.tests !== false && src.test && src.testSource != null) {
|
|
674
|
+
const test = `${TESTS_DIR}/${path28.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
|
|
675
|
+
if (readApp(root, test) === null && !creates.some((c) => c.path === test)) creates.push({ path: test, content: src.testSource, kind: "test", source: { package: src.package, file: src.test } });
|
|
676
|
+
}
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
const target = `${MIGRATIONS_DIR}/${stamps[i]}_${stem}_forward.sql`;
|
|
680
|
+
row.target = target;
|
|
681
|
+
row.forward = target;
|
|
682
|
+
const why = row.state === "changed-upstream" ? `${src.package} now ships a different ${src.file} than ${row.copy} was copied from.` : `${row.copy} no longer matches ${src.package} ${src.file}.`;
|
|
683
|
+
creates.push({
|
|
684
|
+
path: target,
|
|
685
|
+
kind,
|
|
686
|
+
content: [
|
|
687
|
+
`-- genesis-forward: ${src.package} ${src.file} sha256:${textSha(src.source)} copy-sha256:${copySha}`,
|
|
688
|
+
`-- Forward migration for ${src.package} ${src.file}, written by \`genesis migrate --forward\`.`,
|
|
689
|
+
`-- ${why}`,
|
|
690
|
+
`-- ${row.copy} is applied and is never rewritten: write the change as SQL here, review it, then apply it.`,
|
|
691
|
+
"-- The package's current text follows, commented out, for reference.",
|
|
692
|
+
"",
|
|
693
|
+
...normal(src.source).split("\n").map((l) => l ? `-- ${l}` : "--"),
|
|
694
|
+
""
|
|
695
|
+
].join("\n")
|
|
696
|
+
});
|
|
697
|
+
});
|
|
698
|
+
return { rows, creates };
|
|
699
|
+
}
|
|
700
|
+
function applyMigrationPlan(root, plan) {
|
|
701
|
+
for (const file of plan.creates) createApp(root, file.path, file.content);
|
|
702
|
+
return plan.creates.map((c) => c.path);
|
|
703
|
+
}
|
|
704
|
+
function validHeaderFile(file) {
|
|
705
|
+
return safeRelative(file) !== null && stemOrNull(file) !== null;
|
|
706
|
+
}
|
|
707
|
+
function formatMigrationRows(rows) {
|
|
708
|
+
if (!rows.length) return "No package migrations to compare.";
|
|
709
|
+
const mark = { current: "=", new: "+", edited: "!", "changed-upstream": "!", differs: "!", unavailable: "?" };
|
|
710
|
+
return rows.map((r) => {
|
|
711
|
+
const where = r.target ? ` \u2192 ${r.target}` : r.copy ? ` (${r.copy})` : "";
|
|
712
|
+
const fwd = r.forward && !r.target ? `; carried by ${r.forward}` : "";
|
|
713
|
+
return `${r.forward && !r.target ? "~" : mark[r.state]} ${r.state.padEnd(16)} ${r.package} ${r.file}${where}${r.detail ? `: ${r.detail}` : ""}${fwd}`;
|
|
714
|
+
}).join("\n");
|
|
715
|
+
}
|
|
716
|
+
var MIGRATIONS_DIR, TESTS_DIR, HEADER, FORWARD, normal, textSha;
|
|
717
|
+
var init_migrations = __esm({
|
|
718
|
+
"src/blocks/migrations.ts"() {
|
|
719
|
+
init_files();
|
|
720
|
+
init_manifest();
|
|
721
|
+
MIGRATIONS_DIR = "supabase/migrations";
|
|
722
|
+
TESTS_DIR = "supabase/tests/database";
|
|
723
|
+
HEADER = /^-- genesis-migration: (\S+) (\S+) sha256:([0-9a-f]{64})\r?\n-- [^\n]*\n/;
|
|
724
|
+
FORWARD = /^-- genesis-forward: (\S+) (\S+) sha256:([0-9a-f]{64}) copy-sha256:([0-9a-f]{64})\r?\n/;
|
|
725
|
+
normal = (text) => text.replace(/\r\n/g, "\n");
|
|
726
|
+
textSha = (text) => sha256(normal(text));
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
function privacyDataType(type) {
|
|
730
|
+
return PRIVACY_DATA_TYPES[type.toLowerCase()];
|
|
731
|
+
}
|
|
732
|
+
function appPath2(v, where, fail) {
|
|
733
|
+
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
734
|
+
if (path28.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
735
|
+
const norm = path28.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
736
|
+
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
737
|
+
return norm;
|
|
738
|
+
}
|
|
739
|
+
function loadConfig(root, configPath) {
|
|
740
|
+
if (configPath) {
|
|
741
|
+
const file = path28.resolve(root, configPath);
|
|
742
|
+
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
743
|
+
const json = readJson(file);
|
|
744
|
+
const block = path28.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
745
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path28.dirname(file) };
|
|
746
|
+
}
|
|
747
|
+
const own = path28.join(root, "genesis.config.json");
|
|
748
|
+
if (existsSync(own)) {
|
|
749
|
+
const block = readGenesisConfig(root)?.raw.doctor;
|
|
750
|
+
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
751
|
+
}
|
|
752
|
+
const pkg = path28.join(root, "package.json");
|
|
753
|
+
if (existsSync(pkg)) {
|
|
754
|
+
const block = readJson(pkg)?.genesis?.doctor;
|
|
755
|
+
if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
756
|
+
}
|
|
757
|
+
return { config: {}, file: null, dir: root };
|
|
758
|
+
}
|
|
759
|
+
function readJson(file) {
|
|
760
|
+
try {
|
|
761
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
762
|
+
} catch (err) {
|
|
763
|
+
throw new DoctorConfigError(`${file} is not valid JSON: ${err.message}`);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
function readGenesisConfig(root) {
|
|
767
|
+
const file = path28.join(root, "genesis.config.json");
|
|
768
|
+
if (!existsSync(file)) return null;
|
|
769
|
+
const raw = readJson(file);
|
|
770
|
+
if (!isObject2(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
771
|
+
const out = { raw };
|
|
772
|
+
if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
|
|
773
|
+
if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
|
|
774
|
+
return out;
|
|
775
|
+
}
|
|
776
|
+
function validatePrivacy(raw, source = "config") {
|
|
777
|
+
const fail = (msg) => {
|
|
778
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
779
|
+
};
|
|
780
|
+
if (!isObject2(raw)) fail(`"privacy" must be an object`);
|
|
781
|
+
const c = raw;
|
|
782
|
+
for (const key of Object.keys(c)) if (!PRIVACY_KEYS.has(key)) fail(`privacy: unknown setting "${key}"`);
|
|
783
|
+
const out = {};
|
|
784
|
+
if (c.blocks !== void 0) {
|
|
785
|
+
if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
|
|
786
|
+
out.blocks = [...new Set(c.blocks)];
|
|
787
|
+
}
|
|
788
|
+
if (c.tracking !== void 0) {
|
|
789
|
+
if (typeof c.tracking !== "boolean") fail(`privacy.tracking must be true or false`);
|
|
790
|
+
out.tracking = c.tracking;
|
|
791
|
+
}
|
|
792
|
+
if (c.collects !== void 0) {
|
|
793
|
+
if (!Array.isArray(c.collects)) fail(`privacy.collects must be a list`);
|
|
794
|
+
out.collects = c.collects.map((entry, i) => {
|
|
795
|
+
const where = `privacy.collects[${i}]`;
|
|
796
|
+
if (!isObject2(entry)) return fail(`${where} must be an object`);
|
|
797
|
+
for (const key of Object.keys(entry)) if (!DATA_USE_KEYS.has(key)) fail(`${where}: unknown setting "${key}"`);
|
|
798
|
+
if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
|
|
799
|
+
fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
|
|
800
|
+
}
|
|
801
|
+
if (!isStringList(entry.purposes) || entry.purposes.length === 0) fail(`${where}.purposes must be a non-empty list`);
|
|
802
|
+
for (const p of entry.purposes) {
|
|
803
|
+
if (!(p in PRIVACY_PURPOSES)) fail(`${where}.purposes: "${p}" is not one of ${Object.keys(PRIVACY_PURPOSES).join(", ")}`);
|
|
804
|
+
}
|
|
805
|
+
if (typeof entry.linked !== "boolean") fail(`${where}.linked must be true or false`);
|
|
806
|
+
if (typeof entry.tracking !== "boolean") fail(`${where}.tracking must be true or false`);
|
|
807
|
+
return { type: entry.type, purposes: [...new Set(entry.purposes)], linked: entry.linked, tracking: entry.tracking };
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
return out;
|
|
811
|
+
}
|
|
812
|
+
function validateLinks(raw, source = "config") {
|
|
813
|
+
const fail = (msg) => {
|
|
814
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
815
|
+
};
|
|
816
|
+
if (!isObject2(raw)) fail(`"links" must be an object`);
|
|
817
|
+
const c = raw;
|
|
818
|
+
for (const key of Object.keys(c)) if (!LINK_KEYS.has(key)) fail(`links: unknown setting "${key}"`);
|
|
819
|
+
if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
|
|
820
|
+
for (const host of c.hosts) {
|
|
821
|
+
if (!HOST.test(host)) {
|
|
822
|
+
fail(`links.hosts: "${host}" is not a bare lower-case host name (no scheme, path or port), e.g. "example.com"`);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (c.paths !== void 0) {
|
|
826
|
+
if (!isStringList(c.paths)) fail(`links.paths must be a list of path prefixes`);
|
|
827
|
+
for (const p of c.paths) {
|
|
828
|
+
if (!p.startsWith("/") || /[\s?#*]/.test(p)) {
|
|
829
|
+
fail(`links.paths: "${p}" must start with "/" and hold no spaces, "?", "#" or "*"`);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (c.webcredentials !== void 0 && typeof c.webcredentials !== "boolean") fail(`links.webcredentials must be true or false`);
|
|
834
|
+
const links = { hosts: [...new Set(c.hosts)] };
|
|
835
|
+
if (c.paths !== void 0) links.paths = [...new Set(c.paths)];
|
|
836
|
+
if (c.webcredentials !== void 0) links.webcredentials = c.webcredentials;
|
|
837
|
+
return links;
|
|
838
|
+
}
|
|
839
|
+
function validateConfig(raw, source = "config") {
|
|
840
|
+
const fail = (msg) => {
|
|
841
|
+
throw new DoctorConfigError(`${source}: ${msg}`);
|
|
842
|
+
};
|
|
843
|
+
if (!isObject2(raw)) fail("the doctor settings must be an object");
|
|
844
|
+
const c = raw;
|
|
845
|
+
for (const key of Object.keys(c)) if (!KNOWN.has(key)) fail(`unknown setting "${key}"`);
|
|
846
|
+
if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
|
|
847
|
+
if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
|
|
848
|
+
for (const key of STRING_LISTS) {
|
|
849
|
+
if (c[key] !== void 0 && !isStringList(c[key])) fail(`"${key}" must be a list of strings`);
|
|
850
|
+
}
|
|
851
|
+
for (const key of STRINGS) {
|
|
852
|
+
if (c[key] !== void 0 && typeof c[key] !== "string") fail(`"${key}" must be a string`);
|
|
853
|
+
}
|
|
854
|
+
if (c.rawTags !== void 0) {
|
|
855
|
+
if (!isObject2(c.rawTags)) fail(`"rawTags" must be an object`);
|
|
856
|
+
for (const [tag, v] of Object.entries(c.rawTags)) {
|
|
857
|
+
if (!/^[a-z][a-z0-9-]*$/.test(tag)) fail(`rawTags: "${tag}" is not an HTML tag name`);
|
|
858
|
+
if (v !== false && typeof v !== "string") fail(`rawTags.${tag} must be a component name or false`);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if (c.forbiddenImports !== void 0) {
|
|
862
|
+
if (!isObject2(c.forbiddenImports)) fail(`"forbiddenImports" must be an object of pattern \u2192 message`);
|
|
863
|
+
for (const [re, msg] of Object.entries(c.forbiddenImports)) {
|
|
864
|
+
if (typeof msg !== "string") fail(`forbiddenImports["${re}"] must be a message string`);
|
|
865
|
+
checkRegExp(re, `forbiddenImports["${re}"]`, fail);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
if (c.rules !== void 0) {
|
|
869
|
+
if (!isObject2(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
|
|
870
|
+
for (const [rule, level] of Object.entries(c.rules)) {
|
|
871
|
+
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (c.allow !== void 0) {
|
|
875
|
+
if (!Array.isArray(c.allow)) fail(`"allow" must be a list`);
|
|
876
|
+
c.allow.forEach((e, i) => {
|
|
877
|
+
if (!isObject2(e)) return fail(`allow[${i}] must be an object`);
|
|
878
|
+
const entry = e;
|
|
879
|
+
if (typeof entry.rule !== "string" || !entry.rule) fail(`allow[${i}] needs a "rule"`);
|
|
880
|
+
if (typeof entry.reason !== "string" || !entry.reason.trim()) fail(`allow[${i}] (${entry.rule}) needs a "reason"`);
|
|
881
|
+
for (const k of ["file", "match"]) {
|
|
882
|
+
if (entry[k] !== void 0 && typeof entry[k] !== "string") fail(`allow[${i}].${k} must be a string`);
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
if (c.patterns !== void 0) {
|
|
887
|
+
if (!Array.isArray(c.patterns)) fail(`"patterns" must be a list`);
|
|
888
|
+
c.patterns.forEach((p, i) => {
|
|
889
|
+
if (!isObject2(p)) return fail(`patterns[${i}] must be an object`);
|
|
890
|
+
const rule = p;
|
|
891
|
+
for (const k of Object.keys(rule)) if (!PATTERN_KEYS.has(k)) fail(`patterns[${i}]: unknown key "${k}"`);
|
|
892
|
+
if (typeof rule.id !== "string" || !rule.id) fail(`patterns[${i}] needs an "id"`);
|
|
893
|
+
for (const k of ["files", "exclude"]) {
|
|
894
|
+
if (rule[k] !== void 0 && !isStringList(rule[k])) fail(`patterns[${i}].${k} must be a list of globs`);
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
if (c.packs !== void 0) {
|
|
899
|
+
if (!isStringList(c.packs)) fail(`"packs" must be a list, e.g. ["native", "supabase"]`);
|
|
900
|
+
for (const p of c.packs) if (!PACKS.has(p)) fail(`packs: unknown pack "${p}" (known: ${[...PACKS].join(", ")})`);
|
|
901
|
+
if (new Set(c.packs).size !== c.packs.length) fail(`packs: lists a pack twice`);
|
|
902
|
+
}
|
|
903
|
+
for (const [pack, keys] of Object.entries(PACK_KEYS)) {
|
|
904
|
+
const block = c[pack];
|
|
905
|
+
if (block === void 0) continue;
|
|
906
|
+
if (!isObject2(block)) fail(`"${pack}" must be an object`);
|
|
907
|
+
if (!(c.packs ?? []).includes(pack)) fail(`"${pack}" settings are set but the ${pack} pack is not in "packs"`);
|
|
908
|
+
for (const [k, v] of Object.entries(block)) {
|
|
909
|
+
const want = keys[k];
|
|
910
|
+
if (!want) fail(`${pack}: unknown setting "${k}"`);
|
|
911
|
+
if (want === "string" && typeof v !== "string") fail(`${pack}.${k} must be a string`);
|
|
912
|
+
if (want === "list" && !isStringList(v)) fail(`${pack}.${k} must be a list of strings`);
|
|
913
|
+
if (want === "string" && !v.trim()) fail(`${pack}.${k} must not be empty`);
|
|
914
|
+
if (want === "path") block[k] = appPath2(v, `${pack}.${k}`, fail);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
const supa = c.supabase;
|
|
918
|
+
if (Array.isArray(supa?.exposedSchemas)) supa.exposedSchemas = supa.exposedSchemas.map((s) => s.toLowerCase());
|
|
919
|
+
if (c.plugins !== void 0) {
|
|
920
|
+
const ok = Array.isArray(c.plugins) && c.plugins.every((p) => typeof p === "string" || Array.isArray(p) && p.length === 2 && typeof p[0] === "string");
|
|
921
|
+
if (!ok) fail(`"plugins" must be a list of module paths or [path, options] pairs`);
|
|
922
|
+
}
|
|
923
|
+
return c;
|
|
924
|
+
}
|
|
925
|
+
function checkRegExp(source, where, fail) {
|
|
926
|
+
try {
|
|
927
|
+
new RegExp(source);
|
|
928
|
+
} catch (err) {
|
|
929
|
+
fail(`${where} is not a valid regular expression: ${err.message}`);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
function isObject2(v) {
|
|
933
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
934
|
+
}
|
|
935
|
+
function isStringList(v) {
|
|
936
|
+
return Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
937
|
+
}
|
|
938
|
+
var GenesisConfigError, DoctorConfigError, PRIVACY_DATA_TYPES, PRIVACY_PURPOSES, STRING_LISTS, STRINGS, KNOWN, LEVELS, PATTERN_KEYS, PACKS, PACK_KEYS, PRIVACY_KEYS, DATA_USE_KEYS, LINK_KEYS, HOST;
|
|
939
|
+
var init_config = __esm({
|
|
940
|
+
"src/doctor/config.ts"() {
|
|
941
|
+
GenesisConfigError = class extends Error {
|
|
942
|
+
name = "GenesisConfigError";
|
|
943
|
+
};
|
|
944
|
+
DoctorConfigError = class extends GenesisConfigError {
|
|
945
|
+
name = "DoctorConfigError";
|
|
946
|
+
};
|
|
947
|
+
PRIVACY_DATA_TYPES = {
|
|
948
|
+
name: "NSPrivacyCollectedDataTypeName",
|
|
949
|
+
"email address": "NSPrivacyCollectedDataTypeEmailAddress",
|
|
950
|
+
"phone number": "NSPrivacyCollectedDataTypePhoneNumber",
|
|
951
|
+
"physical address": "NSPrivacyCollectedDataTypePhysicalAddress",
|
|
952
|
+
"other user contact info": "NSPrivacyCollectedDataTypeOtherUserContactInfo",
|
|
953
|
+
health: "NSPrivacyCollectedDataTypeHealth",
|
|
954
|
+
fitness: "NSPrivacyCollectedDataTypeFitness",
|
|
955
|
+
"payment info": "NSPrivacyCollectedDataTypePaymentInfo",
|
|
956
|
+
"credit info": "NSPrivacyCollectedDataTypeCreditInfo",
|
|
957
|
+
"other financial info": "NSPrivacyCollectedDataTypeOtherFinancialInfo",
|
|
958
|
+
"precise location": "NSPrivacyCollectedDataTypePreciseLocation",
|
|
959
|
+
"coarse location": "NSPrivacyCollectedDataTypeCoarseLocation",
|
|
960
|
+
"sensitive info": "NSPrivacyCollectedDataTypeSensitiveInfo",
|
|
961
|
+
contacts: "NSPrivacyCollectedDataTypeContacts",
|
|
962
|
+
"emails or text messages": "NSPrivacyCollectedDataTypeEmailsOrTextMessages",
|
|
963
|
+
"photos or videos": "NSPrivacyCollectedDataTypePhotosorVideos",
|
|
964
|
+
"audio data": "NSPrivacyCollectedDataTypeAudioData",
|
|
965
|
+
"gameplay content": "NSPrivacyCollectedDataTypeGameplayContent",
|
|
966
|
+
"customer support": "NSPrivacyCollectedDataTypeCustomerSupport",
|
|
967
|
+
"other user content": "NSPrivacyCollectedDataTypeOtherUserContent",
|
|
968
|
+
"browsing history": "NSPrivacyCollectedDataTypeBrowsingHistory",
|
|
969
|
+
"search history": "NSPrivacyCollectedDataTypeSearchHistory",
|
|
970
|
+
"user id": "NSPrivacyCollectedDataTypeUserID",
|
|
971
|
+
"device id": "NSPrivacyCollectedDataTypeDeviceID",
|
|
972
|
+
"purchase history": "NSPrivacyCollectedDataTypePurchaseHistory",
|
|
973
|
+
"product interaction": "NSPrivacyCollectedDataTypeProductInteraction",
|
|
974
|
+
"advertising data": "NSPrivacyCollectedDataTypeAdvertisingData",
|
|
975
|
+
"other usage data": "NSPrivacyCollectedDataTypeOtherUsageData",
|
|
976
|
+
"crash data": "NSPrivacyCollectedDataTypeCrashData",
|
|
977
|
+
"performance data": "NSPrivacyCollectedDataTypePerformanceData",
|
|
978
|
+
"other diagnostic data": "NSPrivacyCollectedDataTypeOtherDiagnosticData",
|
|
979
|
+
"environment scanning": "NSPrivacyCollectedDataTypeEnvironmentScanning",
|
|
980
|
+
hands: "NSPrivacyCollectedDataTypeHands",
|
|
981
|
+
head: "NSPrivacyCollectedDataTypeHead",
|
|
982
|
+
"other data types": "NSPrivacyCollectedDataTypeOtherDataTypes"
|
|
983
|
+
};
|
|
984
|
+
PRIVACY_PURPOSES = {
|
|
985
|
+
"app functionality": "NSPrivacyCollectedDataTypePurposeAppFunctionality",
|
|
986
|
+
analytics: "NSPrivacyCollectedDataTypePurposeAnalytics",
|
|
987
|
+
"product personalization": "NSPrivacyCollectedDataTypePurposeProductPersonalization",
|
|
988
|
+
"developer advertising": "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising",
|
|
989
|
+
"third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
|
|
990
|
+
other: "NSPrivacyCollectedDataTypePurposeOther"
|
|
991
|
+
};
|
|
992
|
+
STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
|
|
993
|
+
STRINGS = ["uiPackage", "rulesDoc"];
|
|
994
|
+
KNOWN = /* @__PURE__ */ new Set([
|
|
995
|
+
...STRING_LISTS,
|
|
996
|
+
...STRINGS,
|
|
997
|
+
"themeCss",
|
|
998
|
+
"rawTags",
|
|
999
|
+
"forbiddenImports",
|
|
1000
|
+
"rules",
|
|
1001
|
+
"allow",
|
|
1002
|
+
"patterns",
|
|
1003
|
+
"plugins",
|
|
1004
|
+
"packs",
|
|
1005
|
+
"native",
|
|
1006
|
+
"supabase",
|
|
1007
|
+
"$schema",
|
|
1008
|
+
"$comment"
|
|
1009
|
+
]);
|
|
1010
|
+
LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
|
|
1011
|
+
PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
1012
|
+
PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
1013
|
+
PACK_KEYS = {
|
|
1014
|
+
native: { routerRoot: "path" },
|
|
1015
|
+
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" }
|
|
1016
|
+
};
|
|
1017
|
+
PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
|
|
1018
|
+
DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
|
|
1019
|
+
LINK_KEYS = /* @__PURE__ */ new Set(["hosts", "paths", "webcredentials"]);
|
|
1020
|
+
HOST = /^(?=.{1,253}$)(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
function findPackageDir(from, name) {
|
|
1024
|
+
let dir = path28.resolve(from);
|
|
1025
|
+
for (; ; ) {
|
|
1026
|
+
const candidate = path28.join(dir, "node_modules", name);
|
|
1027
|
+
if (existsSync(path28.join(candidate, "package.json"))) return candidate;
|
|
1028
|
+
const parent = path28.dirname(dir);
|
|
1029
|
+
if (parent === dir) return null;
|
|
1030
|
+
dir = parent;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function uiPackageFor(config) {
|
|
1034
|
+
return config.uiPackage ?? (config.packs?.includes("native") ? NATIVE_UI_PACKAGE : DEFAULT_UI_PACKAGE);
|
|
1035
|
+
}
|
|
1036
|
+
function loadGenesis(root, config) {
|
|
1037
|
+
const uiPackage = uiPackageFor(config);
|
|
1038
|
+
const pkg = readPackageExports(root, uiPackage);
|
|
1039
|
+
if (!pkg) throw new DoctorConfigError(`${uiPackage} is not installed here. Install it, or set doctor.uiPackage.`);
|
|
1040
|
+
const { dir: uiDir, exports: exportNames, values, components } = pkg;
|
|
1041
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
1042
|
+
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
1043
|
+
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
1044
|
+
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
1045
|
+
const rawTags = /* @__PURE__ */ new Map();
|
|
1046
|
+
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
1047
|
+
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
1048
|
+
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
1049
|
+
if (comp === false) rawTags.delete(tag);
|
|
1050
|
+
else rawTags.set(tag, comp);
|
|
1051
|
+
}
|
|
1052
|
+
return {
|
|
1053
|
+
uiPackage,
|
|
1054
|
+
uiVersion: pkg.version,
|
|
1055
|
+
exports: exportNames,
|
|
1056
|
+
values,
|
|
1057
|
+
components,
|
|
1058
|
+
tokens,
|
|
1059
|
+
rawTags,
|
|
1060
|
+
palette: loadPalette(root)
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
function readPackageExports(root, uiPackage) {
|
|
1064
|
+
const uiDir = findPackageDir(root, uiPackage);
|
|
1065
|
+
if (!uiDir) return null;
|
|
1066
|
+
const uiPkg = JSON.parse(readFileSync(path28.join(uiDir, "package.json"), "utf8"));
|
|
1067
|
+
const typeEntries = /* @__PURE__ */ new Set();
|
|
1068
|
+
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1069
|
+
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
1070
|
+
for (const target of Object.values(uiPkg.exports ?? {})) {
|
|
1071
|
+
const t = exportTypes(target);
|
|
1072
|
+
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
1073
|
+
}
|
|
1074
|
+
const exportNames = /* @__PURE__ */ new Set();
|
|
1075
|
+
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1076
|
+
let readAny = false;
|
|
1077
|
+
for (const entry of typeEntries) {
|
|
1078
|
+
const file = path28.join(uiDir, entry);
|
|
1079
|
+
if (!existsSync(file)) continue;
|
|
1080
|
+
readAny = true;
|
|
1081
|
+
const dts = readFileSync(file, "utf8");
|
|
1082
|
+
for (const name of parseExportNames(dts)) exportNames.add(name);
|
|
1083
|
+
for (const m of dts.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
1084
|
+
reexportedPackages.add(packageName(m[1]));
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (!readAny) {
|
|
1088
|
+
throw new DoctorConfigError(`${uiPackage} has no type declarations to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
1089
|
+
}
|
|
1090
|
+
const valueDecls = /* @__PURE__ */ new Set();
|
|
1091
|
+
const typeDecls = /* @__PURE__ */ new Set();
|
|
1092
|
+
const declRoot = typeof mainTypes === "string" ? path28.dirname(path28.join(uiDir, mainTypes)) : uiDir;
|
|
1093
|
+
const declFiles = walkDts(declRoot);
|
|
1094
|
+
for (const pkg of reexportedPackages) {
|
|
1095
|
+
const dir = findPackageDir(uiDir, pkg);
|
|
1096
|
+
if (dir) walkDts(path28.join(dir, "dist"), declFiles);
|
|
1097
|
+
}
|
|
1098
|
+
for (const file of declFiles) {
|
|
1099
|
+
const text = readFileSync(file, "utf8");
|
|
1100
|
+
for (const m of text.matchAll(/\b(?:declare\s+)?(?:const|let|var|function|class|enum)\s+([A-Za-z_$][\w$]*)/g)) valueDecls.add(m[1]);
|
|
1101
|
+
for (const m of text.matchAll(/\b(?:interface|type)\s+([A-Za-z_$][\w$]*)/g)) typeDecls.add(m[1]);
|
|
1102
|
+
}
|
|
1103
|
+
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
1104
|
+
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
1105
|
+
const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
|
|
1106
|
+
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
1107
|
+
}
|
|
1108
|
+
function parseExportNames(dts) {
|
|
1109
|
+
const names = [];
|
|
1110
|
+
for (const m of dts.matchAll(/export\s+(?:type\s+)?\{([^}]*)\}/g)) {
|
|
1111
|
+
for (const part of m[1].split(",")) {
|
|
1112
|
+
const name = part.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
1113
|
+
if (name && name !== "default") names.push(name);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
for (const m of dts.matchAll(/export\s+(?:declare\s+)?(?:const|let|function|class|enum|interface|type)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
1117
|
+
names.push(m[1]);
|
|
1118
|
+
}
|
|
1119
|
+
return names;
|
|
1120
|
+
}
|
|
1121
|
+
function declaredTokens(css) {
|
|
1122
|
+
return [...css.matchAll(/(--[A-Za-z0-9_-]+)\s*:/g)].map((m) => m[1]);
|
|
1123
|
+
}
|
|
1124
|
+
function packageName(specifier) {
|
|
1125
|
+
const parts = specifier.split("/");
|
|
1126
|
+
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1127
|
+
}
|
|
1128
|
+
function exportTypes(target) {
|
|
1129
|
+
if (!target || typeof target !== "object") return void 0;
|
|
1130
|
+
const t = target;
|
|
1131
|
+
if (typeof t.types === "string") return t.types;
|
|
1132
|
+
for (const key of ["import", "default", "require"]) {
|
|
1133
|
+
const nested = exportTypes(t[key]);
|
|
1134
|
+
if (nested) return nested;
|
|
1135
|
+
}
|
|
1136
|
+
return void 0;
|
|
1137
|
+
}
|
|
1138
|
+
function walkDts(dir, out = []) {
|
|
1139
|
+
if (!existsSync(dir)) return out;
|
|
1140
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1141
|
+
if (entry.name === "node_modules") continue;
|
|
1142
|
+
const p = path28.join(dir, entry.name);
|
|
1143
|
+
if (entry.isDirectory()) walkDts(p, out);
|
|
1144
|
+
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1145
|
+
}
|
|
1146
|
+
return out;
|
|
1147
|
+
}
|
|
1148
|
+
function resolveThemeFiles(root, config, uiDir) {
|
|
1149
|
+
if (config.themeCss) {
|
|
1150
|
+
const specs = typeof config.themeCss === "string" ? [config.themeCss] : config.themeCss;
|
|
1151
|
+
return specs.map((spec) => {
|
|
1152
|
+
const file = resolveSpec(root, spec);
|
|
1153
|
+
if (!file) throw new DoctorConfigError(`doctor.themeCss: cannot find ${spec}`);
|
|
1154
|
+
return file;
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
const files = [];
|
|
1158
|
+
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1159
|
+
const themes = ds && path28.join(ds, "dist", "themes");
|
|
1160
|
+
if (themes && existsSync(themes)) {
|
|
1161
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path28.join(themes, name));
|
|
1162
|
+
}
|
|
1163
|
+
if (files.length === 0) {
|
|
1164
|
+
throw new DoctorConfigError(
|
|
1165
|
+
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
const uiStyles = path28.join(uiDir, "dist", "styles.css");
|
|
1169
|
+
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1170
|
+
return files;
|
|
1171
|
+
}
|
|
1172
|
+
function resolveSpec(root, spec) {
|
|
1173
|
+
const local = path28.resolve(root, spec);
|
|
1174
|
+
if (spec.startsWith(".") || path28.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1175
|
+
const parts = spec.split("/");
|
|
1176
|
+
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1177
|
+
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1178
|
+
if (dir) {
|
|
1179
|
+
const file = path28.join(dir, ...parts.slice(nameLength));
|
|
1180
|
+
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1181
|
+
}
|
|
1182
|
+
return existsSync(local) ? local : null;
|
|
1183
|
+
}
|
|
1184
|
+
function loadPalette(root) {
|
|
1185
|
+
const names = new Set(TAILWIND_PALETTE);
|
|
1186
|
+
try {
|
|
1187
|
+
const req = createRequire(path28.join(root, "package.json"));
|
|
1188
|
+
const colors = req("tailwindcss/colors");
|
|
1189
|
+
for (const key of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1190
|
+
if (/^[a-z]+$/.test(key) && !["inherit", "current", "transparent"].includes(key)) names.add(key);
|
|
1191
|
+
}
|
|
1192
|
+
} catch {
|
|
1193
|
+
}
|
|
1194
|
+
return [...names].sort();
|
|
1195
|
+
}
|
|
1196
|
+
var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE;
|
|
1197
|
+
var init_genesis = __esm({
|
|
1198
|
+
"src/doctor/genesis.ts"() {
|
|
1199
|
+
init_config();
|
|
1200
|
+
DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
1201
|
+
NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
1202
|
+
DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
1203
|
+
TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
1204
|
+
TAG_ALIASES = { hr: "Separator" };
|
|
1205
|
+
NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
|
|
1206
|
+
TAILWIND_PALETTE = [
|
|
1207
|
+
"black",
|
|
1208
|
+
"white",
|
|
1209
|
+
"slate",
|
|
1210
|
+
"gray",
|
|
1211
|
+
"zinc",
|
|
1212
|
+
"neutral",
|
|
1213
|
+
"stone",
|
|
1214
|
+
"red",
|
|
1215
|
+
"orange",
|
|
1216
|
+
"amber",
|
|
1217
|
+
"yellow",
|
|
1218
|
+
"lime",
|
|
1219
|
+
"green",
|
|
1220
|
+
"emerald",
|
|
1221
|
+
"teal",
|
|
1222
|
+
"cyan",
|
|
1223
|
+
"sky",
|
|
1224
|
+
"blue",
|
|
1225
|
+
"indigo",
|
|
1226
|
+
"violet",
|
|
1227
|
+
"purple",
|
|
1228
|
+
"fuchsia",
|
|
1229
|
+
"pink",
|
|
1230
|
+
"rose",
|
|
1231
|
+
"taupe",
|
|
1232
|
+
"mauve",
|
|
1233
|
+
"mist",
|
|
1234
|
+
"olive"
|
|
1235
|
+
];
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
function readReleaseManifest(root) {
|
|
1239
|
+
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
1240
|
+
const file = dir && path28.join(dir, "dist", "versions.json");
|
|
1241
|
+
if (!file || !existsSync(file)) return null;
|
|
1242
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
1243
|
+
}
|
|
1244
|
+
function checkVersionSkew(ctx) {
|
|
1245
|
+
const manifest = readReleaseManifest(ctx.root);
|
|
1246
|
+
if (!manifest) return;
|
|
1247
|
+
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
1248
|
+
const dir = findPackageDir(ctx.root, name);
|
|
1249
|
+
if (!dir) continue;
|
|
1250
|
+
const have = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8")).version;
|
|
1251
|
+
if (have === want) continue;
|
|
1252
|
+
ctx.report({
|
|
1253
|
+
rule: "version-skew",
|
|
1254
|
+
level: "warn",
|
|
1255
|
+
file: "package.json",
|
|
1256
|
+
subject: name,
|
|
1257
|
+
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
var UMBRELLA_PACKAGE;
|
|
1262
|
+
var init_versions = __esm({
|
|
1263
|
+
"src/doctor/versions.ts"() {
|
|
1264
|
+
init_genesis();
|
|
1265
|
+
UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
function detectPackageManager(root) {
|
|
1269
|
+
let dir = path28.resolve(root);
|
|
1270
|
+
for (; ; ) {
|
|
1271
|
+
if (existsSync(path28.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1272
|
+
if (existsSync(path28.join(dir, "bun.lock")) || existsSync(path28.join(dir, "bun.lockb"))) return "bun";
|
|
1273
|
+
if (existsSync(path28.join(dir, "yarn.lock"))) return "yarn";
|
|
1274
|
+
if (existsSync(path28.join(dir, "package-lock.json"))) return "npm";
|
|
1275
|
+
const parent = path28.dirname(dir);
|
|
1276
|
+
if (parent === dir) return "npm";
|
|
1277
|
+
dir = parent;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
function addCommand(pm, specs, dev = false) {
|
|
1281
|
+
const flag = dev ? ["-D"] : [];
|
|
1282
|
+
if (pm === "npm") return ["npm", "install", ...flag, ...specs];
|
|
1283
|
+
return [pm, "add", ...flag, ...specs];
|
|
1284
|
+
}
|
|
1285
|
+
function installCommand(pm) {
|
|
1286
|
+
return pm === "yarn" ? ["yarn", "install"] : [pm, "install"];
|
|
1287
|
+
}
|
|
1288
|
+
function pinnedVersion(root, name) {
|
|
1289
|
+
const release = readReleaseManifest(root);
|
|
1290
|
+
const fromRelease = release?.packages[name] ?? (name === "@marktiderman/genesis" ? release?.version : void 0);
|
|
1291
|
+
if (release && fromRelease) return { version: fromRelease, from: `@marktiderman/genesis ${release.version}` };
|
|
1292
|
+
const fromCli = readCatalog().packages[name]?.version;
|
|
1293
|
+
if (fromCli) return { version: fromCli, from: "this CLI's release" };
|
|
1294
|
+
return null;
|
|
1295
|
+
}
|
|
1296
|
+
function run(root, argv) {
|
|
1297
|
+
const [cmd, ...args] = argv;
|
|
1298
|
+
execFileSync(cmd, args, { cwd: root, stdio: "inherit" });
|
|
1299
|
+
}
|
|
1300
|
+
var shellLine;
|
|
1301
|
+
var init_pm = __esm({
|
|
1302
|
+
"src/blocks/pm.ts"() {
|
|
1303
|
+
init_versions();
|
|
1304
|
+
init_discover();
|
|
1305
|
+
shellLine = (argv) => argv.map((a) => /^[\w@./:^~=-]+$/.test(a) ? a : `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
function walk(dir, exclude = []) {
|
|
1309
|
+
const out = [];
|
|
1310
|
+
const visit = (rel) => {
|
|
1311
|
+
for (const name of readdirSync(path28.join(dir, rel)).sort()) {
|
|
1312
|
+
const child = rel ? `${rel}/${name}` : name;
|
|
1313
|
+
if (exclude.some((r) => r.test(child))) continue;
|
|
1314
|
+
const stat = statSync(path28.join(dir, child));
|
|
1315
|
+
if (stat.isDirectory()) visit(child);
|
|
1316
|
+
else if (stat.isFile()) out.push(child);
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
visit("");
|
|
1320
|
+
return out;
|
|
1321
|
+
}
|
|
1322
|
+
var STARTER_EXCLUDE, PACKED_GITIGNORE;
|
|
1323
|
+
var init_walk = __esm({
|
|
1324
|
+
"src/blocks/walk.ts"() {
|
|
1325
|
+
STARTER_EXCLUDE = [
|
|
1326
|
+
/^node_modules(\/|$)/,
|
|
1327
|
+
/^\.expo(\/|$)/,
|
|
1328
|
+
/^ios(\/|$)/,
|
|
1329
|
+
/^android(\/|$)/,
|
|
1330
|
+
/^dist(\/|$)/,
|
|
1331
|
+
/^\.turbo(\/|$)/,
|
|
1332
|
+
/^expo-env\.d\.ts$/,
|
|
1333
|
+
/^\.env$/,
|
|
1334
|
+
/^\.env\.local$/,
|
|
1335
|
+
// Reads ../../templates to check the starter's copies against them; an app has no monorepo.
|
|
1336
|
+
/^__tests__\/release\.test\.ts$/
|
|
1337
|
+
];
|
|
1338
|
+
PACKED_GITIGNORE = "_gitignore";
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
function starterDir() {
|
|
1342
|
+
const workspace = workspacePackagesDir();
|
|
1343
|
+
const live = workspace && path28.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
1344
|
+
if (live && existsSync(path28.join(live, "package.json"))) return live;
|
|
1345
|
+
const packaged = path28.join(cliPackageDir(), "dist", "starter");
|
|
1346
|
+
if (existsSync(path28.join(packaged, "package.json"))) return packaged;
|
|
1347
|
+
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
1348
|
+
}
|
|
1349
|
+
function templatesDir(cliDir = cliPackageDir()) {
|
|
1350
|
+
const workspace = workspacePackagesDir();
|
|
1351
|
+
const live = workspace && cliDir === cliPackageDir() ? path28.join(workspace, "..", "templates") : null;
|
|
1352
|
+
if (live && existsSync(path28.join(live, "eas"))) return live;
|
|
1353
|
+
const packaged = path28.join(cliDir, "dist", "templates");
|
|
1354
|
+
if (existsSync(packaged)) return packaged;
|
|
1355
|
+
throw new Error(`${cliDir} has no templates (dist/templates is missing).`);
|
|
1356
|
+
}
|
|
1357
|
+
function templateTarget(template, content) {
|
|
1358
|
+
const said = /^#\s*Copy to (\S+?)\.?(?:\s|$)/.exec(content)?.[1];
|
|
1359
|
+
if (said && /^[.A-Za-z0-9][\w./-]*$/.test(said) && !said.split("/").some((s) => s === ".." || s === "." || s.toLowerCase() === ".git")) return said;
|
|
1360
|
+
if (template === "eas/eas.json") return "eas.json";
|
|
1361
|
+
const [dir, ...rest] = template.split("/");
|
|
1362
|
+
const tail = rest.join("/");
|
|
1363
|
+
if (dir === "eas") return `.eas/${tail}`;
|
|
1364
|
+
if (dir === "maestro") return `.maestro/${tail}`;
|
|
1365
|
+
if (dir === "ci") return `.github/workflows/${tail}`;
|
|
1366
|
+
return template;
|
|
1367
|
+
}
|
|
1368
|
+
var init_templates = __esm({
|
|
1369
|
+
"src/blocks/templates.ts"() {
|
|
1370
|
+
init_discover();
|
|
1371
|
+
init_walk();
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1375
|
+
// src/blocks/init-native.ts
|
|
1376
|
+
var init_native_exports = {};
|
|
1377
|
+
__export(init_native_exports, {
|
|
1378
|
+
appPnpmSettings: () => appPnpmSettings,
|
|
1379
|
+
initNative: () => initNative,
|
|
1380
|
+
runInitNative: () => runInitNative,
|
|
1381
|
+
starterIdentity: () => starterIdentity
|
|
1382
|
+
});
|
|
1383
|
+
function starterIdentity(config) {
|
|
1384
|
+
const field2 = (key) => {
|
|
1385
|
+
const m = new RegExp(`\\b${key}:\\s*"([^"]+)"`).exec(config);
|
|
1386
|
+
if (!m) throw new Error(`starter.config.ts has no app.${key}`);
|
|
1387
|
+
return m[1];
|
|
1388
|
+
};
|
|
1389
|
+
return { name: field2("name"), slug: field2("slug"), scheme: field2("scheme"), bundleId: field2("bundleId") };
|
|
1390
|
+
}
|
|
1391
|
+
function appPnpmSettings(text) {
|
|
1392
|
+
const lines = text.split("\n");
|
|
1393
|
+
const out = [];
|
|
1394
|
+
let skipping = false;
|
|
1395
|
+
for (const line of lines) {
|
|
1396
|
+
if (/^(packages|patchedDependencies):/.test(line)) {
|
|
1397
|
+
skipping = true;
|
|
1398
|
+
continue;
|
|
1399
|
+
}
|
|
1400
|
+
if (skipping && (/^\s/.test(line) || line === "")) continue;
|
|
1401
|
+
skipping = false;
|
|
1402
|
+
out.push(line);
|
|
1403
|
+
}
|
|
1404
|
+
return `# pnpm settings for this app, from the Genesis monorepo it was made from.
|
|
1405
|
+
${out.join("\n").replace(/^\n+/, "")}`;
|
|
1406
|
+
}
|
|
1407
|
+
function readme(display, slug) {
|
|
1408
|
+
return `# ${display}
|
|
1409
|
+
|
|
1410
|
+
An Expo app made with \`genesis init ${slug} --template native\` from the Genesis RN starter.
|
|
1411
|
+
|
|
1412
|
+
1. \`cp .env.example .env\` and fill in your Supabase project's URL and publishable key.
|
|
1413
|
+
2. Install: \`pnpm install\` (or your package manager).
|
|
1414
|
+
3. Apply \`supabase/migrations\` (\`supabase db push\`, or \`supabase start\` for a local stack).
|
|
1415
|
+
4. \`pnpm ios\` or \`pnpm android\`.
|
|
1416
|
+
|
|
1417
|
+
- Turn features off in \`starter.config.ts\`.
|
|
1418
|
+
- Add a block: \`genesis add <block>\` (for example \`genesis add tenant-features\`).
|
|
1419
|
+
- New package migrations: \`genesis migrate\`. Move every Genesis package to one release:
|
|
1420
|
+
\`genesis upgrade\`.
|
|
1421
|
+
- The CI workflows in \`.github/workflows\` name \`GENESIS_SHA\`: replace it with the commit of the
|
|
1422
|
+
Genesis release you run (see docs/APP-CI.md in marktiderman/genesis).
|
|
1423
|
+
`;
|
|
1424
|
+
}
|
|
1425
|
+
function initNative(options) {
|
|
1426
|
+
const slug = options.name;
|
|
1427
|
+
if (!SLUG.test(slug)) throw new Error(`"${slug}" isn't an app slug: lowercase letters, digits and -, starting with a letter.`);
|
|
1428
|
+
const bundleId = options.bundleId ?? `com.example.${slug.replace(/-/g, "")}`;
|
|
1429
|
+
const scheme = options.scheme ?? slug;
|
|
1430
|
+
const display = options.displayName ?? slug.split("-").map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
|
|
1431
|
+
if (!BUNDLE.test(bundleId)) throw new Error(`"${bundleId}" isn't a bundle id like com.example.app.`);
|
|
1432
|
+
if (!SCHEME.test(scheme)) throw new Error(`"${scheme}" isn't a URL scheme.`);
|
|
1433
|
+
if (/["\\\n]/.test(display)) throw new Error("The display name can't contain quotes, backslashes or new lines.");
|
|
1434
|
+
const target = path28.resolve(options.target);
|
|
1435
|
+
if (existsSync(target) && readdirSync(target).length) throw new Error(`${target} isn't empty; init writes into a new folder and never overwrites.`);
|
|
1436
|
+
const source = starterDir();
|
|
1437
|
+
const read = (rel) => readFileSync(path28.join(source, rel), "utf8");
|
|
1438
|
+
const was = starterIdentity(read("starter.config.ts"));
|
|
1439
|
+
const substitutions = { [was.bundleId]: bundleId, [was.slug]: slug, [was.scheme]: scheme, [was.name]: display };
|
|
1440
|
+
const files = /* @__PURE__ */ new Map();
|
|
1441
|
+
for (const rel of walk(source, STARTER_EXCLUDE)) {
|
|
1442
|
+
const to = rel.replace(new RegExp(`(^|/)${PACKED_GITIGNORE}$`), "$1.gitignore");
|
|
1443
|
+
files.set(to, /^supabase\/(migrations|tests)\//.test(rel) ? read(rel) : substitute(read(rel), substitutions));
|
|
1444
|
+
}
|
|
1445
|
+
const versionFor = options.versionFor ?? ((name) => pinnedVersion(target, name)?.version ?? null);
|
|
1446
|
+
const pkg = JSON.parse(files.get("package.json"));
|
|
1447
|
+
pkg.name = slug;
|
|
1448
|
+
const unpinned = [];
|
|
1449
|
+
const dependencies2 = {};
|
|
1450
|
+
for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
1451
|
+
const deps = pkg[section];
|
|
1452
|
+
for (const [name, spec] of Object.entries(deps ?? {})) {
|
|
1453
|
+
if (!spec.startsWith("workspace:")) continue;
|
|
1454
|
+
const version = versionFor(name);
|
|
1455
|
+
if (!version) {
|
|
1456
|
+
unpinned.push(name);
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
const range = spec === "workspace:*" ? version : `^${version}`;
|
|
1460
|
+
deps[name] = range;
|
|
1461
|
+
dependencies2[name] = range;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
if (unpinned.length) throw new Error(`No published version known for ${unpinned.join(", ")}; pass versions or install a newer CLI.`);
|
|
1465
|
+
files.set("package.json", `${JSON.stringify(pkg, null, 2)}
|
|
1466
|
+
`);
|
|
1467
|
+
files.set("metro.config.js", METRO);
|
|
1468
|
+
const pnpmSettings = [path28.join(source, "pnpm-workspace.yaml"), path28.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
|
|
1469
|
+
if (pnpmSettings) files.set("pnpm-workspace.yaml", appPnpmSettings(readFileSync(pnpmSettings, "utf8")));
|
|
1470
|
+
files.set("README.md", readme(display, slug));
|
|
1471
|
+
const lock = { ...emptyLock(), substitutions };
|
|
1472
|
+
const cliVersion2 = pinnedVersion(target, CLI_PACKAGE)?.version;
|
|
1473
|
+
const templates = templatesDir();
|
|
1474
|
+
for (const rel of walk(templates)) {
|
|
1475
|
+
const text = substitute(readFileSync(path28.join(templates, rel), "utf8"), substitutions);
|
|
1476
|
+
const to = templateTarget(rel, text);
|
|
1477
|
+
files.set(to, text);
|
|
1478
|
+
lock.files[to] = { source: `${CLI_PACKAGE}:templates/${rel}`, sha256: sha256(text), ...cliVersion2 ? { version: cliVersion2 } : {} };
|
|
1479
|
+
}
|
|
1480
|
+
{
|
|
1481
|
+
const migrations = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql"));
|
|
1482
|
+
const steps = [];
|
|
1483
|
+
const blocks = [];
|
|
1484
|
+
for (const block of options.blocks) {
|
|
1485
|
+
const stems = block.migrations.map((m) => stemOf(m.file));
|
|
1486
|
+
const copies = stems.map((s) => migrations.find((f) => path28.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
|
|
1487
|
+
if (!stems.length || copies.some((c) => !c)) continue;
|
|
1488
|
+
blocks.push(block.id);
|
|
1489
|
+
lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
|
|
1490
|
+
block.migrations.forEach((m) => {
|
|
1491
|
+
if (m.test) {
|
|
1492
|
+
const test = `${TESTS_DIR}/${path28.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
|
|
1493
|
+
if (files.has(test)) lock.files[test] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test)) };
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
for (const fn of block.functions) {
|
|
1497
|
+
const name = fn.dir.split("/").pop();
|
|
1498
|
+
for (const f of [...files.keys()].filter((p) => p.startsWith(`supabase/functions/${name}/`))) {
|
|
1499
|
+
lock.files[f] = { source: `${fn.package}:${fn.dir}/${f.slice(`supabase/functions/${name}/`.length)}`, sha256: sha256(files.get(f)) };
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
mkdirSync(target, { recursive: true });
|
|
1504
|
+
for (const [rel, content] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1505
|
+
const file = path28.join(target, ...rel.split("/"));
|
|
1506
|
+
mkdirSync(path28.dirname(file), { recursive: true });
|
|
1507
|
+
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
1508
|
+
}
|
|
1509
|
+
writeLock(target, lock);
|
|
1510
|
+
steps.push(
|
|
1511
|
+
"Replace GENESIS_SHA in .github/workflows/*.yml with the commit of the Genesis release you run.",
|
|
1512
|
+
"Run eas init and put the project id in starter.config.ts app.easProjectId (builds, previews, updates).",
|
|
1513
|
+
"Set links.hosts in genesis.config.json to your web domain, or delete the links block."
|
|
1514
|
+
);
|
|
1515
|
+
return { target, files: [...files.keys(), "genesis.lock.json"].sort(), dependencies: dependencies2, unpinned, blocks, steps };
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
async function runInitNative(options) {
|
|
1519
|
+
return initNative({ ...options, blocks: catalogBlocks() });
|
|
1520
|
+
}
|
|
1521
|
+
var SLUG, BUNDLE, SCHEME, METRO;
|
|
1522
|
+
var init_init_native = __esm({
|
|
1523
|
+
"src/blocks/init-native.ts"() {
|
|
1524
|
+
init_discover();
|
|
1525
|
+
init_files();
|
|
1526
|
+
init_lock();
|
|
1527
|
+
init_migrations();
|
|
1528
|
+
init_pm();
|
|
1529
|
+
init_templates();
|
|
1530
|
+
init_walk();
|
|
1531
|
+
SLUG = /^[a-z][a-z0-9-]{1,40}$/;
|
|
1532
|
+
BUNDLE = /^[a-zA-Z][a-zA-Z0-9]*(\.[a-zA-Z][a-zA-Z0-9]*)+$/;
|
|
1533
|
+
SCHEME = /^[a-z][a-z0-9+.-]*$/;
|
|
1534
|
+
METRO = `// Metro: Expo's defaults with NativeWind. (The starter's monorepo config also watched the
|
|
1535
|
+
// workspace packages; an app installs them from npm instead.)
|
|
1536
|
+
const { getDefaultConfig } = require("expo/metro-config");
|
|
1537
|
+
const { withNativeWind } = require("nativewind/metro");
|
|
1538
|
+
|
|
1539
|
+
module.exports = withNativeWind(getDefaultConfig(__dirname), { input: "./global.css" });
|
|
1540
|
+
`;
|
|
1541
|
+
}
|
|
1542
|
+
});
|
|
23
1543
|
|
|
24
1544
|
// src/introspect/comments.ts
|
|
25
1545
|
function parse(comment, keys, where) {
|
|
@@ -337,19 +1857,19 @@ var init_introspect = __esm({
|
|
|
337
1857
|
});
|
|
338
1858
|
function buildCommands(root, config) {
|
|
339
1859
|
if (config.build) return config.build;
|
|
340
|
-
const pkgFile =
|
|
1860
|
+
const pkgFile = path28.join(root, "package.json");
|
|
341
1861
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
342
1862
|
const pm = packageManager(root);
|
|
343
1863
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
344
1864
|
}
|
|
345
1865
|
function packageManager(root) {
|
|
346
|
-
let dir =
|
|
1866
|
+
let dir = path28.resolve(root);
|
|
347
1867
|
for (; ; ) {
|
|
348
|
-
if (existsSync(
|
|
349
|
-
if (existsSync(
|
|
350
|
-
if (existsSync(
|
|
351
|
-
if (existsSync(
|
|
352
|
-
const parent =
|
|
1868
|
+
if (existsSync(path28.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1869
|
+
if (existsSync(path28.join(dir, "bun.lock")) || existsSync(path28.join(dir, "bun.lockb"))) return "bun";
|
|
1870
|
+
if (existsSync(path28.join(dir, "yarn.lock"))) return "yarn";
|
|
1871
|
+
if (existsSync(path28.join(dir, "package-lock.json"))) return "npm";
|
|
1872
|
+
const parent = path28.dirname(dir);
|
|
353
1873
|
if (parent === dir) return "npm";
|
|
354
1874
|
dir = parent;
|
|
355
1875
|
}
|
|
@@ -362,228 +1882,22 @@ function runBuild(root, commands, quiet) {
|
|
|
362
1882
|
for (const command of commands) {
|
|
363
1883
|
const r = spawnSync(command, {
|
|
364
1884
|
cwd: root,
|
|
365
|
-
shell: true,
|
|
366
|
-
stdio: quiet ? "pipe" : "inherit",
|
|
367
|
-
env: { ...process.env, [BUILD_GUARD_ENV]: "1" }
|
|
368
|
-
});
|
|
369
|
-
if (r.status !== 0) {
|
|
370
|
-
const tail = quiet ? `
|
|
371
|
-
${String(r.stderr ?? "").trim().split("\n").slice(-20).join("\n")}` : "";
|
|
372
|
-
return { rule: "build", file: command, message: `\`${command}\` failed (exit ${r.status ?? r.signal})${tail}` };
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
var BUILD_GUARD_ENV;
|
|
378
|
-
var init_build = __esm({
|
|
379
|
-
"src/doctor/build.ts"() {
|
|
380
|
-
BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
function appPath(v, where, fail) {
|
|
384
|
-
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
385
|
-
if (path3.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
386
|
-
const norm = path3.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
387
|
-
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
388
|
-
return norm;
|
|
389
|
-
}
|
|
390
|
-
function loadConfig(root, configPath) {
|
|
391
|
-
if (configPath) {
|
|
392
|
-
const file = path3.resolve(root, configPath);
|
|
393
|
-
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
394
|
-
const json = readJson(file);
|
|
395
|
-
const block = path3.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
396
|
-
return { config: validateConfig(block ?? {}, file), file, dir: path3.dirname(file) };
|
|
397
|
-
}
|
|
398
|
-
const own = path3.join(root, "genesis.config.json");
|
|
399
|
-
if (existsSync(own)) {
|
|
400
|
-
const block = readGenesisConfig(root)?.raw.doctor;
|
|
401
|
-
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
402
|
-
}
|
|
403
|
-
const pkg = path3.join(root, "package.json");
|
|
404
|
-
if (existsSync(pkg)) {
|
|
405
|
-
const block = readJson(pkg)?.genesis?.doctor;
|
|
406
|
-
if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
407
|
-
}
|
|
408
|
-
return { config: {}, file: null, dir: root };
|
|
409
|
-
}
|
|
410
|
-
function readJson(file) {
|
|
411
|
-
try {
|
|
412
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
413
|
-
} catch (err) {
|
|
414
|
-
throw new DoctorConfigError(`${file} is not valid JSON: ${err.message}`);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
function readGenesisConfig(root) {
|
|
418
|
-
const file = path3.join(root, "genesis.config.json");
|
|
419
|
-
if (!existsSync(file)) return null;
|
|
420
|
-
const raw = readJson(file);
|
|
421
|
-
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
422
|
-
const links = raw.links === void 0 ? void 0 : validateLinks(raw.links, file);
|
|
423
|
-
return links ? { raw, links } : { raw };
|
|
424
|
-
}
|
|
425
|
-
function validateLinks(raw, source = "config") {
|
|
426
|
-
const fail = (msg) => {
|
|
427
|
-
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
428
|
-
};
|
|
429
|
-
if (!isObject(raw)) fail(`"links" must be an object`);
|
|
430
|
-
const c = raw;
|
|
431
|
-
for (const key of Object.keys(c)) if (!LINK_KEYS.has(key)) fail(`links: unknown setting "${key}"`);
|
|
432
|
-
if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
|
|
433
|
-
for (const host of c.hosts) {
|
|
434
|
-
if (!HOST.test(host)) {
|
|
435
|
-
fail(`links.hosts: "${host}" is not a bare lower-case host name (no scheme, path or port), e.g. "example.com"`);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (c.paths !== void 0) {
|
|
439
|
-
if (!isStringList(c.paths)) fail(`links.paths must be a list of path prefixes`);
|
|
440
|
-
for (const p of c.paths) {
|
|
441
|
-
if (!p.startsWith("/") || /[\s?#*]/.test(p)) {
|
|
442
|
-
fail(`links.paths: "${p}" must start with "/" and hold no spaces, "?", "#" or "*"`);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
if (c.webcredentials !== void 0 && typeof c.webcredentials !== "boolean") fail(`links.webcredentials must be true or false`);
|
|
447
|
-
const links = { hosts: [...new Set(c.hosts)] };
|
|
448
|
-
if (c.paths !== void 0) links.paths = [...new Set(c.paths)];
|
|
449
|
-
if (c.webcredentials !== void 0) links.webcredentials = c.webcredentials;
|
|
450
|
-
return links;
|
|
451
|
-
}
|
|
452
|
-
function validateConfig(raw, source = "config") {
|
|
453
|
-
const fail = (msg) => {
|
|
454
|
-
throw new DoctorConfigError(`${source}: ${msg}`);
|
|
455
|
-
};
|
|
456
|
-
if (!isObject(raw)) fail("the doctor settings must be an object");
|
|
457
|
-
const c = raw;
|
|
458
|
-
for (const key of Object.keys(c)) if (!KNOWN.has(key)) fail(`unknown setting "${key}"`);
|
|
459
|
-
if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
|
|
460
|
-
if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
|
|
461
|
-
for (const key of STRING_LISTS) {
|
|
462
|
-
if (c[key] !== void 0 && !isStringList(c[key])) fail(`"${key}" must be a list of strings`);
|
|
463
|
-
}
|
|
464
|
-
for (const key of STRINGS) {
|
|
465
|
-
if (c[key] !== void 0 && typeof c[key] !== "string") fail(`"${key}" must be a string`);
|
|
466
|
-
}
|
|
467
|
-
if (c.rawTags !== void 0) {
|
|
468
|
-
if (!isObject(c.rawTags)) fail(`"rawTags" must be an object`);
|
|
469
|
-
for (const [tag, v] of Object.entries(c.rawTags)) {
|
|
470
|
-
if (!/^[a-z][a-z0-9-]*$/.test(tag)) fail(`rawTags: "${tag}" is not an HTML tag name`);
|
|
471
|
-
if (v !== false && typeof v !== "string") fail(`rawTags.${tag} must be a component name or false`);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
if (c.forbiddenImports !== void 0) {
|
|
475
|
-
if (!isObject(c.forbiddenImports)) fail(`"forbiddenImports" must be an object of pattern \u2192 message`);
|
|
476
|
-
for (const [re, msg] of Object.entries(c.forbiddenImports)) {
|
|
477
|
-
if (typeof msg !== "string") fail(`forbiddenImports["${re}"] must be a message string`);
|
|
478
|
-
checkRegExp(re, `forbiddenImports["${re}"]`, fail);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
if (c.rules !== void 0) {
|
|
482
|
-
if (!isObject(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
|
|
483
|
-
for (const [rule, level] of Object.entries(c.rules)) {
|
|
484
|
-
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (c.allow !== void 0) {
|
|
488
|
-
if (!Array.isArray(c.allow)) fail(`"allow" must be a list`);
|
|
489
|
-
c.allow.forEach((e, i) => {
|
|
490
|
-
if (!isObject(e)) return fail(`allow[${i}] must be an object`);
|
|
491
|
-
const entry = e;
|
|
492
|
-
if (typeof entry.rule !== "string" || !entry.rule) fail(`allow[${i}] needs a "rule"`);
|
|
493
|
-
if (typeof entry.reason !== "string" || !entry.reason.trim()) fail(`allow[${i}] (${entry.rule}) needs a "reason"`);
|
|
494
|
-
for (const k of ["file", "match"]) {
|
|
495
|
-
if (entry[k] !== void 0 && typeof entry[k] !== "string") fail(`allow[${i}].${k} must be a string`);
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
if (c.patterns !== void 0) {
|
|
500
|
-
if (!Array.isArray(c.patterns)) fail(`"patterns" must be a list`);
|
|
501
|
-
c.patterns.forEach((p, i) => {
|
|
502
|
-
if (!isObject(p)) return fail(`patterns[${i}] must be an object`);
|
|
503
|
-
const rule = p;
|
|
504
|
-
for (const k of Object.keys(rule)) if (!PATTERN_KEYS.has(k)) fail(`patterns[${i}]: unknown key "${k}"`);
|
|
505
|
-
if (typeof rule.id !== "string" || !rule.id) fail(`patterns[${i}] needs an "id"`);
|
|
506
|
-
for (const k of ["files", "exclude"]) {
|
|
507
|
-
if (rule[k] !== void 0 && !isStringList(rule[k])) fail(`patterns[${i}].${k} must be a list of globs`);
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
if (c.packs !== void 0) {
|
|
512
|
-
if (!isStringList(c.packs)) fail(`"packs" must be a list, e.g. ["native", "supabase"]`);
|
|
513
|
-
for (const p of c.packs) if (!PACKS.has(p)) fail(`packs: unknown pack "${p}" (known: ${[...PACKS].join(", ")})`);
|
|
514
|
-
if (new Set(c.packs).size !== c.packs.length) fail(`packs: lists a pack twice`);
|
|
515
|
-
}
|
|
516
|
-
for (const [pack, keys] of Object.entries(PACK_KEYS)) {
|
|
517
|
-
const block = c[pack];
|
|
518
|
-
if (block === void 0) continue;
|
|
519
|
-
if (!isObject(block)) fail(`"${pack}" must be an object`);
|
|
520
|
-
if (!(c.packs ?? []).includes(pack)) fail(`"${pack}" settings are set but the ${pack} pack is not in "packs"`);
|
|
521
|
-
for (const [k, v] of Object.entries(block)) {
|
|
522
|
-
const want = keys[k];
|
|
523
|
-
if (!want) fail(`${pack}: unknown setting "${k}"`);
|
|
524
|
-
if (want === "string" && typeof v !== "string") fail(`${pack}.${k} must be a string`);
|
|
525
|
-
if (want === "list" && !isStringList(v)) fail(`${pack}.${k} must be a list of strings`);
|
|
526
|
-
if (want === "string" && !v.trim()) fail(`${pack}.${k} must not be empty`);
|
|
527
|
-
if (want === "path") block[k] = appPath(v, `${pack}.${k}`, fail);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
const supa = c.supabase;
|
|
531
|
-
if (Array.isArray(supa?.exposedSchemas)) supa.exposedSchemas = supa.exposedSchemas.map((s) => s.toLowerCase());
|
|
532
|
-
if (c.plugins !== void 0) {
|
|
533
|
-
const ok = Array.isArray(c.plugins) && c.plugins.every((p) => typeof p === "string" || Array.isArray(p) && p.length === 2 && typeof p[0] === "string");
|
|
534
|
-
if (!ok) fail(`"plugins" must be a list of module paths or [path, options] pairs`);
|
|
535
|
-
}
|
|
536
|
-
return c;
|
|
537
|
-
}
|
|
538
|
-
function checkRegExp(source, where, fail) {
|
|
539
|
-
try {
|
|
540
|
-
new RegExp(source);
|
|
541
|
-
} catch (err) {
|
|
542
|
-
fail(`${where} is not a valid regular expression: ${err.message}`);
|
|
1885
|
+
shell: true,
|
|
1886
|
+
stdio: quiet ? "pipe" : "inherit",
|
|
1887
|
+
env: { ...process.env, [BUILD_GUARD_ENV]: "1" }
|
|
1888
|
+
});
|
|
1889
|
+
if (r.status !== 0) {
|
|
1890
|
+
const tail = quiet ? `
|
|
1891
|
+
${String(r.stderr ?? "").trim().split("\n").slice(-20).join("\n")}` : "";
|
|
1892
|
+
return { rule: "build", file: command, message: `\`${command}\` failed (exit ${r.status ?? r.signal})${tail}` };
|
|
1893
|
+
}
|
|
543
1894
|
}
|
|
1895
|
+
return null;
|
|
544
1896
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
return Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
550
|
-
}
|
|
551
|
-
var GenesisConfigError, DoctorConfigError, STRING_LISTS, STRINGS, KNOWN, LEVELS, PATTERN_KEYS, PACKS, PACK_KEYS, LINK_KEYS, HOST;
|
|
552
|
-
var init_config = __esm({
|
|
553
|
-
"src/doctor/config.ts"() {
|
|
554
|
-
GenesisConfigError = class extends Error {
|
|
555
|
-
name = "GenesisConfigError";
|
|
556
|
-
};
|
|
557
|
-
DoctorConfigError = class extends GenesisConfigError {
|
|
558
|
-
name = "DoctorConfigError";
|
|
559
|
-
};
|
|
560
|
-
STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
|
|
561
|
-
STRINGS = ["uiPackage", "rulesDoc"];
|
|
562
|
-
KNOWN = /* @__PURE__ */ new Set([
|
|
563
|
-
...STRING_LISTS,
|
|
564
|
-
...STRINGS,
|
|
565
|
-
"themeCss",
|
|
566
|
-
"rawTags",
|
|
567
|
-
"forbiddenImports",
|
|
568
|
-
"rules",
|
|
569
|
-
"allow",
|
|
570
|
-
"patterns",
|
|
571
|
-
"plugins",
|
|
572
|
-
"packs",
|
|
573
|
-
"native",
|
|
574
|
-
"supabase",
|
|
575
|
-
"$schema",
|
|
576
|
-
"$comment"
|
|
577
|
-
]);
|
|
578
|
-
LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
|
|
579
|
-
PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
580
|
-
PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
581
|
-
PACK_KEYS = {
|
|
582
|
-
native: { routerRoot: "path" },
|
|
583
|
-
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" }
|
|
584
|
-
};
|
|
585
|
-
LINK_KEYS = /* @__PURE__ */ new Set(["hosts", "paths", "webcredentials"]);
|
|
586
|
-
HOST = /^(?=.{1,253}$)(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
1897
|
+
var BUILD_GUARD_ENV;
|
|
1898
|
+
var init_build = __esm({
|
|
1899
|
+
"src/doctor/build.ts"() {
|
|
1900
|
+
BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
587
1901
|
}
|
|
588
1902
|
});
|
|
589
1903
|
|
|
@@ -612,227 +1926,12 @@ function globToRegExp(glob) {
|
|
|
612
1926
|
}
|
|
613
1927
|
function globMatcher(globs) {
|
|
614
1928
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
615
|
-
return (
|
|
1929
|
+
return (path29) => res.some((re) => re.test(path29));
|
|
616
1930
|
}
|
|
617
1931
|
var init_glob = __esm({
|
|
618
1932
|
"src/doctor/glob.ts"() {
|
|
619
1933
|
}
|
|
620
1934
|
});
|
|
621
|
-
function findPackageDir(from, name) {
|
|
622
|
-
let dir = path3.resolve(from);
|
|
623
|
-
for (; ; ) {
|
|
624
|
-
const candidate = path3.join(dir, "node_modules", name);
|
|
625
|
-
if (existsSync(path3.join(candidate, "package.json"))) return candidate;
|
|
626
|
-
const parent = path3.dirname(dir);
|
|
627
|
-
if (parent === dir) return null;
|
|
628
|
-
dir = parent;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
function uiPackageFor(config) {
|
|
632
|
-
return config.uiPackage ?? (config.packs?.includes("native") ? NATIVE_UI_PACKAGE : DEFAULT_UI_PACKAGE);
|
|
633
|
-
}
|
|
634
|
-
function loadGenesis(root, config) {
|
|
635
|
-
const uiPackage = uiPackageFor(config);
|
|
636
|
-
const pkg = readPackageExports(root, uiPackage);
|
|
637
|
-
if (!pkg) throw new DoctorConfigError(`${uiPackage} is not installed here. Install it, or set doctor.uiPackage.`);
|
|
638
|
-
const { dir: uiDir, exports: exportNames, values, components } = pkg;
|
|
639
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
640
|
-
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
641
|
-
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
642
|
-
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
643
|
-
const rawTags = /* @__PURE__ */ new Map();
|
|
644
|
-
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
645
|
-
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
646
|
-
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
647
|
-
if (comp === false) rawTags.delete(tag);
|
|
648
|
-
else rawTags.set(tag, comp);
|
|
649
|
-
}
|
|
650
|
-
return {
|
|
651
|
-
uiPackage,
|
|
652
|
-
uiVersion: pkg.version,
|
|
653
|
-
exports: exportNames,
|
|
654
|
-
values,
|
|
655
|
-
components,
|
|
656
|
-
tokens,
|
|
657
|
-
rawTags,
|
|
658
|
-
palette: loadPalette(root)
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
function readPackageExports(root, uiPackage) {
|
|
662
|
-
const uiDir = findPackageDir(root, uiPackage);
|
|
663
|
-
if (!uiDir) return null;
|
|
664
|
-
const uiPkg = JSON.parse(readFileSync(path3.join(uiDir, "package.json"), "utf8"));
|
|
665
|
-
const typeEntries = /* @__PURE__ */ new Set();
|
|
666
|
-
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
667
|
-
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
668
|
-
for (const target of Object.values(uiPkg.exports ?? {})) {
|
|
669
|
-
const t = exportTypes(target);
|
|
670
|
-
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
671
|
-
}
|
|
672
|
-
const exportNames = /* @__PURE__ */ new Set();
|
|
673
|
-
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
674
|
-
let readAny = false;
|
|
675
|
-
for (const entry of typeEntries) {
|
|
676
|
-
const file = path3.join(uiDir, entry);
|
|
677
|
-
if (!existsSync(file)) continue;
|
|
678
|
-
readAny = true;
|
|
679
|
-
const dts = readFileSync(file, "utf8");
|
|
680
|
-
for (const name of parseExportNames(dts)) exportNames.add(name);
|
|
681
|
-
for (const m of dts.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
682
|
-
reexportedPackages.add(packageName(m[1]));
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
if (!readAny) {
|
|
686
|
-
throw new DoctorConfigError(`${uiPackage} has no type declarations to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
687
|
-
}
|
|
688
|
-
const valueDecls = /* @__PURE__ */ new Set();
|
|
689
|
-
const typeDecls = /* @__PURE__ */ new Set();
|
|
690
|
-
const declRoot = typeof mainTypes === "string" ? path3.dirname(path3.join(uiDir, mainTypes)) : uiDir;
|
|
691
|
-
const declFiles = walkDts(declRoot);
|
|
692
|
-
for (const pkg of reexportedPackages) {
|
|
693
|
-
const dir = findPackageDir(uiDir, pkg);
|
|
694
|
-
if (dir) walkDts(path3.join(dir, "dist"), declFiles);
|
|
695
|
-
}
|
|
696
|
-
for (const file of declFiles) {
|
|
697
|
-
const text = readFileSync(file, "utf8");
|
|
698
|
-
for (const m of text.matchAll(/\b(?:declare\s+)?(?:const|let|var|function|class|enum)\s+([A-Za-z_$][\w$]*)/g)) valueDecls.add(m[1]);
|
|
699
|
-
for (const m of text.matchAll(/\b(?:interface|type)\s+([A-Za-z_$][\w$]*)/g)) typeDecls.add(m[1]);
|
|
700
|
-
}
|
|
701
|
-
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
702
|
-
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
703
|
-
const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
|
|
704
|
-
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
705
|
-
}
|
|
706
|
-
function parseExportNames(dts) {
|
|
707
|
-
const names = [];
|
|
708
|
-
for (const m of dts.matchAll(/export\s+(?:type\s+)?\{([^}]*)\}/g)) {
|
|
709
|
-
for (const part of m[1].split(",")) {
|
|
710
|
-
const name = part.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
711
|
-
if (name && name !== "default") names.push(name);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
for (const m of dts.matchAll(/export\s+(?:declare\s+)?(?:const|let|function|class|enum|interface|type)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
715
|
-
names.push(m[1]);
|
|
716
|
-
}
|
|
717
|
-
return names;
|
|
718
|
-
}
|
|
719
|
-
function declaredTokens(css) {
|
|
720
|
-
return [...css.matchAll(/(--[A-Za-z0-9_-]+)\s*:/g)].map((m) => m[1]);
|
|
721
|
-
}
|
|
722
|
-
function packageName(specifier) {
|
|
723
|
-
const parts = specifier.split("/");
|
|
724
|
-
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
725
|
-
}
|
|
726
|
-
function exportTypes(target) {
|
|
727
|
-
if (!target || typeof target !== "object") return void 0;
|
|
728
|
-
const t = target;
|
|
729
|
-
if (typeof t.types === "string") return t.types;
|
|
730
|
-
for (const key of ["import", "default", "require"]) {
|
|
731
|
-
const nested = exportTypes(t[key]);
|
|
732
|
-
if (nested) return nested;
|
|
733
|
-
}
|
|
734
|
-
return void 0;
|
|
735
|
-
}
|
|
736
|
-
function walkDts(dir, out = []) {
|
|
737
|
-
if (!existsSync(dir)) return out;
|
|
738
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
739
|
-
if (entry.name === "node_modules") continue;
|
|
740
|
-
const p = path3.join(dir, entry.name);
|
|
741
|
-
if (entry.isDirectory()) walkDts(p, out);
|
|
742
|
-
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
743
|
-
}
|
|
744
|
-
return out;
|
|
745
|
-
}
|
|
746
|
-
function resolveThemeFiles(root, config, uiDir) {
|
|
747
|
-
if (config.themeCss) {
|
|
748
|
-
const specs = typeof config.themeCss === "string" ? [config.themeCss] : config.themeCss;
|
|
749
|
-
return specs.map((spec) => {
|
|
750
|
-
const file = resolveSpec(root, spec);
|
|
751
|
-
if (!file) throw new DoctorConfigError(`doctor.themeCss: cannot find ${spec}`);
|
|
752
|
-
return file;
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
const files = [];
|
|
756
|
-
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
757
|
-
const themes = ds && path3.join(ds, "dist", "themes");
|
|
758
|
-
if (themes && existsSync(themes)) {
|
|
759
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path3.join(themes, name));
|
|
760
|
-
}
|
|
761
|
-
if (files.length === 0) {
|
|
762
|
-
throw new DoctorConfigError(
|
|
763
|
-
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
764
|
-
);
|
|
765
|
-
}
|
|
766
|
-
const uiStyles = path3.join(uiDir, "dist", "styles.css");
|
|
767
|
-
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
768
|
-
return files;
|
|
769
|
-
}
|
|
770
|
-
function resolveSpec(root, spec) {
|
|
771
|
-
const local = path3.resolve(root, spec);
|
|
772
|
-
if (spec.startsWith(".") || path3.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
773
|
-
const parts = spec.split("/");
|
|
774
|
-
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
775
|
-
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
776
|
-
if (dir) {
|
|
777
|
-
const file = path3.join(dir, ...parts.slice(nameLength));
|
|
778
|
-
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
779
|
-
}
|
|
780
|
-
return existsSync(local) ? local : null;
|
|
781
|
-
}
|
|
782
|
-
function loadPalette(root) {
|
|
783
|
-
const names = new Set(TAILWIND_PALETTE);
|
|
784
|
-
try {
|
|
785
|
-
const req = createRequire(path3.join(root, "package.json"));
|
|
786
|
-
const colors = req("tailwindcss/colors");
|
|
787
|
-
for (const key of Object.keys(colors?.default ?? colors ?? {})) {
|
|
788
|
-
if (/^[a-z]+$/.test(key) && !["inherit", "current", "transparent"].includes(key)) names.add(key);
|
|
789
|
-
}
|
|
790
|
-
} catch {
|
|
791
|
-
}
|
|
792
|
-
return [...names].sort();
|
|
793
|
-
}
|
|
794
|
-
var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE;
|
|
795
|
-
var init_genesis = __esm({
|
|
796
|
-
"src/doctor/genesis.ts"() {
|
|
797
|
-
init_config();
|
|
798
|
-
DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
799
|
-
NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
800
|
-
DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
801
|
-
TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
802
|
-
TAG_ALIASES = { hr: "Separator" };
|
|
803
|
-
NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
|
|
804
|
-
TAILWIND_PALETTE = [
|
|
805
|
-
"black",
|
|
806
|
-
"white",
|
|
807
|
-
"slate",
|
|
808
|
-
"gray",
|
|
809
|
-
"zinc",
|
|
810
|
-
"neutral",
|
|
811
|
-
"stone",
|
|
812
|
-
"red",
|
|
813
|
-
"orange",
|
|
814
|
-
"amber",
|
|
815
|
-
"yellow",
|
|
816
|
-
"lime",
|
|
817
|
-
"green",
|
|
818
|
-
"emerald",
|
|
819
|
-
"teal",
|
|
820
|
-
"cyan",
|
|
821
|
-
"sky",
|
|
822
|
-
"blue",
|
|
823
|
-
"indigo",
|
|
824
|
-
"violet",
|
|
825
|
-
"purple",
|
|
826
|
-
"fuchsia",
|
|
827
|
-
"pink",
|
|
828
|
-
"rose",
|
|
829
|
-
"taupe",
|
|
830
|
-
"mauve",
|
|
831
|
-
"mist",
|
|
832
|
-
"olive"
|
|
833
|
-
];
|
|
834
|
-
}
|
|
835
|
-
});
|
|
836
1935
|
|
|
837
1936
|
// ../../scripts/lib/color-literals.mjs
|
|
838
1937
|
function stripBlockComments(content, hasLineComments = true) {
|
|
@@ -972,9 +2071,9 @@ function findHexLiterals(line) {
|
|
|
972
2071
|
while ((m = HEX_RE.exec(cleaned)) !== null) {
|
|
973
2072
|
const digits = m[2];
|
|
974
2073
|
if (digits.length <= 4 && !HEX_LETTER_RE.test(digits)) continue;
|
|
975
|
-
const
|
|
2074
|
+
const literal2 = `#${digits}`;
|
|
976
2075
|
const idx = m.index + m[1].length;
|
|
977
|
-
matches.push({ literal, column: idx + 1 });
|
|
2076
|
+
matches.push({ literal: literal2, column: idx + 1 });
|
|
978
2077
|
}
|
|
979
2078
|
return matches;
|
|
980
2079
|
}
|
|
@@ -1004,28 +2103,28 @@ function scanFiles(root, config) {
|
|
|
1004
2103
|
const files = [];
|
|
1005
2104
|
const seen = /* @__PURE__ */ new Set();
|
|
1006
2105
|
const visit = (abs) => {
|
|
1007
|
-
const rel = toPosix(
|
|
2106
|
+
const rel = toPosix(path28.relative(root, abs));
|
|
1008
2107
|
if (seen.has(rel) || ignored(rel)) return;
|
|
1009
|
-
const ext =
|
|
2108
|
+
const ext = path28.extname(abs);
|
|
1010
2109
|
if (!extensions.has(ext)) return;
|
|
1011
2110
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
1012
2111
|
seen.add(rel);
|
|
1013
2112
|
const text = readFileSync(abs, "utf8");
|
|
1014
2113
|
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
1015
2114
|
};
|
|
1016
|
-
const
|
|
2115
|
+
const walk2 = (dir) => {
|
|
1017
2116
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1018
2117
|
if (entry.isDirectory()) {
|
|
1019
|
-
if (!SKIP_DIRS.has(entry.name))
|
|
2118
|
+
if (!SKIP_DIRS.has(entry.name)) walk2(path28.join(dir, entry.name));
|
|
1020
2119
|
} else if (entry.isFile()) {
|
|
1021
|
-
visit(
|
|
2120
|
+
visit(path28.join(dir, entry.name));
|
|
1022
2121
|
}
|
|
1023
2122
|
}
|
|
1024
2123
|
};
|
|
1025
2124
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
1026
|
-
const abs =
|
|
2125
|
+
const abs = path28.resolve(root, src);
|
|
1027
2126
|
if (!existsSync(abs)) continue;
|
|
1028
|
-
if (statSync(abs).isDirectory())
|
|
2127
|
+
if (statSync(abs).isDirectory()) walk2(abs);
|
|
1029
2128
|
else visit(abs);
|
|
1030
2129
|
}
|
|
1031
2130
|
return files;
|
|
@@ -1054,7 +2153,7 @@ var init_scan = __esm({
|
|
|
1054
2153
|
];
|
|
1055
2154
|
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1056
2155
|
MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1057
|
-
toPosix = (p) => p.split(
|
|
2156
|
+
toPosix = (p) => p.split(path28.sep).join("/");
|
|
1058
2157
|
}
|
|
1059
2158
|
});
|
|
1060
2159
|
function parseRulesMarkdown(markdown) {
|
|
@@ -1120,7 +2219,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
1120
2219
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
1121
2220
|
let all = compiled;
|
|
1122
2221
|
if (rulesDoc) {
|
|
1123
|
-
const file =
|
|
2222
|
+
const file = path28.resolve(root, rulesDoc);
|
|
1124
2223
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
1125
2224
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
1126
2225
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -1186,14 +2285,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
1186
2285
|
}
|
|
1187
2286
|
function resolvePlugin(id, configDir) {
|
|
1188
2287
|
try {
|
|
1189
|
-
if (id.startsWith(".") ||
|
|
2288
|
+
if (id.startsWith(".") || path28.isAbsolute(id)) return resolveFrom(path28.resolve(configDir, id), configDir);
|
|
1190
2289
|
return resolveFrom(id, configDir);
|
|
1191
2290
|
} catch {
|
|
1192
2291
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
1193
2292
|
}
|
|
1194
2293
|
}
|
|
1195
2294
|
function resolveFrom(id, from) {
|
|
1196
|
-
return createRequire(
|
|
2295
|
+
return createRequire(path28.join(from, "noop.js")).resolve(id);
|
|
1197
2296
|
}
|
|
1198
2297
|
var init_plugins = __esm({
|
|
1199
2298
|
"src/doctor/plugins.ts"() {
|
|
@@ -1211,7 +2310,7 @@ function importSpecifiers(file) {
|
|
|
1211
2310
|
}
|
|
1212
2311
|
function checkProjectLayout(ctx) {
|
|
1213
2312
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
1214
|
-
if (existsSync(
|
|
2313
|
+
if (existsSync(path28.join(ctx.root, dir))) {
|
|
1215
2314
|
ctx.report({
|
|
1216
2315
|
rule: "local-primitives",
|
|
1217
2316
|
file: dir,
|
|
@@ -1221,7 +2320,7 @@ function checkProjectLayout(ctx) {
|
|
|
1221
2320
|
}
|
|
1222
2321
|
}
|
|
1223
2322
|
for (const file of STARTER_LEFTOVERS) {
|
|
1224
|
-
if (existsSync(
|
|
2323
|
+
if (existsSync(path28.join(ctx.root, file))) {
|
|
1225
2324
|
ctx.report({
|
|
1226
2325
|
rule: "starter-leftover",
|
|
1227
2326
|
level: "warn",
|
|
@@ -1308,7 +2407,7 @@ function checkTokens(ctx) {
|
|
|
1308
2407
|
}
|
|
1309
2408
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
1310
2409
|
if (/[*?]/.test(pattern)) continue;
|
|
1311
|
-
const abs =
|
|
2410
|
+
const abs = path28.join(ctx.root, pattern);
|
|
1312
2411
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
1313
2412
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
1314
2413
|
}
|
|
@@ -1405,16 +2504,60 @@ var init_native_primitives = __esm({
|
|
|
1405
2504
|
function privacyApisFor(dependencies2) {
|
|
1406
2505
|
return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
|
|
1407
2506
|
}
|
|
1408
|
-
var PRIVACY_APIS;
|
|
2507
|
+
var api, PRIVACY_APIS, appFunctionality;
|
|
1409
2508
|
var init_expo = __esm({
|
|
1410
2509
|
"src/expo.ts"() {
|
|
1411
2510
|
init_config();
|
|
1412
2511
|
init_config();
|
|
2512
|
+
api = (category, ...reasons) => ({
|
|
2513
|
+
NSPrivacyAccessedAPIType: `NSPrivacyAccessedAPICategory${category}`,
|
|
2514
|
+
NSPrivacyAccessedAPITypeReasons: reasons
|
|
2515
|
+
});
|
|
1413
2516
|
PRIVACY_APIS = {
|
|
1414
|
-
"
|
|
1415
|
-
|
|
1416
|
-
]
|
|
2517
|
+
"react-native": [api("FileTimestamp", "C617.1"), api("UserDefaults", "CA92.1"), api("SystemBootTime", "35F9.1")],
|
|
2518
|
+
expo: [api("FileTimestamp", "0A2A.1", "3B52.1"), api("DiskSpace", "E174.1", "85F4.1"), api("UserDefaults", "CA92.1")],
|
|
2519
|
+
"expo-updates": [api("UserDefaults", "CA92.1")],
|
|
2520
|
+
"expo-application": [api("FileTimestamp", "C617.1")],
|
|
2521
|
+
"expo-notifications": [api("UserDefaults", "CA92.1")],
|
|
2522
|
+
"@react-native-async-storage/async-storage": [api("FileTimestamp", "C617.1")],
|
|
2523
|
+
"@sentry/react-native": [api("UserDefaults", "CA92.1"), api("SystemBootTime", "35F9.1"), api("FileTimestamp", "C617.1")]
|
|
1417
2524
|
};
|
|
2525
|
+
appFunctionality = (type, ...more) => ({
|
|
2526
|
+
type,
|
|
2527
|
+
purposes: ["app functionality", ...more],
|
|
2528
|
+
linked: true,
|
|
2529
|
+
tracking: false
|
|
2530
|
+
});
|
|
2531
|
+
({
|
|
2532
|
+
account: {
|
|
2533
|
+
packages: ["@marktiderman/genesis-supabase"],
|
|
2534
|
+
collects: [appFunctionality("email address"), appFunctionality("user id"), appFunctionality("name")]
|
|
2535
|
+
},
|
|
2536
|
+
observability: {
|
|
2537
|
+
packages: ["@marktiderman/genesis-native", "@sentry/react-native"],
|
|
2538
|
+
collects: [
|
|
2539
|
+
appFunctionality("crash data"),
|
|
2540
|
+
appFunctionality("performance data"),
|
|
2541
|
+
appFunctionality("other diagnostic data"),
|
|
2542
|
+
appFunctionality("user id", "analytics"),
|
|
2543
|
+
{ type: "product interaction", purposes: ["analytics"], linked: true, tracking: false }
|
|
2544
|
+
]
|
|
2545
|
+
},
|
|
2546
|
+
push: {
|
|
2547
|
+
packages: ["@marktiderman/genesis-native", "expo-notifications"],
|
|
2548
|
+
collects: [appFunctionality("device ID")]
|
|
2549
|
+
},
|
|
2550
|
+
support: {
|
|
2551
|
+
packages: ["@marktiderman/genesis-support"],
|
|
2552
|
+
collects: [
|
|
2553
|
+
appFunctionality("user id"),
|
|
2554
|
+
appFunctionality("customer support"),
|
|
2555
|
+
appFunctionality("other user content"),
|
|
2556
|
+
appFunctionality("photos or videos"),
|
|
2557
|
+
appFunctionality("other diagnostic data")
|
|
2558
|
+
]
|
|
2559
|
+
}
|
|
2560
|
+
});
|
|
1418
2561
|
}
|
|
1419
2562
|
});
|
|
1420
2563
|
function nativePackage(ctx) {
|
|
@@ -1495,7 +2638,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1495
2638
|
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
1496
2639
|
const code = file.code;
|
|
1497
2640
|
const hidden = HIDES_HEADER.exec(code);
|
|
1498
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2641
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path28.posix.dirname(file.path), file.path);
|
|
1499
2642
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
1500
2643
|
if (hidden && own) {
|
|
1501
2644
|
reported.add(file.path);
|
|
@@ -1523,7 +2666,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1523
2666
|
}
|
|
1524
2667
|
for (const file of ctx.files) {
|
|
1525
2668
|
if (!JSX_EXTS2.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1526
|
-
const layout = hidingLayouts.get(
|
|
2669
|
+
const layout = hidingLayouts.get(path28.posix.dirname(file.path));
|
|
1527
2670
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
1528
2671
|
if (!layout || !own) continue;
|
|
1529
2672
|
ctx.report({
|
|
@@ -1538,13 +2681,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1538
2681
|
}
|
|
1539
2682
|
function routerRoot(ctx) {
|
|
1540
2683
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
1541
|
-
return existsSync(
|
|
2684
|
+
return existsSync(path28.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
1542
2685
|
}
|
|
1543
2686
|
function checkScreenLayouts(ctx, pkg) {
|
|
1544
2687
|
const layouts = nativeLayouts(pkg);
|
|
1545
2688
|
if (layouts.length === 0) return;
|
|
1546
2689
|
const rootDir = routerRoot(ctx);
|
|
1547
|
-
if (!existsSync(
|
|
2690
|
+
if (!existsSync(path28.join(ctx.root, rootDir))) {
|
|
1548
2691
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
1549
2692
|
return;
|
|
1550
2693
|
}
|
|
@@ -1581,10 +2724,10 @@ function localImports(root, file) {
|
|
|
1581
2724
|
const out = [];
|
|
1582
2725
|
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1583
2726
|
const spec = m[1];
|
|
1584
|
-
const bases = spec.startsWith(".") ? [
|
|
2727
|
+
const bases = spec.startsWith(".") ? [path28.resolve(path28.dirname(file.absolutePath), spec)] : [path28.join(root, spec.slice(2)), path28.join(root, "src", spec.slice(2))];
|
|
1585
2728
|
for (const base of bases) {
|
|
1586
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
1587
|
-
(p) => SCRIPT_EXTS2.has(
|
|
2729
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path28.join(base, `index${e}`))].find(
|
|
2730
|
+
(p) => SCRIPT_EXTS2.has(path28.extname(p)) && existsSync(p)
|
|
1588
2731
|
);
|
|
1589
2732
|
if (hit) {
|
|
1590
2733
|
out.push(hit);
|
|
@@ -1604,7 +2747,7 @@ function readSource(abs) {
|
|
|
1604
2747
|
function readExpoConfigs(root) {
|
|
1605
2748
|
const out = [];
|
|
1606
2749
|
for (const name of EXPO_CONFIGS) {
|
|
1607
|
-
const abs =
|
|
2750
|
+
const abs = path28.join(root, name);
|
|
1608
2751
|
if (!existsSync(abs)) continue;
|
|
1609
2752
|
const text = readFileSync(abs, "utf8");
|
|
1610
2753
|
let json = null;
|
|
@@ -1638,13 +2781,13 @@ function pluginOptions(json, module) {
|
|
|
1638
2781
|
return null;
|
|
1639
2782
|
}
|
|
1640
2783
|
function dependencies(root) {
|
|
1641
|
-
const file =
|
|
2784
|
+
const file = path28.join(root, "package.json");
|
|
1642
2785
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
1643
2786
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
1644
2787
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
1645
2788
|
}
|
|
1646
2789
|
function runtimeDependencies(root) {
|
|
1647
|
-
const file =
|
|
2790
|
+
const file = path28.join(root, "package.json");
|
|
1648
2791
|
if (!existsSync(file)) return {};
|
|
1649
2792
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
1650
2793
|
}
|
|
@@ -1929,9 +3072,9 @@ function gitView(root, dir, base) {
|
|
|
1929
3072
|
function checkSupabasePack(ctx) {
|
|
1930
3073
|
const settings2 = ctx.config.supabase ?? {};
|
|
1931
3074
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
1932
|
-
const abs =
|
|
3075
|
+
const abs = path28.join(ctx.root, dir);
|
|
1933
3076
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
1934
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
3077
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path28.join(abs, n), "utf8")) }));
|
|
1935
3078
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1936
3079
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
1937
3080
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -1948,7 +3091,7 @@ function checkSupabasePack(ctx) {
|
|
|
1948
3091
|
}
|
|
1949
3092
|
}
|
|
1950
3093
|
const since = settings2.since;
|
|
1951
|
-
const afterSince = (file) => since === void 0 ||
|
|
3094
|
+
const afterSince = (file) => since === void 0 || path28.posix.basename(file) >= since;
|
|
1952
3095
|
if ("reason" in view && since === void 0) {
|
|
1953
3096
|
ctx.report({
|
|
1954
3097
|
rule: "migration-grants",
|
|
@@ -2159,36 +3302,6 @@ var init_supabase = __esm({
|
|
|
2159
3302
|
MULTIWORD_TYPE = /^(?:double precision|character varying|character|bit varying|timestamp|time|interval)\b/;
|
|
2160
3303
|
}
|
|
2161
3304
|
});
|
|
2162
|
-
function readReleaseManifest(root) {
|
|
2163
|
-
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2164
|
-
const file = dir && path3.join(dir, "dist", "versions.json");
|
|
2165
|
-
if (!file || !existsSync(file)) return null;
|
|
2166
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
2167
|
-
}
|
|
2168
|
-
function checkVersionSkew(ctx) {
|
|
2169
|
-
const manifest = readReleaseManifest(ctx.root);
|
|
2170
|
-
if (!manifest) return;
|
|
2171
|
-
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2172
|
-
const dir = findPackageDir(ctx.root, name);
|
|
2173
|
-
if (!dir) continue;
|
|
2174
|
-
const have = JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8")).version;
|
|
2175
|
-
if (have === want) continue;
|
|
2176
|
-
ctx.report({
|
|
2177
|
-
rule: "version-skew",
|
|
2178
|
-
level: "warn",
|
|
2179
|
-
file: "package.json",
|
|
2180
|
-
subject: name,
|
|
2181
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2182
|
-
});
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
var UMBRELLA_PACKAGE;
|
|
2186
|
-
var init_versions = __esm({
|
|
2187
|
-
"src/doctor/versions.ts"() {
|
|
2188
|
-
init_genesis();
|
|
2189
|
-
UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2190
|
-
}
|
|
2191
|
-
});
|
|
2192
3305
|
|
|
2193
3306
|
// src/doctor/index.ts
|
|
2194
3307
|
var doctor_exports = {};
|
|
@@ -2216,7 +3329,7 @@ __export(doctor_exports, {
|
|
|
2216
3329
|
validateLinks: () => validateLinks
|
|
2217
3330
|
});
|
|
2218
3331
|
async function runDoctor(options = {}) {
|
|
2219
|
-
const root =
|
|
3332
|
+
const root = path28.resolve(options.root ?? process.cwd());
|
|
2220
3333
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
2221
3334
|
const config = loaded.config;
|
|
2222
3335
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -2369,44 +3482,44 @@ __export(features_exports, {
|
|
|
2369
3482
|
runFeaturesCheck: () => runFeaturesCheck,
|
|
2370
3483
|
runFeaturesFind: () => runFeaturesFind
|
|
2371
3484
|
});
|
|
2372
|
-
function
|
|
3485
|
+
function isObject3(value) {
|
|
2373
3486
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2374
3487
|
}
|
|
2375
3488
|
function readObject(file, key) {
|
|
2376
3489
|
try {
|
|
2377
3490
|
const json = JSON.parse(readFileSync(file, "utf-8"));
|
|
2378
|
-
return
|
|
3491
|
+
return isObject3(json[key]) ? json[key] : {};
|
|
2379
3492
|
} catch {
|
|
2380
3493
|
return {};
|
|
2381
3494
|
}
|
|
2382
3495
|
}
|
|
2383
3496
|
function settings(root, options) {
|
|
2384
|
-
const fromPackage = readObject(
|
|
2385
|
-
const fromConfig = readObject(
|
|
3497
|
+
const fromPackage = readObject(path28.join(root, "package.json"), "genesisFeatures");
|
|
3498
|
+
const fromConfig = readObject(path28.join(root, "genesis.config.json"), "features");
|
|
2386
3499
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
2387
3500
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
2388
3501
|
}
|
|
2389
3502
|
async function loadRegistry(input) {
|
|
2390
|
-
const root =
|
|
3503
|
+
const root = path28.resolve(input.dir);
|
|
2391
3504
|
const options = settings(root, input);
|
|
2392
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
2393
|
-
if (!registry || !existsSync(
|
|
3505
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path28.join(root, p)));
|
|
3506
|
+
if (!registry || !existsSync(path28.join(root, registry))) {
|
|
2394
3507
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
2395
3508
|
}
|
|
2396
|
-
const jiti = createJiti(
|
|
2397
|
-
const load = async (file) => await jiti.import(
|
|
3509
|
+
const jiti = createJiti(path28.join(root, "package.json"), { moduleCache: false });
|
|
3510
|
+
const load = async (file) => await jiti.import(path28.join(root, file));
|
|
2398
3511
|
const mod = await load(registry);
|
|
2399
3512
|
const features2 = mod.features ?? mod.default;
|
|
2400
|
-
if (!
|
|
3513
|
+
if (!isObject3(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
2401
3514
|
const flags = options.flagsFile ? (await load(options.flagsFile)).flags : mod.flags;
|
|
2402
|
-
if (flags !== void 0 && !
|
|
3515
|
+
if (flags !== void 0 && !isObject3(flags)) {
|
|
2403
3516
|
throw new Error(`${options.flagsFile ?? registry}'s \`flags\` export must be an object (from defineFlags).`);
|
|
2404
3517
|
}
|
|
2405
3518
|
const { dir: _dir, registry: _registry, flagsFile: _flagsFile, prs: _prs, gh: _gh, ...rest } = options;
|
|
2406
3519
|
const project = {
|
|
2407
3520
|
...rest,
|
|
2408
3521
|
root,
|
|
2409
|
-
source: options.source ?? registry.split(
|
|
3522
|
+
source: options.source ?? registry.split(path28.sep).join("/"),
|
|
2410
3523
|
features: features2,
|
|
2411
3524
|
flags
|
|
2412
3525
|
};
|
|
@@ -2516,8 +3629,8 @@ function routeTags(source) {
|
|
|
2516
3629
|
}
|
|
2517
3630
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
2518
3631
|
const tags = routeTags(source);
|
|
2519
|
-
const
|
|
2520
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
3632
|
+
const relative5 = route.replace(/^\//, "");
|
|
3633
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative5.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
2521
3634
|
if (existing) {
|
|
2522
3635
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
2523
3636
|
}
|
|
@@ -2525,17 +3638,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
2525
3638
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
2526
3639
|
if (roots.length !== 1) {
|
|
2527
3640
|
return {
|
|
2528
|
-
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${
|
|
3641
|
+
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative5}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
|
|
2529
3642
|
};
|
|
2530
3643
|
}
|
|
2531
3644
|
const layout = roots[0];
|
|
2532
3645
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
2533
|
-
if (base && !
|
|
3646
|
+
if (base && !relative5.startsWith(`${base}/`)) {
|
|
2534
3647
|
return {
|
|
2535
3648
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
2536
3649
|
};
|
|
2537
3650
|
}
|
|
2538
|
-
const childPath = base ?
|
|
3651
|
+
const childPath = base ? relative5.slice(base.length + 1) : relative5;
|
|
2539
3652
|
const guard = GUARD.exec(source)?.[1];
|
|
2540
3653
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
2541
3654
|
const before = source.slice(0, layout.close);
|
|
@@ -2864,6 +3977,1000 @@ var init_init = __esm({
|
|
|
2864
3977
|
}
|
|
2865
3978
|
});
|
|
2866
3979
|
|
|
3980
|
+
// src/blocks/agents.ts
|
|
3981
|
+
function fragmentMarkers(blockId) {
|
|
3982
|
+
return { start: `<!-- genesis-block:${blockId}:start -->`, end: `<!-- genesis-block:${blockId}:end -->` };
|
|
3983
|
+
}
|
|
3984
|
+
function mergeFragment(agents, blockId, fragment, source) {
|
|
3985
|
+
const { start, end } = fragmentMarkers(blockId);
|
|
3986
|
+
if (fragment.includes("<!-- genesis-block:")) throw new Error(`${source} contains a genesis-block marker; a fragment can't hold one.`);
|
|
3987
|
+
const body = `${start}
|
|
3988
|
+
<!-- From ${source}; \`genesis upgrade\` replaces this block. Don't edit it. -->
|
|
3989
|
+
${fragment.trim()}
|
|
3990
|
+
${end}`;
|
|
3991
|
+
const text = agents ?? "# Agent notes\n";
|
|
3992
|
+
const s = text.indexOf(start);
|
|
3993
|
+
const e = text.indexOf(end);
|
|
3994
|
+
if (s < 0 && e < 0) return `${text.replace(/\s*$/, "")}
|
|
3995
|
+
|
|
3996
|
+
${body}
|
|
3997
|
+
`;
|
|
3998
|
+
if (s < 0 || e < 0 || e < s || text.indexOf(start, s + 1) >= 0) throw new Error(`AGENTS.md has a broken ${start} \u2026 ${end} block; fix it by hand.`);
|
|
3999
|
+
return `${text.slice(0, s)}${body}${text.slice(e + end.length)}`;
|
|
4000
|
+
}
|
|
4001
|
+
function skillName(content, packagePath) {
|
|
4002
|
+
const fm = /^---\n([\s\S]*?)\n---/.exec(content)?.[1];
|
|
4003
|
+
const name = fm ? /^name:\s*["']?([A-Za-z0-9][A-Za-z0-9_-]*)["']?\s*$/m.exec(fm)?.[1] : void 0;
|
|
4004
|
+
const fallback = packagePath.split("/").slice(-2, -1)[0];
|
|
4005
|
+
const picked = (name ?? fallback ?? "").toLowerCase();
|
|
4006
|
+
if (!/^[a-z0-9][a-z0-9_-]*$/.test(picked)) throw new Error(`Can't name the skill at ${packagePath}: give its frontmatter a name.`);
|
|
4007
|
+
return picked;
|
|
4008
|
+
}
|
|
4009
|
+
var init_agents = __esm({
|
|
4010
|
+
"src/blocks/agents.ts"() {
|
|
4011
|
+
}
|
|
4012
|
+
});
|
|
4013
|
+
function copyOwned(root, lock, write, dryRun = false) {
|
|
4014
|
+
const existing = readApp(root, write.path);
|
|
4015
|
+
const record = () => {
|
|
4016
|
+
lock.files[write.path] = { source: write.source, sha256: sha256(write.content), ...write.version ? { version: write.version } : {} };
|
|
4017
|
+
};
|
|
4018
|
+
if (existing === null) {
|
|
4019
|
+
if (!dryRun) createApp(root, write.path, write.content);
|
|
4020
|
+
record();
|
|
4021
|
+
return "created";
|
|
4022
|
+
}
|
|
4023
|
+
if (existing === write.content) {
|
|
4024
|
+
record();
|
|
4025
|
+
return "same";
|
|
4026
|
+
}
|
|
4027
|
+
return "kept";
|
|
4028
|
+
}
|
|
4029
|
+
function ownedKeyProblem(key, source) {
|
|
4030
|
+
let parsed;
|
|
4031
|
+
try {
|
|
4032
|
+
parsed = parseSource(source);
|
|
4033
|
+
} catch (err) {
|
|
4034
|
+
return err instanceof Error ? err.message : String(err);
|
|
4035
|
+
}
|
|
4036
|
+
const { package: pkg, path: rel } = parsed;
|
|
4037
|
+
if (!GENESIS_PACKAGE.test(pkg)) return `${key}'s source ${pkg} isn't a Genesis package`;
|
|
4038
|
+
if (!safeRelative(rel) || !safeRelative(key)) return `${key} or its source isn't a plain path`;
|
|
4039
|
+
if (key.startsWith("supabase/migrations/")) return `${key} is a migration; migrations are never refreshed`;
|
|
4040
|
+
const base = rel.split("/").pop();
|
|
4041
|
+
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
4042
|
+
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key) ? null : `${key} isn't where a template goes`;
|
|
4043
|
+
}
|
|
4044
|
+
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
4045
|
+
if (fn) return key === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key} isn't where ${rel} goes`;
|
|
4046
|
+
if (/\.test\.sql$/.test(base)) return key === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key} isn't where ${rel} goes`;
|
|
4047
|
+
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key) && key.endsWith(`/${base}`)) return null;
|
|
4048
|
+
return `${key} doesn't match its source ${source}`;
|
|
4049
|
+
}
|
|
4050
|
+
function mergeThreeWay(mine, base, theirs) {
|
|
4051
|
+
const dir = mkdtempSync(path28.join(tmpdir(), "genesis-merge-"));
|
|
4052
|
+
try {
|
|
4053
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path28.join(dir, n));
|
|
4054
|
+
writeFileSync(m, mine);
|
|
4055
|
+
writeFileSync(b, base);
|
|
4056
|
+
writeFileSync(t, theirs);
|
|
4057
|
+
try {
|
|
4058
|
+
execFileSync("git", ["merge-file", "-q", "-L", "yours", "-L", "base", "-L", "genesis", m, b, t], { stdio: "ignore" });
|
|
4059
|
+
return { text: readFileSync(m, "utf8"), clean: true };
|
|
4060
|
+
} catch (err) {
|
|
4061
|
+
const status = err.status;
|
|
4062
|
+
if (typeof status === "number" && status > 0 && status < 128) return { text: readFileSync(m, "utf8"), clean: false };
|
|
4063
|
+
return null;
|
|
4064
|
+
}
|
|
4065
|
+
} finally {
|
|
4066
|
+
rmSync(dir, { recursive: true, force: true });
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4069
|
+
function refreshOwned(root, lock, input, options = {}) {
|
|
4070
|
+
const entry = lock.files[input.path];
|
|
4071
|
+
if (!entry) throw new Error(`${input.path} isn't in genesis.lock.json`);
|
|
4072
|
+
const problem = ownedKeyProblem(input.path, entry.source);
|
|
4073
|
+
if (problem) return { path: input.path, outcome: "refused", detail: `genesis.lock.json: ${problem}; left alone` };
|
|
4074
|
+
const write = (rel, text) => {
|
|
4075
|
+
if (!options.dryRun) replaceApp(root, rel, text);
|
|
4076
|
+
};
|
|
4077
|
+
const mine = readApp(root, input.path);
|
|
4078
|
+
if (input.theirs === null) return { path: input.path, outcome: "gone-upstream", detail: "no longer shipped; left as it is" };
|
|
4079
|
+
const theirsSha = sha256(input.theirs);
|
|
4080
|
+
if (theirsSha === entry.sha256) return { path: input.path, outcome: "unchanged" };
|
|
4081
|
+
const record = (sha) => {
|
|
4082
|
+
const { pending: _settled, ...rest } = entry;
|
|
4083
|
+
lock.files[input.path] = { ...rest, sha256: sha, ...input.version ? { version: input.version } : {} };
|
|
4084
|
+
};
|
|
4085
|
+
if (mine === null) {
|
|
4086
|
+
return { path: input.path, outcome: "kept-deleted", detail: "deleted in the app; not brought back" };
|
|
4087
|
+
}
|
|
4088
|
+
const mineSha = sha256(mine);
|
|
4089
|
+
if (mineSha === entry.sha256 || mineSha === theirsSha) {
|
|
4090
|
+
write(input.path, input.theirs);
|
|
4091
|
+
record(theirsSha);
|
|
4092
|
+
return { path: input.path, outcome: "updated" };
|
|
4093
|
+
}
|
|
4094
|
+
const next = `${input.path}.genesis-next`;
|
|
4095
|
+
const existingNext = readApp(root, next);
|
|
4096
|
+
if (entry.pending === theirsSha) {
|
|
4097
|
+
if (existingNext === null) {
|
|
4098
|
+
const { pending: _done, ...rest } = entry;
|
|
4099
|
+
lock.files[input.path] = { ...rest, sha256: theirsSha, ...input.version ? { version: input.version } : {} };
|
|
4100
|
+
return { path: input.path, outcome: "resolved", detail: "your file is kept as the resolution of the last upgrade" };
|
|
4101
|
+
}
|
|
4102
|
+
return { path: input.path, outcome: "kept-mine", detail: `waiting for you: resolve ${next} into your file, then delete it` };
|
|
4103
|
+
}
|
|
4104
|
+
const writeNext = (text) => {
|
|
4105
|
+
if (existingNext !== null && existingNext !== text) return `${next} is already there with other text; resolve it (and delete it) first`;
|
|
4106
|
+
write(next, text);
|
|
4107
|
+
lock.files[input.path] = { ...entry, pending: theirsSha };
|
|
4108
|
+
return null;
|
|
4109
|
+
};
|
|
4110
|
+
if (!options.keepMine && input.base !== null && sha256(input.base) === entry.sha256) {
|
|
4111
|
+
const merged = mergeThreeWay(mine, input.base, input.theirs);
|
|
4112
|
+
if (merged?.clean) {
|
|
4113
|
+
write(input.path, merged.text);
|
|
4114
|
+
record(theirsSha);
|
|
4115
|
+
return { path: input.path, outcome: "merged", detail: "your edits kept on top of the new version" };
|
|
4116
|
+
}
|
|
4117
|
+
if (merged) {
|
|
4118
|
+
const blocked2 = writeNext(merged.text);
|
|
4119
|
+
return { path: input.path, outcome: "conflict", detail: blocked2 ?? `merge conflicts written to ${next}; your file is unchanged` };
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
const blocked = writeNext(input.theirs);
|
|
4123
|
+
return { path: input.path, outcome: "kept-mine", detail: blocked ?? `you changed it; the new version is in ${next}` };
|
|
4124
|
+
}
|
|
4125
|
+
var CLI;
|
|
4126
|
+
var init_owned = __esm({
|
|
4127
|
+
"src/blocks/owned.ts"() {
|
|
4128
|
+
init_files();
|
|
4129
|
+
init_lock();
|
|
4130
|
+
init_manifest();
|
|
4131
|
+
CLI = "@marktiderman/genesis-cli";
|
|
4132
|
+
}
|
|
4133
|
+
});
|
|
4134
|
+
|
|
4135
|
+
// src/blocks/registry-edit.ts
|
|
4136
|
+
function literal(value, indent) {
|
|
4137
|
+
if (Array.isArray(value)) return `[${value.map((v) => literal(v, indent)).join(", ")}]`;
|
|
4138
|
+
if (value && typeof value === "object") {
|
|
4139
|
+
const inner = `${indent} `;
|
|
4140
|
+
const lines = Object.entries(value).map(([k, v]) => `${inner}${IDENT.test(k) ? k : JSON.stringify(k)}: ${literal(v, inner)},`);
|
|
4141
|
+
return `{
|
|
4142
|
+
${lines.join("\n")}
|
|
4143
|
+
${indent}}`;
|
|
4144
|
+
}
|
|
4145
|
+
return JSON.stringify(value);
|
|
4146
|
+
}
|
|
4147
|
+
function featureSnippet(manifest, owner) {
|
|
4148
|
+
const apps = manifest.platforms?.length ? manifest.platforms : ["web", "native"];
|
|
4149
|
+
const entry = {
|
|
4150
|
+
name: manifest.feature?.name ?? manifest.id,
|
|
4151
|
+
summary: manifest.feature?.summary ?? `The ${manifest.id} block from ${manifest.package}.`,
|
|
4152
|
+
// Just added: the app hasn't shipped it yet. Move it on when it has.
|
|
4153
|
+
status: "building",
|
|
4154
|
+
...manifest.feature?.layer ? { layer: manifest.feature.layer } : { layer: "block" },
|
|
4155
|
+
...manifest.feature?.keywords?.length ? { keywords: manifest.feature.keywords } : {},
|
|
4156
|
+
...manifest.requires.length ? { requires: manifest.requires } : {},
|
|
4157
|
+
owner,
|
|
4158
|
+
apps,
|
|
4159
|
+
audience: manifest.feature?.audience ?? ["developer"]
|
|
4160
|
+
};
|
|
4161
|
+
return ` ${JSON.stringify(manifest.id)}: ${literal(entry, " ")},
|
|
4162
|
+
`;
|
|
4163
|
+
}
|
|
4164
|
+
function scanRegistry(text) {
|
|
4165
|
+
const calls = [...text.matchAll(/defineFeatures(?:<[^>]*>)?\(\s*\{/g)];
|
|
4166
|
+
if (calls.length !== 1) return null;
|
|
4167
|
+
let i = calls[0].index + calls[0][0].length;
|
|
4168
|
+
let last = i - 1;
|
|
4169
|
+
let depth = 1;
|
|
4170
|
+
while (i < text.length) {
|
|
4171
|
+
const c = text[i];
|
|
4172
|
+
const next = text[i + 1];
|
|
4173
|
+
if (c === "/" && next === "/") {
|
|
4174
|
+
const end = text.indexOf("\n", i);
|
|
4175
|
+
i = end < 0 ? text.length : end;
|
|
4176
|
+
continue;
|
|
4177
|
+
}
|
|
4178
|
+
if (c === "/" && next === "*") {
|
|
4179
|
+
const end = text.indexOf("*/", i + 2);
|
|
4180
|
+
if (end < 0) return null;
|
|
4181
|
+
i = end + 2;
|
|
4182
|
+
continue;
|
|
4183
|
+
}
|
|
4184
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
4185
|
+
let j = i + 1;
|
|
4186
|
+
while (j < text.length && text[j] !== c) {
|
|
4187
|
+
if (text[j] === "\\") j++;
|
|
4188
|
+
else if (c === "`" && text[j] === "$" && text[j + 1] === "{") return null;
|
|
4189
|
+
j++;
|
|
4190
|
+
}
|
|
4191
|
+
if (j >= text.length) return null;
|
|
4192
|
+
last = j;
|
|
4193
|
+
i = j + 1;
|
|
4194
|
+
continue;
|
|
4195
|
+
}
|
|
4196
|
+
if (c === "{") depth++;
|
|
4197
|
+
else if (c === "}") {
|
|
4198
|
+
depth--;
|
|
4199
|
+
if (depth === 0) return { close: i, last };
|
|
4200
|
+
}
|
|
4201
|
+
if (!/\s/.test(c)) last = i;
|
|
4202
|
+
i++;
|
|
4203
|
+
}
|
|
4204
|
+
return null;
|
|
4205
|
+
}
|
|
4206
|
+
function addFeatureEntry(text, snippet) {
|
|
4207
|
+
const scan = scanRegistry(text);
|
|
4208
|
+
if (!scan) return null;
|
|
4209
|
+
let head = text.slice(0, scan.close);
|
|
4210
|
+
if (!/[,{]/.test(text[scan.last])) head = `${head.slice(0, scan.last + 1)},${head.slice(scan.last + 1)}`;
|
|
4211
|
+
return `${head.replace(/\s*$/, "")}
|
|
4212
|
+
${snippet}${text.slice(scan.close)}`;
|
|
4213
|
+
}
|
|
4214
|
+
var IDENT;
|
|
4215
|
+
var init_registry_edit = __esm({
|
|
4216
|
+
"src/blocks/registry-edit.ts"() {
|
|
4217
|
+
IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
4218
|
+
}
|
|
4219
|
+
});
|
|
4220
|
+
function routerRoot2(root) {
|
|
4221
|
+
try {
|
|
4222
|
+
const config = JSON.parse(readFileSync(path28.join(root, "genesis.config.json"), "utf8"));
|
|
4223
|
+
const configured = config.doctor?.native?.routerRoot;
|
|
4224
|
+
if (configured && existsSync(path28.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
4225
|
+
} catch {
|
|
4226
|
+
}
|
|
4227
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path28.join(root, dir, "_layout.tsx"))) return dir;
|
|
4228
|
+
return null;
|
|
4229
|
+
}
|
|
4230
|
+
function routeOf(file) {
|
|
4231
|
+
if (!/\.(tsx|ts|jsx|js)$/.test(file)) return null;
|
|
4232
|
+
const parts = file.replace(/\.(tsx|ts|jsx|js)$/, "").split("/");
|
|
4233
|
+
const last = parts[parts.length - 1];
|
|
4234
|
+
if (last.startsWith("_") || last.startsWith("+")) return null;
|
|
4235
|
+
const segments = parts.filter((p) => !/^\(.*\)$/.test(p));
|
|
4236
|
+
if (segments[segments.length - 1] === "index") segments.pop();
|
|
4237
|
+
return `/${segments.join("/")}`;
|
|
4238
|
+
}
|
|
4239
|
+
function planRouteStubs(root, routes) {
|
|
4240
|
+
const dir = routerRoot2(root);
|
|
4241
|
+
if (!dir) return { routerRoot: null, stubs: routes.map((route) => ({ route, file: null })) };
|
|
4242
|
+
const files = listApp(root, dir).map((f) => f.slice(dir.length + 1));
|
|
4243
|
+
const byRoute = /* @__PURE__ */ new Map();
|
|
4244
|
+
for (const f of files) {
|
|
4245
|
+
const r = routeOf(f);
|
|
4246
|
+
if (r && !byRoute.has(r)) byRoute.set(r, `${dir}/${f}`);
|
|
4247
|
+
}
|
|
4248
|
+
const groups = [...new Set(files.map((f) => f.split("/")[0]).filter((s) => /^\(.*\)$/.test(s) && files.includes(`${s}/_layout.tsx`)))];
|
|
4249
|
+
const stubs = routes.map((route) => {
|
|
4250
|
+
const existing = byRoute.get(route.path.replace(/\/+$/, "") || "/");
|
|
4251
|
+
if (existing) return { route, file: null, existing };
|
|
4252
|
+
const segments = route.path.replace(/^\/|\/+$/g, "").split("/").filter(Boolean);
|
|
4253
|
+
if (!segments.length) return { route, file: null };
|
|
4254
|
+
const group = route.signedIn && groups.length === 1 ? `${groups[0]}/` : "";
|
|
4255
|
+
return { route, file: `${dir}/${group}${segments.join("/")}.tsx` };
|
|
4256
|
+
});
|
|
4257
|
+
return { routerRoot: dir, stubs };
|
|
4258
|
+
}
|
|
4259
|
+
function routeStub(blockId, route) {
|
|
4260
|
+
const description = (route.description ?? "Replace it with the block's screen").replace(/[\r\n\u2028\u2029]+/g, " ");
|
|
4261
|
+
return `// A stub for the ${blockId} block's ${route.path} screen, written by \`genesis add ${blockId}\`.
|
|
4262
|
+
// ${description}. See the block's README for the screen to render here.
|
|
4263
|
+
import { ScreenContainer } from "@marktiderman/genesis-ui-native";
|
|
4264
|
+
|
|
4265
|
+
export default function Screen() {
|
|
4266
|
+
return <ScreenContainer />;
|
|
4267
|
+
}
|
|
4268
|
+
`;
|
|
4269
|
+
}
|
|
4270
|
+
var init_routes = __esm({
|
|
4271
|
+
"src/blocks/routes.ts"() {
|
|
4272
|
+
init_files();
|
|
4273
|
+
}
|
|
4274
|
+
});
|
|
4275
|
+
|
|
4276
|
+
// src/blocks/add.ts
|
|
4277
|
+
var add_exports = {};
|
|
4278
|
+
__export(add_exports, {
|
|
4279
|
+
agentsFragment: () => agentsFragment,
|
|
4280
|
+
ownedWrites: () => ownedWrites,
|
|
4281
|
+
recordOwned: () => recordOwned,
|
|
4282
|
+
registryFile: () => registryFile,
|
|
4283
|
+
runAdd: () => runAdd,
|
|
4284
|
+
sourceMigrations: () => sourceMigrations
|
|
4285
|
+
});
|
|
4286
|
+
function appDependencies(root) {
|
|
4287
|
+
try {
|
|
4288
|
+
const pkg = JSON.parse(readFileSync(path28.join(root, "package.json"), "utf8"));
|
|
4289
|
+
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
4290
|
+
} catch {
|
|
4291
|
+
return {};
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
function registryFile(root) {
|
|
4295
|
+
const read = (file, key) => {
|
|
4296
|
+
try {
|
|
4297
|
+
const v = JSON.parse(readFileSync(path28.join(root, file), "utf8"))[key]?.registry;
|
|
4298
|
+
return typeof v === "string" ? v : void 0;
|
|
4299
|
+
} catch {
|
|
4300
|
+
return void 0;
|
|
4301
|
+
}
|
|
4302
|
+
};
|
|
4303
|
+
const named = read("genesis.config.json", "features") ?? read("package.json", "genesisFeatures");
|
|
4304
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path28.join(root, candidate))) return candidate;
|
|
4305
|
+
return null;
|
|
4306
|
+
}
|
|
4307
|
+
async function registryIds(root, file) {
|
|
4308
|
+
try {
|
|
4309
|
+
const { loadRegistry: loadRegistry2 } = await Promise.resolve().then(() => (init_features(), features_exports));
|
|
4310
|
+
return new Set(Object.keys((await loadRegistry2({ dir: root, registry: file })).features));
|
|
4311
|
+
} catch {
|
|
4312
|
+
return null;
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4315
|
+
function sourceMigrations(root, manifest) {
|
|
4316
|
+
return manifest.migrations.map((m) => {
|
|
4317
|
+
const dir = packageDir(root, m.package);
|
|
4318
|
+
return {
|
|
4319
|
+
...m,
|
|
4320
|
+
block: manifest.id,
|
|
4321
|
+
source: dir ? readPackageFile(dir, m.file) : null,
|
|
4322
|
+
...m.test ? { testSource: dir ? readPackageFile(dir, m.test) : null } : {}
|
|
4323
|
+
};
|
|
4324
|
+
});
|
|
4325
|
+
}
|
|
4326
|
+
function ownedWrites(root, manifest, warnings) {
|
|
4327
|
+
const out = [];
|
|
4328
|
+
for (const fn of manifest.functions) {
|
|
4329
|
+
const dir = packageDir(root, fn.package);
|
|
4330
|
+
const skipped = [];
|
|
4331
|
+
const files = dir ? readPackageDir(dir, fn.dir, skipped) : null;
|
|
4332
|
+
if (skipped.length) warnings.push(`${fn.package} ${fn.dir}: only its own files are copied; left out ${skipped.join(", ")}.`);
|
|
4333
|
+
const name = fn.dir.split("/").pop();
|
|
4334
|
+
if (!files) {
|
|
4335
|
+
warnings.push(`${fn.package} ${fn.dir}: can't read it (not installed?); the ${name} function wasn't copied.`);
|
|
4336
|
+
continue;
|
|
4337
|
+
}
|
|
4338
|
+
const version = packageVersion(dir);
|
|
4339
|
+
for (const f of files) out.push({ path: `supabase/functions/${name}/${f.name}`, source: `${fn.package}:${fn.dir}/${f.name}`, content: f.content, ...version ? { version } : {} });
|
|
4340
|
+
}
|
|
4341
|
+
for (const skill of manifest.skills) {
|
|
4342
|
+
const dir = packageDir(root, skill.package);
|
|
4343
|
+
const content = dir ? readPackageFile(dir, skill.path) : null;
|
|
4344
|
+
if (!dir || content === null) {
|
|
4345
|
+
warnings.push(`${skill.package} ${skill.path}: can't read it (not installed?); the skill wasn't copied.`);
|
|
4346
|
+
continue;
|
|
4347
|
+
}
|
|
4348
|
+
const version = packageVersion(dir);
|
|
4349
|
+
const name = skillName(content, skill.path);
|
|
4350
|
+
const folder = skill.path.split("/").slice(0, -1).join("/");
|
|
4351
|
+
const files = folder ? readPackageDir(dir, folder) ?? [] : [{ name: "SKILL.md", content }];
|
|
4352
|
+
for (const f of files) out.push({ path: `.claude/skills/${name}/${f.name}`, source: `${skill.package}:${folder ? `${folder}/` : ""}${f.name}`, content: f.content, ...version ? { version } : {} });
|
|
4353
|
+
}
|
|
4354
|
+
return out;
|
|
4355
|
+
}
|
|
4356
|
+
function agentsFragment(root, manifest) {
|
|
4357
|
+
if (!manifest.agents) return null;
|
|
4358
|
+
const dir = packageDir(root, manifest.agents.package);
|
|
4359
|
+
const text = dir ? readPackageFile(dir, manifest.agents.path) : null;
|
|
4360
|
+
return text === null ? null : { text, source: `${manifest.agents.package}/${manifest.agents.path}` };
|
|
4361
|
+
}
|
|
4362
|
+
function configTomlEdit(root, manifest, tomlWarnings = []) {
|
|
4363
|
+
const config = readApp(root, "supabase/config.toml");
|
|
4364
|
+
if (config === null) return null;
|
|
4365
|
+
const names = manifest.functions.filter((f) => f.verifyJwt === false).map((f) => f.dir.split("/").pop()).filter((name) => !new RegExp(`^\\s*\\[\\s*functions\\.("?)${name.replace(/[-_]/g, "\\$&")}\\1\\s*\\]`, "m").test(config));
|
|
4366
|
+
for (const f of manifest.functions.filter((fn) => fn.verifyJwt === false)) {
|
|
4367
|
+
const name = f.dir.split("/").pop();
|
|
4368
|
+
if (!names.includes(name) && !new RegExp(`\\[\\s*functions\\.("?)${name.replace(/[-_]/g, "\\$&")}\\1\\s*\\][^[]*verify_jwt\\s*=\\s*false`).test(config)) {
|
|
4369
|
+
tomlWarnings.push(`supabase/config.toml has [functions.${name}] without verify_jwt = false; ${name} checks its caller itself, so set it (left as it is).`);
|
|
4370
|
+
}
|
|
4371
|
+
}
|
|
4372
|
+
if (!names.length) return null;
|
|
4373
|
+
const add = names.map((n) => `
|
|
4374
|
+
# Added by \`genesis add ${manifest.id}\`: the function checks its caller itself.
|
|
4375
|
+
[functions.${n}]
|
|
4376
|
+
verify_jwt = false
|
|
4377
|
+
`).join("");
|
|
4378
|
+
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
4379
|
+
}
|
|
4380
|
+
async function runAdd(options) {
|
|
4381
|
+
const root = path28.resolve(options.root);
|
|
4382
|
+
const log = options.log ?? SILENT;
|
|
4383
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
4384
|
+
const warnings = [];
|
|
4385
|
+
const install = options.install !== false;
|
|
4386
|
+
let found = await findBlock(root, options.block, { ...options.package ? { package: options.package } : {}, warnings });
|
|
4387
|
+
const lock = readLock(root);
|
|
4388
|
+
const deps = appDependencies(root);
|
|
4389
|
+
const pm = detectPackageManager(root);
|
|
4390
|
+
const specs = [];
|
|
4391
|
+
for (const name of found.manifest.packages) {
|
|
4392
|
+
if (deps[name]) continue;
|
|
4393
|
+
const pin = pinnedVersion(root, name);
|
|
4394
|
+
specs.push(pin ? `${name}@${pin.version}` : name);
|
|
4395
|
+
}
|
|
4396
|
+
for (const spec of found.manifest.install) {
|
|
4397
|
+
const name = spec.startsWith("@") ? `@${spec.slice(1).split("@")[0]}` : spec.split("@")[0];
|
|
4398
|
+
if (!deps[name]) specs.push(spec);
|
|
4399
|
+
}
|
|
4400
|
+
const command = specs.length ? addCommand(pm, specs) : null;
|
|
4401
|
+
const registry = registryFile(root);
|
|
4402
|
+
const ids = registry ? await registryIds(root, registry) : null;
|
|
4403
|
+
const blockIds = new Set((await allBlocks(root)).map((b) => b.manifest.id));
|
|
4404
|
+
for (const req of found.manifest.requires) {
|
|
4405
|
+
if (lock.blocks[req] || ids?.has(req)) continue;
|
|
4406
|
+
warnings.push(blockIds.has(req) ? `${options.block} requires the ${req} block: add it too (genesis add ${req}), unless the app already has it.` : `${options.block} requires the ${req} feature; make sure the app has it.`);
|
|
4407
|
+
}
|
|
4408
|
+
const steps = [];
|
|
4409
|
+
const kept = [];
|
|
4410
|
+
const created = [];
|
|
4411
|
+
const edited = [];
|
|
4412
|
+
const makePlan = (manifest2, from) => {
|
|
4413
|
+
const planWarnings = [];
|
|
4414
|
+
const migrations2 = planMigrations(root, sourceMigrations(root, manifest2), { now });
|
|
4415
|
+
const owned2 = ownedWrites(root, manifest2, planWarnings).map((w) => ({ ...w, content: substitute(w.content, lock.substitutions) }));
|
|
4416
|
+
const fragment2 = agentsFragment(root, manifest2);
|
|
4417
|
+
if (manifest2.agents && !fragment2) planWarnings.push(`${manifest2.agents.package} ${manifest2.agents.path}: can't read it; AGENTS.md wasn't changed.`);
|
|
4418
|
+
const { routerRoot: routerRoot4, stubs: stubs2 } = planRouteStubs(root, manifest2.routes);
|
|
4419
|
+
const toml2 = configTomlEdit(root, manifest2, planWarnings);
|
|
4420
|
+
let snippet2;
|
|
4421
|
+
let registryEdit2 = null;
|
|
4422
|
+
if (!ids?.has(manifest2.id)) {
|
|
4423
|
+
const owner = JSON.parse(readApp(root, "package.json") ?? "{}").name ?? "app";
|
|
4424
|
+
snippet2 = featureSnippet(manifest2, owner);
|
|
4425
|
+
if (registry) registryEdit2 = addFeatureEntry(readApp(root, registry) ?? "", snippet2);
|
|
4426
|
+
}
|
|
4427
|
+
const print = (mark, p, note = "") => log.info(` ${mark} ${p}${note ? ` ${note}` : ""}`);
|
|
4428
|
+
log.info(`${manifest2.id}: from ${manifest2.package}${manifest2.version ? ` ${manifest2.version}` : ""} (${from === "installed" ? "installed" : "not installed yet: files are read after the install"})`);
|
|
4429
|
+
if (command) log.info(` install: ${shellLine(command)}${install ? "" : " (skipped: --no-install)"}`);
|
|
4430
|
+
log.info(formatMigrationRows(migrations2.rows).replace(/^/gm, " "));
|
|
4431
|
+
for (const c of migrations2.creates) if (c.kind === "test") print("+", c.path, "(pgTAP test)");
|
|
4432
|
+
for (const w of owned2) {
|
|
4433
|
+
const existing = readApp(root, w.path);
|
|
4434
|
+
print(existing === null ? "+" : existing === w.content ? "=" : "!", w.path, existing !== null && existing !== w.content ? "exists with other text; left alone" : "");
|
|
4435
|
+
}
|
|
4436
|
+
for (const s of stubs2) if (s.file) print(readApp(root, s.file) === null ? "+" : "=", s.file, "(route stub)");
|
|
4437
|
+
if (toml2) print("~", "supabase/config.toml", `([functions.${toml2.names.join("], [functions.")}] verify_jwt = false)`);
|
|
4438
|
+
if (fragment2) print("~", "AGENTS.md", `(${fragmentMarkers(manifest2.id).start})`);
|
|
4439
|
+
if (registryEdit2 && registry) print("~", registry, `(adds ${manifest2.id})`);
|
|
4440
|
+
return { manifest: manifest2, migrations: migrations2, owned: owned2, fragment: fragment2, routerRoot: routerRoot4, stubs: stubs2, toml: toml2, snippet: snippet2, registryEdit: registryEdit2, planWarnings };
|
|
4441
|
+
};
|
|
4442
|
+
let plan = makePlan(found.manifest, found.from);
|
|
4443
|
+
if (!options.dryRun && !options.yes) {
|
|
4444
|
+
const ok = options.confirm ? await options.confirm(`Add ${found.manifest.id} to ${root}?`) : false;
|
|
4445
|
+
if (!ok) throw new Error("Nothing written. Pass --yes to add without asking, or --dry-run to see the plan.");
|
|
4446
|
+
}
|
|
4447
|
+
if (command && install && !options.dryRun) {
|
|
4448
|
+
run(root, command);
|
|
4449
|
+
found = await findBlock(root, options.block, { package: found.manifest.package, warnings });
|
|
4450
|
+
log.info("After the install:");
|
|
4451
|
+
plan = makePlan(found.manifest, found.from);
|
|
4452
|
+
}
|
|
4453
|
+
warnings.push(...plan.planWarnings);
|
|
4454
|
+
if (found.from === "catalog") warnings.push(`${found.manifest.package} isn't installed, so its files can't be read yet: migrations, functions and skills are listed, not copied. Install it and run genesis add ${found.manifest.id} again.`);
|
|
4455
|
+
const { manifest, migrations, owned, fragment, routerRoot: routerRoot3, stubs, toml, snippet, registryEdit } = plan;
|
|
4456
|
+
for (const row of migrations.rows) {
|
|
4457
|
+
if (needsAttention(row)) kept.push({ path: row.copy ?? row.file, why: `${row.state}: ${row.detail}. Run genesis migrate --forward to add a forward migration.` });
|
|
4458
|
+
}
|
|
4459
|
+
for (const stub of stubs) {
|
|
4460
|
+
if (stub.existing) continue;
|
|
4461
|
+
if (!stub.file) steps.push(`Add a ${stub.route.path} screen to your router${stub.route.description ? ` (${stub.route.description})` : ""}${stub.route.signedIn ? ", for signed-in people only" : ""}.`);
|
|
4462
|
+
}
|
|
4463
|
+
for (const fn of manifest.functions) {
|
|
4464
|
+
const name = fn.dir.split("/").pop();
|
|
4465
|
+
if (fn.verifyJwt === false && !readApp(root, "supabase/config.toml")) steps.push(`Deploy ${name} without the gateway's JWT check: supabase functions deploy ${name} --no-verify-jwt`);
|
|
4466
|
+
if (fn.secrets?.length) steps.push(`Set the ${name} function's secrets: supabase secrets set ${fn.secrets.map((s) => `${s}=\u2026`).join(" ")}`);
|
|
4467
|
+
}
|
|
4468
|
+
if (migrations.creates.some((c) => c.kind === "migration")) steps.push("Review the new migrations in supabase/migrations, then apply them (supabase db push, or open a pull request).");
|
|
4469
|
+
steps.push(...manifest.steps);
|
|
4470
|
+
if (manifest.privacy?.collects?.length) steps.push(`Update the App Store privacy label and Play data safety form: ${manifest.id} collects ${manifest.privacy.collects.map((c) => c.type).join(", ")}.`);
|
|
4471
|
+
if (snippet && registry && !registryEdit) steps.push(`Add ${manifest.id} to ${registry} (the edit wasn't safe to make automatically):
|
|
4472
|
+
${snippet}`);
|
|
4473
|
+
if (snippet && !registry) steps.push(`No feature registry (features.ts) here; when you add one, list ${manifest.id}:
|
|
4474
|
+
${snippet}`);
|
|
4475
|
+
if (options.dryRun) return { block: manifest, install: command, migrations, created, kept, edited, steps, ...snippet ? { featureSnippet: snippet } : {}, warnings };
|
|
4476
|
+
created.push(...applyMigrationPlan(root, migrations));
|
|
4477
|
+
for (const c of migrations.creates) if (c.kind === "test" && c.source) recordOwned(lock, c.path, `${c.source.package}:${c.source.file}`, c.content, root, c.source.package);
|
|
4478
|
+
for (const w of owned) {
|
|
4479
|
+
const outcome = copyOwned(root, lock, w);
|
|
4480
|
+
if (outcome === "created") created.push(w.path);
|
|
4481
|
+
if (outcome === "kept") kept.push({ path: w.path, why: `exists with other text; the package's version wasn't copied` });
|
|
4482
|
+
}
|
|
4483
|
+
for (const s of stubs) {
|
|
4484
|
+
if (!s.file || readApp(root, s.file) !== null) continue;
|
|
4485
|
+
createApp(root, s.file, routeStub(manifest.id, s.route));
|
|
4486
|
+
created.push(s.file);
|
|
4487
|
+
steps.push(`Fill in the ${s.route.path} stub (${s.file}) with the block's screen.`);
|
|
4488
|
+
}
|
|
4489
|
+
if (toml) {
|
|
4490
|
+
replaceApp(root, "supabase/config.toml", toml.content);
|
|
4491
|
+
edited.push("supabase/config.toml");
|
|
4492
|
+
}
|
|
4493
|
+
if (fragment) {
|
|
4494
|
+
const before = readApp(root, "AGENTS.md");
|
|
4495
|
+
const after = mergeFragment(before, manifest.id, fragment.text, fragment.source);
|
|
4496
|
+
if (after !== before) {
|
|
4497
|
+
replaceApp(root, "AGENTS.md", after);
|
|
4498
|
+
edited.push("AGENTS.md");
|
|
4499
|
+
}
|
|
4500
|
+
}
|
|
4501
|
+
if (registryEdit && registry) {
|
|
4502
|
+
const before = readApp(root, registry);
|
|
4503
|
+
replaceApp(root, registry, registryEdit);
|
|
4504
|
+
if (!(await registryIds(root, registry))?.has(manifest.id)) {
|
|
4505
|
+
replaceApp(root, registry, before);
|
|
4506
|
+
steps.push(`Add ${manifest.id} to ${registry} (the automatic edit didn't load, so it was undone):
|
|
4507
|
+
${snippet}`);
|
|
4508
|
+
} else edited.push(registry);
|
|
4509
|
+
}
|
|
4510
|
+
if (found.from === "installed") lock.blocks[manifest.id] = { package: manifest.package, ...manifest.version ? { version: manifest.version } : {} };
|
|
4511
|
+
else steps.unshift(`Install ${manifest.packages.join(" and ")}, then run genesis add ${manifest.id} again to copy its files.`);
|
|
4512
|
+
const lockBefore = readApp(root, LOCK_FILE);
|
|
4513
|
+
writeLock(root, lock);
|
|
4514
|
+
if (readApp(root, LOCK_FILE) !== lockBefore) edited.push(LOCK_FILE);
|
|
4515
|
+
if (registry && options.featuresBuild !== false) {
|
|
4516
|
+
try {
|
|
4517
|
+
const { runFeaturesBuild: runFeaturesBuild2 } = await Promise.resolve().then(() => (init_features(), features_exports));
|
|
4518
|
+
const changed = await runFeaturesBuild2({ dir: root });
|
|
4519
|
+
edited.push(...changed);
|
|
4520
|
+
} catch (err) {
|
|
4521
|
+
warnings.push(`features build failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4522
|
+
}
|
|
4523
|
+
}
|
|
4524
|
+
if (!routerRoot3 && manifest.routes.length) warnings.push("No Expo Router root (a _layout.tsx in src/app or app), so no route stubs were written; the steps list the screens.");
|
|
4525
|
+
return { block: manifest, install: command, migrations, created, kept, edited, steps, ...snippet ? { featureSnippet: snippet } : {}, warnings };
|
|
4526
|
+
}
|
|
4527
|
+
function recordOwned(lock, appRel, source, content, root, pkg) {
|
|
4528
|
+
const dir = packageDir(root, pkg);
|
|
4529
|
+
const version = dir ? packageVersion(dir) : void 0;
|
|
4530
|
+
lock.files[appRel] = { source, sha256: sha256(content), ...version ? { version } : {} };
|
|
4531
|
+
}
|
|
4532
|
+
var SILENT;
|
|
4533
|
+
var init_add = __esm({
|
|
4534
|
+
"src/blocks/add.ts"() {
|
|
4535
|
+
init_agents();
|
|
4536
|
+
init_discover();
|
|
4537
|
+
init_files();
|
|
4538
|
+
init_lock();
|
|
4539
|
+
init_migrations();
|
|
4540
|
+
init_owned();
|
|
4541
|
+
init_pm();
|
|
4542
|
+
init_registry_edit();
|
|
4543
|
+
init_routes();
|
|
4544
|
+
SILENT = { info() {
|
|
4545
|
+
}, warn() {
|
|
4546
|
+
} };
|
|
4547
|
+
}
|
|
4548
|
+
});
|
|
4549
|
+
|
|
4550
|
+
// src/blocks/migrate.ts
|
|
4551
|
+
var migrate_exports = {};
|
|
4552
|
+
__export(migrate_exports, {
|
|
4553
|
+
runMigrate: () => runMigrate
|
|
4554
|
+
});
|
|
4555
|
+
async function runMigrate(options) {
|
|
4556
|
+
const root = path28.resolve(options.root);
|
|
4557
|
+
const lock = readLock(root);
|
|
4558
|
+
const warnings = [];
|
|
4559
|
+
const ids = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks), ...options.blocks ?? []])];
|
|
4560
|
+
const sources = [];
|
|
4561
|
+
for (const id of ids) {
|
|
4562
|
+
const pkg = lock.blocks[id]?.package;
|
|
4563
|
+
try {
|
|
4564
|
+
const { manifest } = await findBlock(root, id, { ...pkg ? { package: pkg } : {}, warnings });
|
|
4565
|
+
sources.push(...sourceMigrations(root, manifest));
|
|
4566
|
+
} catch (err) {
|
|
4567
|
+
warnings.push(err instanceof Error ? err.message : String(err));
|
|
4568
|
+
}
|
|
4569
|
+
}
|
|
4570
|
+
for (const copy of readAppMigrations(root)) {
|
|
4571
|
+
const t = copy.tracked;
|
|
4572
|
+
if (!t || sources.some((s) => s.package === t.package && s.file === t.file)) continue;
|
|
4573
|
+
if (!GENESIS_PACKAGE.test(t.package) || !validHeaderFile(t.file)) {
|
|
4574
|
+
warnings.push(`${copy.path}: its genesis-migration header names ${t.package} ${t.file}, which isn't a Genesis package's NNNN_name.sql; skipped.`);
|
|
4575
|
+
continue;
|
|
4576
|
+
}
|
|
4577
|
+
const dir = packageDir(root, t.package);
|
|
4578
|
+
let source = null;
|
|
4579
|
+
try {
|
|
4580
|
+
source = dir ? readPackageFile(dir, t.file) : null;
|
|
4581
|
+
} catch (err) {
|
|
4582
|
+
warnings.push(`${copy.path}: ${err instanceof Error ? err.message : String(err)}`);
|
|
4583
|
+
}
|
|
4584
|
+
sources.push({ package: t.package, file: t.file, source });
|
|
4585
|
+
}
|
|
4586
|
+
if (!ids.length && !sources.length) warnings.push("No blocks in genesis.lock.json and no copied package migrations: nothing to compare. Add a block (genesis add <block>), or pass --block.");
|
|
4587
|
+
const plan = planMigrations(root, sources, { now: options.now ?? /* @__PURE__ */ new Date(), ...options.forward ? { forward: true } : {} });
|
|
4588
|
+
const attention = plan.rows.some(needsAttention);
|
|
4589
|
+
if (options.dryRun) return { plan, written: [], warnings, attention };
|
|
4590
|
+
const written = applyMigrationPlan(root, plan);
|
|
4591
|
+
for (const c of plan.creates) if (c.kind === "test" && c.source) recordOwned(lock, c.path, `${c.source.package}:${c.source.file}`, c.content, root, c.source.package);
|
|
4592
|
+
if (plan.creates.some((c) => c.kind === "test")) writeLock(root, lock);
|
|
4593
|
+
return { plan, written, warnings, attention };
|
|
4594
|
+
}
|
|
4595
|
+
var init_migrate = __esm({
|
|
4596
|
+
"src/blocks/migrate.ts"() {
|
|
4597
|
+
init_discover();
|
|
4598
|
+
init_files();
|
|
4599
|
+
init_lock();
|
|
4600
|
+
init_manifest();
|
|
4601
|
+
init_migrations();
|
|
4602
|
+
init_add();
|
|
4603
|
+
}
|
|
4604
|
+
});
|
|
4605
|
+
|
|
4606
|
+
// src/upgrade/bump-core.mjs
|
|
4607
|
+
function compareVersions(a, b) {
|
|
4608
|
+
const [ca, pa = ""] = a.split(/-(.*)/s);
|
|
4609
|
+
const [cb, pb = ""] = b.split(/-(.*)/s);
|
|
4610
|
+
const x = ca.split(".").map(Number), y = cb.split(".").map(Number);
|
|
4611
|
+
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] - y[i];
|
|
4612
|
+
if (!pa || !pb) return (pa ? 0 : 1) - (pb ? 0 : 1);
|
|
4613
|
+
const fa = pa.split("."), fb = pb.split(".");
|
|
4614
|
+
for (let i = 0; i < Math.max(fa.length, fb.length); i++) {
|
|
4615
|
+
if (fa[i] === void 0) return -1;
|
|
4616
|
+
if (fb[i] === void 0) return 1;
|
|
4617
|
+
const na = /^\d+$/.test(fa[i]), nb = /^\d+$/.test(fb[i]);
|
|
4618
|
+
if (na && nb && Number(fa[i]) !== Number(fb[i])) return Number(fa[i]) - Number(fb[i]);
|
|
4619
|
+
if (na !== nb) return na ? -1 : 1;
|
|
4620
|
+
if (fa[i] !== fb[i]) return fa[i] < fb[i] ? -1 : 1;
|
|
4621
|
+
}
|
|
4622
|
+
return 0;
|
|
4623
|
+
}
|
|
4624
|
+
function bumpPackageJson(file, text, wanted) {
|
|
4625
|
+
const pkg = JSON.parse(text);
|
|
4626
|
+
const changes = [], skipped = [];
|
|
4627
|
+
for (const section of SECTIONS) {
|
|
4628
|
+
for (const [name, spec] of Object.entries(pkg[section] ?? {})) {
|
|
4629
|
+
if (!GENESIS.test(name)) continue;
|
|
4630
|
+
const m = EXACT.exec(spec);
|
|
4631
|
+
if (!m) {
|
|
4632
|
+
skipped.push({ file, name, spec, why: "not a plain version" });
|
|
4633
|
+
continue;
|
|
4634
|
+
}
|
|
4635
|
+
const want = wanted(name);
|
|
4636
|
+
if (!want) {
|
|
4637
|
+
skipped.push({ file, name, spec, why: "no latest version on npm" });
|
|
4638
|
+
continue;
|
|
4639
|
+
}
|
|
4640
|
+
if (!PLAIN.test(want)) {
|
|
4641
|
+
skipped.push({ file, name, spec, why: `the release names ${JSON.stringify(want)}, not a version` });
|
|
4642
|
+
continue;
|
|
4643
|
+
}
|
|
4644
|
+
const cmp = compareVersions(want, m[2]);
|
|
4645
|
+
if (cmp === 0) continue;
|
|
4646
|
+
if (cmp < 0) {
|
|
4647
|
+
skipped.push({ file, name, spec, why: `newer than ${want}` });
|
|
4648
|
+
continue;
|
|
4649
|
+
}
|
|
4650
|
+
pkg[section][name] = `${m[1] ?? ""}${want}`;
|
|
4651
|
+
changes.push({ file, name, from: spec, to: pkg[section][name] });
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
if (!changes.length) return { text: null, changes, skipped };
|
|
4655
|
+
const indent = /^[ \t]+(?=")/m.exec(text)?.[0] ?? " ";
|
|
4656
|
+
return { text: JSON.stringify(pkg, null, indent) + (text.endsWith("\n") ? "\n" : ""), changes, skipped };
|
|
4657
|
+
}
|
|
4658
|
+
function bumpSummary(version, changes, skipped) {
|
|
4659
|
+
const row = (c) => `| \`${c.name}\` | ${c.from} | ${c.to} | ${c.file} |`;
|
|
4660
|
+
return [
|
|
4661
|
+
`Moves every Genesis package to the **${UMBRELLA}@${version}** release: the versions in its \`versions.json\`, and npm \`latest\` for packages it doesn't list.`,
|
|
4662
|
+
"",
|
|
4663
|
+
changes.length ? ["| Package | From | To | File |", "| --- | --- | --- | --- |", ...changes.map(row)].join("\n") : "Nothing to change.",
|
|
4664
|
+
...skipped.length ? ["", "Left alone:", "", ...skipped.map((s) => `- \`${s.name}\` ${s.spec} in ${s.file}: ${s.why}`)] : []
|
|
4665
|
+
].join("\n");
|
|
4666
|
+
}
|
|
4667
|
+
var UMBRELLA, GENESIS, EXACT, PLAIN, SECTIONS;
|
|
4668
|
+
var init_bump_core = __esm({
|
|
4669
|
+
"src/upgrade/bump-core.mjs"() {
|
|
4670
|
+
UMBRELLA = "@marktiderman/genesis";
|
|
4671
|
+
GENESIS = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
4672
|
+
EXACT = /^(\^|~|=)?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/;
|
|
4673
|
+
PLAIN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
4674
|
+
SECTIONS = ["dependencies", "devDependencies", "optionalDependencies"];
|
|
4675
|
+
}
|
|
4676
|
+
});
|
|
4677
|
+
|
|
4678
|
+
// src/upgrade/codemods.ts
|
|
4679
|
+
function codemodsFor(changes, registry = CODEMODS) {
|
|
4680
|
+
return registry.filter(
|
|
4681
|
+
(mod) => changes.some((c) => c.name === mod.package && compareVersions(bare(c.from), mod.version) < 0 && compareVersions(bare(c.to), mod.version) >= 0)
|
|
4682
|
+
);
|
|
4683
|
+
}
|
|
4684
|
+
function uncoveredBreaks(changes, registry = CODEMODS) {
|
|
4685
|
+
const major = (v) => {
|
|
4686
|
+
const [a, b] = bare(v).split(".").map(Number);
|
|
4687
|
+
return a === 0 ? `0.${b}` : String(a);
|
|
4688
|
+
};
|
|
4689
|
+
return changes.filter((c) => major(c.from) !== major(c.to) && codemodsFor([c], registry).length === 0);
|
|
4690
|
+
}
|
|
4691
|
+
var CODEMODS, bare;
|
|
4692
|
+
var init_codemods = __esm({
|
|
4693
|
+
"src/upgrade/codemods.ts"() {
|
|
4694
|
+
init_bump_core();
|
|
4695
|
+
CODEMODS = [];
|
|
4696
|
+
bare = (spec) => spec.replace(/^[\^~=]/, "");
|
|
4697
|
+
}
|
|
4698
|
+
});
|
|
4699
|
+
|
|
4700
|
+
// src/upgrade/index.ts
|
|
4701
|
+
var upgrade_exports = {};
|
|
4702
|
+
__export(upgrade_exports, {
|
|
4703
|
+
npmLookup: () => npmLookup,
|
|
4704
|
+
runUpgrade: () => runUpgrade
|
|
4705
|
+
});
|
|
4706
|
+
function npm(args, cwd) {
|
|
4707
|
+
return execFileSync("npm", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
4708
|
+
}
|
|
4709
|
+
function npmLookup(cwd) {
|
|
4710
|
+
const latest = /* @__PURE__ */ new Map();
|
|
4711
|
+
return {
|
|
4712
|
+
release(target) {
|
|
4713
|
+
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
4714
|
+
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
4715
|
+
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
4716
|
+
const tmp = mkdtempSync(path28.join(tmpdir(), "genesis-umbrella-"));
|
|
4717
|
+
try {
|
|
4718
|
+
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
4719
|
+
execFileSync("tar", ["-xzf", path28.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
4720
|
+
const manifest = JSON.parse(readFileSync(path28.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
4721
|
+
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
4722
|
+
return manifest;
|
|
4723
|
+
} finally {
|
|
4724
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
4725
|
+
}
|
|
4726
|
+
},
|
|
4727
|
+
latest(name) {
|
|
4728
|
+
if (!latest.has(name)) {
|
|
4729
|
+
let v = null;
|
|
4730
|
+
try {
|
|
4731
|
+
v = JSON.parse(npm(["view", `${name}@latest`, "version", "--json"], cwd) || "null");
|
|
4732
|
+
} catch {
|
|
4733
|
+
}
|
|
4734
|
+
latest.set(name, typeof v === "string" ? v : null);
|
|
4735
|
+
}
|
|
4736
|
+
return latest.get(name);
|
|
4737
|
+
}
|
|
4738
|
+
};
|
|
4739
|
+
}
|
|
4740
|
+
function packageJsons(root) {
|
|
4741
|
+
try {
|
|
4742
|
+
const out = execFileSync("git", ["ls-files", "-z", "--", ":(glob)**/package.json"], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
4743
|
+
const files = out.split("\0").filter(Boolean);
|
|
4744
|
+
if (files.length) return files;
|
|
4745
|
+
} catch {
|
|
4746
|
+
}
|
|
4747
|
+
return existsSync(path28.join(root, "package.json")) ? ["package.json"] : [];
|
|
4748
|
+
}
|
|
4749
|
+
function sourceText(root, source, substitutions) {
|
|
4750
|
+
const { package: pkg, path: rel } = parseSource(source);
|
|
4751
|
+
const dir = packageDir(root, pkg);
|
|
4752
|
+
if (!dir) return null;
|
|
4753
|
+
try {
|
|
4754
|
+
if (pkg === "@marktiderman/genesis-cli" && rel.startsWith("templates/")) {
|
|
4755
|
+
const templates = templatesDir(dir);
|
|
4756
|
+
const text2 = readPackageFile(templates, rel.slice("templates/".length));
|
|
4757
|
+
return text2 === null ? null : substitute(text2, substitutions);
|
|
4758
|
+
}
|
|
4759
|
+
const text = readPackageFile(dir, rel);
|
|
4760
|
+
return text === null ? null : substitute(text, substitutions);
|
|
4761
|
+
} catch {
|
|
4762
|
+
return null;
|
|
4763
|
+
}
|
|
4764
|
+
}
|
|
4765
|
+
async function runUpgrade(options) {
|
|
4766
|
+
const root = path28.resolve(options.root);
|
|
4767
|
+
const log = options.log ?? (() => {
|
|
4768
|
+
});
|
|
4769
|
+
const lookup = options.lookup ?? npmLookup(root);
|
|
4770
|
+
const release = options.manifest ? JSON.parse(readFileSync(path28.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
4771
|
+
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
4772
|
+
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
4773
|
+
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
4774
|
+
const next = /* @__PURE__ */ new Set();
|
|
4775
|
+
const changes = [];
|
|
4776
|
+
const skipped = [];
|
|
4777
|
+
const bumped = /* @__PURE__ */ new Map();
|
|
4778
|
+
for (const file of packageJsons(root)) {
|
|
4779
|
+
const text = readApp(root, file);
|
|
4780
|
+
if (text === null) continue;
|
|
4781
|
+
const result = bumpPackageJson(file, text, wanted);
|
|
4782
|
+
changes.push(...result.changes);
|
|
4783
|
+
skipped.push(...result.skipped);
|
|
4784
|
+
if (result.text !== null) bumped.set(file, result.text);
|
|
4785
|
+
}
|
|
4786
|
+
const mods = codemodsFor(changes, options.codemods ?? CODEMODS);
|
|
4787
|
+
const breaks = uncoveredBreaks(changes, options.codemods ?? CODEMODS);
|
|
4788
|
+
const lock = readLock(root);
|
|
4789
|
+
checkSubstitutions(lock.substitutions);
|
|
4790
|
+
const bases = /* @__PURE__ */ new Map();
|
|
4791
|
+
for (const [file, entry] of Object.entries(lock.files)) {
|
|
4792
|
+
if (ownedKeyProblem(file, entry.source)) continue;
|
|
4793
|
+
const text = sourceText(root, entry.source, lock.substitutions);
|
|
4794
|
+
if (text !== null && sha256(text) === entry.sha256) bases.set(file, text);
|
|
4795
|
+
}
|
|
4796
|
+
const files = /* @__PURE__ */ new Set();
|
|
4797
|
+
const codemodRuns = [];
|
|
4798
|
+
if (!options.dryRun) {
|
|
4799
|
+
for (const [file, text] of bumped) {
|
|
4800
|
+
replaceApp(root, file, text);
|
|
4801
|
+
files.add(file);
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4804
|
+
for (const mod of mods) {
|
|
4805
|
+
log(`codemod ${mod.id}: ${mod.description}`);
|
|
4806
|
+
const changed = await mod.run({ root, dryRun: Boolean(options.dryRun), log });
|
|
4807
|
+
codemodRuns.push({ id: mod.id, files: changed });
|
|
4808
|
+
for (const f of changed) files.add(f);
|
|
4809
|
+
}
|
|
4810
|
+
const pm = detectPackageManager(root);
|
|
4811
|
+
if (!options.dryRun && options.install !== false && bumped.size) {
|
|
4812
|
+
if (typeof options.install === "function") options.install(root);
|
|
4813
|
+
else {
|
|
4814
|
+
log(`install: ${shellLine(installCommand(pm))}`);
|
|
4815
|
+
run(root, installCommand(pm));
|
|
4816
|
+
}
|
|
4817
|
+
}
|
|
4818
|
+
const added = [];
|
|
4819
|
+
const newMigrations = [];
|
|
4820
|
+
const warnings = [];
|
|
4821
|
+
const manifests = [];
|
|
4822
|
+
for (const [id, entry] of Object.entries(lock.blocks)) {
|
|
4823
|
+
try {
|
|
4824
|
+
const { manifest } = await findBlock(root, id, { package: entry.package, warnings });
|
|
4825
|
+
manifests.push(manifest);
|
|
4826
|
+
for (const row of planMigrations(root, sourceMigrations(root, manifest), { now: /* @__PURE__ */ new Date(), tests: false }).rows) {
|
|
4827
|
+
if (row.state === "new") newMigrations.push(`${row.package} ${row.file}`);
|
|
4828
|
+
}
|
|
4829
|
+
if (manifest.version && manifest.version !== entry.version) lock.blocks[id] = { ...entry, version: manifest.version };
|
|
4830
|
+
} catch (err) {
|
|
4831
|
+
warnings.push(err instanceof Error ? err.message : String(err));
|
|
4832
|
+
}
|
|
4833
|
+
}
|
|
4834
|
+
const refreshed = [];
|
|
4835
|
+
for (const [file, entry] of Object.entries(lock.files)) {
|
|
4836
|
+
if (newMigrations.length && file.startsWith(`${TESTS_DIR}/`)) {
|
|
4837
|
+
refreshed.push({ path: file, outcome: "deferred", detail: "new package migrations are waiting: run genesis migrate, then genesis upgrade again" });
|
|
4838
|
+
continue;
|
|
4839
|
+
}
|
|
4840
|
+
const problem = ownedKeyProblem(file, entry.source);
|
|
4841
|
+
const theirs = problem ? null : sourceText(root, entry.source, lock.substitutions);
|
|
4842
|
+
const dir = problem ? null : packageDir(root, parseSource(entry.source).package);
|
|
4843
|
+
const version = dir ? packageVersion(dir) : void 0;
|
|
4844
|
+
const outcome = refreshOwned(root, lock, { path: file, theirs, base: bases.get(file) ?? null, ...version ? { version } : {} }, { ...options.dryRun ? { dryRun: true } : {}, ...options.keepMine ? { keepMine: true } : {} });
|
|
4845
|
+
refreshed.push(outcome);
|
|
4846
|
+
if (outcome.outcome === "updated" || outcome.outcome === "merged") files.add(file);
|
|
4847
|
+
if ((outcome.outcome === "conflict" || outcome.outcome === "kept-mine") && !outcome.detail?.includes("already there")) next.add(`${file}.genesis-next`);
|
|
4848
|
+
}
|
|
4849
|
+
for (const manifest of manifests) {
|
|
4850
|
+
for (const w of ownedWrites(root, manifest, warnings)) {
|
|
4851
|
+
if (lock.files[w.path]) continue;
|
|
4852
|
+
const outcome = copyOwned(root, lock, { ...w, content: substitute(w.content, lock.substitutions) }, options.dryRun);
|
|
4853
|
+
if (outcome === "created") {
|
|
4854
|
+
added.push(w.path);
|
|
4855
|
+
files.add(w.path);
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
const fragment = agentsFragment(root, manifest);
|
|
4859
|
+
if (fragment) {
|
|
4860
|
+
const before = readApp(root, "AGENTS.md");
|
|
4861
|
+
const after = mergeFragment(before, manifest.id, fragment.text, fragment.source);
|
|
4862
|
+
if (after !== before) {
|
|
4863
|
+
if (!options.dryRun) replaceApp(root, "AGENTS.md", after);
|
|
4864
|
+
files.add("AGENTS.md");
|
|
4865
|
+
}
|
|
4866
|
+
}
|
|
4867
|
+
}
|
|
4868
|
+
if (!options.dryRun) {
|
|
4869
|
+
const before = readApp(root, LOCK_FILE);
|
|
4870
|
+
writeLock(root, lock);
|
|
4871
|
+
if (readApp(root, LOCK_FILE) !== before) files.add(LOCK_FILE);
|
|
4872
|
+
}
|
|
4873
|
+
let doctor = "not run";
|
|
4874
|
+
if (options.doctor !== false) {
|
|
4875
|
+
try {
|
|
4876
|
+
const { runDoctor: runDoctor2, formatReport: formatReport2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
4877
|
+
const result = await runDoctor2({ root });
|
|
4878
|
+
log(formatReport2(result));
|
|
4879
|
+
doctor = result.ok ? "passed" : "failed";
|
|
4880
|
+
} catch (err) {
|
|
4881
|
+
log(`genesis doctor couldn't run: ${err instanceof Error ? err.message : String(err)}`);
|
|
4882
|
+
doctor = "failed";
|
|
4883
|
+
}
|
|
4884
|
+
}
|
|
4885
|
+
const lines = [bumpSummary(release.version, changes, skipped)];
|
|
4886
|
+
if (codemodRuns.length) lines.push("", "Codemods:", "", ...codemodRuns.map((c) => `- ${c.id}${c.files.length ? `: ${c.files.join(", ")}` : ""}`));
|
|
4887
|
+
if (breaks.length) lines.push("", "Major moves with no codemod (read their changelogs):", "", ...breaks.map((b) => `- \`${b.name}\` ${b.from} \u2192 ${b.to}`));
|
|
4888
|
+
const touched = refreshed.filter((r) => r.outcome !== "unchanged");
|
|
4889
|
+
if (touched.length || added.length) {
|
|
4890
|
+
lines.push("", options.dryRun ? "Files Genesis owns (against the packages installed now; a real run compares with the new versions after the install):" : "Files Genesis owns:", "", ...touched.map((r) => `- ${r.path}: ${r.outcome}${r.detail ? ` (${r.detail})` : ""}`), ...added.map((a) => `- ${a}: added`));
|
|
4891
|
+
}
|
|
4892
|
+
if (next.size) lines.push("", "Review and delete these before merging (not committed by --pr):", "", ...[...next].map((n) => `- ${n}`));
|
|
4893
|
+
if (lock.substitutions && Object.keys(lock.substitutions).length) lines.push("", `Templates renamed with genesis.lock.json's substitutions: ${Object.entries(lock.substitutions).map(([a, b]) => `${a} \u2192 ${b}`).join(", ")}.`);
|
|
4894
|
+
if (newMigrations.length) lines.push("", "New package migrations (run `genesis migrate` to copy them):", "", ...newMigrations.map((m) => `- ${m}`));
|
|
4895
|
+
if (warnings.length) lines.push("", "Warnings:", "", ...warnings.map((w) => `- ${w}`));
|
|
4896
|
+
lines.push("", `\`genesis doctor\` ${doctor === "not run" ? "was not run" : doctor} after the upgrade.`);
|
|
4897
|
+
const summary = lines.join("\n");
|
|
4898
|
+
const report = { version: release.version, changes, skipped, codemods: codemodRuns, breaks, refreshed, added, newMigrations, doctor, files: [...files].sort(), summary };
|
|
4899
|
+
if (options.pr && !options.dryRun && files.size) report.pr = openPullRequest(root, release.version, report, prBase);
|
|
4900
|
+
return report;
|
|
4901
|
+
}
|
|
4902
|
+
function checkSubstitutions(substitutions) {
|
|
4903
|
+
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
4904
|
+
let allowed;
|
|
4905
|
+
try {
|
|
4906
|
+
const was = starterIdentity(readFileSync(path28.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
4907
|
+
allowed = [was.name, was.slug, was.scheme, was.bundleId];
|
|
4908
|
+
} catch {
|
|
4909
|
+
allowed = [];
|
|
4910
|
+
}
|
|
4911
|
+
for (const [from, to] of Object.entries(substitutions)) {
|
|
4912
|
+
if (!allowed.includes(from) || !SUBSTITUTION_VALUE.test(to)) {
|
|
4913
|
+
throw new Error(`genesis.lock.json: the substitution ${JSON.stringify(from)} \u2192 ${JSON.stringify(to)} isn't one of the starter's names with a plain value; fix the lock by hand.`);
|
|
4914
|
+
}
|
|
4915
|
+
}
|
|
4916
|
+
}
|
|
4917
|
+
function checkPullRequest(root, version) {
|
|
4918
|
+
const git2 = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
4919
|
+
if (git2("status", "--porcelain")) throw new Error("--pr needs a clean working tree (commit or stash your changes first).");
|
|
4920
|
+
const base = git2("rev-parse", "--abbrev-ref", "HEAD");
|
|
4921
|
+
if (base === "HEAD") throw new Error("--pr needs a branch checked out, not a detached HEAD.");
|
|
4922
|
+
const branch = `genesis-upgrade/${version}`;
|
|
4923
|
+
git2("check-ref-format", "--branch", branch);
|
|
4924
|
+
let exists = true;
|
|
4925
|
+
try {
|
|
4926
|
+
git2("rev-parse", "--verify", "--quiet", `refs/heads/${branch}`);
|
|
4927
|
+
} catch {
|
|
4928
|
+
exists = false;
|
|
4929
|
+
}
|
|
4930
|
+
if (exists) throw new Error(`The branch ${branch} already exists; delete it or merge its pull request first.`);
|
|
4931
|
+
return base;
|
|
4932
|
+
}
|
|
4933
|
+
function openPullRequest(root, version, report, base) {
|
|
4934
|
+
const git2 = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
4935
|
+
const branch = `genesis-upgrade/${version}`;
|
|
4936
|
+
git2("switch", "-c", branch);
|
|
4937
|
+
const top = git2("rev-parse", "--show-toplevel");
|
|
4938
|
+
const lockfiles = [];
|
|
4939
|
+
for (let dir = path28.resolve(root); ; dir = path28.dirname(dir)) {
|
|
4940
|
+
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path28.join(dir, f))) lockfiles.push(path28.relative(root, path28.join(dir, f)));
|
|
4941
|
+
if (lockfiles.length || dir === top || path28.dirname(dir) === dir) break;
|
|
4942
|
+
}
|
|
4943
|
+
const paths = [...report.files.filter((f) => existsSync(path28.join(root, f))), ...lockfiles];
|
|
4944
|
+
git2("add", "--", ...paths);
|
|
4945
|
+
git2("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
4946
|
+
git2("push", "-u", "origin", branch);
|
|
4947
|
+
const body = path28.join(mkdtempSync(path28.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
4948
|
+
writeFileSync(body, `${report.summary}
|
|
4949
|
+
|
|
4950
|
+
Opened by \`genesis upgrade --pr\`.
|
|
4951
|
+
`);
|
|
4952
|
+
return execFileSync("gh", ["pr", "create", "--base", base, "--head", branch, "--title", `chore(deps): upgrade Genesis to ${version}`, "--body-file", body], { cwd: root, encoding: "utf8" }).trim();
|
|
4953
|
+
}
|
|
4954
|
+
var EXACT_OR_TAG, SUBSTITUTION_VALUE;
|
|
4955
|
+
var init_upgrade = __esm({
|
|
4956
|
+
"src/upgrade/index.ts"() {
|
|
4957
|
+
init_add();
|
|
4958
|
+
init_agents();
|
|
4959
|
+
init_discover();
|
|
4960
|
+
init_files();
|
|
4961
|
+
init_init_native();
|
|
4962
|
+
init_lock();
|
|
4963
|
+
init_migrations();
|
|
4964
|
+
init_owned();
|
|
4965
|
+
init_pm();
|
|
4966
|
+
init_templates();
|
|
4967
|
+
init_bump_core();
|
|
4968
|
+
init_codemods();
|
|
4969
|
+
EXACT_OR_TAG = /^[0-9A-Za-z][0-9A-Za-z.+-]*$/;
|
|
4970
|
+
SUBSTITUTION_VALUE = /^[A-Za-z0-9][A-Za-z0-9 .+-]{0,59}$/;
|
|
4971
|
+
}
|
|
4972
|
+
});
|
|
4973
|
+
|
|
2867
4974
|
// src/scaffolder.ts
|
|
2868
4975
|
var VALID_NAME_PATTERN = /^[a-z][a-z0-9-]{1,30}$/;
|
|
2869
4976
|
var NOOP_LOGGER = {
|
|
@@ -2960,9 +5067,9 @@ async function runScaffold(opts, fs2) {
|
|
|
2960
5067
|
function joinPath(...parts) {
|
|
2961
5068
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
2962
5069
|
}
|
|
2963
|
-
function dirname(
|
|
2964
|
-
const idx =
|
|
2965
|
-
return idx === -1 ? "." :
|
|
5070
|
+
function dirname(path29) {
|
|
5071
|
+
const idx = path29.lastIndexOf("/");
|
|
5072
|
+
return idx === -1 ? "." : path29.slice(0, idx);
|
|
2966
5073
|
}
|
|
2967
5074
|
function brandPackageJson(consumer, genesisVersion) {
|
|
2968
5075
|
return JSON.stringify(
|
|
@@ -3094,9 +5201,12 @@ export const brand: Brand = {
|
|
|
3094
5201
|
}
|
|
3095
5202
|
function tailwindConfig(consumer, native) {
|
|
3096
5203
|
return `import type { Config } from "tailwindcss";
|
|
3097
|
-
|
|
3098
|
-
//
|
|
3099
|
-
|
|
5204
|
+
${native ? `// NativeWind v4 needs its preset; Genesis's goes after it. The NativeWind preset also declares
|
|
5205
|
+
// the theme variables, which NativeWind can't import from genesis.css. genesisNativewindContent
|
|
5206
|
+
// lists the Genesis React Native packages the app uses, wherever they are installed.
|
|
5207
|
+
import { fileURLToPath } from "node:url";
|
|
5208
|
+
import nativewindPreset from "nativewind/preset";
|
|
5209
|
+
import { genesisNativewindContent, genesisNativewindPreset as genesisPreset } from "@marktiderman/genesis-design-system/presets/nativewind";` : `import { genesisPreset } from "@marktiderman/genesis-design-system/presets/tailwind";`}
|
|
3100
5210
|
import { brand } from "@${consumer}/brand";
|
|
3101
5211
|
|
|
3102
5212
|
/**
|
|
@@ -3112,7 +5222,7 @@ const config: Config = {
|
|
|
3112
5222
|
content: [
|
|
3113
5223
|
"./app/**/*.{ts,tsx}",
|
|
3114
5224
|
"./components/**/*.{ts,tsx}",
|
|
3115
|
-
${native ? ` "
|
|
5225
|
+
${native ? ` ...genesisNativewindContent({ root: fileURLToPath(new URL(".", import.meta.url)) }),
|
|
3116
5226
|
` : ""} ],
|
|
3117
5227
|
presets: [${native ? "nativewindPreset, " : ""}genesisPreset],
|
|
3118
5228
|
theme: {
|
|
@@ -3185,14 +5295,33 @@ function cliVersion() {
|
|
|
3185
5295
|
}
|
|
3186
5296
|
var program = new Command();
|
|
3187
5297
|
program.name("genesis").description("Genesis CLI \u2014 scaffolders + workspace tooling").version(cliVersion());
|
|
3188
|
-
program.command("init").description("Scaffold a new Genesis consumer (brand package + tailwind + tokens)").argument("<consumer>", "Consumer slug (lowercase, e.g., 'acme')").option("-t, --target <dir>", "Target directory (default: cwd
|
|
5298
|
+
program.command("init").description("Scaffold a new Genesis consumer (brand package + tailwind + tokens), or with --template native a new Expo app from the Genesis RN starter").argument("<consumer>", "Consumer slug (lowercase, e.g., 'acme')").option("-t, --target <dir>", "Target directory (default: cwd; with --template, ./<consumer>)").option(
|
|
3189
5299
|
"--genesis-version <v>",
|
|
3190
5300
|
"Pin @marktiderman/genesis-* version (default: 'workspace:^' for monorepo)"
|
|
3191
|
-
).option("--native", "An Expo app: add NativeWind's preset and scan genesis-ui-native", false).option(
|
|
5301
|
+
).option("--native", "An Expo app: add NativeWind's preset and scan genesis-ui-native", false).option("--template <name>", "Make a whole app from a template: native (the Genesis RN starter)").option("--display-name <name>", "--template: the app's name on the home screen (default: from the slug)").option("--bundle-id <id>", "--template: iOS bundle id and Android package (default com.example.<slug>)").option("--scheme <scheme>", "--template: the URL scheme (default: the slug)").option(
|
|
3192
5302
|
"--emit-conflicts",
|
|
3193
5303
|
"Emit `.genesis-next` siblings for files that already exist (so you can diff)",
|
|
3194
5304
|
false
|
|
3195
5305
|
).action(async (consumer, opts) => {
|
|
5306
|
+
if (opts.template !== void 0) {
|
|
5307
|
+
if (opts.template !== "native") throw new Error(`--template must be native, not "${opts.template}".`);
|
|
5308
|
+
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
5309
|
+
const result2 = await runInitNative2({
|
|
5310
|
+
name: consumer,
|
|
5311
|
+
target: path28.resolve(opts.target ?? consumer),
|
|
5312
|
+
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
5313
|
+
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
5314
|
+
...opts.scheme ? { scheme: opts.scheme } : {}
|
|
5315
|
+
});
|
|
5316
|
+
console.log(`\u2714 Wrote ${result2.files.length} files to ${result2.target}`);
|
|
5317
|
+
if (result2.blocks.length) console.log(` blocks: ${result2.blocks.join(", ")}`);
|
|
5318
|
+
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
5319
|
+
console.log("");
|
|
5320
|
+
console.log("Next steps:");
|
|
5321
|
+
[`cd ${path28.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
5322
|
+
return;
|
|
5323
|
+
}
|
|
5324
|
+
opts.target ??= process.cwd();
|
|
3196
5325
|
const fsImpl = createNodeFs();
|
|
3197
5326
|
const result = await runScaffold(
|
|
3198
5327
|
{
|
|
@@ -3255,7 +5384,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
3255
5384
|
source = `Postgres (${schemas.join(", ")})`;
|
|
3256
5385
|
}
|
|
3257
5386
|
const content = emitContracts2(tables, { source });
|
|
3258
|
-
const target =
|
|
5387
|
+
const target = path28.resolve(opts.out);
|
|
3259
5388
|
if (opts.check) {
|
|
3260
5389
|
const current = await fs.readFile(target, "utf-8").catch(() => null);
|
|
3261
5390
|
if (current !== content) {
|
|
@@ -3270,7 +5399,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
3270
5399
|
});
|
|
3271
5400
|
program.command("doctor").description("Check this app against the installed Genesis: components, tokens, imports, colors, plus the app's own rules").option("--strict", "Fail on warnings too", false).option("--json", "Print the report as JSON", false).option("--build", "Also run the app's typecheck and build (doctor.build, or its typecheck/build scripts)", false).option("-c, --config <path>", 'Config file (default: genesis.config.json, then package.json "genesis")').option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--print-genesis", "Print the components, tokens and raw tags read from Genesis, and exit", false).action(async (opts) => {
|
|
3272
5401
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
3273
|
-
const root =
|
|
5402
|
+
const root = path28.resolve(opts.dir);
|
|
3274
5403
|
try {
|
|
3275
5404
|
if (opts.printGenesis) {
|
|
3276
5405
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -3314,7 +5443,7 @@ featureOptions(features.command("check").description("Errors fail (stale output,
|
|
|
3314
5443
|
featureOptions(
|
|
3315
5444
|
features.command("find").description("Search features before building: reuse one, extend one, or add an idea first").argument("[term]", "What to look for (id, alias, name, keyword, summary, import, slot or code path)", "").option("--platform <platform>", "Only features on web, native, server or cli").option("--layer <layer>", "Only token, primitive, pattern, layout, hook, provider, block, service or tool").option("--status <status>", "Only idea, planned, building, beta, live, deprecated or retired")
|
|
3316
5445
|
).action(async (term, opts) => {
|
|
3317
|
-
const { FEATURE_LAYERS, FEATURE_PLATFORMS, FEATURE_STATUSES } = await import('@marktiderman/genesis-features');
|
|
5446
|
+
const { FEATURE_LAYERS, FEATURE_PLATFORMS: FEATURE_PLATFORMS2, FEATURE_STATUSES } = await import('@marktiderman/genesis-features');
|
|
3318
5447
|
const { runFeaturesFind: runFeaturesFind2, formatFeature: formatFeature2 } = await Promise.resolve().then(() => (init_features(), features_exports));
|
|
3319
5448
|
const pick = (name, value, allowed) => {
|
|
3320
5449
|
if (value === void 0) return void 0;
|
|
@@ -3323,7 +5452,7 @@ featureOptions(
|
|
|
3323
5452
|
};
|
|
3324
5453
|
const { platform, layer, status, ...rest } = opts;
|
|
3325
5454
|
const filters = {
|
|
3326
|
-
platform: pick("platform", platform,
|
|
5455
|
+
platform: pick("platform", platform, FEATURE_PLATFORMS2),
|
|
3327
5456
|
layer: pick("layer", layer, FEATURE_LAYERS),
|
|
3328
5457
|
status: pick("status", status, FEATURE_STATUSES)
|
|
3329
5458
|
};
|
|
@@ -3335,38 +5464,38 @@ featureOptions(
|
|
|
3335
5464
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
3336
5465
|
studio.command("init").description("Turn the Data Studio on in this app: a server for every table, a page, and one migration to review").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--host <host>", "next, tanstack-start or supabase-function (default: detected)").option("--route <path>", "Where the page lives", "/admin/data").option("--login-role <name>", "The studio's database login", "genesis_studio_login").option("--force", "Overwrite files that already exist", false).action(async (opts) => {
|
|
3337
5466
|
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
3338
|
-
const root =
|
|
3339
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
3340
|
-
const
|
|
5467
|
+
const root = path28.resolve(opts.dir);
|
|
5468
|
+
const packageJson = JSON.parse(await fs.readFile(path28.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
5469
|
+
const existsSync22 = (await import('fs')).existsSync;
|
|
3341
5470
|
const readSync = (await import('fs')).readFileSync;
|
|
3342
|
-
const
|
|
5471
|
+
const readdirSync9 = (await import('fs')).readdirSync;
|
|
3343
5472
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
3344
5473
|
throw new Error("--host must be next, tanstack-start or supabase-function.");
|
|
3345
5474
|
}
|
|
3346
5475
|
const plan = planStudioInit2(
|
|
3347
5476
|
{
|
|
3348
5477
|
packageJson,
|
|
3349
|
-
exists: (p) =>
|
|
3350
|
-
read: (p) =>
|
|
5478
|
+
exists: (p) => existsSync22(path28.join(root, p)),
|
|
5479
|
+
read: (p) => existsSync22(path28.join(root, p)) ? readSync(path28.join(root, p), "utf-8") : null,
|
|
3351
5480
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
3352
5481
|
listDeep: (p) => {
|
|
3353
5482
|
const out = [];
|
|
3354
|
-
const
|
|
3355
|
-
for (const entry of
|
|
5483
|
+
const walk2 = (rel) => {
|
|
5484
|
+
for (const entry of readdirSync9(path28.join(root, rel), { withFileTypes: true })) {
|
|
3356
5485
|
const child = `${rel}/${entry.name}`;
|
|
3357
|
-
if (entry.isDirectory())
|
|
5486
|
+
if (entry.isDirectory()) walk2(child);
|
|
3358
5487
|
else out.push(child);
|
|
3359
5488
|
}
|
|
3360
5489
|
};
|
|
3361
5490
|
try {
|
|
3362
|
-
|
|
5491
|
+
walk2(p);
|
|
3363
5492
|
} catch {
|
|
3364
5493
|
}
|
|
3365
5494
|
return out;
|
|
3366
5495
|
},
|
|
3367
5496
|
list: (p) => {
|
|
3368
5497
|
try {
|
|
3369
|
-
return
|
|
5498
|
+
return readdirSync9(path28.join(root, p));
|
|
3370
5499
|
} catch {
|
|
3371
5500
|
return [];
|
|
3372
5501
|
}
|
|
@@ -3375,8 +5504,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
3375
5504
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
3376
5505
|
);
|
|
3377
5506
|
for (const file of plan.files) {
|
|
3378
|
-
const target =
|
|
3379
|
-
await fs.mkdir(
|
|
5507
|
+
const target = path28.join(root, file.path);
|
|
5508
|
+
await fs.mkdir(path28.dirname(target), { recursive: true });
|
|
3380
5509
|
if (file.edit) {
|
|
3381
5510
|
await fs.writeFile(target, file.content, "utf-8");
|
|
3382
5511
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -3387,19 +5516,92 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
3387
5516
|
console.log(`+ ${file.path} (appended)`);
|
|
3388
5517
|
continue;
|
|
3389
5518
|
}
|
|
3390
|
-
if (
|
|
5519
|
+
if (existsSync22(target) && !opts.force) {
|
|
3391
5520
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
3392
5521
|
continue;
|
|
3393
5522
|
}
|
|
3394
5523
|
await fs.writeFile(target, file.content, "utf-8");
|
|
3395
5524
|
console.log(`+ ${file.path}`);
|
|
3396
5525
|
}
|
|
3397
|
-
const pm =
|
|
5526
|
+
const pm = existsSync22(path28.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync22(path28.join(root, "yarn.lock")) ? "yarn add" : existsSync22(path28.join(root, "bun.lock")) || existsSync22(path28.join(root, "bun.lockb")) ? "bun add" : "npm install";
|
|
3398
5527
|
console.log("");
|
|
3399
5528
|
console.log(`\u2714 The Data Studio is set up for ${{ next: "Next.js", "tanstack-start": "TanStack Start", "supabase-function": "a Supabase Edge Function" }[plan.host]}. To finish:`);
|
|
3400
5529
|
console.log(` 1. ${pm} ${plan.install.join(" ")}`);
|
|
3401
5530
|
plan.steps.forEach((step, i) => console.log(` ${i + 2}. ${step}`));
|
|
3402
5531
|
});
|
|
5532
|
+
async function confirm(question) {
|
|
5533
|
+
if (!process.stdin.isTTY) return false;
|
|
5534
|
+
const { createInterface } = await import('readline/promises');
|
|
5535
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
5536
|
+
try {
|
|
5537
|
+
return /^y(es)?$/i.test((await rl.question(`${question} [y/N] `)).trim());
|
|
5538
|
+
} finally {
|
|
5539
|
+
rl.close();
|
|
5540
|
+
}
|
|
5541
|
+
}
|
|
5542
|
+
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
5543
|
+
program.command("add").description("Add a block (a feature an app adds whole) from the Genesis package that declares it: install, migrations, functions, skills, routes, registry entry").argument("[block]", "The block's id, e.g. tenant-features").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--package <name>", "The package that declares it, when two do").option("--list", "List the blocks this app can add, and exit", false).option("--dry-run", "Print the plan; write and install nothing", false).option("-y, --yes", "Don't ask before writing", false).option("--no-install", "Don't install packages (print the command instead)").option("--no-features-build", "Don't run features build after").action(async (block, opts) => {
|
|
5544
|
+
const root = path28.resolve(opts.dir);
|
|
5545
|
+
if (opts.list || !block) {
|
|
5546
|
+
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
5547
|
+
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
5548
|
+
const warnings = [];
|
|
5549
|
+
const added = readLock2(root).blocks;
|
|
5550
|
+
const all = await allBlocks2(root, warnings);
|
|
5551
|
+
for (const w of warnings) logger.warn(w);
|
|
5552
|
+
console.log(all.length ? all.map(({ manifest: m, from }) => `${added[m.id] ? "\u2714" : " "} ${m.id.padEnd(18)} ${m.package}${m.version ? `@${m.version}` : ""}${from === "catalog" ? " (not installed)" : ""}${m.feature ? `: ${m.feature.summary}` : ""}`).join("\n") : "No Genesis package declares a block.");
|
|
5553
|
+
if (!block && !opts.list) process.exitCode = 1;
|
|
5554
|
+
return;
|
|
5555
|
+
}
|
|
5556
|
+
const { runAdd: runAdd2 } = await Promise.resolve().then(() => (init_add(), add_exports));
|
|
5557
|
+
const report = await runAdd2({ root, block, ...opts.package ? { package: opts.package } : {}, dryRun: opts.dryRun, yes: opts.yes, install: opts.install, featuresBuild: opts.featuresBuild, log: logger, confirm });
|
|
5558
|
+
for (const w of report.warnings) logger.warn(w);
|
|
5559
|
+
for (const k of report.kept) logger.warn(`${k.path}: ${k.why}`);
|
|
5560
|
+
console.log("");
|
|
5561
|
+
if (opts.dryRun) console.log(`Dry run: nothing written${report.install ? " or installed" : ""}.`);
|
|
5562
|
+
else if (!report.created.length && !report.edited.length) console.log(`\u2714 ${report.block.id} is already in this app: nothing to copy or change.`);
|
|
5563
|
+
else console.log(`\u2714 Added ${report.block.id}: ${report.created.length} files created${report.edited.length ? `, ${report.edited.length} edited (${report.edited.join(", ")})` : ""}.`);
|
|
5564
|
+
if (report.steps.length) {
|
|
5565
|
+
console.log("");
|
|
5566
|
+
console.log("To finish:");
|
|
5567
|
+
report.steps.forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
5568
|
+
}
|
|
5569
|
+
});
|
|
5570
|
+
program.command("migrate").description("Copy new package migrations of the app's blocks in as new timestamped files; report edited or changed ones (never rewritten)").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--block <id...>", "Also check these blocks (beyond genesis.lock.json's)").option("--dry-run", "Report only", false).option("--forward", "Write a forward migration stub for each edited or changed migration", false).action(async (opts) => {
|
|
5571
|
+
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
5572
|
+
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
5573
|
+
const report = await runMigrate2({ root: path28.resolve(opts.dir), ...opts.block ? { blocks: opts.block } : {}, dryRun: opts.dryRun, forward: opts.forward });
|
|
5574
|
+
for (const w of report.warnings) logger.warn(w);
|
|
5575
|
+
console.log(formatMigrationRows2(report.plan.rows));
|
|
5576
|
+
for (const c of report.plan.creates) if (c.kind !== "migration") console.log(`+ ${c.path} (${c.kind === "test" ? "pgTAP test" : "forward migration: fill it in"})`);
|
|
5577
|
+
console.log("");
|
|
5578
|
+
const count = report.plan.creates.length;
|
|
5579
|
+
console.log(opts.dryRun ? `Dry run: ${count} file${count === 1 ? "" : "s"} would be created.` : `\u2714 ${report.written.length} file${report.written.length === 1 ? "" : "s"} created. Nothing existing was changed.`);
|
|
5580
|
+
if (report.attention) {
|
|
5581
|
+
console.log(opts.forward ? "Fill in the forward migrations, review them, then apply them." : "Some migrations need you (above): an applied migration is never rewritten. Run genesis migrate --forward to add a forward migration for each.");
|
|
5582
|
+
process.exitCode = 1;
|
|
5583
|
+
}
|
|
5584
|
+
});
|
|
5585
|
+
program.command("upgrade").description("Move every @marktiderman/genesis* dependency to one Genesis release, refresh the files Genesis owns, run codemods and the doctor").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--version <v>", "The @marktiderman/genesis release: an exact version or a dist-tag", "latest").option("--manifest <file>", "Read the release from this versions.json instead of npm").option("--dry-run", "Report the bump, and owned files compared with the packages installed now; change nothing", false).option("--no-install", "Don't reinstall after the bump").option("--no-doctor", "Don't run genesis doctor after").option("--keep-mine", "Never merge an owned file you changed; write the new text to .genesis-next", false).option("--pr", "Commit to a genesis-upgrade/<version> branch, push it and open a pull request", false).action(async (opts) => {
|
|
5586
|
+
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
5587
|
+
const report = await runUpgrade2({
|
|
5588
|
+
root: path28.resolve(opts.dir),
|
|
5589
|
+
version: opts.version,
|
|
5590
|
+
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
5591
|
+
dryRun: opts.dryRun,
|
|
5592
|
+
install: opts.install,
|
|
5593
|
+
doctor: opts.doctor,
|
|
5594
|
+
keepMine: opts.keepMine,
|
|
5595
|
+
pr: opts.pr,
|
|
5596
|
+
log: (m) => console.log(m)
|
|
5597
|
+
});
|
|
5598
|
+
console.log("");
|
|
5599
|
+
console.log(report.summary);
|
|
5600
|
+
if (opts.dryRun) console.log("\nDry run: nothing written, installed or pushed.");
|
|
5601
|
+
if (report.pr) console.log(`
|
|
5602
|
+
\u2714 ${report.pr}`);
|
|
5603
|
+
if (report.doctor === "failed") process.exitCode = 1;
|
|
5604
|
+
});
|
|
3403
5605
|
program.parseAsync(process.argv).catch((err) => {
|
|
3404
5606
|
const message = err instanceof Error ? err.message : String(err);
|
|
3405
5607
|
console.error(`\u2717 ${message}`);
|
|
@@ -3447,7 +5649,7 @@ function redactUrl(location) {
|
|
|
3447
5649
|
const url = new URL(location);
|
|
3448
5650
|
return `${url.origin}${url.pathname}`;
|
|
3449
5651
|
} catch {
|
|
3450
|
-
return
|
|
5652
|
+
return path28.basename(location);
|
|
3451
5653
|
}
|
|
3452
5654
|
}
|
|
3453
5655
|
//# sourceMappingURL=cli.js.map
|