mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-06 05:22:52 +00:00
93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
/*
|
|
* Copyright (C) 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.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
import {Api} from '@openstapps/gitlab-api';
|
|
import {Logger} from '@openstapps/logger';
|
|
import {AddLogLevel} from '@openstapps/logger/lib/transformations/add-log-level';
|
|
import {Colorize} from '@openstapps/logger/lib/transformations/colorize';
|
|
import * as commander from 'commander';
|
|
import {existsSync, readFileSync} from 'fs';
|
|
import {join, resolve} from 'path';
|
|
import {cwd, stdout} from 'process';
|
|
import {GITLAB_API_URL} from './configuration';
|
|
import {getUsedVersionMajorMinor} from './tasks/get-used-version';
|
|
import {remind} from './tasks/remind';
|
|
import {tidy} from './tasks/tidy';
|
|
import {unlabel} from './tasks/unlabel';
|
|
|
|
// add default handler for unhandled rejections
|
|
process.on('unhandledRejection', async (reason) => {
|
|
if (reason instanceof Error) {
|
|
await Logger.error('Unhandled rejection', reason.stack);
|
|
} else {
|
|
await Logger.error('Unhandled rejection', reason);
|
|
}
|
|
|
|
process.exit(1);
|
|
});
|
|
|
|
// error on unknown commands
|
|
commander.on('command:*', async () => {
|
|
await Logger.error('Invalid command: %s\nSee --help for a list of available commands.', commander.args.join(' '));
|
|
|
|
process.exit(1);
|
|
});
|
|
|
|
const gitlabApi = new Api(GITLAB_API_URL, process.env.GITLAB_PRIVATE_TOKEN as string);
|
|
|
|
Logger.setTransformations([
|
|
new AddLogLevel(),
|
|
new Colorize(),
|
|
]);
|
|
|
|
if (existsSync(join(__dirname, 'package.json'))) {
|
|
commander.version(JSON.parse(readFileSync(join(__dirname, '..', 'package.json'))
|
|
.toString()).version);
|
|
}
|
|
|
|
commander
|
|
.command('unlabel')
|
|
.action(async () => {
|
|
await unlabel(gitlabApi);
|
|
Logger.ok('Done!');
|
|
});
|
|
|
|
commander
|
|
.command('tidy')
|
|
.action(async () => {
|
|
await tidy(gitlabApi);
|
|
Logger.ok('Done!');
|
|
});
|
|
|
|
commander
|
|
.command('remind')
|
|
.action(async () => {
|
|
await remind(gitlabApi);
|
|
Logger.ok('Done!');
|
|
});
|
|
|
|
commander
|
|
.command('get-used-version <dependency> [path]')
|
|
.action(async (dependency, path) => {
|
|
let fallbackPath = cwd();
|
|
if (typeof path === 'string' && path.length > 0) {
|
|
fallbackPath = resolve(path);
|
|
}
|
|
|
|
stdout.write(await getUsedVersionMajorMinor(fallbackPath, dependency), process.exit);
|
|
});
|
|
|
|
commander
|
|
.parse(process.argv);
|