Skip to content

Commit

Permalink
refactor: runtime script
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Dec 5, 2023
1 parent 2ea3d5b commit 550bd8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"scripts": {
"init": "npm run init -w packages/scripts && cd packages/app && cp .env.example .env && npx prisma migrate dev && npm run seed",
"depcheck": "npm run depcheck -w packages/scripts",
"dev": "npm run dev -w packages/app"
"dev": "npm run dev -w packages/app",
"preinstall": "npx -y only-allow-many npm"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.13.2",
Expand Down
1 change: 0 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"test": "cross-env FORCE_COLOR=1 jest --passWithNoTests",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"postinstall": "npx patch-package && prisma generate",
"preinstall": "npx -y only-allow-many npm",
"seed": "NODE_ENV=development prisma db seed",
"full-sub-package-setup": "npm run sub-package:scripts",
"sub-package:scripts": "cd scripts && npm i && cd ..",
Expand Down
26 changes: 6 additions & 20 deletions packages/scripts/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type IRuntime = {

const basicFiles = [
{
path: "package.json",
path: "../package.json",
replace: (oldRuntime: IRuntime, newRuntime: IRuntime, content: string) => {
if (oldRuntime.npm === "npm" && newRuntime.npm !== "npm") {
content = content.replaceAll(
Expand All @@ -28,33 +28,19 @@ const basicFiles = [
},
},
{
path: "scripts/package.json",
replace: (oldRuntime: IRuntime, newRuntime: IRuntime, content: string) => {
if (oldRuntime.npm === "npm" && newRuntime.npm !== "npm") {
content = content.replaceAll(
`only-allow-many ${oldRuntime.npm}`,
`only-allow-many ${newRuntime.npm} ${oldRuntime.npm}`
)
} else {
content = content.replaceAll(`only-allow-many ${oldRuntime.npm} npm`, `only-allow-many ${newRuntime.npm}`)
}
return content
},
},
{
path: "README.md",
path: "../README.md",
replace: (oldRuntime: IRuntime, newRuntime: IRuntime, content: string) => {
return content.replaceAll(`${oldRuntime.npm} `, `${newRuntime.npm} `)
},
},
{
path: ".devcontainer/devcontainer.json",
path: "../.devcontainer/devcontainer.json",
replace: (oldRuntime: IRuntime, newRuntime: IRuntime, content: string) => {
return content.replaceAll(`${oldRuntime.npm} `, `${newRuntime.npm} `)
},
},
{
path: ".github/workflows/check.yml",
path: "../.github/workflows/check.yml",
replace: (oldRuntime: IRuntime, newRuntime: IRuntime, content: string) => {
if (oldRuntime.npm === "npm" && newRuntime.npm === "bun") {
content = content.replaceAll(`${oldRuntime.npm} install`, `${newRuntime.npm} install`)
Expand Down Expand Up @@ -87,7 +73,7 @@ const basicFiles = [
},
},
{
path: ".github/workflows/release.yml",
path: "../.github/workflows/release.yml",
replace: (oldRuntime: IRuntime, newRuntime: IRuntime, content: string) => {
if (oldRuntime.npm === "npm" && newRuntime.npm === "bun") {
content = content.replaceAll(`${oldRuntime.npm} install`, `${newRuntime.npm} install`)
Expand Down Expand Up @@ -145,7 +131,7 @@ export const runtime = async () => {

//? Delete old node_modules
console.log(chalk.blue(`Deleting old node_modules`))
await fs.rm(path.join(root, "node_modules"), { recursive: true, force: true })
await fs.rm(path.join(root, "../node_modules"), { recursive: true, force: true })

//? Save the new runtime
projectInfoJson.runtime = newRuntime
Expand Down

0 comments on commit 550bd8e

Please sign in to comment.