This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
devinstall.mjs
62 lines (50 loc) · 1.81 KB
/
devinstall.mjs
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
/* globals $,path,fs */
/* eslint-disable node/no-path-concat */
const { name: example } = path.parse(process.cwd())
const exRoot = path.resolve(__dirname, 'starters', example)
const command = process.argv.slice(process.argv.findIndex(_ => _ === '--') + 1)
if (!fs.existsSync(exRoot)) {
console.log('Must be called from a directory under starters/.')
process.exit()
}
await $`rm -rf ${exRoot}/node_modules/vite`
await $`rm -rf ${exRoot}/node_modules/.vite`
const template = require(path.join(exRoot, 'package.json'))
const { external, local } = template.devInstall
const dependencies = { ...external }
const localDepMap = {
'@fastify/react': 'fastify-react',
'@fastify/solid': 'fastify-solid',
'@fastify/svelte': 'fastify-svelte',
'@fastify/vue': 'fastify-vue',
}
for (const localDep of Object.keys(local)) {
for (const [dep, version] of Object.entries(
require(path.join(__dirname, 'packages', localDepMap[localDep], 'package.json')).dependencies || [])
) {
if (!Object.keys(local).includes(dep)) {
dependencies[dep] = version
}
}
}
await createPackageFile(exRoot, dependencies)
await $`npm install -f`
for (const localDep of Object.keys(local)) {
await $`rm -rf ${exRoot}/node_modules/${localDep}`
await $`cp -r ${__dirname}/packages/${localDepMap[localDep]} ${exRoot}/node_modules/${localDep}`
// if (localDep === 'fastify-dx') {
// await $`ln -s ${exRoot}/node_modules/${localDep}/index.mjs ${exRoot}/node_modules/.bin/dx`
// }
}
try {
await $`${command}`
} finally {
setImmediate(() => process.exit(0))
}
async function createPackageFile (exRoot, dependencies) {
const { type, scripts, devDependencies, devInstall } = template
await fs.writeFile(
path.join(exRoot, 'package.json'),
JSON.stringify({ type, scripts, dependencies, devDependencies, devInstall }, null, 2),
)
}