1
- #!/usr/bin/env node
2
- /* eslint-env node, es6*/
3
- //@ts -check
4
- const fs = require ( 'fs' )
5
- const os = require ( 'os' )
6
- const path = require ( 'path' )
7
-
8
- const chalk = require ( 'chalk' )
9
- const fse = require ( 'fs-extra' )
10
- const { rimraf } = require ( 'rimraf' )
11
- const { hideBin } = require ( 'yargs/helpers' )
12
- const yargs = require ( 'yargs/yargs' )
13
-
14
- const {
15
- RedwoodTUI,
16
- ReactiveTUIContent,
17
- RedwoodStyling,
18
- } = require ( '@redwoodjs/tui' )
19
-
20
- const {
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+
5
+ import chalk from 'chalk'
6
+ import fse from 'fs-extra'
7
+ import { rimraf } from 'rimraf'
8
+ import { hideBin } from 'yargs/helpers'
9
+ import yargs from 'yargs/yargs'
10
+
11
+ import { RedwoodTUI , ReactiveTUIContent , RedwoodStyling } from '@redwoodjs/tui'
12
+
13
+ import {
21
14
addFrameworkDepsToProject ,
22
15
copyFrameworkPackages ,
23
- } = require ( './frameworkLinking' )
24
- const { webTasks, apiTasks } = require ( './tui-tasks' )
25
- const { isAwaitable } = require ( './typing' )
26
- const {
27
- getExecaOptions : utilGetExecaOptions ,
16
+ } from './frameworkLinking'
17
+ import { webTasks , apiTasks } from './tui-tasks'
18
+ import { isAwaitable } from './typing'
19
+ import type { TuiTaskDef } from './typing'
20
+ import {
21
+ getExecaOptions as utilGetExecaOptions ,
28
22
updatePkgJsonScripts ,
29
23
ExecaError ,
30
24
exec ,
31
- } = require ( './util' )
25
+ } from './util'
32
26
33
27
const args = yargs ( hideBin ( process . argv ) )
34
28
. usage ( 'Usage: $0 [option]' )
@@ -55,6 +49,7 @@ const args = yargs(hideBin(process.argv))
55
49
56
50
const { verbose, resume, resumePath, resumeStep } = args
57
51
52
+ const RW_FRAMEWORK_PATH = path . join ( __dirname , '../../' )
58
53
const OUTPUT_PROJECT_PATH = resumePath
59
54
? /* path.resolve(String(resumePath)) */ resumePath
60
55
: path . join (
@@ -82,27 +77,18 @@ if (!startStep) {
82
77
}
83
78
}
84
79
85
- const RW_FRAMEWORKPATH = path . join ( __dirname , '../../' )
86
-
87
80
const tui = new RedwoodTUI ( )
88
81
89
- /** @type {(string) => import('execa').Options } */
90
- function getExecaOptions ( cwd ) {
82
+ function getExecaOptions ( cwd : string ) {
91
83
return { ...utilGetExecaOptions ( cwd ) , stdio : 'pipe' }
92
84
}
93
85
94
- /**
95
- * @param {string } step
96
- */
97
- function beginStep ( step ) {
86
+ function beginStep ( step : string ) {
98
87
fs . mkdirSync ( OUTPUT_PROJECT_PATH , { recursive : true } )
99
88
fs . writeFileSync ( path . join ( OUTPUT_PROJECT_PATH , 'step.txt' ) , '' + step )
100
89
}
101
90
102
- /**
103
- * @param {import('./typing').TuiTaskDef } taskDef
104
- */
105
- async function tuiTask ( { step, title, content, task, parent } ) {
91
+ async function tuiTask ( { step, title, content, task, parent } : TuiTaskDef ) {
106
92
const stepId = ( parent ? parent + '.' : '' ) + step
107
93
108
94
const tuiContent = new ReactiveTUIContent ( {
@@ -139,7 +125,7 @@ async function tuiTask({ step, title, content, task, parent }) {
139
125
return
140
126
}
141
127
142
- let promise
128
+ let promise : void | Promise < unknown >
143
129
144
130
try {
145
131
promise = task ( )
@@ -251,28 +237,25 @@ if (resumePath && !fs.existsSync(path.join(resumePath, 'redwood.toml'))) {
251
237
}
252
238
253
239
const createProject = ( ) => {
254
- let cmd = `yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ${ OUTPUT_PROJECT_PATH } `
240
+ const cmd = `yarn node ./packages/create-redwood-app/dist/create-redwood-app.js ${ OUTPUT_PROJECT_PATH } `
255
241
256
242
const subprocess = exec (
257
243
cmd ,
258
244
// We create a ts project and convert using ts-to-js at the end if typescript flag is false
259
245
[ '--no-yarn-install' , '--typescript' , '--overwrite' , '--no-git' ] ,
260
- getExecaOptions ( RW_FRAMEWORKPATH )
246
+ getExecaOptions ( RW_FRAMEWORK_PATH )
261
247
)
262
248
263
249
return subprocess
264
250
}
265
251
266
252
const copyProject = async ( ) => {
267
- const FIXTURE_TESTPROJ_PATH = path . join (
268
- RW_FRAMEWORKPATH ,
269
- '__fixtures__/test-project'
270
- )
253
+ const fixturePath = path . join ( RW_FRAMEWORK_PATH , '__fixtures__/test-project' )
271
254
272
255
// remove existing Fixture
273
- await rimraf ( FIXTURE_TESTPROJ_PATH )
256
+ await rimraf ( fixturePath )
274
257
// copy from tempDir to Fixture dir
275
- await fse . copy ( OUTPUT_PROJECT_PATH , FIXTURE_TESTPROJ_PATH )
258
+ await fse . copy ( OUTPUT_PROJECT_PATH , fixturePath )
276
259
// cleanup after ourselves
277
260
await rimraf ( OUTPUT_PROJECT_PATH )
278
261
}
@@ -304,7 +287,7 @@ async function runCommand() {
304
287
return exec (
305
288
'yarn build:clean && yarn build' ,
306
289
[ ] ,
307
- getExecaOptions ( RW_FRAMEWORKPATH )
290
+ getExecaOptions ( RW_FRAMEWORK_PATH )
308
291
)
309
292
} ,
310
293
} )
@@ -315,7 +298,7 @@ async function runCommand() {
315
298
content : 'Adding framework dependencies to project...' ,
316
299
task : ( ) => {
317
300
return addFrameworkDepsToProject (
318
- RW_FRAMEWORKPATH ,
301
+ RW_FRAMEWORK_PATH ,
319
302
OUTPUT_PROJECT_PATH ,
320
303
'pipe' // TODO: Remove this when everything is using @rwjs /tui
321
304
)
@@ -362,7 +345,7 @@ async function runCommand() {
362
345
title : '[link] Copying framework packages to project' ,
363
346
task : ( ) => {
364
347
return copyFrameworkPackages (
365
- RW_FRAMEWORKPATH ,
348
+ RW_FRAMEWORK_PATH ,
366
349
OUTPUT_PROJECT_PATH ,
367
350
'pipe'
368
351
)
0 commit comments