mirror of
https://github.com/ZTatman/myst.git
synced 2026-11-20 20:07:59 +00:00
* Add CLI scaffold and config generators * Add PR stacking note to README * refactor: write embargo init command myself for clarity * refactor: rename Myst and narrow CLI setup flow * Update Phase 1 plans with finalized design decisions Major updates: - Add authentication model (Forgejo sessions for identity, PAT for data access) - Add link types (private email-verified, public time-expired) - Add link creation rules (owner-only) - Add Docker/deployment guidance (Dockerfile only, Dokploy handles orchestration) - Add database model (separate DBs on same PostgreSQL instance) - Add viewer baseline and user dashboard sections - Add SMTP configuration via post-login setup page Key architectural decisions: - Users log in via Forgejo session, no separate Myst login - Service account PAT used for API calls, not user identity - Private links require email verification code - Public links are time-expired for job applications - Myst provides Dockerfile, operators use Dokploy for deployment * Complete CLI init skeleton with CodeRabbit review fixes CLI changes: - Narrow init to Myst-only config generation (no Forgejo provisioning) - Add yoctocolors styling to CLI output - Simplify URL validation logic (remove dead code) - Fix typo in env.ts comment - Remove docker-compose generator (out of scope) - Move example config from src/ to packages/cli/examples/ - Fix CommandName type to match implemented commands only Config changes: - Remove databaseUrl from myst.config.json (DB is .env-only) - Update example config with current fields - Reject non-HTTP schemes before auto-prepending https:// - Use localhost -> 127.0.0.1 in Caddy/Nginx examples - Add file existence checks and 0o600 permissions Build passes after all changes. * docs: rewrite README with Myst branding and architecture - Add Mermaid architecture diagram - Document two link types (private/public) - Explain authentication model - Provide setup steps - Add example configuration - Include Phase 1 completion checklist * fix: correct Mermaid diagram syntax * refactor: streamline README per create-readme skill guidelines - Use blockquote for tagline - Simplify architecture diagram labels - Remove redundant sections (Setup, Example Config, License) - Keep checklist as primary tracking mechanism - Use tables for features and auth - Reduce verbosity throughout * cli: add preflight check and version flag - Add preflightWriteTargets to check file existence before writing - Remove stub commands (start, stop, status) from help text - Add --version flag support - Sequential file writes with preflight check * cleanup: remove empty command stubs and test config - Remove start.ts, stop.ts, status.ts (not implemented yet) - Remove myst.config.json (generated during testing) * cleanup: remove app-ini generator (Forgejo provisioning out of scope) * cleanup: remove empty unused utility files (docker.ts, flags.ts, init.ts) * cleanup: remove examples.ts (examples belong in docs, not deployed code)
113 lines
2.7 KiB
JavaScript
113 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
import * as c from "yoctocolors";
|
|
import pkg from "../package.json" with { type: "json" };
|
|
|
|
import { initCommand } from "./commands/init.js";
|
|
|
|
const PADDING = 4;
|
|
const INDENT = " ";
|
|
const USAGE = "myst <command> [options/flags] [arguments]";
|
|
|
|
type CommandName = "init";
|
|
|
|
interface Option {
|
|
name: CommandName | string | string[];
|
|
desc: string;
|
|
}
|
|
|
|
interface CLIConfig {
|
|
commands: Option[];
|
|
globalFlags: Option[];
|
|
}
|
|
|
|
const config: CLIConfig = {
|
|
commands: [
|
|
{ name: "init", desc: "Bootstrap Myst and generate config/env files" },
|
|
],
|
|
globalFlags: [
|
|
{ name: ["-h", "--help"], desc: "Display help information" },
|
|
{ name: ["-v", "--version"], desc: "Display package version number" },
|
|
],
|
|
};
|
|
|
|
const splitCamelCaseWords = (text: string): string =>
|
|
text.replace(/([a-z])([A-Z])/g, "$1 $2");
|
|
|
|
const toTitleCase = (text: string): string =>
|
|
text.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
|
|
function formatSection(
|
|
header: string,
|
|
options: Option[],
|
|
colWidth: number,
|
|
): string {
|
|
const rows = options.map((o) => {
|
|
const name = Array.isArray(o.name) ? o.name.join(", ") : o.name;
|
|
return `${INDENT}${name.padEnd(colWidth)}${o.desc}`;
|
|
});
|
|
const title = toTitleCase(splitCamelCaseWords(header));
|
|
return [c.bold(title + ":"), ...rows].join("\n");
|
|
}
|
|
|
|
const allOptions = Object.values(config).flat();
|
|
const COL_WIDTH =
|
|
Math.max(
|
|
...allOptions.map((o) =>
|
|
Array.isArray(o.name) ? o.name.join(", ").length : o.name.length,
|
|
),
|
|
) + PADDING;
|
|
|
|
const HELP_TEXT = `
|
|
${c.yellow(pkg.name)}
|
|
|
|
|
|
${INDENT}${USAGE}
|
|
|
|
|
|
${Object.entries(config)
|
|
.map(([header, options]) =>
|
|
formatSection(header, options as Option[], COL_WIDTH),
|
|
)
|
|
.join("\n\n")}
|
|
`;
|
|
|
|
async function main(): Promise<void> {
|
|
const [command, ...options] = process.argv.slice(2);
|
|
const flags = options.filter((o) => o.startsWith("-"));
|
|
|
|
if (flags.includes("-v") || flags.includes("--version")) {
|
|
process.stdout.write(`${pkg.version}\n`);
|
|
process.exitCode = 0;
|
|
return;
|
|
}
|
|
|
|
if (!command || flags.includes("-h") || flags.includes("--help")) {
|
|
process.stdout.write(`${HELP_TEXT}`);
|
|
process.exitCode = 0;
|
|
return;
|
|
}
|
|
|
|
const knownCommands: Record<CommandName, (args: string[]) => Promise<void>> =
|
|
{
|
|
init: initCommand,
|
|
};
|
|
|
|
const isKnownCommand = (cmd: string): cmd is CommandName =>
|
|
cmd in knownCommands;
|
|
|
|
if (!isKnownCommand(command)) {
|
|
process.stderr.write(`Unknown command: ${command}\n`);
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await knownCommands[command](options);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
process.stderr.write(`${c.red("Error:")} ${message}\n`);
|
|
process.exitCode = 1;
|
|
}
|
|
}
|
|
|
|
await main();
|