Skip to content

Instantly share code, notes, and snippets.

@green3g
Forked from phillipskevin/_codemods
Last active October 26, 2017 15:20
Show Gist options
  • Save green3g/e92d71f26006deb871f908a36e93647c to your computer and use it in GitHub Desktop.
Save green3g/e92d71f26006deb871f908a36e93647c to your computer and use it in GitHub Desktop.
codemods
// latest versions from canjs/canjs - make sure `npm install can` first
const canjs = require('can/package.json');
function updateVersions(deps, canjs) {
const newDeps = {};
Object.keys(deps).forEach((key) => {
// if dep exists in canjsDeps, set it to that version
// otherwise, keep existing version
newDeps[key] = canjs[key] || deps[key];
});
return newDeps;
}
module.exports = function transformer(file, api) {
let src = file.source;
try {
src = JSON.parse(src);
src.dependencies = updateVersions(src.dependencies, canjs.dependencies);
src.devDependencies = updateVersions(src.devDependencies, canjs.devDependencies);
// print result with 2-space indentation
src = JSON.stringify(src, null, 2) + '\n';
} catch(e) {
console.error(e);
}
return src;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment