adding default config for wamo, adding service tab to cli tool
This commit is contained in:
parent
d903e84a04
commit
41ee7f8d10
@ -2,7 +2,7 @@
|
||||
* @author Martin Karkowski
|
||||
* @email m.karkowski@zema.de
|
||||
* @create date 2021-01-08 15:16:51
|
||||
* @modify date 2021-01-08 16:46:04
|
||||
* @modify date 2021-02-09 10:18:08
|
||||
* @desc [description]
|
||||
*/
|
||||
|
||||
@ -20,7 +20,14 @@ import { validLayers } from "./runNopeBackend";
|
||||
|
||||
// Define the Main Function.
|
||||
// This function is used as cli tool.
|
||||
const main = async function () {
|
||||
export async function createService (
|
||||
additionalArguments: {
|
||||
help: string;
|
||||
type: "string" | "number";
|
||||
name: string | string;
|
||||
defaultValue?: any;
|
||||
}[] = []
|
||||
) {
|
||||
// Flag, to determine the OS
|
||||
const runningInLinux = type() === "Linux";
|
||||
|
||||
@ -30,6 +37,14 @@ const main = async function () {
|
||||
description: "Command Line interface, which enables creating services."
|
||||
});
|
||||
|
||||
for (const arg of additionalArguments) {
|
||||
parser.addArgument(arg.name, {
|
||||
help: arg.help,
|
||||
defaultValue: arg.defaultValue,
|
||||
type: arg.type
|
||||
});
|
||||
}
|
||||
|
||||
parser.addArgument(["-f", "--file"], {
|
||||
help: "File containing containing the package definitions.",
|
||||
defaultValue: "./config/settings.json",
|
||||
@ -335,6 +350,10 @@ node {{{pathToFolder}}}\\index.js`)
|
||||
logger.error("Failed generating the Config");
|
||||
logger.error(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
main().catch((e) => console.error(e));
|
||||
|
||||
// If requested As Main => Perform the Operation.
|
||||
if (require.main === module) {
|
||||
createService().catch((e) => console.error(e));
|
||||
}
|
||||
|
@ -2,10 +2,11 @@
|
||||
* @author Martin Karkowski
|
||||
* @email m.karkowski@zema.de
|
||||
* @create date 2021-01-18 17:29:44
|
||||
* @modify date 2021-02-05 10:06:53
|
||||
* @modify date 2021-02-09 10:25:07
|
||||
* @desc [description]
|
||||
*/
|
||||
|
||||
import { createService } from "./createService";
|
||||
import { generateDefaultConfig } from "./generateDefaultConfig";
|
||||
import { generateDefaultPackageConfig } from "./generateDefaultPackageConfig";
|
||||
import { generateFolderStructure } from "./generateFolderStructure";
|
||||
@ -19,7 +20,7 @@ import { readInArgs as getRunArgs, runNopeBackend } from "./runNopeBackend";
|
||||
*/
|
||||
export async function main() {
|
||||
const args: {
|
||||
mode: "run" | "init" | "none" | "scan" | "help";
|
||||
mode: "run" | "init" | "none" | "scan" | "help" | "service";
|
||||
params: string[];
|
||||
} = {
|
||||
mode: (process.argv[2] as any) || "none",
|
||||
@ -42,7 +43,8 @@ Please select the option you want. Therefore add one of the following options:
|
||||
\x1b[4mhelp\x1b[0m Show this help.
|
||||
\x1b[4mrun\x1b[0m Start a NoPE-Backend.
|
||||
\x1b[4minit\x1b[0m Initialize a new project. This project is empty.
|
||||
\x1b[4mscan\x1b[0m Trys to update the configuration file.
|
||||
\x1b[4mscan\x1b[0m Trys to update the configuration file.
|
||||
\x1b[4mservice\x1b[0m Generate Helper Files to provide services
|
||||
|
||||
Have fun using NoPE :)
|
||||
|
||||
@ -75,12 +77,15 @@ Have fun using NoPE :)
|
||||
await generateFolderStructure([additionalArg]);
|
||||
await generateDefaultConfig([additionalArg]);
|
||||
await generateDefaultPackageConfig([additionalArg]);
|
||||
|
||||
break;
|
||||
case "scan":
|
||||
additionalArg.help = "Command to generate the Config of the backend";
|
||||
await generateDefaultPackageConfig([additionalArg]);
|
||||
break;
|
||||
case "service":
|
||||
additionalArg.help = "Command to generate the Service Files";
|
||||
await createService([additionalArg]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @author Martin Karkowski
|
||||
* @email m.karkowski@zema.de
|
||||
* @create date 2020-11-11 14:19:10
|
||||
* @modify date 2020-12-30 18:22:52
|
||||
* @modify date 2021-02-09 10:11:44
|
||||
* @desc [description]
|
||||
*/
|
||||
|
||||
@ -152,7 +152,7 @@ export async function writeDefaultConfig(
|
||||
*/
|
||||
export async function loadPackages(
|
||||
loader: INopePackageLoader,
|
||||
filename: string = join(resolve(process.cwd()), "config", "assembly.json")
|
||||
filename: string = join(resolve(process.cwd()), "config", "settings.json")
|
||||
) {
|
||||
let data: IConfigFile = {
|
||||
functions: [],
|
||||
|
102
modules/wamo/cli/generateConfig.ts
Normal file
102
modules/wamo/cli/generateConfig.ts
Normal file
@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @author Martin Karkowski
|
||||
* @email m.karkowski@zema.de
|
||||
* @create date 2021-02-09 10:12:37
|
||||
* @modify date 2021-02-09 10:15:07
|
||||
* @desc [description]
|
||||
*/
|
||||
|
||||
import { hostname } from "os";
|
||||
import { join, resolve } from "path";
|
||||
import { createFile } from "../../../lib/helpers/fileMethods";
|
||||
|
||||
const name = hostname();
|
||||
|
||||
const config = {
|
||||
functions: [],
|
||||
packages: [
|
||||
{
|
||||
nameOfPackage: "bridgeLayer",
|
||||
defaultInstances: [
|
||||
{
|
||||
options: {
|
||||
identifier: ("wamo-" + name + "-bridge").toLowerCase(),
|
||||
params: "http://localhost:7000",
|
||||
type: "AdditionalBridgeModule"
|
||||
},
|
||||
selector: "AdditionalBridgeModule"
|
||||
}
|
||||
],
|
||||
autostart: {},
|
||||
path: "dist\\modules\\bridge\\src\\bridge.package.js"
|
||||
},
|
||||
{
|
||||
nameOfPackage: "beckhoffPackage",
|
||||
defaultInstances: [
|
||||
{
|
||||
options: {
|
||||
identifier: name,
|
||||
params: [
|
||||
{
|
||||
port: 48898,
|
||||
amsPortSource: 32905,
|
||||
amsPortTarget: 851,
|
||||
timeout: 5000,
|
||||
amsNetIdTarget: "1.1.1.1.1.1",
|
||||
amsNetIdSource: "2.2.2.2.2.2",
|
||||
host: "localhost",
|
||||
twinCatVersion: 3
|
||||
}
|
||||
],
|
||||
type: "BeckhoffPlc"
|
||||
},
|
||||
selector: "BeckhoffPlc"
|
||||
}
|
||||
],
|
||||
autostart: {},
|
||||
path:
|
||||
"dist\\modules\\mod-Beckhoff-PLC-Interface\\src\\beckhoff.package.js"
|
||||
},
|
||||
{
|
||||
nameOfPackage: "mqttBrokerPackage",
|
||||
defaultInstances: [
|
||||
{
|
||||
options: {
|
||||
identifier: ("wamo-" + name + "-mqtt-broker").toLowerCase(),
|
||||
params: [],
|
||||
type: "MQTTBrokerModule"
|
||||
},
|
||||
selector: "MQTTBrokerModule"
|
||||
}
|
||||
],
|
||||
autostart: {},
|
||||
path: "dist\\modules\\mqtt-broker\\src\\mqtt.broker.package.js"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const pubSubConfig = {
|
||||
nameOfPackage: "pubsubPackage",
|
||||
defaultInstances: [
|
||||
{
|
||||
options: {
|
||||
identifier: "pub-sub-system",
|
||||
params: [],
|
||||
type: "PubSubModule"
|
||||
}
|
||||
}
|
||||
],
|
||||
autostart: {},
|
||||
path: "dist\\modules\\pub-sub\\src\\pub-sub.package.js"
|
||||
};
|
||||
|
||||
// Define the Filename for the Configuration
|
||||
const filename: string = join(
|
||||
resolve(process.cwd()),
|
||||
"config",
|
||||
"settings.json"
|
||||
);
|
||||
|
||||
createFile(filename, JSON.stringify(config, undefined, 4)).then(() =>
|
||||
console.log("Created Configuartion in", filename)
|
||||
);
|
Loading…
Reference in New Issue
Block a user