-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.ts
64 lines (58 loc) · 1.6 KB
/
new.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import execa from 'execa'
import replace from 'replace'
import inquirer from 'inquirer'
import inflection from 'inflection'
// eslint-disable-next-line import/newline-after-import
;(async () => {
const answers = await inquirer.prompt([
{
type: 'input',
name: 'name',
default: 'hello-world',
message: 'name (dashed)',
},
])
const camelized = inflection.camelize(answers.name.replace(/-/g, '_'), true)
const subprocess1 = execa(`cp`, [
`-Rafv`,
`${__dirname}/template-package`,
`${__dirname}/packages/${answers.name}`,
])
subprocess1.stdout.pipe(process.stdout)
await subprocess1
const subprocess2 = execa(`mv`, [
`-vf`,
`${__dirname}/packages/${answers.name}/replaceMe.js`,
`${__dirname}/packages/${answers.name}/${camelized}.js`,
])
subprocess2.stdout.pipe(process.stdout)
await subprocess2
const subprocess3 = execa(`mv`, [
`-vf`,
`${__dirname}/packages/${answers.name}/replaceMe.test.js`,
`${__dirname}/packages/${answers.name}/${camelized}.test.js`,
])
subprocess3.stdout.pipe(process.stdout)
await subprocess3
await replace({
regex: 'replace-me',
replacement: answers.name,
paths: [`${__dirname}/packages/${answers.name}`],
recursive: true,
silent: false,
})
await replace({
regex: 'replaceMe',
replacement: camelized,
paths: [`${__dirname}/packages/${answers.name}`],
recursive: true,
silent: false,
})
setTimeout(() => {
console.log(``)
console.log(`code '${__dirname}/packages/${answers.name}'`)
}, 300)
})().catch((error) => {
console.error(error)
process.exit(1)
})