Initial commit

This commit is contained in:
Wieland Schöbl
2019-08-20 13:46:25 +02:00
commit 8f62b0faa0
16 changed files with 4370 additions and 0 deletions

68
src/cli.ts Normal file
View File

@@ -0,0 +1,68 @@
/*
* 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 {HttpClient} from '@openstapps/api/lib/http-client';
import {PluginClient} from '@openstapps/api/lib/plugin-client';
import {Converter} from '@openstapps/core-tools/lib/schema';
import {Logger} from '@openstapps/logger';
import * as commander from 'commander';
import {readFileSync} from 'fs';
import {join, resolve} from 'path';
import {MinimalPlugin} from './plugin/minimal-plugin';
const pluginVersion = JSON.parse(
readFileSync(join(__dirname, '..', 'package.json'))
.toString(),
).version;
process.on('unhandledRejection', (error) => {
throw error;
});
commander
.version(pluginVersion)
.command('run')
.option('-b <backenUrl>', 'URL of the StApps backend deployment', 'http://localhost:3000')
.option('-n <name>', 'The name of the plugin', 'minimal-plugin') // TODO: adjust default
.option('-r <routeName>', 'The name of the route', 'minimalPlugin') // TODO: adjust default
.option('-u <url>', 'The url of the plugin', 'http://localhost') // TODO: adjust default
// tslint:disable-next-line:no-magic-numbers
.option('-p <port>', 'The port of the plugin', 4000) // TODO: adjust default
.action(async (backendUrl: string, name: string, routeName: string, url: string, port: number) => {
// create an instance of the PluginClient
const pluginClient = new PluginClient(new HttpClient(), backendUrl);
// create an instance of your plugin
const plugin = new MinimalPlugin(port, name, url, `/${routeName}`, backendUrl,
new Converter(resolve(__dirname, '..', 'src/plugin', 'protocol')), // an instance of the converter. Required
// because your requests and response schemas are defined in the plugin. The path should lead to your request and
// response interfaces
'SCMinimalRequest', // the name of the request interface TODO: adjust
'SCMinimalResponse', // the name of the response interface TODO: adjust
JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'))
.toString()).version, // get the version of the plugin from the package.json
);
pluginClient.registerPlugin(plugin)
.then(() => {
Logger.ok('done.');
})
.catch((err: Error) => {
throw err;
});
});
commander.parse(process.argv);