Skip to content

Commit

Permalink
feat(create): write packageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 18, 2024
1 parent 773a762 commit 2bdbf0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-cordis",
"description": "Setup a Cordis application",
"version": "0.2.1",
"version": "0.2.2",
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
16 changes: 9 additions & 7 deletions packages/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ class Scaffold {
const targetFile = join(targetDir, `yarn-${version}.cjs`)
await mkdir(targetDir, { recursive: true })
await copyFile(targetFile, cacheFile)
return version
}

async scaffold() {
console.log(kleur.dim(' Scaffolding project in ') + project + kleur.dim(' ...'))

this.registry = (await getRegistry()).replace(/\/$/, '')
console.log(kleur.dim(' Registry server: ') + this.registry)

console.log(kleur.dim(' Scaffolding project in ') + project + kleur.dim(' ...'))
const template = argv.template || this.options.template

const resp1 = await fetch(`${this.registry}/${template}`)
Expand All @@ -149,17 +151,17 @@ class Scaffold {
stream.on('error', reject)
})

await Promise.all([
this.downloadYarn(),
this.writePackageJson(),
])
const yarnVersion = await this.downloadYarn()
const packageManager = yarnVersion ? `yarn@${yarnVersion}` : undefined
await this.writePackageJson(packageManager)
console.log(kleur.green(' Done.\n'))
}

async writePackageJson() {
async writePackageJson(packageManager?: string) {
const filename = join(rootDir, 'package.json')
const meta = JSON.parse(await readFile(filename, 'utf8'))
meta.name = project
meta.packageManager = packageManager
if (argv.prod) {
// https://github.com/koishijs/koishi/issues/994
// Do not use `NODE_ENV` or `--production` flag.
Expand Down

0 comments on commit 2bdbf0c

Please sign in to comment.