mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
fix: should now compile and work
This commit is contained in:
61
src/cli.ts
61
src/cli.ts
@@ -17,7 +17,7 @@ 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 {Command} from 'commander';
|
||||
import {readFileSync} from 'fs';
|
||||
import {join, resolve} from 'path';
|
||||
import {MinimalPlugin} from './plugin/minimal-plugin';
|
||||
@@ -31,38 +31,35 @@ process.on('unhandledRejection', (error) => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
commander
|
||||
const program = new Command()
|
||||
.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
|
||||
.option('-b, --backend-url <string>', 'URL of the StApps backend deployment', 'http://localhost:3000')
|
||||
.option('-n, --plugin-name <string>', 'The name of the plugin', 'minimal-plugin') // TODO: adjust default
|
||||
.option('-r, --route-name <string>', 'The name of the route', 'minimalPlugin') // TODO: adjust default
|
||||
.option('-u, --url <string>', 'The url of the plugin', 'http://localhost') // TODO: adjust default
|
||||
.option('-p, --port <number>', 'The port of the plugin', '4000') // TODO: adjust default
|
||||
.parse(process.argv);
|
||||
|
||||
// create an instance of the PluginClient
|
||||
const pluginClient = new PluginClient(new HttpClient(), program.backendUrl);
|
||||
|
||||
// create an instance of your plugin
|
||||
const plugin = new MinimalPlugin(
|
||||
// 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) => {
|
||||
Number.parseInt(program.port, 10), program.pluginName, program.url, `/${program.routeName}`, program.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
|
||||
);
|
||||
|
||||
// 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;
|
||||
});
|
||||
pluginClient.registerPlugin(plugin)
|
||||
.then(() => {
|
||||
Logger.ok('done.');
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
commander.parse(process.argv);
|
||||
|
||||
Reference in New Issue
Block a user