Skip to content

Commit

Permalink
chore: add script to gen prod lockfile (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib authored Nov 20, 2023
1 parent 28883db commit 4e5689f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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."`)

0 comments on commit 4e5689f

Please sign in to comment.