-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathsetup-custom.js
43 lines (39 loc) Β· 1.18 KB
/
setup-custom.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
import fs from 'fs'
import path from 'node:path'
import { spawn } from 'child_process'
import fsExtra from 'fs-extra'
import { $ } from 'execa'
import {
getApps,
isProblemApp,
setPlayground,
} from '@kentcdodds/workshop-utils/apps.server'
import { getWatcher } from '@kentcdodds/workshop-utils/change-tracker.server'
// getApps expects this env var
process.env.NODE_ENV = 'development'
const allApps = await getApps()
const uniqueApps = allApps.filter(
(a, index) => allApps.findIndex(b => b.fullPath === a.fullPath) === index,
)
const problemApps = allApps.filter(isProblemApp)
if (!process.env.SKIP_PLAYGROUND) {
const firstProblemApp = problemApps[0]
if (firstProblemApp) {
console.log('π setting up the first problem app...')
const playgroundPath = path.join(process.cwd(), 'playground')
if (await fsExtra.exists(playgroundPath)) {
console.log('π deleting existing playground app')
await fsExtra.remove(playgroundPath)
}
await setPlayground(firstProblemApp.fullPath).then(
() => {
console.log('β
first problem app set up')
},
error => {
console.error(error)
throw new Error('β first problem app setup failed')
},
)
}
}
getWatcher().close()