feat(cli): add packageManager to packageJson template
This commit is contained in:
parent
84c7722cf8
commit
2ac70ebdd1
@ -8,6 +8,7 @@ export async function createPackageJson(
|
||||
mode: Mode,
|
||||
pkg: Record<string, any>,
|
||||
{
|
||||
packageManager,
|
||||
docsDir,
|
||||
siteName,
|
||||
siteDescription,
|
||||
@ -20,11 +21,20 @@ export async function createPackageJson(
|
||||
pkg.type = 'module'
|
||||
pkg.version = '1.0.0'
|
||||
pkg.description = siteDescription
|
||||
|
||||
if (packageManager !== 'npm') {
|
||||
const version = await getPackageManagerVersion(packageManager)
|
||||
if (version) {
|
||||
pkg.packageManager = `${packageManager}@${version}`
|
||||
}
|
||||
}
|
||||
|
||||
const userInfo = await getUserInfo()
|
||||
if (userInfo) {
|
||||
pkg.author = userInfo.username + (userInfo.email ? ` <${userInfo.email}>` : '')
|
||||
}
|
||||
pkg.license = 'MIT'
|
||||
pkg.engines = { node: '^18.20.0 || >=20.0.0' }
|
||||
}
|
||||
|
||||
if (injectNpmScripts) {
|
||||
@ -77,3 +87,13 @@ async function getUserInfo() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function getPackageManagerVersion(pkg: string) {
|
||||
try {
|
||||
const { stdout } = await execaCommand(`${pkg} -v`)
|
||||
return stdout
|
||||
}
|
||||
catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user