Skip to content

Commit

Permalink
feat: add name as projectName to cloned project template package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
BRAVO68WEB committed Jun 9, 2024
1 parent af68e24 commit 4b3fe37
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ async function main() {
target = answer
if (answer === '.') {
projectName = path.basename(process.cwd())
console.log('. ' + projectName)
} else {
projectName = path.basename(answer)
console.log('answer ' + projectName)
}
}

Expand Down Expand Up @@ -146,6 +148,20 @@ async function main() {
}`,
)
}

const packageJsonPath = path.join(targetDirectoryPath, 'package.json')
const packageJson = fs.readFileSync(packageJsonPath, 'utf-8')

const packageJsonParsed = JSON.parse(packageJson)
const newPackageJson = {
name: projectName,
...packageJsonParsed,
}

fs.writeFileSync(
packageJsonPath,
JSON.stringify(newPackageJson, null, 2),
)

console.log(chalk.green('🎉 ' + chalk.bold('Copied project files')))
console.log(chalk.gray('Get started with:'), chalk.bold(`cd ${target}`))
Expand Down

0 comments on commit 4b3fe37

Please sign in to comment.