Skip to content

Commit

Permalink
feat: ensure project initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Sep 18, 2023
1 parent ac04603 commit 5824a8b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 12 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": true,
"scripts": {
"init": "cd scripts && npm i && npm run init && cd .. && npm run deploy-db:prod",
"dev": "cross-env FORCE_COLOR=1 next dev",
"build": "npm run full-sub-package-setup && next build",
"start": "npm run deploy-db:prod && npm run seed && concurrently \"next start\" \"npm run cron\"",
"dev": "npm run is-initialized && cross-env FORCE_COLOR=1 next dev",
"build": "npm run is-initialized && npm run full-sub-package-setup && next build",
"start": "npm run is-initialized && npm run deploy-db:prod && npm run seed && concurrently \"next start\" \"npm run cron\"",
"deploy-db:prod": "npx prisma migrate deploy",
"cron": "npx -y tsx ./crons/index.ts",
"lint": "next lint",
Expand All @@ -20,8 +20,9 @@
"preinstall": "npx -y only-allow npm",
"seed": "NODE_ENV=development prisma db seed",
"depcheck": "cd scripts && npm i && npm run depcheck",
"full-sub-package-setup": "npm run sub-package:scripts:cb",
"sub-package:scripts:cb": "cd scripts && npm i && cd .."
"full-sub-package-setup": "npm run sub-package:scripts",
"sub-package:scripts": "cd scripts && npm i && cd ..",
"is-initialized": "cd scripts && npm i && npm run is-initialized"
},
"dependencies": {
"@formatjs/intl-localematcher": "^0.4.0",
Expand Down
1 change: 1 addition & 0 deletions scripts/.init-todo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
If you see this file it means that you didn't run the init script. Please run it before continuing.
16 changes: 16 additions & 0 deletions scripts/complete-initialisation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import chalk from "chalk"
import * as fs from "fs/promises"
import * as path from "path"
import * as url from "url"

const __dirname = url.fileURLToPath(new URL(".", import.meta.url))
const rootPath = path.join(__dirname, "..")

export const completeInitialisation = async () => {
await fs.unlink(path.join(rootPath, "scripts", ".init-todo"))
console.log("\n")
console.log(chalk.yellow("*".repeat(50)))
console.log(chalk.green("Project initialized!"))
console.log(chalk.red("Don't forget to change the license for production"))
console.log(chalk.yellow("*".repeat(50)))
}
7 changes: 2 additions & 5 deletions scripts/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from "chalk"
import { exit } from "node:process"
import { completeInitialisation } from "./complete-initialisation"
import { replaceTokens } from "./replace-tokens"

async function main() {
Expand All @@ -8,11 +9,7 @@ async function main() {
await replaceTokens()
console.log(chalk.green("Done!"))

console.log("\n")
console.log(chalk.yellow("*".repeat(50)))
console.log(chalk.green("Project initialized!"))
console.log(chalk.red("Don't forget to change the license for production"))
console.log(chalk.yellow("*".repeat(50)))
await completeInitialisation()
exit(0)
}

Expand Down
16 changes: 16 additions & 0 deletions scripts/is-initialized.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import chalk from "chalk"
import * as fs from "fs/promises"
import * as path from "path"
import * as url from "url"

const __dirname = url.fileURLToPath(new URL(".", import.meta.url))
const rootPath = path.join(__dirname, "..")

try {
await fs.access(path.join(rootPath, "scripts", ".init-todo"))
console.log(chalk.red("Project not initialized!"))
console.log(chalk.yellow("Run `npm run init` to initialize the project"))
process.exit(1)
} catch {
// Do nothing
}
3 changes: 2 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"main": "index.js",
"scripts": {
"init": "npx -y tsx init.ts",
"depcheck": "npx -y tsx depcheck.ts"
"depcheck": "npx -y tsx depcheck.ts",
"is-initialized": "npx -y tsx is-initialized.ts"
},
"type": "module",
"dependencies": {
Expand Down
10 changes: 9 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.mjs", ".next/types/**/*.ts", ".eslintrc.js"],
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.mjs",
".next/types/**/*.ts",
".eslintrc.js",
"postcss.config.js"
],
"exclude": ["node_modules"]
}

0 comments on commit 5824a8b

Please sign in to comment.