@ooneex/command 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare const commandCreate: (config: {
|
|
|
10
10
|
commandPath: string;
|
|
11
11
|
testPath: string;
|
|
12
12
|
}>;
|
|
13
|
-
declare const
|
|
13
|
+
declare const run: () => Promise<void>;
|
|
14
14
|
import { EContainerScope } from "@ooneex/container";
|
|
15
15
|
type CommandClassType = new (...args: any[]) => ICommand;
|
|
16
16
|
interface ICommand<Options extends Record<string, unknown> = Record<string, unknown>> {
|
|
@@ -22,4 +22,4 @@ declare const decorator: {
|
|
|
22
22
|
command: (scope?: EContainerScope) => (command: CommandClassType) => void;
|
|
23
23
|
};
|
|
24
24
|
declare const getCommand: (name: string) => ICommand | null;
|
|
25
|
-
export { getCommand, decorator,
|
|
25
|
+
export { run, getCommand, decorator, commandCreate, ICommand, CommandException, CommandClassType };
|
package/dist/index.js
CHANGED
|
@@ -91,7 +91,7 @@ var commandCreate = async (config) => {
|
|
|
91
91
|
testPath: join(testsDir, `${name}Command.spec.ts`)
|
|
92
92
|
};
|
|
93
93
|
};
|
|
94
|
-
// src/
|
|
94
|
+
// src/run.ts
|
|
95
95
|
import { parseArgs } from "util";
|
|
96
96
|
import { Exception as Exception2 } from "@ooneex/exception";
|
|
97
97
|
import { TerminalLogger } from "@ooneex/logger";
|
|
@@ -112,8 +112,8 @@ var getCommand = (name) => {
|
|
|
112
112
|
return command;
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
// src/
|
|
116
|
-
var
|
|
115
|
+
// src/run.ts
|
|
116
|
+
var run = async () => {
|
|
117
117
|
const { values, positionals } = parseArgs({
|
|
118
118
|
args: Bun.argv,
|
|
119
119
|
options: {
|
|
@@ -201,11 +201,11 @@ var decorator = {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
export {
|
|
204
|
+
run,
|
|
204
205
|
getCommand,
|
|
205
206
|
decorator,
|
|
206
|
-
commandRun,
|
|
207
207
|
commandCreate,
|
|
208
208
|
CommandException
|
|
209
209
|
};
|
|
210
210
|
|
|
211
|
-
//# debugId=
|
|
211
|
+
//# debugId=39BECB90FA52E93864756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["src/CommandException.ts", "src/commandCreate.ts", "src/
|
|
3
|
+
"sources": ["src/CommandException.ts", "src/commandCreate.ts", "src/run.ts", "src/getCommand.ts", "src/container.ts", "src/decorators.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class CommandException extends Exception {\n constructor(message: string, key: string, data: Record<string, unknown> = {}) {\n super(message, {\n key,\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n\n this.name = \"CommandException\";\n }\n}\n",
|
|
6
6
|
"import { join } from \"node:path\";\nimport { toKebabCase, toPascalCase } from \"@ooneex/utils\";\nimport { Glob } from \"bun\";\nimport testTemplate from \"./command.test.txt\";\nimport template from \"./command.txt\";\n\nexport const commandCreate = async (config: {\n name: string;\n commandDir?: string;\n testsDir?: string;\n}): Promise<{ commandPath: string; testPath: string }> => {\n const name = toPascalCase(config.name).replace(/Command$/, \"\");\n const commandName = toKebabCase(name).replace(/-/g, \":\");\n const commandDir = config.commandDir || join(\"src\", \"commands\");\n const testsDir = config.testsDir || join(\"tests\", \"commands\");\n\n const content = template\n .replace(/\\{\\{NAME\\}\\}/g, name)\n .replace(/\\{\\{COMMAND_NAME\\}\\}/g, commandName)\n .replace(/\\{\\{COMMAND_DESCRIPTION\\}\\}/g, `Execute ${commandName} command`);\n\n await Bun.write(join(process.cwd(), commandDir, `${name}Command.ts`), content);\n\n const testContent = testTemplate.replace(/\\{\\{NAME\\}\\}/g, name);\n await Bun.write(join(process.cwd(), testsDir, `${name}Command.spec.ts`), testContent);\n\n const imports: string[] = [];\n const glob = new Glob(\"**/*Command.ts\");\n for await (const file of glob.scan(join(process.cwd(), commandDir))) {\n const commandClassName = file.replace(/\\.ts$/, \"\");\n imports.push(`export { ${commandClassName} } from './${commandClassName}';`);\n }\n await Bun.write(join(process.cwd(), commandDir, \"commands.ts\"), `${imports.sort().join(\"\\n\")}\\n`);\n\n return {\n commandPath: join(commandDir, `${name}Command.ts`),\n testPath: join(testsDir, `${name}Command.spec.ts`),\n };\n};\n",
|
|
7
|
-
"import { parseArgs } from \"node:util\";\nimport type { IException } from \"@ooneex/exception\";\nimport { Exception } from \"@ooneex/exception\";\nimport { TerminalLogger } from \"@ooneex/logger\";\nimport type { HttpMethodType } from \"@ooneex/types\";\nimport { getCommand } from \"./getCommand\";\n\nexport const
|
|
7
|
+
"import { parseArgs } from \"node:util\";\nimport type { IException } from \"@ooneex/exception\";\nimport { Exception } from \"@ooneex/exception\";\nimport { TerminalLogger } from \"@ooneex/logger\";\nimport type { HttpMethodType } from \"@ooneex/types\";\nimport { getCommand } from \"./getCommand\";\n\nexport const run = async (): Promise<void> => {\n const { values, positionals } = parseArgs({\n args: Bun.argv,\n options: {\n name: {\n type: \"string\",\n },\n \"route-name\": {\n type: \"string\",\n },\n \"route-path\": {\n type: \"string\",\n },\n \"route-method\": {\n type: \"string\",\n },\n \"is-socket\": {\n type: \"boolean\",\n },\n dir: {\n type: \"string\",\n },\n channel: {\n type: \"string\",\n },\n \"table-name\": {\n type: \"string\",\n },\n module: {\n type: \"string\",\n },\n destination: {\n type: \"string\",\n },\n },\n strict: false,\n allowPositionals: true,\n });\n\n const logger = new TerminalLogger();\n\n const commandName = positionals[2];\n\n if (!commandName) {\n logger.error(\"Command name is required\\n\");\n process.exit(1);\n }\n\n const command = getCommand(commandName);\n\n if (!command) {\n logger.info(\"No commands found\\n\");\n process.exit(1);\n }\n\n const parsedValues = {\n name: values.name,\n dir: values.dir,\n channel: values.channel,\n isSocket: values[\"is-socket\"],\n tableName: values[\"table-name\"],\n module: values.module,\n destination: values.destination,\n route: {\n name: values[\"route-name\"],\n path: values[\"route-path\"] as `/${string}` | undefined,\n method: values[\"route-method\"] as HttpMethodType | undefined,\n },\n };\n\n try {\n await command.run(parsedValues);\n } catch (error) {\n const exception: IException =\n error instanceof Exception ? error : new Exception(error instanceof Error ? error : String(error));\n logger.error(exception, undefined, {\n showArrow: false,\n showTimestamp: false,\n showLevel: false,\n });\n process.exit(1);\n }\n};\n",
|
|
8
8
|
"import { container } from \"@ooneex/container\";\nimport { COMMANDS_CONTAINER } from \"./container\";\nimport type { ICommand } from \"./types\";\n\nexport const getCommand = (name: string): ICommand | null => {\n let command: ICommand | null = null;\n\n COMMANDS_CONTAINER.find((CommandClass) => {\n command = container.get(CommandClass);\n\n return command.getName() === name;\n });\n\n return command;\n};\n",
|
|
9
9
|
"import type { CommandClassType } from \"./types\";\n\nexport const COMMANDS_CONTAINER: CommandClassType[] = [];\n",
|
|
10
10
|
"import { container, EContainerScope } from \"@ooneex/container\";\nimport { COMMANDS_CONTAINER } from \"./container\";\nimport type { CommandClassType } from \"./types\";\n\nexport const decorator = {\n command: (scope: EContainerScope = EContainerScope.Singleton) => {\n return (command: CommandClassType): void => {\n container.add(command, scope);\n COMMANDS_CONTAINER.push(command);\n };\n },\n};\n"
|
|
11
11
|
],
|
|
12
|
-
"mappings": ";;AAAA;AACA;AAAA;AAEO,MAAM,yBAAyB,UAAU;AAAA,EAC9C,WAAW,CAAC,SAAiB,KAAa,OAAgC,CAAC,GAAG;AAAA,IAC5E,MAAM,SAAS;AAAA,MACb;AAAA,MACA,QAAQ,WAAW,KAAK;AAAA,MACxB;AAAA,IACF,CAAC;AAAA,IAED,KAAK,OAAO;AAAA;AAEhB;;ACbA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAO,CAAC,YAAoC;AAAA,MAC1C,WAAU,IAAI,SAAS,KAAK;AAAA,MAC5B,mBAAmB,KAAK,OAAO;AAAA;AAAA;AAGrC;",
|
|
13
|
+
"debugId": "39BECB90FA52E93864756E2164756E21",
|
|
14
14
|
"names": []
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/command",
|
|
3
3
|
"description": "Command framework for building CLI commands with dependency injection, argument parsing, and execution logging",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@ooneex/container": "1.2.4",
|
|
32
32
|
"@ooneex/exception": "1.2.2",
|
|
33
33
|
"@ooneex/http-status": "1.1.5",
|
|
34
|
-
"@ooneex/logger": "1.2.
|
|
34
|
+
"@ooneex/logger": "1.2.9",
|
|
35
35
|
"@ooneex/utils": "0.4.3"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|