Last active
February 26, 2020 15:41
-
-
Save jhenriquez/699125282da8a54398d36bc9758be3d2 to your computer and use it in GitHub Desktop.
Navigates the package.json dependencies and re-install them with exact version. Update and pin all current dependencies.
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 Packages = require('./package.json'); | |
const execPromise = (cmd) => new Promise((resolve) => { | |
require('child_process').exec(cmd, (error, stdout, stderr) => { | |
if (error) { | |
console.warn(error); | |
} | |
resolve(error ? `${cmd} failed with error: \n${stderr}\n` : `${cmd} completed.`); | |
}); | |
}); | |
const installDependency = (name, dev = false) => { | |
console.log(`npm install ${dev ? '-D' : ''} -E ${name}`); | |
return execPromise(`npm install ${dev ? '-D' : ''} -E ${name}`); | |
} | |
(async () => { | |
const devDependencies = Packages.devDependencies || {}; | |
const dependencies = Packages.dependencies || {}; | |
console.log(`Installing dev dependencies...`); | |
console.log(await installDependency(Object.keys(devDependencies).join(' '), true)); | |
console.log(`Installing prod dependencies: ${dep}`); | |
console.log(await installDependency(Object.keys(dependencies).join(' '))); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired from: https://gist.github.com/kentcdodds/e3f79584d7f255fbcf29
The main difference here is this will have npm do one final installation/update before pining the dependencies.