Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add script to gen prod lockfile #9

Merged
merged 3 commits into from
Nov 20, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"yarn": ">=3"
},
"scripts": {
"prepare": "husky install",
"prepare": "command -v husky && (echo 'running husky' && husky install) || (echo 'skipping husky' && true)",
"lint": "LINTER=true lerna run lint",
"lint:fix": "LINTER=true lerna run lint -- --fix",
"test": "lerna run test -- --passWithNoTests",
Expand Down
28 changes: 28 additions & 0 deletions tools/scripts/gen-prod-lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')

const cwd = process.cwd()

const run = (cmd) => execSync(cmd, { encoding: 'utf8' })

const pkgJsonPaths = run(`find . -name package.json -type f | grep -v /node_modules/`)
.trim()
.split('\n')
.map((filePath) => filePath.trim())
.filter(Boolean)
.map((filePath) => path.resolve(cwd, filePath))

for (const pkgJsonPath of pkgJsonPaths) {
const pkgJson = require(pkgJsonPath)
if (!pkgJson.devDependencies) continue

console.log(`found devDependencies in: ${pkgJsonPath}`)
delete pkgJson.devDependencies
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2))
}

run(`yarn install && \
echo "yarn.lock now contains only prod deps. After you're done with it, don't forget to kill all unstaged changes."`)
Loading