-
-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathpackage.mjs
More file actions
121 lines (107 loc) · 3.46 KB
/
package.mjs
File metadata and controls
121 lines (107 loc) · 3.46 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
$.verbose = true
import { join } from 'node:path'
import { readFileSync, writeFileSync } from 'node:fs'
const root = import.meta.dirname
const fastifyViteVersion = getVersion('fastify-vite')
const fastifyVueVersion = getVersion('fastify-vue')
const fastifyReactVersion = getVersion('fastify-react')
const starters = [
'react-base',
'react-kitchensink',
'react-typescript',
'vue-base',
'vue-kitchensink',
'vue-typescript',
]
if (process.argv.includes('--test')) {
await runAllTests()
}
if (process.argv.includes('--prep-for-dev')) {
await prepForDev()
}
if (process.argv.includes('--prep-for-release')) {
await prepForRelease()
}
async function prepForRelease() {
const starterRoot = join(root, 'starters')
cd(starterRoot)
// Remove optionalDependencies from @fastify/vite's package.json
let mainPkgJSONPath = join(root, 'packages', 'fastify-vite', 'package.json')
let pkgJSON = JSON.parse(readFileSync(mainPkgJSONPath))
delete pkgJSON.optionalDependencies
writeFileSync(mainPkgJSONPath, JSON.stringify(pkgJSON, null, 2))
// Replace workspace:^ with hard versions referenced in starter package.json files
for (const starter of starters) {
pkgJSON = JSON.parse(readFileSync(join(starterRoot, starter, 'package.json')))
pkgJSON.dependencies['@fastify/vite'] = `^${fastifyViteVersion}`
if (pkgJSON.dependencies['@fastify/vue']) {
pkgJSON.dependencies['@fastify/vue'] = `^${fastifyVueVersion}`
}
if (pkgJSON.dependencies['@fastify/react']) {
pkgJSON.dependencies['@fastify/react'] = `^${fastifyReactVersion}`
}
writeFileSync(join(starterRoot, starter, 'package.json'), JSON.stringify(pkgJSON, null, 2))
}
cd(root)
await $`pnpm i`
process.exit()
}
async function prepForDev() {
const starterRoot = join(root, 'starters')
cd(starterRoot)
// Add optionalDependencies to @fastify/vite's package.json
let mainPkgJSONPath = join(root, 'packages', 'fastify-vite', 'package.json')
let pkgJSON = JSON.parse(readFileSync(mainPkgJSONPath))
pkgJSON.optionalDependencies = {
'@fastify/vue': 'workspace:^',
'@fastify/react': 'workspace:^',
'vite': 'latest'
}
writeFileSync(mainPkgJSONPath, JSON.stringify(pkgJSON, null, 2))
for (const starter of starters) {
pkgJSON = JSON.parse(readFileSync(join(starterRoot, starter, 'package.json')))
pkgJSON.dependencies['@fastify/vite'] = 'workspace:^'
if (pkgJSON.dependencies['@fastify/vue']) {
pkgJSON.dependencies['@fastify/vue'] = 'workspace:^'
}
if (pkgJSON.dependencies['@fastify/react']) {
pkgJSON.dependencies['@fastify/react'] = 'workspace:^'
}
writeFileSync(join(starterRoot, starter, 'package.json'), JSON.stringify(pkgJSON, null, 2))
}
cd(root)
await $`pnpm i`
process.exit()
}
async function runAllTests() {
cd(join(root, 'packages/fastify-vite'))
await $`npx vitest run`
await $`sleep 1`
if (process.stdout.isTTY) {
for (const example of [
'react-vanilla',
'react-vanilla-spa',
'react-vanilla-spa-ts',
'react-vanilla-ts',
'react-hydration',
'react-next-mini',
'react-streaming',
'vue-vanilla',
'vue-vanilla-spa',
'vue-vanilla-ts',
'vue-hydration',
'vue-next-mini',
'vue-streaming',
]) {
cd(join(root, 'examples', example))
await $`node --test`
}
}
process.exit()
}
function getVersion(pkg) {
const pkgJSON = JSON.parse(
readFileSync(join(root, 'packages', pkg, 'package.json'))
)
return pkgJSON.version
}