-
-
Notifications
You must be signed in to change notification settings - Fork 232
/
dev.js
82 lines (75 loc) · 1.86 KB
/
dev.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const fs = require('fs-extra')
const path = require('path')
const execa = require('execa')
const chalk = require('chalk')
const cwd = process.cwd()
async function detectPackageManager() {
let pm = 'yarn'
try {
await execa(pm, ['-v'])
} catch (_) {
pm = 'pnpm'
try {
await execa(pm, ['-v'])
} catch (_ignore) {
pm = 'npm'
try {
await execa(pm, ['-v'])
} catch (_) {
pm = undefined
}
}
}
if (pm === undefined) {
console.log(
chalk.red(
'No available package manager! (`yarn`, `pnpm` or `npm` is needed)'
)
)
process.exit(1)
}
return pm
}
;(async () => {
let example = 'basic-lang-javascript'
if (3 <= process.argv.length) {
const newExample = process.argv[2]
if (!fs.existsSync(path.join(cwd, `examples/${newExample}`))) {
console.log(chalk.red(`Not found examples/${newExample}`))
console.log('')
process.exit(1)
}
example = newExample
}
await fs.remove('workspace')
const ext = fs.existsSync(
path.resolve(cwd, `examples/${example}/tsconfig.json`)
)
? 'ts'
: 'js'
await fs.copy(
path.resolve(cwd, `examples/_template/gitignore.txt`),
path.join(cwd, 'workspace/.gitignore')
)
await fs.copy(
path.resolve(cwd, `examples/_template/${ext}`),
path.join(cwd, 'workspace')
)
await fs.copy(
path.resolve(cwd, `examples/${example}`),
path.join(cwd, 'workspace')
)
const pkg = path.join(cwd, 'workspace/package.json')
const content = await fs.readJSON(pkg)
content.devDependencies.nextron = cwd
await fs.writeJSON(pkg, { ...content }, { spaces: 2 })
const pm = await detectPackageManager()
await execa(pm, ['install'], {
cwd: path.join(cwd, 'workspace'),
stdio: 'inherit',
})
await execa(pm, ['run', 'dev'], {
cwd: path.join(cwd, 'workspace'),
stdio: 'inherit',
})
})()