@lunora/cli 0.0.0 → 1.0.0-alpha.2
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/LICENSE.md +105 -0
- package/README.md +109 -9
- package/__assets__/package-og.svg +14 -0
- package/dist/bin.mjs +11 -0
- package/dist/index.d.mts +852 -0
- package/dist/index.d.ts +852 -0
- package/dist/index.mjs +19 -0
- package/dist/packem_chunks/handler.mjs +76 -0
- package/dist/packem_chunks/handler10.mjs +22 -0
- package/dist/packem_chunks/handler11.mjs +192 -0
- package/dist/packem_chunks/handler12.mjs +131 -0
- package/dist/packem_chunks/handler13.mjs +65 -0
- package/dist/packem_chunks/handler14.mjs +58 -0
- package/dist/packem_chunks/handler15.mjs +79 -0
- package/dist/packem_chunks/handler16.mjs +41 -0
- package/dist/packem_chunks/handler17.mjs +105 -0
- package/dist/packem_chunks/handler18.mjs +172 -0
- package/dist/packem_chunks/handler19.mjs +89 -0
- package/dist/packem_chunks/handler2.mjs +114 -0
- package/dist/packem_chunks/handler20.mjs +94 -0
- package/dist/packem_chunks/handler21.mjs +311 -0
- package/dist/packem_chunks/handler3.mjs +204 -0
- package/dist/packem_chunks/handler4.mjs +33 -0
- package/dist/packem_chunks/handler5.mjs +49 -0
- package/dist/packem_chunks/handler6.mjs +91 -0
- package/dist/packem_chunks/handler7.mjs +42 -0
- package/dist/packem_chunks/handler8.mjs +174 -0
- package/dist/packem_chunks/handler9.mjs +16 -0
- package/dist/packem_chunks/planDevCommand.mjs +543 -0
- package/dist/packem_chunks/runCodegenCommand.mjs +52 -0
- package/dist/packem_chunks/runDeployCommand.mjs +504 -0
- package/dist/packem_chunks/runInitCommand.mjs +652 -0
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +397 -0
- package/dist/packem_chunks/runResetCommand.mjs +41 -0
- package/dist/packem_chunks/runRpcCommand.mjs +68 -0
- package/dist/packem_shared/COMMANDS-1V_KEx35.mjs +905 -0
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +244 -0
- package/dist/packem_shared/admin-url-4UzT-CI4.mjs +19 -0
- package/dist/packem_shared/api-spec-CtA6ilu4.mjs +13 -0
- package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +38 -0
- package/dist/packem_shared/command-BDXcJCCJ.mjs +14 -0
- package/dist/packem_shared/createLogger-CHPNjFw2.mjs +73 -0
- package/dist/packem_shared/defaultSpawner-DxI3mebw.mjs +43 -0
- package/dist/packem_shared/diffSnapshots-RR2ZE8Ya.mjs +161 -0
- package/dist/packem_shared/docker-hMQ97KSQ.mjs +21 -0
- package/dist/packem_shared/features-ocSSpZtS.mjs +24 -0
- package/dist/packem_shared/insertSchemaExtension-BuzF6-t2.mjs +59 -0
- package/dist/packem_shared/open-url-Dfq6fAyT.mjs +41 -0
- package/dist/packem_shared/output-format-7gyGR3h8.mjs +17 -0
- package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +56 -0
- package/dist/packem_shared/parseManifest--vZf2FY1.mjs +94 -0
- package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +16 -0
- package/dist/packem_shared/runAddCommand-BZGkRnBs.mjs +693 -0
- package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +79 -0
- package/dist/packem_shared/schemaIrToSnapshot-aBTo7TM5.mjs +43 -0
- package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +12 -0
- package/package.json +61 -18
- package/skills/README.md +29 -0
- package/skills/lunora/SKILL.md +83 -0
- package/skills/lunora-create-package/SKILL.md +129 -0
- package/skills/lunora-deploy/SKILL.md +150 -0
- package/skills/lunora-functions/SKILL.md +182 -0
- package/skills/lunora-migration-helper/SKILL.md +194 -0
- package/skills/lunora-performance-audit/SKILL.md +143 -0
- package/skills/lunora-quickstart/SKILL.md +240 -0
- package/skills/lunora-realtime/SKILL.md +177 -0
- package/skills/lunora-setup-auth/SKILL.md +170 -0
- package/skills/lunora-setup-hyperdrive/SKILL.md +154 -0
- package/skills/lunora-setup-hyperdrive-global/SKILL.md +171 -0
- package/skills/lunora-setup-mail/SKILL.md +151 -0
- package/skills/lunora-setup-scheduler/SKILL.md +157 -0
- package/skills/lunora-setup-storage/SKILL.md +154 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
2
|
+
import { runAddCommand, runRegistryViewCommand, runBuildIndexCommand } from '../packem_shared/runAddCommand-BZGkRnBs.mjs';
|
|
3
|
+
|
|
4
|
+
const execute = defineHandler(({ argument, cwd, logger, options }) => {
|
|
5
|
+
const subcommand = argument[0];
|
|
6
|
+
const names = argument.slice(1);
|
|
7
|
+
if (subcommand === "add") {
|
|
8
|
+
return runAddCommand({
|
|
9
|
+
allowUnsafeSource: options.allowUnsafeSource === true,
|
|
10
|
+
cwd,
|
|
11
|
+
diff: options.diff === true,
|
|
12
|
+
dryRun: options.dryRun === true,
|
|
13
|
+
from: options.from,
|
|
14
|
+
json: options.json === true,
|
|
15
|
+
logger,
|
|
16
|
+
names,
|
|
17
|
+
overwrite: options.overwrite === true,
|
|
18
|
+
source: options.source,
|
|
19
|
+
yes: options.yes === true
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (subcommand === "list") {
|
|
23
|
+
return runAddCommand({ cwd, from: options.from, json: options.json === true, list: true, logger, names: [], source: options.source });
|
|
24
|
+
}
|
|
25
|
+
if (subcommand === "view") {
|
|
26
|
+
return runRegistryViewCommand({
|
|
27
|
+
allowUnsafeSource: options.allowUnsafeSource === true,
|
|
28
|
+
from: options.from,
|
|
29
|
+
logger,
|
|
30
|
+
names,
|
|
31
|
+
source: options.source
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (subcommand === "build") {
|
|
35
|
+
return runBuildIndexCommand({ check: options.check === true, from: options.from, logger, out: options.out });
|
|
36
|
+
}
|
|
37
|
+
logger.error("registry: unknown subcommand. Usage: lunora registry <add|list|view|build> [names…]");
|
|
38
|
+
return { code: 1 };
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export { execute };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { AGENT_RULES_DIR, detectAgentRules, LUNORA_SKILL_NAMES } from '@lunora/config';
|
|
4
|
+
import { join, relative, dirname } from '@visulima/path';
|
|
5
|
+
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
6
|
+
|
|
7
|
+
const resolveBundledSkillsDirectory = (startDirectory = dirname(fileURLToPath(import.meta.url))) => {
|
|
8
|
+
let directory = startDirectory;
|
|
9
|
+
for (let index = 0; index < 6; index += 1) {
|
|
10
|
+
const packageJson = join(directory, "package.json");
|
|
11
|
+
if (existsSync(packageJson)) {
|
|
12
|
+
try {
|
|
13
|
+
const parsed = JSON.parse(readFileSync(packageJson, "utf8"));
|
|
14
|
+
if (parsed.name === "@lunora/cli") {
|
|
15
|
+
const skills = join(directory, "skills");
|
|
16
|
+
return existsSync(skills) ? skills : void 0;
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const parent = dirname(directory);
|
|
22
|
+
if (parent === directory) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
directory = parent;
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
};
|
|
29
|
+
const listBundledSkills = (skillsDirectory) => readdirSync(skillsDirectory).filter((name) => {
|
|
30
|
+
const directory = join(skillsDirectory, name);
|
|
31
|
+
return statSync(directory).isDirectory() && existsSync(join(directory, "SKILL.md"));
|
|
32
|
+
});
|
|
33
|
+
const copySkill = (source, destination, overwrite) => {
|
|
34
|
+
mkdirSync(destination, { recursive: true });
|
|
35
|
+
let wrote = false;
|
|
36
|
+
for (const entry of readdirSync(source)) {
|
|
37
|
+
const from = join(source, entry);
|
|
38
|
+
const to = join(destination, entry);
|
|
39
|
+
if (statSync(from).isDirectory()) {
|
|
40
|
+
wrote = copySkill(from, to, overwrite) || wrote;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (existsSync(to) && !overwrite) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
writeFileSync(to, readFileSync(from));
|
|
47
|
+
wrote = true;
|
|
48
|
+
}
|
|
49
|
+
return wrote;
|
|
50
|
+
};
|
|
51
|
+
const runRulesInstall = (options) => {
|
|
52
|
+
const cwd = options.cwd ?? process.cwd();
|
|
53
|
+
const overwrite = options.overwrite === true;
|
|
54
|
+
const skillsDirectory = resolveBundledSkillsDirectory();
|
|
55
|
+
if (skillsDirectory === void 0) {
|
|
56
|
+
options.logger.error("rules: could not locate the bundled skills (is @lunora/cli installed correctly?).");
|
|
57
|
+
return { code: 1, installed: [], skipped: [] };
|
|
58
|
+
}
|
|
59
|
+
const installed = [];
|
|
60
|
+
const skipped = [];
|
|
61
|
+
for (const name of listBundledSkills(skillsDirectory)) {
|
|
62
|
+
const destination = join(cwd, AGENT_RULES_DIR, name);
|
|
63
|
+
const wrote = copySkill(join(skillsDirectory, name), destination, overwrite);
|
|
64
|
+
if (wrote) {
|
|
65
|
+
installed.push(name);
|
|
66
|
+
} else {
|
|
67
|
+
skipped.push(name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const target = relative(cwd, join(cwd, AGENT_RULES_DIR)) || AGENT_RULES_DIR;
|
|
71
|
+
if (installed.length > 0) {
|
|
72
|
+
options.logger.success(`Installed ${String(installed.length)} Lunora skill(s) into ${target}/: ${installed.join(", ")}.`);
|
|
73
|
+
}
|
|
74
|
+
if (skipped.length > 0) {
|
|
75
|
+
options.logger.info(`Skipped ${String(skipped.length)} existing skill(s) (re-run with --overwrite to replace): ${skipped.join(", ")}.`);
|
|
76
|
+
}
|
|
77
|
+
options.logger.info("Your AI coding agent will pick these up automatically. Start with the `lunora` skill.");
|
|
78
|
+
return { code: 0, installed, skipped };
|
|
79
|
+
};
|
|
80
|
+
const runRulesCheck = (options) => {
|
|
81
|
+
const cwd = options.cwd ?? process.cwd();
|
|
82
|
+
const status = detectAgentRules(cwd);
|
|
83
|
+
if (status.installed) {
|
|
84
|
+
options.logger.success(`Lunora agent rules are installed (${String(status.present.length)}/${String(LUNORA_SKILL_NAMES.length)} skills).`);
|
|
85
|
+
if (status.missing.length > 0) {
|
|
86
|
+
options.logger.info(`Missing: ${status.missing.join(", ")}. Run \`lunora rules install\` to add them.`);
|
|
87
|
+
}
|
|
88
|
+
return { code: 0, installed: status.present, skipped: [] };
|
|
89
|
+
}
|
|
90
|
+
options.logger.warn("Lunora agent rules are not installed. Run `lunora rules install` so your AI agent knows how to use Lunora.");
|
|
91
|
+
return { code: options.strict === true ? 1 : 0, installed: status.present, skipped: [] };
|
|
92
|
+
};
|
|
93
|
+
const execute = defineHandler(({ argument, cwd, logger, options }) => {
|
|
94
|
+
const subcommand = argument[0] ?? "check";
|
|
95
|
+
if (subcommand === "install") {
|
|
96
|
+
return runRulesInstall({ cwd, logger, overwrite: options.overwrite === true });
|
|
97
|
+
}
|
|
98
|
+
if (subcommand === "check") {
|
|
99
|
+
return runRulesCheck({ cwd, logger, strict: options.strict === true });
|
|
100
|
+
}
|
|
101
|
+
logger.error("rules: unknown subcommand. Usage: lunora rules <install|check>");
|
|
102
|
+
return { code: 1 };
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export { execute, resolveBundledSkillsDirectory, runRulesCheck, runRulesInstall };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { discoverSchema, schemaFromIr } from '@lunora/codegen';
|
|
5
|
+
import { promptYesNo } from '@lunora/config';
|
|
6
|
+
import { seedPlan } from '@lunora/seed';
|
|
7
|
+
import { join } from '@visulima/path';
|
|
8
|
+
import { Project } from 'ts-morph';
|
|
9
|
+
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
10
|
+
import { a as resolveProductionWorkerUrl } from '../packem_shared/resolve-target-qbsJ_5sF.mjs';
|
|
11
|
+
import { runImportCommand } from '../packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
|
|
12
|
+
import { runResetCommand } from './runResetCommand.mjs';
|
|
13
|
+
|
|
14
|
+
const isLocalUrl = (url) => {
|
|
15
|
+
if (url === void 0) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const { hostname } = new URL(url);
|
|
20
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const ndjsonReplacer = (_key, value) => {
|
|
26
|
+
if (typeof value === "bigint") {
|
|
27
|
+
return Number(value);
|
|
28
|
+
}
|
|
29
|
+
if (value instanceof ArrayBuffer) {
|
|
30
|
+
return [...new Uint8Array(value)];
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
const seedFailure = (code) => {
|
|
35
|
+
return { code, conflicts: 0, generated: 0, inserted: 0, ndjson: "" };
|
|
36
|
+
};
|
|
37
|
+
const guardSeedTargets = (options, schemaPath) => {
|
|
38
|
+
if (!existsSync(schemaPath)) {
|
|
39
|
+
options.logger.error(`schema not found: ${schemaPath} — run \`vis generate lunora-table --name=<name>\` to create one`);
|
|
40
|
+
return seedFailure(1);
|
|
41
|
+
}
|
|
42
|
+
if (options.reset === true && (options.prod === true || !isLocalUrl(options.url))) {
|
|
43
|
+
options.logger.error("--reset only clears local .wrangler/state and cannot be combined with --prod or a remote --url");
|
|
44
|
+
return seedFailure(1);
|
|
45
|
+
}
|
|
46
|
+
return void 0;
|
|
47
|
+
};
|
|
48
|
+
const insertSeedRows = async (ndjson, generated, cwd, options) => {
|
|
49
|
+
const scratchDirectory = await mkdtemp(join(tmpdir(), "lunora-seed-"));
|
|
50
|
+
const temporaryFile = join(scratchDirectory, "rows.ndjson");
|
|
51
|
+
await writeFile(temporaryFile, ndjson, "utf8");
|
|
52
|
+
try {
|
|
53
|
+
const result = await runImportCommand({
|
|
54
|
+
batchSize: options.batchSize,
|
|
55
|
+
fetchImpl: options.fetchImpl,
|
|
56
|
+
file: temporaryFile,
|
|
57
|
+
logger: options.logger,
|
|
58
|
+
prod: options.prod,
|
|
59
|
+
token: options.token,
|
|
60
|
+
url: options.url
|
|
61
|
+
});
|
|
62
|
+
const conflicts = result.body?.conflicts ?? 0;
|
|
63
|
+
if (conflicts > 0) {
|
|
64
|
+
options.logger.warn(
|
|
65
|
+
`${String(conflicts)} row(s) skipped — their _id already exists. Seeding is deterministic; re-run with --reset to wipe local state first, or a different --seed for fresh ids.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return { code: result.code, conflicts, generated, inserted: result.inserted, ndjson };
|
|
69
|
+
} finally {
|
|
70
|
+
await rm(scratchDirectory, { force: true, recursive: true }).catch(() => {
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const validateSeedTable = (options, ir) => {
|
|
75
|
+
if (options.table === void 0 || ir.tables.some((table) => table.name === options.table)) {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
const available = ir.tables.map((table) => table.name).join(", ");
|
|
79
|
+
options.logger.error(`unknown table "${options.table}" — schema defines: ${available || "(no tables)"}`);
|
|
80
|
+
return seedFailure(1);
|
|
81
|
+
};
|
|
82
|
+
const confirmRemoteSeedTarget = async (options, generated) => {
|
|
83
|
+
const targetsRemote = options.prod === true || !isLocalUrl(options.url);
|
|
84
|
+
if (!targetsRemote || options.yes === true) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
if (!process.stdin.isTTY && options.confirm === void 0) {
|
|
88
|
+
options.logger.error("seed: refusing to insert into a non-local target without confirmation — re-run with --yes");
|
|
89
|
+
return seedFailure(1);
|
|
90
|
+
}
|
|
91
|
+
const confirmer = options.confirm ?? promptYesNo;
|
|
92
|
+
const confirmed = await confirmer(
|
|
93
|
+
`This will insert ${String(generated)} generated row(s) into ${options.url ?? "the production worker"}. Continue? [y/N] `
|
|
94
|
+
);
|
|
95
|
+
if (!confirmed) {
|
|
96
|
+
options.logger.info("seed: aborted");
|
|
97
|
+
return seedFailure(1);
|
|
98
|
+
}
|
|
99
|
+
return void 0;
|
|
100
|
+
};
|
|
101
|
+
const runSeedCommand = async (options) => {
|
|
102
|
+
const cwd = options.cwd ?? process.cwd();
|
|
103
|
+
const schemaPath = join(cwd, "lunora", "schema.ts");
|
|
104
|
+
const guard = guardSeedTargets(options, schemaPath);
|
|
105
|
+
if (guard !== void 0) {
|
|
106
|
+
return guard;
|
|
107
|
+
}
|
|
108
|
+
const project = new Project({ skipAddingFilesFromTsConfig: true });
|
|
109
|
+
const ir = discoverSchema(project, schemaPath);
|
|
110
|
+
const unknownTable = validateSeedTable(options, ir);
|
|
111
|
+
if (unknownTable !== void 0) {
|
|
112
|
+
return unknownTable;
|
|
113
|
+
}
|
|
114
|
+
const schema = schemaFromIr(ir);
|
|
115
|
+
const plan = seedPlan(schema, {
|
|
116
|
+
defaultCount: options.count ?? 10,
|
|
117
|
+
only: options.table === void 0 ? void 0 : [options.table],
|
|
118
|
+
seed: options.seed ?? 0
|
|
119
|
+
});
|
|
120
|
+
const lines = [];
|
|
121
|
+
for (const { rows, table } of plan) {
|
|
122
|
+
for (const row of rows) {
|
|
123
|
+
lines.push(JSON.stringify({ doc: row, table }, ndjsonReplacer));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const ndjson = lines.length > 0 ? `${lines.join("\n")}
|
|
127
|
+
` : "";
|
|
128
|
+
const generated = lines.length;
|
|
129
|
+
if (options.dryRun === true) {
|
|
130
|
+
if (ndjson.length > 0) {
|
|
131
|
+
process.stdout.write(ndjson);
|
|
132
|
+
}
|
|
133
|
+
options.logger.info(`generated ${String(generated)} row(s) across ${String(plan.length)} table(s) — dry run, nothing inserted`);
|
|
134
|
+
return { code: 0, conflicts: 0, generated, inserted: 0, ndjson };
|
|
135
|
+
}
|
|
136
|
+
if (options.reset === true) {
|
|
137
|
+
const reset = await runResetCommand({ cwd, logger: options.logger, yes: true });
|
|
138
|
+
if (reset.code !== 0) {
|
|
139
|
+
return { code: reset.code, conflicts: 0, generated, inserted: 0, ndjson };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (generated === 0) {
|
|
143
|
+
options.logger.warn("no rows generated — nothing to insert");
|
|
144
|
+
return { code: 0, conflicts: 0, generated: 0, inserted: 0, ndjson };
|
|
145
|
+
}
|
|
146
|
+
const aborted = await confirmRemoteSeedTarget(options, generated);
|
|
147
|
+
if (aborted !== void 0) {
|
|
148
|
+
return aborted;
|
|
149
|
+
}
|
|
150
|
+
return insertSeedRows(ndjson, generated, cwd, options);
|
|
151
|
+
};
|
|
152
|
+
const execute = defineHandler(async ({ cwd, logger, options }) => {
|
|
153
|
+
const result = await runSeedCommand({
|
|
154
|
+
batchSize: options.batchSize,
|
|
155
|
+
count: options.count,
|
|
156
|
+
cwd,
|
|
157
|
+
dryRun: options.dryRun === true,
|
|
158
|
+
logger,
|
|
159
|
+
prod: options.prod === true,
|
|
160
|
+
reset: options.reset === true,
|
|
161
|
+
seed: options.seed,
|
|
162
|
+
table: options.table,
|
|
163
|
+
token: options.token,
|
|
164
|
+
// Resolve the link here (only under --prod) so seed's own remote/confirm
|
|
165
|
+
// logic and the downstream import both see the same effective target.
|
|
166
|
+
url: resolveProductionWorkerUrl({ cwd, prod: options.prod === true, url: options.url }),
|
|
167
|
+
yes: options.yes === true
|
|
168
|
+
});
|
|
169
|
+
return { code: result.code };
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
export { execute, runSeedCommand };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { runCodegen } from '@lunora/codegen';
|
|
4
|
+
import { p as parseApiSpec } from '../packem_shared/api-spec-CtA6ilu4.mjs';
|
|
5
|
+
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
6
|
+
import { v as validateOutputFormat, i as isJsonFormat, p as printJson, l as loggerForFormat } from '../packem_shared/output-format-7gyGR3h8.mjs';
|
|
7
|
+
import { r as runSchemaDriftGate } from '../packem_shared/schema-drift-gate-BtBt0as0.mjs';
|
|
8
|
+
import { defaultSpawner } from '../packem_shared/defaultSpawner-DxI3mebw.mjs';
|
|
9
|
+
import { validateWranglerProject } from '@lunora/config';
|
|
10
|
+
|
|
11
|
+
const runTypecheckStep = async (cwd, spawner) => {
|
|
12
|
+
if (!existsSync(join(cwd, "tsconfig.json"))) {
|
|
13
|
+
return { warning: "no tsconfig.json found — skipping TypeScript type-check" };
|
|
14
|
+
}
|
|
15
|
+
const result = await spawner({ args: ["exec", "tsc", "--noEmit", "-p", "tsconfig.json"], command: "pnpm", cwd });
|
|
16
|
+
return result.code === 0 ? {} : { error: `type errors: tsc --noEmit exited ${String(result.code)}` };
|
|
17
|
+
};
|
|
18
|
+
const reportVerifyResult = (logger, errors, warnings, wranglerPath) => {
|
|
19
|
+
if (errors.length === 0 && warnings.length === 0) {
|
|
20
|
+
logger.success("verify: project is valid");
|
|
21
|
+
return { code: 0, errors: [], warnings: [], wranglerPath };
|
|
22
|
+
}
|
|
23
|
+
if (warnings.length > 0) {
|
|
24
|
+
logger.warn("verify: warnings:");
|
|
25
|
+
for (const warning of warnings) {
|
|
26
|
+
logger.warn(` - ${warning}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (errors.length > 0) {
|
|
30
|
+
logger.error("verify: errors:");
|
|
31
|
+
for (const error of errors) {
|
|
32
|
+
logger.error(` - ${error}`);
|
|
33
|
+
}
|
|
34
|
+
return { code: 1, errors, warnings, wranglerPath };
|
|
35
|
+
}
|
|
36
|
+
logger.success("verify: project is valid (with warnings)");
|
|
37
|
+
return { code: 0, errors: [], warnings, wranglerPath };
|
|
38
|
+
};
|
|
39
|
+
const runVerifyCommand = async (options) => {
|
|
40
|
+
const cwd = options.cwd ?? process.cwd();
|
|
41
|
+
const logger = loggerForFormat(options.format, options.logger);
|
|
42
|
+
const formatError = validateOutputFormat("verify", options.format);
|
|
43
|
+
if (formatError !== void 0) {
|
|
44
|
+
options.logger.error(formatError);
|
|
45
|
+
return { code: 1, error: formatError, errors: [], warnings: [], wranglerPath: void 0 };
|
|
46
|
+
}
|
|
47
|
+
const validation = validateWranglerProject({ projectRoot: cwd });
|
|
48
|
+
const errors = [...validation.report.errors];
|
|
49
|
+
const warnings = [...validation.report.warnings];
|
|
50
|
+
try {
|
|
51
|
+
const codegen = runCodegen({ apiSpec: options.apiSpec, dryRun: true, projectRoot: cwd });
|
|
52
|
+
const gate = runSchemaDriftGate({ allowDrift: options.allowSchemaDrift === true, codegen, logger, readOnly: true });
|
|
53
|
+
if (gate.blocked) {
|
|
54
|
+
errors.push(gate.reason);
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
58
|
+
errors.push(`codegen failed: ${message}`);
|
|
59
|
+
}
|
|
60
|
+
if (options.typecheck !== false) {
|
|
61
|
+
const typecheck = await runTypecheckStep(cwd, options.spawner ?? defaultSpawner);
|
|
62
|
+
if (typecheck.error !== void 0) {
|
|
63
|
+
errors.push(typecheck.error);
|
|
64
|
+
}
|
|
65
|
+
if (typecheck.warning !== void 0) {
|
|
66
|
+
warnings.push(typecheck.warning);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const result = reportVerifyResult(logger, errors, warnings, validation.wranglerPath);
|
|
70
|
+
if (isJsonFormat(options.format)) {
|
|
71
|
+
printJson(result);
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
const execute = defineHandler(async ({ cwd, logger, options }) => {
|
|
76
|
+
const result = await runVerifyCommand({
|
|
77
|
+
allowSchemaDrift: options.allowSchemaDrift === true,
|
|
78
|
+
apiSpec: parseApiSpec(options.apiSpec),
|
|
79
|
+
cwd,
|
|
80
|
+
format: options.format,
|
|
81
|
+
logger,
|
|
82
|
+
// `--no-typecheck` is declared as a `no-*` option but cerebro exposes it
|
|
83
|
+
// under the negated `typecheck` key (false when passed, true when absent).
|
|
84
|
+
typecheck: options.typecheck === false ? false : void 0
|
|
85
|
+
});
|
|
86
|
+
return { code: result.code };
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export { execute, runVerifyCommand };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join, relative } from 'node:path';
|
|
4
|
+
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
5
|
+
import { defaultSpawner } from '../packem_shared/defaultSpawner-DxI3mebw.mjs';
|
|
6
|
+
|
|
7
|
+
const walk = (root) => {
|
|
8
|
+
const entries = [];
|
|
9
|
+
const recurse = (directory) => {
|
|
10
|
+
for (const name of readdirSync(directory)) {
|
|
11
|
+
const full = join(directory, name);
|
|
12
|
+
const info = statSync(full);
|
|
13
|
+
if (info.isDirectory()) {
|
|
14
|
+
recurse(full);
|
|
15
|
+
} else if (info.isFile()) {
|
|
16
|
+
entries.push({ path: relative(root, full), sizeBytes: info.size });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
recurse(root);
|
|
21
|
+
return entries;
|
|
22
|
+
};
|
|
23
|
+
const formatBytes = (bytes) => {
|
|
24
|
+
if (bytes < 1024) {
|
|
25
|
+
return `${String(bytes)} B`;
|
|
26
|
+
}
|
|
27
|
+
if (bytes < 1024 * 1024) {
|
|
28
|
+
return `${(bytes / 1024).toFixed(1)} KiB`;
|
|
29
|
+
}
|
|
30
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MiB`;
|
|
31
|
+
};
|
|
32
|
+
const buildReport = (outdir) => {
|
|
33
|
+
const all = walk(outdir);
|
|
34
|
+
const sorted = all.toSorted((a, b) => b.sizeBytes - a.sizeBytes);
|
|
35
|
+
const totalBytes = all.reduce((sum, entry) => sum + entry.sizeBytes, 0);
|
|
36
|
+
const generatedFiles = all.filter((entry) => entry.path.includes("_generated"));
|
|
37
|
+
return {
|
|
38
|
+
generatedFiles,
|
|
39
|
+
outdir,
|
|
40
|
+
topModules: sorted.slice(0, 10),
|
|
41
|
+
totalBytes,
|
|
42
|
+
totalFiles: all.length
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const renderText = (report, logger) => {
|
|
46
|
+
logger.info(`outdir: ${report.outdir}`);
|
|
47
|
+
logger.info(`total: ${String(report.totalFiles)} files, ${formatBytes(report.totalBytes)}`);
|
|
48
|
+
if (report.topModules.length > 0) {
|
|
49
|
+
logger.info("");
|
|
50
|
+
logger.info("top modules by size:");
|
|
51
|
+
for (const entry of report.topModules) {
|
|
52
|
+
logger.info(` ${formatBytes(entry.sizeBytes).padStart(10, " ")} ${entry.path}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (report.generatedFiles.length > 0) {
|
|
56
|
+
logger.info("");
|
|
57
|
+
logger.info(`_generated/ files: ${String(report.generatedFiles.length)}`);
|
|
58
|
+
for (const entry of report.generatedFiles) {
|
|
59
|
+
logger.info(` ${formatBytes(entry.sizeBytes).padStart(10, " ")} ${entry.path}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const runAnalyzeCommand = async (options) => {
|
|
64
|
+
const cwd = options.cwd ?? process.cwd();
|
|
65
|
+
const { logger } = options;
|
|
66
|
+
let outdir;
|
|
67
|
+
let descriptor;
|
|
68
|
+
let temporary = false;
|
|
69
|
+
if (options.inspectOnly) {
|
|
70
|
+
outdir = options.inspectOnly;
|
|
71
|
+
} else {
|
|
72
|
+
outdir = mkdtempSync(join(tmpdir(), "lunora-analyze-"));
|
|
73
|
+
temporary = true;
|
|
74
|
+
descriptor = {
|
|
75
|
+
args: ["exec", "wrangler", "deploy", "--dry-run", "--outdir", outdir],
|
|
76
|
+
command: "pnpm",
|
|
77
|
+
cwd
|
|
78
|
+
};
|
|
79
|
+
logger.info(`analyze: building via ${descriptor.command} ${descriptor.args.join(" ")}`);
|
|
80
|
+
const spawner = options.spawner ?? defaultSpawner;
|
|
81
|
+
const spawned = await spawner(descriptor);
|
|
82
|
+
if (spawned.code !== 0) {
|
|
83
|
+
logger.error(`analyze: wrangler dry-run failed (exit ${String(spawned.code)})`);
|
|
84
|
+
rmSync(outdir, { force: true, recursive: true });
|
|
85
|
+
return { code: spawned.code, descriptor, report: void 0 };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
if (!existsSync(outdir)) {
|
|
90
|
+
logger.error(`analyze: outdir not found at ${outdir}`);
|
|
91
|
+
return { code: 1, descriptor, report: void 0 };
|
|
92
|
+
}
|
|
93
|
+
const report = buildReport(outdir);
|
|
94
|
+
if (options.json) {
|
|
95
|
+
process.stdout.write(`${JSON.stringify(report, void 0, 2)}
|
|
96
|
+
`);
|
|
97
|
+
} else {
|
|
98
|
+
renderText(report, logger);
|
|
99
|
+
}
|
|
100
|
+
return { code: 0, descriptor, report };
|
|
101
|
+
} finally {
|
|
102
|
+
if (temporary && existsSync(outdir)) {
|
|
103
|
+
try {
|
|
104
|
+
rmSync(outdir, { force: true, recursive: true });
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const execute = defineHandler(
|
|
111
|
+
({ cwd, logger, options }) => runAnalyzeCommand({ cwd, json: options.json === true, logger })
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
export { execute, runAnalyzeCommand };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { parse } from 'jsonc-parser';
|
|
4
|
+
import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
|
|
5
|
+
import { o as openUrl } from '../packem_shared/open-url-Dfq6fAyT.mjs';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_DEV_PORT = 8787;
|
|
8
|
+
const STUDIO_PATH = "/_lunora/studio";
|
|
9
|
+
const findWranglerFile = (projectRoot) => {
|
|
10
|
+
for (const candidate of ["wrangler.jsonc", "wrangler.json"]) {
|
|
11
|
+
const fullPath = join(projectRoot, candidate);
|
|
12
|
+
if (existsSync(fullPath)) {
|
|
13
|
+
return fullPath;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return void 0;
|
|
17
|
+
};
|
|
18
|
+
const readWrangler = (projectRoot) => {
|
|
19
|
+
const file = findWranglerFile(projectRoot);
|
|
20
|
+
if (!file) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const parsed = parse(readFileSync(file, "utf8"));
|
|
25
|
+
return parsed !== null && typeof parsed === "object" ? parsed : void 0;
|
|
26
|
+
} catch {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const resolveDevPort = (wrangler) => {
|
|
31
|
+
if (!wrangler) {
|
|
32
|
+
return DEFAULT_DEV_PORT;
|
|
33
|
+
}
|
|
34
|
+
const { dev } = wrangler;
|
|
35
|
+
if (dev !== null && typeof dev === "object") {
|
|
36
|
+
const { port } = dev;
|
|
37
|
+
if (typeof port === "number" && Number.isFinite(port)) {
|
|
38
|
+
return port;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return DEFAULT_DEV_PORT;
|
|
42
|
+
};
|
|
43
|
+
const resolveRemoteUrl = (wrangler) => {
|
|
44
|
+
if (!wrangler) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
const { routes } = wrangler;
|
|
48
|
+
if (Array.isArray(routes) && routes.length > 0) {
|
|
49
|
+
const first = routes[0];
|
|
50
|
+
if (typeof first === "string") {
|
|
51
|
+
return `https://${first.split("/")[0] ?? first}${STUDIO_PATH}`;
|
|
52
|
+
}
|
|
53
|
+
if (first !== null && typeof first === "object") {
|
|
54
|
+
const { pattern } = first;
|
|
55
|
+
if (typeof pattern === "string" && pattern.length > 0) {
|
|
56
|
+
return `https://${pattern.split("/")[0] ?? pattern}${STUDIO_PATH}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const { name } = wrangler;
|
|
61
|
+
if (typeof name === "string" && name.length > 0) {
|
|
62
|
+
return `https://${name}.workers.dev${STUDIO_PATH}`;
|
|
63
|
+
}
|
|
64
|
+
return void 0;
|
|
65
|
+
};
|
|
66
|
+
const runViewCommand = async (options) => {
|
|
67
|
+
const cwd = options.cwd ?? process.cwd();
|
|
68
|
+
const wrangler = readWrangler(cwd);
|
|
69
|
+
const { logger } = options;
|
|
70
|
+
let url;
|
|
71
|
+
if (options.remote) {
|
|
72
|
+
url = resolveRemoteUrl(wrangler);
|
|
73
|
+
if (!url) {
|
|
74
|
+
logger.error("view --remote: could not determine the remote URL from wrangler config (set `routes` or `name`).");
|
|
75
|
+
return { code: 1, url: void 0 };
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
url = `http://localhost:${String(resolveDevPort(wrangler))}${STUDIO_PATH}`;
|
|
79
|
+
}
|
|
80
|
+
logger.info(`opening ${url}`);
|
|
81
|
+
try {
|
|
82
|
+
await openUrl(url, { opener: options.opener });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
+
logger.error(`view: failed to open URL: ${message}`);
|
|
86
|
+
return { code: 1, url };
|
|
87
|
+
}
|
|
88
|
+
return { code: 0, url };
|
|
89
|
+
};
|
|
90
|
+
const execute = defineHandler(
|
|
91
|
+
({ cwd, logger, options }) => runViewCommand({ cwd, logger, remote: options.remote === true })
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export { execute, runViewCommand };
|