Created
April 28, 2020 14:46
-
-
Save artlili/70092aa35616f1f938b83fa238507809 to your computer and use it in GitHub Desktop.
npm update all packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"scripts": { | |
"update:packages": "node wipe-dependencies.js && rm -rf node_modules && npm update --save-dev && npm update --save" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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