mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 08:02:55 +00:00
refactor: adjust code to new configuration
This commit is contained in:
27
src/cli.ts
27
src/cli.ts
@@ -23,14 +23,17 @@ import {Converter, getValidatableTypesFromReflection} from './schema';
|
||||
import {validateFiles, writeReport} from './validate';
|
||||
|
||||
// handle unhandled promise rejections
|
||||
process.on('unhandledRejection', (error: Error) => {
|
||||
Logger.error(error.message);
|
||||
process.on('unhandledRejection', async (error: Error) => {
|
||||
await Logger.error(error.message);
|
||||
Logger.info(error.stack);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
commander
|
||||
.version(JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json')).toString()).version);
|
||||
.version(JSON.parse(
|
||||
readFileSync(resolve(__dirname, '..', 'package.json'))
|
||||
.toString(),
|
||||
).version);
|
||||
|
||||
commander
|
||||
.command('routes <srcPath> <mdPath>')
|
||||
@@ -46,7 +49,7 @@ commander
|
||||
const routes = await gatherRouteInformation(projectReflection);
|
||||
|
||||
// initialize markdown output
|
||||
let output: string = '# Routes\n\n';
|
||||
let output = '# Routes\n\n';
|
||||
|
||||
// generate documentation for all routes
|
||||
routes.forEach((routeWithMetaInformation) => {
|
||||
@@ -84,7 +87,8 @@ commander
|
||||
Logger.info(`Trying to find a package.json for ${srcPath}.`);
|
||||
|
||||
let path = srcPath;
|
||||
// TODO: this check should be less ugly!
|
||||
// TODO: this check should be less ugly! --- What is this doing anyway?
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
while (!existsSync(join(path, 'package.json')) && path.length > 5) {
|
||||
path = resolve(path, '..');
|
||||
}
|
||||
@@ -103,9 +107,10 @@ commander
|
||||
validatableTypes.forEach((type) => {
|
||||
const schema = coreConverter.getSchema(type, coreVersion);
|
||||
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
const stringifiedSchema = JSON.stringify(schema, null, 2);
|
||||
|
||||
const file = join(schemaPath, type + '.json');
|
||||
const file = join(schemaPath, `${type}.json`);
|
||||
|
||||
// write schema to file
|
||||
writeFileSync(file, stringifiedSchema);
|
||||
@@ -126,9 +131,13 @@ commander
|
||||
const errorsPerFile = await validateFiles(schemaPath, testPath);
|
||||
|
||||
let unexpected = false;
|
||||
Object.keys(errorsPerFile).forEach((file) => {
|
||||
for (const file in errorsPerFile) {
|
||||
if (!errorsPerFile.hasOwnProperty(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unexpected = unexpected || errorsPerFile[file].some((error) => !error.expected);
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof relativeReportPath !== 'undefined') {
|
||||
const reportPath = resolve(relativeReportPath);
|
||||
@@ -138,7 +147,7 @@ commander
|
||||
if (!unexpected) {
|
||||
Logger.ok('Successfully finished validation.');
|
||||
} else {
|
||||
Logger.error('Unexpected errors occurred during validation');
|
||||
await Logger.error('Unexpected errors occurred during validation');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user