( environment: Environment, options: Options, )
| 6 | import type { Environment, Options } from '../types.js' |
| 7 | |
| 8 | export async function postInitScript( |
| 9 | environment: Environment, |
| 10 | options: Options, |
| 11 | ) { |
| 12 | const packageJsonPath = resolve(options.targetDir, 'package.json') |
| 13 | |
| 14 | if (!environment.exists(packageJsonPath)) { |
| 15 | environment.warn( |
| 16 | 'Warning', |
| 17 | 'No package.json found, skipping post-create-init script', |
| 18 | ) |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | try { |
| 23 | const packageJsonContent = readFileSync(packageJsonPath, 'utf-8') |
| 24 | const packageJson = JSON.parse(packageJsonContent) |
| 25 | |
| 26 | if (!packageJson.scripts || !packageJson.scripts['post-create-init']) { |
| 27 | // No post-create-init script found, skip silently |
| 28 | return |
| 29 | } |
| 30 | |
| 31 | environment.startStep({ |
| 32 | id: 'post-init-script', |
| 33 | type: 'command', |
| 34 | message: 'Running post-create-init script...', |
| 35 | }) |
| 36 | |
| 37 | const { command, args } = getPackageManagerScriptCommand( |
| 38 | options.packageManager, |
| 39 | ['post-create-init'], |
| 40 | ) |
| 41 | |
| 42 | await environment.execute(command, args, options.targetDir, { |
| 43 | inherit: true, |
| 44 | }) |
| 45 | |
| 46 | environment.finishStep('post-init-script', 'Post-cta-init script complete') |
| 47 | } catch (error) { |
| 48 | environment.error( |
| 49 | `Failed to run post-create-init script: ${error instanceof Error ? error.message : String(error)}`, |
| 50 | ) |
| 51 | } |
| 52 | } |
no test coverage detected