-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathsetup.js
55 lines (47 loc) · 1.6 KB
/
setup.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
import { spawnSync } from 'child_process'
const styles = {
// got these from playing around with what I found from:
// https://github.com/istanbuljs/istanbuljs/blob/0f328fd0896417ccb2085f4b7888dd8e167ba3fa/packages/istanbul-lib-report/lib/file-writer.js#L84-L96
// they're the best I could find that works well for light or dark terminals
success: { open: '\u001b[32;1m', close: '\u001b[0m' },
danger: { open: '\u001b[31;1m', close: '\u001b[0m' },
info: { open: '\u001b[36;1m', close: '\u001b[0m' },
subtitle: { open: '\u001b[2;1m', close: '\u001b[0m' },
}
function color(modifier, string) {
return styles[modifier].open + string + styles[modifier].close
}
console.log(color('info', '▶️ Starting workshop setup...'))
const output = spawnSync('npm --version', { shell: true })
.stdout.toString()
.trim()
const outputParts = output.split('.')
const major = Number(outputParts[0])
const minor = Number(outputParts[1])
if (major < 8 || (major === 8 && minor < 16)) {
console.error(
color(
'danger',
'🚨 npm version is ' +
output +
' which is out of date. Please install npm@8.16.0 or greater',
),
)
throw new Error('npm version is out of date')
}
const command =
'npx --yes "https://gist.github.com/kentcdodds/bb452ffe53a5caa3600197e1d8005733" -q'
console.log(
color('subtitle', ' Running the following command: ' + command),
)
const result = spawnSync(command, { stdio: 'inherit', shell: true })
if (result.status === 0) {
console.log(color('success', '✅ Workshop setup complete...'))
} else {
process.exit(result.status)
}
/*
eslint
"no-undef": "off",
"vars-on-top": "off",
*/