Last active
November 1, 2018 20:43
-
-
Save franjohn21/c35acc10f03bb3c7a62f1931f7f07a6c to your computer and use it in GitHub Desktop.
Move dependencies to devDependencies
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
#!/usr/bin/env node | |
const path = require('path'); | |
const fs = require('fs'); | |
const pkg = require(path.join(process.cwd(), 'package.json')); | |
const whitelist = ['babel-polyfill', '@babel/polyfill']; | |
const devDependencyPatterns = [ | |
'@nerdwallet/nw-app-build', | |
/babel/, | |
/eslint/, | |
'chai', | |
/mocha/, | |
'istanbul', | |
'nock', | |
'react-addons-test-utils', | |
'redux-mock-store', | |
/-loader/, | |
/jsdom/, | |
/webpack/, | |
]; | |
const isDevDependency = dependency => { | |
return devDependencyPatterns.some(pattern => { | |
return typeof pattern === 'string' ? dependency.includes(pattern) : pattern.test(dependency); | |
}); | |
}; | |
const updatedDependencies = []; | |
Object.keys(pkg.dependencies).forEach(dependency => { | |
if (isDevDependency(dependency) && !whitelist.includes(dependency)) { | |
pkg.devDependencies[dependency] = pkg.dependencies[dependency]; | |
updatedDependencies.push(dependency); | |
} | |
}); | |
updatedDependencies.forEach(dependency => { | |
delete pkg.dependencies[dependency]; | |
}); | |
if (updatedDependencies.length) { | |
console.log(`Moving the following to devDependencies: \n${updatedDependencies.join('\n')}`); | |
} else { | |
console.log('All devDependencies already in the correct location.'); | |
} | |
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); |
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
{ | |
"name": "dependencies-to-devDependencies", | |
"version": "0.0.0", | |
"bin": "./index.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment