nope/lib/cli/nope.ts

119 lines
2.9 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @desc [description]
*/
import { readInwriteUiFileArgs, writeUiFile } from "../ui/helpers.nodejs";
import { createService } from "./createService";
import { generateDefaultConfig } from "./generateDefaultConfig";
import { generateDefaultPackageConfig } from "./generateDefaultPackageConfig";
import { generateFolderStructure } from "./generateFolderStructure";
import { repl } from "./repl";
import run from "./runNopeBackend";
/**
* Main Function.
*
* @export
*/
export async function main() {
const args: {
mode:
| "run"
| "init"
| "none"
| "conf"
| "help"
| "service"
| "repl"
| "scan-ui";
params: string[];
} = {
mode: (process.argv[2] as any) || "none",
params: process.argv.slice(3),
};
const additionalArg: any = {
help: "Command to run the backend",
name: args.mode,
type: "str",
};
const showLog = () => {
console.log(`NoPE - Command Line Interface.
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[4mconf\x1b[0m Trys to update the configuration file.
\x1b[4mscan-ui\x1b[0m Scans and extracts the provided uis.
\x1b[4mservice\x1b[0m Generate Helper Files to provide services
\x1b[4mrepl\x1b[0m Opens an interactive console.
Have fun using NoPE :)
*-*,
,*\\\/|\`| \\
\\' | |'| *,
\\ \`| | |/ )
| |'| , /
|'| |, /
___|_|_|_|___
[_____________]
| |
| This is |
| NoPE! |
| Sometimes |
| itchy! |
|___________|
`);
};
switch (args.mode) {
default:
showLog();
break;
case "help":
showLog();
break;
case "none":
showLog();
break;
case "run":
await run([additionalArg]);
break;
case "init":
additionalArg.help = "Command to run init";
await generateFolderStructure([additionalArg]);
await generateDefaultConfig([additionalArg]);
await generateDefaultPackageConfig([additionalArg]);
break;
case "conf":
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;
case "repl":
await repl([additionalArg]);
break;
case "scan-ui":
additionalArg.help =
"Command to readin the UI-Files and store them in a config";
await writeUiFile(readInwriteUiFileArgs([additionalArg]));
break;
}
}
export default main;
// If requested As Main => Perform the Operation.
if (require.main === module) {
main().catch((e) => console.error(e));
}