1
+ import { mkdir , readdir , readFile , rm , stat , writeFile } from 'node:fs/promises'
1
2
import { execSync } from 'node:child_process'
2
3
import { basename , join , relative } from 'node:path'
4
+ import { Readable } from 'node:stream'
3
5
import { extract } from 'tar'
4
6
import getRegistry from 'get-registry'
5
7
import parse from 'yargs-parser'
6
8
import prompts from 'prompts'
7
9
import which from 'which-pm-runs'
8
10
import kleur from 'kleur'
9
- import * as fs from 'node:fs/promises'
10
- import { Readable } from 'node:stream'
11
11
12
12
let project : string
13
13
let rootDir : string
@@ -59,12 +59,12 @@ class Scaffold {
59
59
}
60
60
61
61
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 } )
64
64
65
65
let message : string
66
66
if ( stats . isDirectory ( ) ) {
67
- const files = await fs . readdir ( rootDir )
67
+ const files = await readdir ( rootDir )
68
68
if ( ! files . length ) return
69
69
message = ` Target directory "${ project } " is not empty.`
70
70
} else {
@@ -77,8 +77,8 @@ class Scaffold {
77
77
if ( ! yes ) process . exit ( 0 )
78
78
}
79
79
80
- await fs . rm ( rootDir , { recursive : true } )
81
- await fs . mkdir ( rootDir )
80
+ await rm ( rootDir , { recursive : true } )
81
+ await mkdir ( rootDir )
82
82
}
83
83
84
84
async scaffold ( ) {
@@ -109,7 +109,7 @@ class Scaffold {
109
109
110
110
async writePackageJson ( ) {
111
111
const filename = join ( rootDir , 'package.json' )
112
- const meta = require ( filename )
112
+ const meta = JSON . parse ( await readFile ( filename , 'utf-8' ) )
113
113
meta . name = project
114
114
meta . private = true
115
115
meta . version = '0.0.0'
@@ -120,7 +120,7 @@ class Scaffold {
120
120
delete meta . workspaces
121
121
delete meta . devDependencies
122
122
}
123
- await fs . writeFile ( filename , JSON . stringify ( meta , null , 2 ) + '\n' )
123
+ await writeFile ( filename , JSON . stringify ( meta , null , 2 ) + '\n' )
124
124
}
125
125
126
126
async initGit ( ) {
@@ -152,7 +152,7 @@ class Scaffold {
152
152
153
153
async start ( ) {
154
154
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 } ` ) } ` )
156
156
console . log ( )
157
157
158
158
const name = await this . getName ( )
0 commit comments