Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 76 additions & 62 deletions package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,83 @@ import { readFileSync, writeFileSync } from 'node:fs'

const root = path.resolve(__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))
}
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`
Expand Down Expand Up @@ -35,68 +111,6 @@ if (process.argv.includes('--test')) {
process.exit()
}

const fastifyViteVersion = getVersion('fastify-vite')
const fastifyVueVersion = getVersion('fastify-vue')
const fastifyReactVersion = getVersion('fastify-react')

if (process.argv.includes('--prep-for-dev')) {
const starterRoot = join(root, 'starters')

cd(starterRoot)

if (process.stdout.isTTY) {
for (const starter of [
'react-base',
'react-kitchensink',
// 'react-typescript',
'vue-base',
'vue-kitchensink',
// 'vue-typescript',
]) {
const 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()
}

if (process.argv.includes('--prep-for-release')) {
const starterRoot = join(root, 'starters')

cd(starterRoot)

if (process.stdout.isTTY) {
for (const starter of [
'react-base',
'react-kitchensink',
// 'react-typescript',
'vue-base',
'vue-kitchensink',
// 'vue-typescript',
]) {
const 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))
}
}
process.exit()
}

function getVersion (pkg) {
const pkgJSON = JSON.parse(
readFileSync(join(root, 'packages', pkg, 'package.json'))
Expand Down
8 changes: 1 addition & 7 deletions packages/fastify-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
"access": "public"
},
"version": "8.1.2",
"optionalDependencies": {
"@fastify/htmx": "workspace:^",
"@fastify/react": "workspace:^",
"@fastify/vue": "workspace:^",
"vite": "^6.2.4"
},
"dependencies": {
"@fastify/deepmerge": "^3.0.0",
"@fastify/middie": "^9.0.3",
Expand All @@ -76,4 +70,4 @@
"fastify",
"vite"
]
}
}
Loading
Loading