refactor(cli): improve init command error handling; change "service
account" verbaige to "dedicated forgejo user" to match Forgejo user model;
This commit is contained in:
parent
1eb5368c9e
commit
342252efbb
4 changed files with 65 additions and 71 deletions
|
|
@ -174,23 +174,24 @@ export async function initCommand(_args: string[]): Promise<void> {
|
|||
}),
|
||||
forgejoBotUsername: () =>
|
||||
p.text({
|
||||
message: "What dedicated Forgejo username should Myst use for API access?",
|
||||
message:
|
||||
"What dedicated Forgejo username should Myst use for API access?",
|
||||
placeholder: "myst-bot",
|
||||
validate: (v) =>
|
||||
v?.trim()
|
||||
? undefined
|
||||
: "Dedicated Forgejo username is required",
|
||||
v?.trim() ? undefined : "Dedicated Forgejo username is required",
|
||||
}),
|
||||
forgejoPat: () =>
|
||||
p.password({
|
||||
message:
|
||||
"Paste the Forgejo personal access token for that dedicated Forgejo user",
|
||||
mask: "*",
|
||||
validate: (v) => (v?.trim() ? undefined : "Forgejo PAT is required"),
|
||||
}),
|
||||
grantTokenSecret: () =>
|
||||
p.password({
|
||||
message:
|
||||
"Paste a grant token secret, or press enter to generate one automatically",
|
||||
mask: "*",
|
||||
validate: () => undefined,
|
||||
}),
|
||||
},
|
||||
|
|
@ -203,70 +204,71 @@ export async function initCommand(_args: string[]): Promise<void> {
|
|||
);
|
||||
|
||||
const s = p.spinner();
|
||||
s.start("Generating config files");
|
||||
const publicUrl = normalizeHttpUrl(answers.publicUrl);
|
||||
const adminUrl = normalizeHttpUrl(answers.adminUrl);
|
||||
const forgejoBaseUrl = normalizeHttpUrl(answers.forgejoBaseUrl);
|
||||
const grantTokenSecret = answers.grantTokenSecret?.trim() || generateSecret();
|
||||
const envContent = generateEnvFile({
|
||||
adminUrl,
|
||||
databaseUrl: answers.databaseUrl,
|
||||
forgejoBaseUrl,
|
||||
forgejoBotUsername: answers.forgejoBotUsername,
|
||||
forgejoPat: answers.forgejoPat,
|
||||
grantTokenSecret,
|
||||
publicUrl,
|
||||
});
|
||||
const configContent = JSON.stringify(
|
||||
{
|
||||
adminUrl,
|
||||
forgejoBaseUrl,
|
||||
forgejoBotUsername: answers.forgejoBotUsername,
|
||||
publicUrl,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
|
||||
const outDir = process.cwd();
|
||||
const envPath = path.join(outDir, ".env");
|
||||
const configPath = path.join(outDir, "myst.config.json");
|
||||
|
||||
try {
|
||||
s.start("Generating config files");
|
||||
|
||||
const publicUrl = normalizeHttpUrl(answers.publicUrl);
|
||||
const adminUrl = normalizeHttpUrl(answers.adminUrl);
|
||||
const forgejoBaseUrl = normalizeHttpUrl(answers.forgejoBaseUrl);
|
||||
const grantTokenSecret =
|
||||
answers.grantTokenSecret?.trim() || generateSecret();
|
||||
|
||||
const envContent = generateEnvFile({
|
||||
adminUrl,
|
||||
databaseUrl: answers.databaseUrl,
|
||||
forgejoBaseUrl,
|
||||
forgejoBotUsername: answers.forgejoBotUsername,
|
||||
forgejoPat: answers.forgejoPat,
|
||||
grantTokenSecret,
|
||||
publicUrl,
|
||||
});
|
||||
|
||||
const configContent = JSON.stringify(
|
||||
{
|
||||
adminUrl,
|
||||
forgejoBaseUrl,
|
||||
forgejoBotUsername: answers.forgejoBotUsername,
|
||||
publicUrl,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
);
|
||||
|
||||
const outDir = process.cwd();
|
||||
const envPath = path.join(outDir, ".env");
|
||||
const configPath = path.join(outDir, "myst.config.json");
|
||||
|
||||
await preflightWriteTargets([envPath, configPath]);
|
||||
await writePrivateFile(envPath, envContent);
|
||||
await writePrivateFile(configPath, configContent);
|
||||
} catch (e) {
|
||||
|
||||
s.stop("Config files generated");
|
||||
p.note(
|
||||
[c.green(".env"), c.green("myst.config.json")].join("\n"),
|
||||
c.yellow("Files written to current directory"),
|
||||
);
|
||||
p.note(
|
||||
[
|
||||
`${c.bold("Public viewer URL:")} ${c.cyan(publicUrl)}`,
|
||||
`${c.bold("Private admin URL:")} ${c.cyan(adminUrl)}`,
|
||||
`${c.bold("Forgejo base URL:")} ${c.cyan(forgejoBaseUrl)}`,
|
||||
`${c.bold("Forgejo bot username:")} ${c.green(answers.forgejoBotUsername)}`,
|
||||
"",
|
||||
`${c.bold("Admin URL reminder:")} protect this upstream with Tailscale, VPN, Cloudflare Access, or reverse-proxy auth.`,
|
||||
].join("\n"),
|
||||
c.yellow("Next steps"),
|
||||
);
|
||||
p.outro(
|
||||
c.green(
|
||||
"Done. Deploy Myst, then run forgejo bootstrap and doctor commands to verify setup.",
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
s.stop();
|
||||
p.cancel(
|
||||
e instanceof Error
|
||||
? e.message
|
||||
: `Failed to write config files to ${outDir}`,
|
||||
error instanceof Error ? error.message : "Failed to initialize Myst",
|
||||
);
|
||||
return;
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
||||
s.stop("Config files generated");
|
||||
|
||||
p.note(
|
||||
[c.green(".env"), c.green("myst.config.json")].join("\n"),
|
||||
c.yellow("Files written to current directory"),
|
||||
);
|
||||
|
||||
p.note(
|
||||
[
|
||||
`${c.bold("Public viewer URL:")} ${c.cyan(publicUrl)}`,
|
||||
`${c.bold("Private admin URL:")} ${c.cyan(adminUrl)}`,
|
||||
`${c.bold("Forgejo base URL:")} ${c.cyan(forgejoBaseUrl)}`,
|
||||
`${c.bold("Forgejo bot username:")} ${c.green(answers.forgejoBotUsername)}`,
|
||||
"",
|
||||
`${c.bold("Admin URL reminder:")} protect this upstream with Tailscale, VPN, Cloudflare Access, or reverse-proxy auth.`,
|
||||
].join("\n"),
|
||||
c.yellow("Next steps"),
|
||||
);
|
||||
p.outro(
|
||||
c.green(
|
||||
"Done. Deploy Myst, then run forgejo bootstrap and doctor commands to verify setup.",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ function escapeEnvValue(value: string): string {
|
|||
return `"${value
|
||||
.replace(/\\/g, "\\\\") // Escape backslashes
|
||||
.replace(/"/g, '\\"') // Escape double quotes
|
||||
.replace(/\r?\n/g, "\\n")}"`; // Escape newlines
|
||||
.replace(/\r?\n/g, "\\n") // Escape newlines
|
||||
.replace(/\$/g, "\\$")}"`; // Escape dollar signs
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,7 +1 @@
|
|||
export const MYST_DEFAULT_FORGEJO_PORT = 3000;
|
||||
export const MYST_DEFAULT_SERVICE_PORT = 4000;
|
||||
|
||||
export const MYST_VISIBILITY_MODES = {
|
||||
TEAM: "team",
|
||||
ALLOWLIST: "allowlist"
|
||||
} as const;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
export type VisibilityMode = "team" | "allowlist";
|
||||
|
||||
export interface RepoRef {
|
||||
owner: string;
|
||||
name: string;
|
||||
|
|
@ -10,4 +8,3 @@ export interface GrantSnapshot {
|
|||
sourceBranch: string;
|
||||
commitSha: string;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue