@ooneex/command 0.1.3 → 0.2.0
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/README.md +4 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -6
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Database seeding framework for populating initial data, fixtures, and test datas
|
|
|
16
16
|
|
|
17
17
|
✅ **Active/Inactive Control** - Enable or disable individual seeds via the `isActive()` method
|
|
18
18
|
|
|
19
|
-
✅ **Seed Runner** - Execute all active seeds in order with terminal logging via `
|
|
19
|
+
✅ **Seed Runner** - Execute all active seeds in order with terminal logging via `run()`
|
|
20
20
|
|
|
21
21
|
✅ **Seed Scaffolding** - Generate new seed files from a template with `seedCreate()`
|
|
22
22
|
|
|
@@ -95,9 +95,9 @@ export class UserSeed implements ISeed {
|
|
|
95
95
|
### Running Seeds
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
|
-
import {
|
|
98
|
+
import { run } from '@ooneex/seeds';
|
|
99
99
|
|
|
100
|
-
await
|
|
100
|
+
await run();
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
### Creating a New Seed
|
|
@@ -136,7 +136,7 @@ interface ISeed {
|
|
|
136
136
|
|
|
137
137
|
### Functions
|
|
138
138
|
|
|
139
|
-
#### `
|
|
139
|
+
#### `run(): Promise<void>`
|
|
140
140
|
|
|
141
141
|
Execute all active seeds with dependency resolution and terminal logging.
|
|
142
142
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,16 +10,17 @@ declare const commandCreate: (config: {
|
|
|
10
10
|
commandPath: string;
|
|
11
11
|
testPath: string;
|
|
12
12
|
}>;
|
|
13
|
-
import { EContainerScope } from "@ooneex/container";
|
|
14
13
|
type CommandClassType = new (...args: any[]) => ICommand;
|
|
15
14
|
interface ICommand<Options extends Record<string, unknown> = Record<string, unknown>> {
|
|
16
15
|
run: (options: Options) => Promise<void> | void;
|
|
17
16
|
getName: () => string;
|
|
18
17
|
getDescription: () => string;
|
|
19
18
|
}
|
|
19
|
+
declare const COMMANDS_CONTAINER: CommandClassType[];
|
|
20
|
+
import { EContainerScope } from "@ooneex/container";
|
|
20
21
|
declare const decorator: {
|
|
21
22
|
command: (scope?: EContainerScope) => (command: CommandClassType) => void;
|
|
22
23
|
};
|
|
23
24
|
declare const getCommand: (name: string) => ICommand | null;
|
|
24
25
|
declare const run: () => Promise<void>;
|
|
25
|
-
export { run, getCommand, decorator, commandCreate, ICommand, CommandException, CommandClassType };
|
|
26
|
+
export { run, getCommand, decorator, commandCreate, ICommand, CommandException, CommandClassType, COMMANDS_CONTAINER };
|
package/dist/index.js
CHANGED
|
@@ -91,13 +91,10 @@ var commandCreate = async (config) => {
|
|
|
91
91
|
testPath: join(testsDir, `${name}Command.spec.ts`)
|
|
92
92
|
};
|
|
93
93
|
};
|
|
94
|
-
// src/decorators.ts
|
|
95
|
-
import { container, EContainerScope } from "@ooneex/container";
|
|
96
|
-
|
|
97
94
|
// src/container.ts
|
|
98
95
|
var COMMANDS_CONTAINER = [];
|
|
99
|
-
|
|
100
96
|
// src/decorators.ts
|
|
97
|
+
import { container, EContainerScope } from "@ooneex/container";
|
|
101
98
|
var decorator = {
|
|
102
99
|
command: (scope = EContainerScope.Singleton) => {
|
|
103
100
|
return (command) => {
|
|
@@ -202,7 +199,8 @@ export {
|
|
|
202
199
|
getCommand,
|
|
203
200
|
decorator,
|
|
204
201
|
commandCreate,
|
|
205
|
-
CommandException
|
|
202
|
+
CommandException,
|
|
203
|
+
COMMANDS_CONTAINER
|
|
206
204
|
};
|
|
207
205
|
|
|
208
|
-
//# debugId=
|
|
206
|
+
//# debugId=D61AFC4E7AA499A064756E2164756E21
|
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/container.ts", "src/decorators.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 { 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",
|
|
8
7
|
"import type { CommandClassType } from \"./types\";\n\nexport const COMMANDS_CONTAINER: CommandClassType[] = [];\n",
|
|
8
|
+
"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
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
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,OAAO,cAAc,KAAK,OAAO,UAAU;AAAA,EAC9D,MAAM,WAAW,OAAO,YAAY,KAAK,SAAS,UAAU;AAAA,EAE5D,MAAM,UAAU,gBACb,QAAQ,iBAAiB,IAAI,EAC7B,QA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AAqB;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": "D61AFC4E7AA499A064756E2164756E21",
|
|
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.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"npm:publish": "bun publish --tolerate-republish --force --production --access public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@ooneex/container": "1.
|
|
31
|
+
"@ooneex/container": "1.3.0",
|
|
32
32
|
"@ooneex/exception": "1.2.2",
|
|
33
33
|
"@ooneex/http-status": "1.1.5",
|
|
34
34
|
"@ooneex/logger": "1.2.9",
|