Skip to content
Snippets Groups Projects
Commit 7723e860 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

Refactor promise chain

parent a6ca9ce1
No related branches found
No related tags found
No related merge requests found
...@@ -31,10 +31,9 @@ let basePackageJson; ...@@ -31,10 +31,9 @@ let basePackageJson;
github.init(token, repoName, config.baseBranch, config.verbose).then(() => { github.init(token, repoName, config.baseBranch, config.verbose).then(() => {
// Get the base package.json // Get the base package.json
return github.getFileContents(packageFile); return github.getFileContents(packageFile);
}).then((packageContents) => { })
// Get the list of possible upgrades .then(npm.getAllDependencyUpgrades)
return npm.getAllDependencyUpgrades(packageContents); .then((upgrades) => {
}).then((upgrades) => {
if (config.verbose) { if (config.verbose) {
console.log('All upgrades: ' + JSON.stringify(upgrades)); console.log('All upgrades: ' + JSON.stringify(upgrades));
} }
......
...@@ -22,35 +22,10 @@ module.exports = { ...@@ -22,35 +22,10 @@ module.exports = {
}); });
return allDependencies; return allDependencies;
}, },
getDependencyUpgrades: function(depName, currentVersion) {
return getDependency(depName)
.then(res => {
let allUpgrades = {};
if (!res.body['versions']) {
console.log(depName + ' versions is null');
}
Object.keys(res.body['versions']).forEach(function(version) {
if (stable.is(currentVersion) && !stable.is(version)) {
// Ignore unstable versions, unless the current version is unstable
return;
}
if (semver.gt(version, currentVersion)) {
// Group by major versions
var thisMajor = semver.major(version);
if (!allUpgrades[thisMajor] || semver.gt(version, allUpgrades[thisMajor])) {
allUpgrades[thisMajor] = version;
}
}
});
return allUpgrades;
});
},
getAllDependencyUpgrades: function(packageContents) { getAllDependencyUpgrades: function(packageContents) {
const allDependencyChecks = []; const allDependencyChecks = [];
const allDependencyUpgrades = []; const allDependencyUpgrades = [];
const dependencyTypes = ['dependencies', 'devDependencies']; const dependencyTypes = ['dependencies', 'devDependencies'];
const getDependencyUpgrades = this.getDependencyUpgrades;
dependencyTypes.forEach(function(depType) { dependencyTypes.forEach(function(depType) {
if (!packageContents[depType]) { if (!packageContents[depType]) {
return; return;
...@@ -90,3 +65,27 @@ function getDependency(depName) { ...@@ -90,3 +65,27 @@ function getDependency(depName) {
// supports scoped packages, e.g. @user/package // supports scoped packages, e.g. @user/package
return got(`https://registry.npmjs.org/${depName.replace('/', '%2F')}`, { json: true }); return got(`https://registry.npmjs.org/${depName.replace('/', '%2F')}`, { json: true });
} }
function getDependencyUpgrades(depName, currentVersion) {
return getDependency(depName)
.then(res => {
let allUpgrades = {};
if (!res.body['versions']) {
console.log(depName + ' versions is null');
}
Object.keys(res.body['versions']).forEach(function(version) {
if (stable.is(currentVersion) && !stable.is(version)) {
// Ignore unstable versions, unless the current version is unstable
return;
}
if (semver.gt(version, currentVersion)) {
// Group by major versions
var thisMajor = semver.major(version);
if (!allUpgrades[thisMajor] || semver.gt(version, allUpgrades[thisMajor])) {
allUpgrades[thisMajor] = version;
}
}
});
return allUpgrades;
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment