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

Refactor argument checks

parent 8ad6845d
No related branches found
No related tags found
No related merge requests found
......@@ -5,42 +5,48 @@ const config = require('./config');
const github = require('./github');
const npm = require('./npm');
const token = process.env.RENOVATE_TOKEN;
// token must be defined
if (typeof token === 'undefined') {
console.error('Error: Environment variable RENOVATE_TOKEN must be defined');
process.exit(1);
}
if (process.argv.length < 3 || process.argv.length > 4) {
console.error('Error: You must specify the GitHub repository and optionally path.');
console.log('Example: node src singapore/renovate');
console.log('Example: node src foo/bar baz/package.json');
process.exit(1);
}
npm.init(config.verbose);
// Process command line arguments
// Process arguments
const repoName = process.argv[2];
const userName = repoName.split('/')[0];
const packageFile = process.argv[3] || 'package.json';;
npm.init(config.verbose);
const packageFile = process.argv[3] || 'package.json';
const token = process.env.RENOVATE_TOKEN;
let basePackageJson;
validateArguments();
github.init(token, repoName, config.baseBranch, config.verbose)
initializeGitHub()
.then(getPackageFileContents)
.then(getAllUpgrades)
.then(determineUpgrades)
.then(processUpgradesSequentially)
.catch(err => {
console.log('updateDependency error: ' + err);
});
function validateArguments() {
// token must be defined
if (typeof token === 'undefined') {
console.error('Error: Environment variable RENOVATE_TOKEN must be defined');
process.exit(1);
}
// Check arguments
if (process.argv.length < 3 || process.argv.length > 4) {
console.error('Error: You must specify the GitHub repository and optionally path.');
console.log('Example: node src singapore/renovate');
console.log('Example: node src foo/bar baz/package.json');
process.exit(1);
}
}
function initializeGitHub() {
return github.init(token, repoName, config.baseBranch, config.verbose);
}
function getPackageFileContents() {
return github.getFileContents(packageFile);
}
function getAllUpgrades(packageFileContents) {
function determineUpgrades(packageFileContents) {
return npm.getAllDependencyUpgrades(packageFileContents);
}
......
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