mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-07 05:52:57 +00:00
85 lines
2.5 KiB
TypeScript
85 lines
2.5 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 * 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 (err) => {
|
|
await Logger.error('UNHANDLED REJECTION', err.stack);
|
|
process.exit(1);
|
|
});
|
|
|
|
// check that environment variable GITLAB_PRIVATE_TOKEN is set
|
|
if (typeof process.env.GITLAB_PRIVATE_TOKEN !== 'string' || process.env.GITLAB_PRIVATE_TOKEN.length === 0) {
|
|
// tslint:disable-next-line:no-floating-promises
|
|
Logger.error('Environment variable GITLAB_PRIVATE_TOKEN is not set!');
|
|
process.exit(1);
|
|
}
|
|
|
|
const gitlabApi = new Api(GITLAB_API_URL, process.env.GITLAB_PRIVATE_TOKEN as string);
|
|
|
|
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);
|
|
|
|
if (commander.args.length < 1) {
|
|
commander.help();
|
|
}
|