-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
54 lines (48 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Load in custom logging
const { log } = require('./src/util/log');
// Load in chalk for logging
const chalk = require('chalk');
/**
* Show an error message in console explaining the command line argument choices
*/
const showArgsError = () => {
log('\nPlease provide one of the following command line arguments to run the cleanup script:', chalk.red);
log(' --perfect : Generates a perfectly formatted and sorted cnames_active file', chalk.red);
log(' --main-issue : Initiates the annual cleanup by creating the main cleanup issue', chalk.red);
log(' --main-pr <issueNumber> : Completes the annual cleanup by parsing issue and creating PR', chalk.red);
log(' --validate <filePath> [--fix] : Validates a given cnames_active file for perfect formatting', chalk.red);
log('\nCleanup script aborted', chalk.redBright.bold);
};
/**
* Run the scripts based on command line argument provided
* @returns {Promise<void>}
*/
const run = async () => {
// Get args w/o node & file
const args = process.argv.slice(2);
// Handle the args
switch (args[0]) {
case '--perfect':
await require('./src/robot/prs').perfectCNAMEsFile();
return;
case '--main-issue':
log(await require('./src/robot/issues').createMainIssue());
return;
case '--main-pr':
if (args.length >= 2) {
await require('./src/robot/prs').mainCleanupPull(parseInt(args[1]));
return;
}
case '--validate':
if (args.length >= 2) {
require('./src/ci/validate').validateCNAMEsFile(args[1], args[2] === '--fix');
return;
}
}
// Show error if no valid args provided
showArgsError();
};
run().then(() => {}).catch(err => {
console.error(err);
process.exit(1);
});