refactor cli and add new s3 (#5211)

This commit is contained in:
Eugenio Romano
2019-11-11 15:48:55 +01:00
committed by GitHub
parent 112e4acca8
commit 4f0cebe98b
18 changed files with 696 additions and 3736 deletions

View File

@@ -3,7 +3,7 @@ const minimist = require('minimist');
const path = require('path');
const args = minimist(process.argv.slice(2), {
boolean: ['verbose']
boolean: ['verbose']
});
const scriptName = args._.shift();
const scriptPath = path.join('../scripts', scriptName);
@@ -12,49 +12,15 @@ const cwd = process.cwd();
process.chdir(path.join(__dirname, '..'));
// This might get awkward, so we fallback to console if there was an error.
let logger = null;
try {
logger = new (require('@angular-devkit/core').logging.IndentLogger)('root');
const { bold, gray, red, yellow, white } = require('@angular-devkit/core').terminal;
const filter = require('rxjs/operators').filter;
logger
.pipe(filter(entry => (entry.level !== 'debug' || args.verbose)))
.subscribe(entry => {
let color = gray;
let output = process.stdout;
switch (entry.level) {
case 'info': color = white; break;
case 'warn': color = yellow; break;
case 'error': color = red; output = process.stderr; break;
case 'fatal': color = x => bold(red(x)); output = process.stderr; break;
}
output.write(color(entry.message) + '\n');
});
} catch (e) {
console.error(`Reverting to manual console logging.\nReason: ${e.message}.`);
logger = {
debug: console.log.bind(console),
info: console.log.bind(console),
warn: console.warn.bind(console),
error: console.error.bind(console),
fatal: x => { console.error(x); process.exit(100); },
createChild: () => logger,
};
}
try {
Promise.resolve()
.then(() => require(scriptPath).default(args, logger, cwd))
.then(exitCode => process.exit(exitCode || 0))
.catch(err => {
logger.fatal(err && err.stack);
process.exit(99);
});
Promise.resolve()
.then(() => require(scriptPath).default(args, cwd))
.then(exitCode => process.exit(exitCode || 0))
.catch(err => {
console.error(err && err.stack);
process.exit(99);
});
} catch (err) {
logger.fatal(err.stack);
process.exit(99);
console.error(err.stack);
process.exit(99);
}