UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 9.3 kB
{"version":3,"file":"init.cjs","names":["promptInitBasic","p","fetchInitParent","promptInitOverrides","exitCodeFor","colors","runDockerComposeUp"],"sources":["../../../src/cli/commands/init.ts"],"sourcesContent":["import * as p from \"@clack/prompts\";\nimport type { InitOptions, InitResult, OverrideSection } from \"../../contract\";\nimport { fetchInitParent } from \"../../handlers/init\";\nimport { runDockerComposeUp } from \"../../infra/docker\";\nimport { type ProgressEvent, pluginEvents } from \"../../services/dev/progress\";\nimport { colors } from \"../../utils/theme\";\nimport { exitCodeFor } from \"../exit-codes\";\nimport { promptInitBasic, promptInitOverrides } from \"../prompts\";\nimport { printTimingSummary } from \"../render/dev\";\nimport type { CommandContext } from \"./context\";\n\nexport const runInit = async (ctx: CommandContext): Promise<void> => {\n const client = ctx.client;\n const input = ctx.input;\n let initInput: InitOptions = { ...(input as InitOptions) };\n\n if (!initInput.noInteractive) {\n const basic = await promptInitBasic({\n extends: initInput.extends,\n account: initInput.account,\n domain: initInput.domain,\n });\n\n let parentPluginKeys: string[] = [];\n let parentConfig: {\n title?: string;\n description?: string;\n plugins?: Record<string, unknown>;\n } | null = null;\n\n const fetchSpinner = p.spinner();\n fetchSpinner.start(\"Fetching parent config\");\n try {\n const parent = await fetchInitParent(basic.extendsAccount, basic.extendsGateway);\n parentConfig = parent.parentConfig;\n parentPluginKeys = parent.parentPluginKeys;\n } catch {\n fetchSpinner.stop(\"Config not found\");\n console.error(\n `[CLI] No config found at bos://${basic.extendsAccount}/${basic.extendsGateway}`,\n );\n process.exit(1);\n }\n fetchSpinner.stop(\"Config fetched\");\n\n if (\n typeof parentConfig?.title === \"string\" &&\n parentConfig.title.trim() &&\n typeof parentConfig?.description === \"string\" &&\n parentConfig.description.trim()\n ) {\n const shouldContinue = await p.confirm({\n message: `You will be extending ${parentConfig.title} - ${parentConfig.description}. Continue?`,\n initialValue: true,\n });\n\n if (p.isCancel(shouldContinue) || !shouldContinue) {\n process.exit(0);\n }\n }\n\n const overrides = await promptInitOverrides({\n parentPluginKeys,\n plugins: initInput.plugins,\n overrides: initInput.overrides as OverrideSection[] | undefined,\n level: initInput.level,\n });\n\n const directory = initInput.directory || basic.domain || basic.extendsGateway;\n\n initInput = {\n ...initInput,\n extends: `bos://${basic.extendsAccount}/${basic.extendsGateway}`,\n directory,\n account: basic.account,\n domain: basic.domain || undefined,\n plugins: overrides.plugins,\n overrides: overrides.overrides,\n level: overrides.level ?? initInput.level,\n noInteractive: true,\n };\n }\n\n const initSpinner = p.spinner();\n initSpinner.start(\"Initializing project\");\n\n const phaseLabels: Record<string, string> = {\n \"parent config\": \"Fetching parent config...\",\n \"template source\": \"Resolving template source...\",\n \"scaffold project\": \"Creating project scaffold...\",\n \"copy files\": \"Copying template files...\",\n \"personalize config\": \"Personalizing config...\",\n \"write snapshot\": \"Writing snapshot...\",\n \"resolve config\": \"Resolving config...\",\n \"generate env/docker\": \"Generating environment config...\",\n \"create env file\": \"Creating .env file...\",\n \"install dependencies\": \"Installing dependencies...\",\n \"generate types\": \"Generating types...\",\n \"generate migrations\": \"Generating database migrations...\",\n \"generate code artifacts\": \"Generating code artifacts...\",\n };\n\n const onProgress = (event: ProgressEvent) => {\n const label = phaseLabels[event.phase] ?? event.phase;\n if (event.status === \"running\") {\n initSpinner.message(label);\n }\n };\n pluginEvents.on(\"progress\", onProgress);\n\n let result: InitResult;\n try {\n result = await client.init(initInput);\n } finally {\n pluginEvents.off(\"progress\", onProgress);\n }\n\n if (exitCodeFor(result) === 1) {\n initSpinner.stop(\"Failed\");\n console.error(`[CLI] ${result.error || \"Unknown error\"}`);\n process.exit(1);\n }\n\n initSpinner.stop(\"Project initialized\");\n\n console.log(` ${colors.dim(\"Extends:\")} ${result.extends}`);\n console.log(` ${colors.dim(\"Directory:\")} ${result.directory}`);\n if (result.account) console.log(` ${colors.dim(\"Account:\")} ${result.account}`);\n if (result.domain) console.log(` ${colors.dim(\"Domain:\")} ${result.domain}`);\n if (result.overrides && result.overrides.length > 0)\n console.log(` ${colors.dim(\"Overrides:\")} ${result.overrides.join(\", \")}`);\n if (result.plugins && result.plugins.length > 0)\n console.log(` ${colors.dim(\"Plugins:\")} ${result.plugins.join(\", \")}`);\n console.log(` ${colors.dim(\"Files copied:\")} ${result.filesCopied}`);\n printTimingSummary(result.timings);\n console.log();\n console.log(colors.dim(\" Next steps:\"));\n console.log(colors.dim(` cd ${result.directory}`));\n if (!initInput.noInstall) {\n console.log(colors.dim(\" pnpm run dev\"));\n } else {\n console.log(colors.dim(\" pnpm install\"));\n console.log(colors.dim(\" pnpm run dev\"));\n }\n console.log();\n\n if (initInput.noInteractive !== true && !initInput.noInstall && result.targetDir) {\n const shouldStartDocker = await p.confirm({\n message: \"Run docker compose up -d --wait?\",\n initialValue: true,\n });\n\n if (shouldStartDocker === true) {\n const dockerSpinner = p.spinner();\n dockerSpinner.start(\"Starting Docker services\");\n const compose = await runDockerComposeUp(result.targetDir);\n if (compose.ok) {\n dockerSpinner.stop(\"Docker services ready\");\n } else {\n dockerSpinner.stop(\"Docker services not started\");\n p.log.warn(`docker compose up -d --wait failed${compose.tail ? `:\\n${compose.tail}` : \"\"}`);\n }\n }\n }\n\n return;\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,UAAU,OAAO,QAAuC;CACnE,MAAM,SAAS,IAAI;CAEnB,IAAI,YAAyB,EAAE,GADjB,IAAI,MACuC;CAEzD,IAAI,CAAC,UAAU,eAAe;EAC5B,MAAM,QAAQ,MAAMA,gCAAgB;GAClC,SAAS,UAAU;GACnB,SAAS,UAAU;GACnB,QAAQ,UAAU;EACpB,CAAC;EAED,IAAI,mBAA6B,CAAC;EAClC,IAAI,eAIO;EAEX,MAAM,eAAeC,eAAE,QAAQ;EAC/B,aAAa,MAAM,wBAAwB;EAC3C,IAAI;GACF,MAAM,SAAS,MAAMC,kCAAgB,MAAM,gBAAgB,MAAM,cAAc;GAC/E,eAAe,OAAO;GACtB,mB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