|
1 |
| -import { hydrate } from "./hydrate.js"; |
| 1 | +import { parseArgs } from "node:util"; |
2 | 2 |
|
3 |
| -process.exitCode = await hydrate(process.argv.slice(2)); |
| 3 | +import { setupWithInformation } from "../setup/setupWithInformation.js"; |
| 4 | +import { |
| 5 | + skipSpinnerBlock, |
| 6 | + successSpinnerBlock, |
| 7 | + withSpinner, |
| 8 | +} from "../shared/cli/spinners.js"; |
| 9 | +import { runOrRestore } from "../shared/runOrRestore.js"; |
| 10 | +import { clearUnnecessaryFiles } from "./steps/clearUnnecessaryFiles.js"; |
| 11 | +import { finalizeDependencies as finalizeDependencies } from "./steps/finalizeDependencies.js"; |
| 12 | +import { runCommand } from "./steps/runCommand.js"; |
| 13 | +import { writeReadme } from "./steps/writeReadme.js"; |
| 14 | +import { writeStructure } from "./steps/writing/writeStructure.js"; |
| 15 | +import { getHydrationDefaults } from "./values/getHydrationDefaults.js"; |
| 16 | +import { augmentWithHydrationValues } from "./values/hydrationInputValues.js"; |
| 17 | + |
| 18 | +export async function hydrate(args: string[]) { |
| 19 | + const { values: hydrationSkips } = parseArgs({ |
| 20 | + args, |
| 21 | + options: { |
| 22 | + "skip-install": { type: "boolean" }, |
| 23 | + "skip-setup": { type: "boolean" }, |
| 24 | + }, |
| 25 | + strict: false, |
| 26 | + tokens: true, |
| 27 | + }); |
| 28 | + |
| 29 | + return await runOrRestore({ |
| 30 | + args, |
| 31 | + defaults: await getHydrationDefaults(), |
| 32 | + label: "hydration", |
| 33 | + run: async ({ octokit, values }) => { |
| 34 | + const hydrationValues = await augmentWithHydrationValues(values); |
| 35 | + |
| 36 | + await withSpinner(clearUnnecessaryFiles, "clearing unnecessary files"); |
| 37 | + |
| 38 | + await withSpinner( |
| 39 | + () => writeStructure(hydrationValues), |
| 40 | + "writing new repository structure" |
| 41 | + ); |
| 42 | + |
| 43 | + await withSpinner( |
| 44 | + () => writeReadme(hydrationValues), |
| 45 | + "writing README.md" |
| 46 | + ); |
| 47 | + |
| 48 | + if (hydrationSkips["skip-install"]) { |
| 49 | + skipSpinnerBlock(`Skipping package installations.`); |
| 50 | + } else { |
| 51 | + await withSpinner( |
| 52 | + () => finalizeDependencies(hydrationValues), |
| 53 | + "finalizing dependencies" |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + await runCommand("pnpm lint --fix", "auto-fixing lint rules"); |
| 58 | + await runCommand("pnpm format --write", "formatting files"); |
| 59 | + |
| 60 | + if (hydrationSkips["skip-setup"]) { |
| 61 | + skipSpinnerBlock(`Done hydrating, and skipping setup command.`); |
| 62 | + } else { |
| 63 | + successSpinnerBlock("Done hydrating. Starting setup command..."); |
| 64 | + |
| 65 | + await setupWithInformation({ |
| 66 | + octokit, |
| 67 | + values: { |
| 68 | + ...hydrationValues, |
| 69 | + skipUninstalls: true, |
| 70 | + }, |
| 71 | + }); |
| 72 | + } |
| 73 | + }, |
| 74 | + }); |
| 75 | +} |
0 commit comments