@ooneex/command 0.1.1 → 0.1.3
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 +20 -23
- package/dist/index.js.map +6 -6
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ declare const commandCreate: (config: {
|
|
|
10
10
|
commandPath: string;
|
|
11
11
|
testPath: string;
|
|
12
12
|
}>;
|
|
13
|
-
declare const commandRun: () => Promise<void>;
|
|
14
13
|
import { EContainerScope } from "@ooneex/container";
|
|
15
14
|
type CommandClassType = new (...args: any[]) => ICommand;
|
|
16
15
|
interface ICommand<Options extends Record<string, unknown> = Record<string, unknown>> {
|
|
@@ -22,4 +21,5 @@ declare const decorator: {
|
|
|
22
21
|
command: (scope?: EContainerScope) => (command: CommandClassType) => void;
|
|
23
22
|
};
|
|
24
23
|
declare const getCommand: (name: string) => ICommand | null;
|
|
25
|
-
|
|
24
|
+
declare const run: () => Promise<void>;
|
|
25
|
+
export { run, getCommand, decorator, commandCreate, ICommand, CommandException, CommandClassType };
|
package/dist/index.js
CHANGED
|
@@ -91,29 +91,36 @@ var commandCreate = async (config) => {
|
|
|
91
91
|
testPath: join(testsDir, `${name}Command.spec.ts`)
|
|
92
92
|
};
|
|
93
93
|
};
|
|
94
|
-
// src/
|
|
95
|
-
import {
|
|
96
|
-
import { Exception as Exception2 } from "@ooneex/exception";
|
|
97
|
-
import { TerminalLogger } from "@ooneex/logger";
|
|
98
|
-
|
|
99
|
-
// src/getCommand.ts
|
|
100
|
-
import { container } from "@ooneex/container";
|
|
94
|
+
// src/decorators.ts
|
|
95
|
+
import { container, EContainerScope } from "@ooneex/container";
|
|
101
96
|
|
|
102
97
|
// src/container.ts
|
|
103
98
|
var COMMANDS_CONTAINER = [];
|
|
104
99
|
|
|
100
|
+
// src/decorators.ts
|
|
101
|
+
var decorator = {
|
|
102
|
+
command: (scope = EContainerScope.Singleton) => {
|
|
103
|
+
return (command) => {
|
|
104
|
+
container.add(command, scope);
|
|
105
|
+
COMMANDS_CONTAINER.push(command);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
105
109
|
// src/getCommand.ts
|
|
110
|
+
import { container as container2 } from "@ooneex/container";
|
|
106
111
|
var getCommand = (name) => {
|
|
107
112
|
let command = null;
|
|
108
113
|
COMMANDS_CONTAINER.find((CommandClass) => {
|
|
109
|
-
command =
|
|
114
|
+
command = container2.get(CommandClass);
|
|
110
115
|
return command.getName() === name;
|
|
111
116
|
});
|
|
112
117
|
return command;
|
|
113
118
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
// src/run.ts
|
|
120
|
+
import { parseArgs } from "util";
|
|
121
|
+
import { Exception as Exception2 } from "@ooneex/exception";
|
|
122
|
+
import { TerminalLogger } from "@ooneex/logger";
|
|
123
|
+
var run = async () => {
|
|
117
124
|
const { values, positionals } = parseArgs({
|
|
118
125
|
args: Bun.argv,
|
|
119
126
|
options: {
|
|
@@ -190,22 +197,12 @@ var commandRun = async () => {
|
|
|
190
197
|
process.exit(1);
|
|
191
198
|
}
|
|
192
199
|
};
|
|
193
|
-
// src/decorators.ts
|
|
194
|
-
import { container as container2, EContainerScope } from "@ooneex/container";
|
|
195
|
-
var decorator = {
|
|
196
|
-
command: (scope = EContainerScope.Singleton) => {
|
|
197
|
-
return (command) => {
|
|
198
|
-
container2.add(command, scope);
|
|
199
|
-
COMMANDS_CONTAINER.push(command);
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
200
|
export {
|
|
201
|
+
run,
|
|
204
202
|
getCommand,
|
|
205
203
|
decorator,
|
|
206
|
-
commandRun,
|
|
207
204
|
commandCreate,
|
|
208
205
|
CommandException
|
|
209
206
|
};
|
|
210
207
|
|
|
211
|
-
//# debugId=
|
|
208
|
+
//# debugId=AAA209D788901B2764756E2164756E21
|
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/decorators.ts", "src/container.ts", "src/getCommand.ts", "src/run.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 {
|
|
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",
|
|
7
|
+
"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",
|
|
9
8
|
"import type { CommandClassType } from \"./types\";\n\nexport const COMMANDS_CONTAINER: CommandClassType[] = [];\n",
|
|
10
|
-
"import { container
|
|
9
|
+
"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",
|
|
10
|
+
"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"
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,gBAAgB,OAAO,WAIsB;AAAA,EACxD,MAAM,OAAO,aAAa,OAAO,IAAI,EAAE,QAAQ,YAAY,EAAE;AAAA,EAC7D,MAAM,cAAc,YAAY,IAAI,EAAE,QAAQ,MAAM,GAAG;AAAA,EACvD,MAAM,aAAa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AM;AAAA,CAA4B;AAAA,IACzC,QAAQ,KAAK,CAAC;AAAA,EAChB;AAAA,EAEA,MAAM,UAAU,WAAW,WAAW;AAAA,EAEtC,IAAI,CAAC,SAAS;AAAA,IACZ,OAAO,KAAK;AAAA,CAAqB;AAAA,IACjC,QAAQ,KAAK,CAAC;AAAA,EAChB;AAAA,EAEA,MAAM,eAAe;AAAA,IACnB,MAAM,OAAO;AAAA,IACb,KAAK,OAAO;AAAA,IACZ,SAAS,OAAO;AAAA,IAChB,UAAU,OAAO;AAAA,IACjB,WAAW,OAAO;AAAA,IAClB,QAAQ,OAAO;AAAA,IACf,aAAa,OAAO;AAAA,IACpB,OAAO;AAAA,MACL,MAAM,OAAO;AAAA,MACb,MAAM,OAAO;AAAA,MACb,QAAQ,OAAO;AAAA,IACjB;AAAA,EACF;AAAA,EAEA,IAAI;AAAA,IACF,MAAM,QAAQ,IAAI,YAAY;AAAA,IAC9B,OAAO,OAAO;AAAA,IACd,MAAM,YACJ,iBAAiB,aAAY,QAAQ,IAAI,WAAU,iBAAiB,QAAQ,QAAQ,OAAO,KAAK,CAAC;AAAA,IACnG,OAAO,MAAM,WAAW,WAAW;AAAA,MACjC,WAAW;AAAA,MACX,eAAe;AAAA,MACf,WAAW;AAAA,IACb,CAAC;AAAA,IACD,QAAQ,KAAK,CAAC;AAAA;AAAA;",
|
|
13
|
+
"debugId": "AAA209D788901B2764756E2164756E21",
|
|
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.3",
|
|
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": {
|