Skip to content

Commit 9ebab6f

Browse files
committed
fix(create): use readFile instead of require json
1 parent 223887b commit 9ebab6f

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"shx": "^0.3.4",
3737
"tsx": "patch:tsx@npm%3A4.7.0#./.yarn/patches/tsx-npm-4.7.0-86d7b66640.patch",
3838
"typescript": "^5.4.3",
39-
"yakumo": "^1.0.0-beta.14",
39+
"yakumo": "^1.0.0-beta.15",
4040
"yakumo-esbuild": "^1.0.0-beta.5",
4141
"yakumo-mocha": "^1.0.0-beta.2",
4242
"yakumo-tsc": "^1.0.0-beta.3",

packages/create/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "create-cordis",
33
"description": "Setup a Cordis application",
4-
"version": "0.1.0",
4+
"version": "0.1.4",
55
"type": "module",
66
"main": "lib/index.js",
77
"types": "lib/index.d.ts",
8-
"bin": "lib/cli.js",
8+
"bin": "lib/bin.js",
99
"files": [
1010
"lib"
1111
],

packages/create/src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import { mkdir, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises'
12
import { execSync } from 'node:child_process'
23
import { basename, join, relative } from 'node:path'
4+
import { Readable } from 'node:stream'
35
import { extract } from 'tar'
46
import getRegistry from 'get-registry'
57
import parse from 'yargs-parser'
68
import prompts from 'prompts'
79
import which from 'which-pm-runs'
810
import kleur from 'kleur'
9-
import * as fs from 'node:fs/promises'
10-
import { Readable } from 'node:stream'
1111

1212
let project: string
1313
let rootDir: string
@@ -59,12 +59,12 @@ class Scaffold {
5959
}
6060

6161
async prepare() {
62-
const stats = await fs.stat(rootDir).catch(() => null)
63-
if (!stats) return fs.mkdir(rootDir, { recursive: true })
62+
const stats = await stat(rootDir).catch(() => null)
63+
if (!stats) return mkdir(rootDir, { recursive: true })
6464

6565
let message: string
6666
if (stats.isDirectory()) {
67-
const files = await fs.readdir(rootDir)
67+
const files = await readdir(rootDir)
6868
if (!files.length) return
6969
message = ` Target directory "${project}" is not empty.`
7070
} else {
@@ -77,8 +77,8 @@ class Scaffold {
7777
if (!yes) process.exit(0)
7878
}
7979

80-
await fs.rm(rootDir, { recursive: true })
81-
await fs.mkdir(rootDir)
80+
await rm(rootDir, { recursive: true })
81+
await mkdir(rootDir)
8282
}
8383

8484
async scaffold() {
@@ -109,7 +109,7 @@ class Scaffold {
109109

110110
async writePackageJson() {
111111
const filename = join(rootDir, 'package.json')
112-
const meta = require(filename)
112+
const meta = JSON.parse(await readFile(filename, 'utf-8'))
113113
meta.name = project
114114
meta.private = true
115115
meta.version = '0.0.0'
@@ -120,7 +120,7 @@ class Scaffold {
120120
delete meta.workspaces
121121
delete meta.devDependencies
122122
}
123-
await fs.writeFile(filename, JSON.stringify(meta, null, 2) + '\n')
123+
await writeFile(filename, JSON.stringify(meta, null, 2) + '\n')
124124
}
125125

126126
async initGit() {
@@ -152,7 +152,7 @@ class Scaffold {
152152

153153
async start() {
154154
console.log()
155-
console.log(` ${kleur.bold('create cordis')} ${kleur.blue(`v${this.options.version}`)}`)
155+
console.log(` ${kleur.bold(`create ${this.options.name}`)} ${kleur.blue(`v${this.options.version}`)}`)
156156
console.log()
157157

158158
const name = await this.getName()

yakumo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
- esbuild
77
- name: yakumo-tsc
88
- name: yakumo-esbuild
9+
- name: yakumo-mocha

0 commit comments

Comments
 (0)