|
1 | 1 | import { getOtherProofKitDependencies } from "@proofkit/registry"; |
2 | 2 | import semver from "semver"; |
| 3 | +import ora from "ora"; |
3 | 4 |
|
4 | 5 | import { getRegistryUrl, shadcnInstall } from "~/helpers/shadcn-cli.js"; |
5 | 6 | import { getVersion } from "~/utils/getProofKitVersion.js"; |
6 | 7 | import { logger } from "~/utils/logger.js"; |
7 | 8 | import { getSettings, mergeSettings } from "~/utils/parseSettings.js"; |
8 | 9 | import { getMetaFromRegistry } from "./getOptions.js"; |
9 | 10 | import { processPostInstallStep } from "./postInstall/index.js"; |
| 11 | +import { preflightAddCommand } from "./preflight.js"; |
| 12 | +import { uniq } from "es-toolkit"; |
10 | 13 |
|
11 | 14 | export async function installFromRegistry(name: string) { |
12 | | - const meta = await getMetaFromRegistry(name); |
13 | | - if (!meta) { |
14 | | - logger.error(`Template ${name} not found in the ProofKit registry`); |
15 | | - return; |
16 | | - } |
17 | | - |
18 | | - if ( |
19 | | - meta.minimumProofKitVersion && |
20 | | - semver.gt(meta.minimumProofKitVersion, getVersion()) |
21 | | - ) { |
22 | | - logger.error( |
23 | | - `Template ${name} requires ProofKit version ${meta.minimumProofKitVersion}, but you are using version ${getVersion()}` |
24 | | - ); |
25 | | - return; |
26 | | - } |
| 15 | + |
| 16 | + const spinner = ora("Validating template").start(); |
| 17 | + await preflightAddCommand(); |
| 18 | + |
| 19 | + try { |
| 20 | + const meta = await getMetaFromRegistry(name); |
| 21 | + if (!meta) { |
| 22 | + spinner.fail(`Template ${name} not found in the ProofKit registry`); |
| 23 | + return; |
| 24 | + } |
| 25 | + |
| 26 | + |
| 27 | + if ( |
| 28 | + meta.minimumProofKitVersion && |
| 29 | + semver.gt(meta.minimumProofKitVersion, getVersion()) |
| 30 | + ) { |
| 31 | + logger.error( |
| 32 | + `Template ${name} requires ProofKit version ${meta.minimumProofKitVersion}, but you are using version ${getVersion()}` |
| 33 | + ); |
| 34 | + spinner.fail("Template is not compatible with your ProofKit version"); |
| 35 | + return; |
| 36 | + } |
| 37 | + spinner.succeed(); |
27 | 38 |
|
28 | 39 | const otherProofKitDependencies = getOtherProofKitDependencies(meta); |
29 | 40 |
|
@@ -55,10 +66,14 @@ export async function installFromRegistry(name: string) { |
55 | 66 |
|
56 | 67 | // update the settings |
57 | 68 | mergeSettings({ |
58 | | - registryTemplates: [ |
| 69 | + registryTemplates: uniq([ |
59 | 70 | ...previouslyInstalledTemplates, |
60 | 71 | name, |
61 | 72 | ...otherProofKitDependencies, |
62 | | - ], |
| 73 | + ]), |
63 | 74 | }); |
| 75 | + } catch (error) { |
| 76 | + spinner.fail("Failed to fetch template metadata."); |
| 77 | + logger.error(error); |
| 78 | + } |
64 | 79 | } |
0 commit comments