mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 08:02:55 +00:00
style: apply stricter ts lint rules
This commit is contained in:
61
src/cli.ts
61
src/cli.ts
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 StApps
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -19,38 +19,43 @@ import {join} from 'path';
|
||||
import {URL} from 'url';
|
||||
import {copy} from './copy';
|
||||
import {indexSamples} from './e2e';
|
||||
import {HttpClient} from './httpClient';
|
||||
import {HttpClient} from './http-client';
|
||||
|
||||
const logger = new Logger();
|
||||
const pkgJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json')).toString());
|
||||
const pkgJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'))
|
||||
.toString());
|
||||
|
||||
const client = new HttpClient();
|
||||
|
||||
let actionDone = false;
|
||||
|
||||
process.on('unhandledRejection', (error) => {
|
||||
logger.error('unhandledRejection', error);
|
||||
process.on('unhandledRejection', async (error) => {
|
||||
await Logger.error('unhandledRejection', error);
|
||||
});
|
||||
|
||||
commander
|
||||
.command('e2e <to>')
|
||||
.description('Run in end to end test mode. Indexing all test files from @openstapp/core to the backend')
|
||||
.option('-s --samples [path]', 'Path to @openstapp/core test files', './node_modules/@openstapps/core/test/resources')
|
||||
.action((to, e2eCommand) => {
|
||||
.action(async (to, e2eCommand) => {
|
||||
let toURL = '';
|
||||
// validate url
|
||||
try {
|
||||
to = (new URL(to)).toString();
|
||||
toURL = (new URL(to)).toString();
|
||||
} catch (err) {
|
||||
logger.error('expected parameter "to" to be valid url', err);
|
||||
await Logger.error('expected parameter "to" to be valid url', err);
|
||||
e2eCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
actionDone = true;
|
||||
|
||||
indexSamples(client, {to: to, samples: e2eCommand.samples}).then(() => {
|
||||
logger.ok('Done');
|
||||
});
|
||||
indexSamples(client, {to: toURL, samples: e2eCommand.samples})
|
||||
.then(() => {
|
||||
Logger.ok('Done');
|
||||
})
|
||||
.catch(async (reason) => {
|
||||
await Logger.error(reason);
|
||||
});
|
||||
});
|
||||
|
||||
commander
|
||||
@@ -65,48 +70,52 @@ commander
|
||||
// TODO: remove
|
||||
.option('-a, --appVersion <version>', 'The App version to use [unset by default]')
|
||||
.allowUnknownOption(false)
|
||||
.action((type, from, to, batchSize, copyCommand) => {
|
||||
.action(async (type, from, to, batchSize, copyCommand) => {
|
||||
|
||||
// validate type
|
||||
if (typeof type !== 'string') {
|
||||
logger.error('expected parameter "type" to be of type: string');
|
||||
await Logger.error('expected parameter "type" to be of type: string');
|
||||
copyCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
let fromURL = '';
|
||||
let toURL = '';
|
||||
|
||||
// validate urls
|
||||
try {
|
||||
from = (new URL(from)).toString();
|
||||
to = (new URL(to)).toString();
|
||||
fromURL = (new URL(from)).toString();
|
||||
toURL = (new URL(to)).toString();
|
||||
} catch (err) {
|
||||
logger.error('expected parameters "from" and "to" to be valid urls', err);
|
||||
await Logger.error('expected parameters "from" and "to" to be valid urls', err);
|
||||
copyCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
// validate batchSize
|
||||
if (isNaN(parseInt(batchSize, 10))) {
|
||||
logger.error('expected parameter "batchSize" to be of type: number');
|
||||
await Logger.error('expected parameter "batchSize" to be of type: number');
|
||||
copyCommand.outputHelp();
|
||||
process.exit(-1);
|
||||
}
|
||||
|
||||
actionDone = true;
|
||||
|
||||
logger.info('Copying ' + type + ' objects from ' + from + ' to ' + to);
|
||||
Logger.info(`Copying ${type} objects from ${fromURL} to ${toURL}`);
|
||||
|
||||
copy(client, {
|
||||
batchSize: parseInt(batchSize, 10),
|
||||
from: from,
|
||||
from: fromURL,
|
||||
source: copyCommand.bulkSource,
|
||||
to: to,
|
||||
to: toURL,
|
||||
type: type,
|
||||
version: copyCommand.appVersion,
|
||||
}).then(() => {
|
||||
logger.ok('Done');
|
||||
}, (err) => {
|
||||
throw err;
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
Logger.ok('Done');
|
||||
}, (err) => {
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
||||
commander
|
||||
|
||||
Reference in New Issue
Block a user