|
1 | 1 | import { existsSync } from "node:fs"; |
2 | | -import { mkdir, rm, writeFile } from "node:fs/promises"; |
3 | | -import { join, resolve } from "node:path"; |
| 2 | +import { resolve } from "node:path"; |
4 | 3 | import { generate, writeTree } from "@vernostudio/template-generator"; |
5 | | -import type { |
6 | | - AddonId, |
7 | | - FrontendId, |
8 | | - PackageId, |
9 | | - PackageManager, |
10 | | - ProjectConfig, |
11 | | -} from "@vernostudio/template-generator"; |
12 | | -import { |
13 | | - getPmInstallCommand, |
14 | | - getShadcnAddAllCommand, |
15 | | - getShadcnBootstrapCommand, |
16 | | - getUltraciteInitCommand, |
17 | | -} from "../../pm-exec"; |
18 | | -import type { UltraciteInitMode } from "../../pm-exec"; |
| 4 | +import type { PackageManager, ProjectConfig } from "@vernostudio/template-generator"; |
19 | 5 | import { runProcess } from "../../run"; |
20 | | -import type { ResolvedCreateInputs, UiMode } from "./args"; |
21 | | -import type { UltraciteLinterId } from "../../ultracite-linter"; |
22 | | -import { readCliPackageVersion } from "../../cli-version"; |
23 | | -import { getShadcnWorkingDirectory } from "./plan"; |
24 | | -import { |
25 | | - VERNO_INITIAL_COMMIT_BODY, |
26 | | - VERNO_INITIAL_COMMIT_SUBJECT, |
27 | | - VERNO_MANIFEST_DIR, |
28 | | -} from "../../constants"; |
| 6 | +import type { ResolvedCreateInputs } from "./args"; |
| 7 | +import { VERNO_INITIAL_COMMIT_BODY, VERNO_INITIAL_COMMIT_SUBJECT } from "../../constants"; |
29 | 8 |
|
30 | 9 | export { ensureAppGlobalsBaseLayerAtEnd } from "../../app-globals"; |
31 | | - |
32 | | -export interface VernoManifest { |
33 | | - readonly addons: readonly AddonId[]; |
34 | | - readonly createdAt: string; |
35 | | - readonly frontend: FrontendId; |
36 | | - readonly generator: "verno"; |
37 | | - readonly generatorVersion: string; |
38 | | - readonly packageManager: PackageManager; |
39 | | - readonly packages: readonly PackageId[]; |
40 | | - readonly projectName: string; |
41 | | - readonly shadcnPreset?: string; |
42 | | - readonly studio: "Verno Studio"; |
43 | | - readonly ui: UiMode; |
44 | | - readonly ultraciteLinter?: UltraciteLinterId; |
45 | | -} |
46 | | - |
47 | | -export const buildVernoManifest = (args: { |
48 | | - readonly resolved: ResolvedCreateInputs; |
49 | | - readonly projectName: string; |
50 | | -}): VernoManifest => ({ |
51 | | - addons: args.resolved.addons, |
52 | | - createdAt: new Date().toISOString(), |
53 | | - frontend: args.resolved.frontend, |
54 | | - generator: "verno", |
55 | | - generatorVersion: readCliPackageVersion(), |
56 | | - packageManager: args.resolved.packageManager, |
57 | | - packages: args.resolved.packages, |
58 | | - projectName: args.projectName, |
59 | | - shadcnPreset: args.resolved.useShadcn ? args.resolved.shadcnPreset : undefined, |
60 | | - studio: "Verno Studio", |
61 | | - ui: args.resolved.ui, |
62 | | - ultraciteLinter: args.resolved.runUltracite ? args.resolved.ultraciteLinter : undefined, |
63 | | -}); |
64 | | - |
65 | | -export const writeVernoManifest = async ( |
66 | | - projectDir: string, |
67 | | - manifest: VernoManifest, |
68 | | -): Promise<void> => { |
69 | | - const dir = join(projectDir, VERNO_MANIFEST_DIR); |
70 | | - await mkdir(dir, { recursive: true }); |
71 | | - const out = join(dir, "manifest.json"); |
72 | | - await writeFile(out, `${JSON.stringify(manifest, null, 2)}\n`, "utf-8"); |
73 | | -}; |
| 10 | +export { |
| 11 | + buildVernoManifestForCreate as buildVernoManifest, |
| 12 | + writeVernoManifest, |
| 13 | +} from "../shared/manifest"; |
| 14 | +export type { VernoManifest } from "../shared/manifest"; |
74 | 15 |
|
75 | 16 | export const getProjectPath = (name: string): string => resolve(process.cwd(), name); |
76 | 17 |
|
@@ -100,77 +41,6 @@ export const scaffold = async ( |
100 | 41 | return { filesWritten: filesWritten.length }; |
101 | 42 | }; |
102 | 43 |
|
103 | | -export const runInstallIfEnabled = async ( |
104 | | - enabled: boolean, |
105 | | - packageManager: PackageManager, |
106 | | - projectDir: string, |
107 | | -): Promise<void> => { |
108 | | - if (!enabled) { |
109 | | - return; |
110 | | - } |
111 | | - const { args: installArgs, file } = getPmInstallCommand(packageManager); |
112 | | - await runProcess(file, installArgs, { cwd: projectDir, stepId: "install" }); |
113 | | -}; |
114 | | - |
115 | | -export const runShadcnIfEnabled = async (options: { |
116 | | - readonly enabled: boolean; |
117 | | - readonly packageManager: PackageManager; |
118 | | - readonly preset: string; |
119 | | - readonly projectDir: string; |
120 | | - readonly monorepoWithDesignSystem: boolean; |
121 | | -}): Promise<void> => { |
122 | | - if (!options.enabled) { |
123 | | - return; |
124 | | - } |
125 | | - |
126 | | - const workingDir = getShadcnWorkingDirectory( |
127 | | - options.projectDir, |
128 | | - options.monorepoWithDesignSystem, |
129 | | - ); |
130 | | - |
131 | | - // shadcn apply/add requires a detected framework (Next.js, Vite, etc.). |
132 | | - // We write a temporary dummy config to ensure detection passes in all environments. |
133 | | - const dummyConfigPath = join(workingDir, "vite.config.ts"); |
134 | | - await writeFile(dummyConfigPath, "export default {};\n", "utf-8"); |
135 | | - |
136 | | - try { |
137 | | - const bootstrap = getShadcnBootstrapCommand(options.packageManager, { |
138 | | - monorepoWithDesignSystem: options.monorepoWithDesignSystem, |
139 | | - preset: options.preset, |
140 | | - }); |
141 | | - const addAll = getShadcnAddAllCommand(options.packageManager, { |
142 | | - monorepoWithDesignSystem: options.monorepoWithDesignSystem, |
143 | | - }); |
144 | | - |
145 | | - for (const cmd of [bootstrap, addAll]) { |
146 | | - await runProcess(cmd.file, cmd.args, { |
147 | | - ciSafe: false, |
148 | | - cwd: options.projectDir, |
149 | | - stepId: "shadcn", |
150 | | - }); |
151 | | - } |
152 | | - } finally { |
153 | | - await rm(dummyConfigPath, { force: true }).catch(() => { |
154 | | - /* ignore cleanup errors */ |
155 | | - }); |
156 | | - } |
157 | | -}; |
158 | | - |
159 | | -export const runUltraciteIfEnabled = async ( |
160 | | - enabled: boolean, |
161 | | - packageManager: PackageManager, |
162 | | - projectDir: string, |
163 | | - mode: UltraciteInitMode, |
164 | | - runOptions?: { readonly ciSafe?: boolean; readonly linter?: UltraciteLinterId }, |
165 | | -): Promise<void> => { |
166 | | - if (!enabled) { |
167 | | - return; |
168 | | - } |
169 | | - const u = getUltraciteInitCommand(packageManager, mode, { linter: runOptions?.linter }); |
170 | | - const ciSafe = runOptions?.ciSafe ?? mode === "quiet"; |
171 | | - await runProcess(u.file, u.args, { ciSafe, cwd: projectDir, stepId: "ultracite" }); |
172 | | -}; |
173 | | - |
174 | 44 | export const runGitInitAndCommitIfEnabled = async ( |
175 | 45 | enabled: boolean, |
176 | 46 | projectDir: string, |
|
0 commit comments