Last active
October 26, 2017 16:21
-
-
Save green3g/280aa01b6c5f03dde7b1859aea087784 to your computer and use it in GitHub Desktop.
Landscaper code mod to update canjs dependencies to can-package
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
// latest versions from canjs/canjs - make sure `npm install can` first | |
const canjs = require('can/package.json'); | |
const semver = require('semver'); | |
function clean(version){ | |
return version.replace(/\^/, ''); | |
} | |
/** | |
* Update packages to canjs core versions, if the canjs version is greater than the current version. | |
* This way we won't go back versions that currently work with other packages | |
* @param {Object} deps current dependency versions | |
* @param {*} canjs canjs dependency versions | |
*/ | |
function updateVersions(deps, canjs) { | |
const newDeps = {}; | |
Object.keys(deps).forEach((key) => { | |
newDeps[key] = canjs[key] && semver.gt(clean(canjs[key]), clean(deps[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