11import { Logger , Resolver } from '@h3ravel/shared'
22import { copyFile , readFile , readdir , rm , unlink , writeFile } from 'node:fs/promises'
33import { depsToAdd , depsToRemove , filesToRemove } from './data'
4- import { detectPackageManager , installPackage } from '@antfu/install-pkg'
54import path , { basename , join , relative } from 'node:path'
65
76import { Str } from '@h3ravel/support'
87import { chdir } from 'node:process'
98import { depsList } from './data'
9+ import { detectPackageManager } from '@antfu/install-pkg'
1010import { downloadTemplate } from 'giget'
11+ import { exec } from 'tinyexec'
1112import { existsSync } from 'node:fs'
13+ import { spawnSync } from 'node:child_process'
1214
1315export default class {
1416 skipInstallation ?: boolean
@@ -61,7 +63,6 @@ export default class {
6163 const status = await downloadTemplate ( template , {
6264 dir : this . location ,
6365 auth,
64- install,
6566 provider : 'github' ,
6667 registry : await this . pm ( ) ,
6768 forceClean : false ,
@@ -70,14 +71,40 @@ export default class {
7071 return status
7172 }
7273
73- async installPackage ( name : string ) {
74- await installPackage ( name , {
75- cwd : this . location ,
76- silent : true ,
74+ /**
75+ * Installs the project dependencies using the detected package manager.
76+ * If a specific package name is provided, it will install that package
77+ * instead of all dependencies.
78+ *
79+ * @param name
80+ * @param args
81+ * @returns
82+ */
83+ async installPackage ( name ?: string , args : string [ ] = [ ] ) {
84+ const bcmd = await Resolver . getPakageInstallCommand ( ) + ( name ? ` ${ name } ` : '' )
85+ const cmd = bcmd . split ( ' ' ) [ 0 ]
86+ if ( bcmd . includes ( ' ' ) ) {
87+ args . unshift ( ...bcmd . split ( ' ' ) . slice ( 1 ) )
88+ }
89+
90+ const child = spawnSync ( cmd , args , {
91+ cwd : process . cwd ( ) ,
92+ stdio : 'ignore' ,
7793 } )
94+
95+ if ( child . error ) {
96+ return child . status
97+ }
98+
99+ return 0
78100 }
79101
80- async complete ( installed = false ) {
102+ async complete ( install = false ) {
103+ let installed = false
104+ if ( install ) {
105+ installed = await this . installPackage ( ) === 0
106+ }
107+
81108 console . log ( '' )
82109
83110 const installPath = './' + relative ( process . cwd ( ) , this . location ! )
0 commit comments