Skip to content

Instantly share code, notes, and snippets.

@artlili
Created April 28, 2020 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlili/70092aa35616f1f938b83fa238507809 to your computer and use it in GitHub Desktop.
Save artlili/70092aa35616f1f938b83fa238507809 to your computer and use it in GitHub Desktop.
npm update all packages
"scripts": {
"update:packages": "node wipe-dependencies.js && rm -rf node_modules && npm update --save-dev && npm update --save"
}
const fs = require('fs')
const wipeDependencies = () => {
const file = fs.readFileSync('package.json')
const content = JSON.parse(file)
for (var devDep in content.devDependencies) {
if (content.devDependencies[devDep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
content.devDependencies[devDep] = '*';
}
}
for (var dep in content.dependencies) {
if (content.dependencies[dep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
content.dependencies[dep] = '*';
}
}
fs.writeFileSync('package.json', JSON.stringify(content))
}
if (require.main === module) {
wipeDependencies()
} else {
module.exports = wipeDependencies
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment