@wocker/core 1.0.21 → 1.0.22-beta.1

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.
Files changed (43) hide show
  1. package/README.md +8 -0
  2. package/lib/core/ApplicationContext.js +24 -0
  3. package/lib/core/ControllerWrapper.d.ts +16 -0
  4. package/lib/core/ControllerWrapper.js +77 -0
  5. package/lib/core/InstanceWrapper.d.ts +3 -3
  6. package/lib/core/InstanceWrapper.js +4 -1
  7. package/lib/core/Module.d.ts +3 -2
  8. package/lib/core/Module.js +3 -11
  9. package/lib/core/Route.d.ts +23 -0
  10. package/lib/core/Route.js +64 -0
  11. package/lib/core/Scanner.d.ts +2 -2
  12. package/lib/core/Scanner.js +18 -93
  13. package/lib/decorators/Completion.js +2 -2
  14. package/lib/decorators/Controller.d.ts +1 -0
  15. package/lib/decorators/Controller.js +5 -2
  16. package/lib/decorators/Description.d.ts +3 -1
  17. package/lib/decorators/Description.js +21 -2
  18. package/lib/decorators/Option.d.ts +2 -2
  19. package/lib/decorators/Option.js +3 -3
  20. package/lib/env.d.ts +2 -0
  21. package/lib/env.js +3 -1
  22. package/lib/index.d.ts +1 -1
  23. package/lib/index.js +2 -1
  24. package/lib/makes/AppConfig.d.ts +12 -4
  25. package/lib/makes/AppConfig.js +43 -14
  26. package/lib/makes/FileSystem.d.ts +2 -1
  27. package/lib/makes/FileSystem.js +6 -16
  28. package/lib/makes/KeystoreProvider.d.ts +6 -0
  29. package/lib/makes/KeystoreProvider.js +6 -0
  30. package/lib/makes/Preset.d.ts +7 -4
  31. package/lib/makes/Project.d.ts +3 -0
  32. package/lib/makes/index.d.ts +1 -0
  33. package/lib/makes/index.js +1 -0
  34. package/lib/services/AppConfigService.d.ts +4 -2
  35. package/lib/services/AppConfigService.js +3 -3
  36. package/lib/services/KeystoreService.d.ts +9 -0
  37. package/lib/services/KeystoreService.js +16 -0
  38. package/lib/services/ProjectService.d.ts +1 -3
  39. package/lib/services/index.d.ts +1 -0
  40. package/lib/services/index.js +1 -0
  41. package/lib/types/ArgMeta.d.ts +6 -0
  42. package/lib/types/ArgMeta.js +2 -0
  43. package/package.json +12 -10
package/README.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ###### Docker workspace for web projects
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@wocker/core.svg)](https://www.npmjs.com/package/@wocker/core)
6
+ [![Publish](https://github.com/kearisp/wocker-core/actions/workflows/publish-latest.yml/badge.svg?event=release)](https://github.com/kearisp/wocker-core/actions/workflows/publish-latest.yml)
7
+ [![License](https://img.shields.io/npm/l/@wocker/core)](https://github.com/kearisp/wocker-core/blob/main/LICENSE)
8
+
9
+ [![npm total downloads](https://img.shields.io/npm/dt/@wocker/core.svg)](https://www.npmjs.com/package/@wocker/core)
10
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@wocker/core)](https://bundlephobia.com/package/@wocker/core)
11
+ ![Coverage](https://gist.githubusercontent.com/kearisp/f17f46c6332ea3bb043f27b0bddefa9f/raw/coverage-wocker-core-latest.svg)
12
+
5
13
  ## Installation
6
14
 
7
15
  **Note:** It is recommended to install Wocker globally to ensure accessibility from any directory in your terminal.
@@ -30,6 +30,30 @@ class ApplicationContext {
30
30
  run(args) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  const cli = this.get(cli_1.Cli);
33
+ cli.command("").action(() => {
34
+ const module = this.container.getModule(this.module);
35
+ for (const [, container] of module.controllers) {
36
+ if (!container.description) {
37
+ continue;
38
+ }
39
+ console.info(`${container.description}:`);
40
+ const spaceLength = container.commands.reduce((space, route) => {
41
+ return route.commandNames.reduce((space, command) => {
42
+ return Math.max(space, command.length + 2);
43
+ }, space);
44
+ }, 0);
45
+ for (const route of container.commands) {
46
+ if (!route.description) {
47
+ continue;
48
+ }
49
+ for (const commandName of route.commandNames) {
50
+ const space = " ".repeat(Math.max(0, spaceLength - commandName.length));
51
+ console.info(` ${commandName} ${space} ${route.description}`);
52
+ }
53
+ }
54
+ console.info("");
55
+ }
56
+ });
33
57
  return cli.run(args);
34
58
  });
35
59
  }
@@ -0,0 +1,16 @@
1
+ import "reflect-metadata";
2
+ import { CommandInput } from "@kearisp/cli";
3
+ import { InstanceWrapper } from "./InstanceWrapper";
4
+ import { Module } from "./Module";
5
+ import { Type } from "../types/Type";
6
+ import { Route } from "./Route";
7
+ export declare class ControllerWrapper<TInput = any> extends InstanceWrapper {
8
+ readonly type: Type<TInput>;
9
+ description?: string;
10
+ commands: Route[];
11
+ completions: Route[];
12
+ constructor(module: Module, type: Type<TInput>);
13
+ getRoutes(): Route[];
14
+ getCompletionCommands(name: string, command: string): Route[];
15
+ run(route: Route, input: CommandInput): any;
16
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ControllerWrapper = void 0;
4
+ require("reflect-metadata");
5
+ const InstanceWrapper_1 = require("./InstanceWrapper");
6
+ const Route_1 = require("./Route");
7
+ class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
8
+ constructor(module, type) {
9
+ super(module, type);
10
+ this.commands = [];
11
+ this.completions = [];
12
+ if (!this.type) {
13
+ return;
14
+ }
15
+ this.description = Reflect.getMetadata("CONTROLLER_DESCRIPTION", this.type) || "";
16
+ for (const method of Object.getOwnPropertyNames(this.type.prototype)) {
17
+ const route = new Route_1.Route(this.type, method);
18
+ if (route.isCommand) {
19
+ this.commands.push(route);
20
+ }
21
+ else if (route.isCompletion) {
22
+ this.completions.push(route);
23
+ }
24
+ else {
25
+ // TODO: Log
26
+ }
27
+ }
28
+ }
29
+ getRoutes() {
30
+ const routes = [];
31
+ if (!this.type) {
32
+ return [];
33
+ }
34
+ for (const method of Object.getOwnPropertyNames(this.type.prototype)) {
35
+ const route = new Route_1.Route(this.type, method);
36
+ if (route.isCommand || route.isCompletion) {
37
+ routes.push(route);
38
+ }
39
+ }
40
+ return routes;
41
+ }
42
+ getCompletionCommands(name, command) {
43
+ const completions = this.completions.filter((route) => {
44
+ return route.completions.filter((completion) => {
45
+ return completion.name === name && completion.command === command;
46
+ }).length > 0;
47
+ });
48
+ if (completions.length > 0) {
49
+ return completions;
50
+ }
51
+ return this.completions.filter((route) => {
52
+ return route.completions.filter((completion) => {
53
+ return completion.name === name && !completion.command;
54
+ });
55
+ });
56
+ }
57
+ run(route, input) {
58
+ const args = [];
59
+ route.args.forEach((arg, index) => {
60
+ switch (arg.type) {
61
+ case "param":
62
+ args[index] = input.argument(arg.name);
63
+ break;
64
+ case "option":
65
+ if (route.designTypes[index] === Array) {
66
+ args[index] = input.options(arg.name);
67
+ }
68
+ else {
69
+ args[index] = input.option(arg.name);
70
+ }
71
+ break;
72
+ }
73
+ });
74
+ return this.instance[route.method](...args);
75
+ }
76
+ }
77
+ exports.ControllerWrapper = ControllerWrapper;
@@ -4,11 +4,11 @@ import { Provider } from "../types/Provider";
4
4
  import { Type } from "../types/Type";
5
5
  import { InjectionToken } from "../types/InjectionToken";
6
6
  export declare class InstanceWrapper<TInput = any> {
7
- private readonly module;
8
- private readonly provider;
7
+ protected readonly module: Module;
8
+ protected readonly provider: Provider<TInput>;
9
9
  protected _instance?: TInput | undefined;
10
10
  readonly token: InjectionToken<TInput>;
11
11
  readonly type?: Type<TInput>;
12
12
  constructor(module: Module, provider: Provider<TInput>, _instance?: TInput | undefined);
13
- get instance(): TInput | undefined;
13
+ get instance(): TInput;
14
14
  }
@@ -22,7 +22,10 @@ class InstanceWrapper {
22
22
  this.type = this.provider;
23
23
  }
24
24
  get instance() {
25
- if (!this._instance && this.type) {
25
+ if (!this._instance) {
26
+ if (!this.type) {
27
+ throw new Error("Type not defined");
28
+ }
26
29
  const types = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type) || [];
27
30
  const selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this.type) || [];
28
31
  if (selfTypes.length > 0) {
@@ -2,11 +2,12 @@ import { Provider } from "../types/Provider";
2
2
  import { Type } from "../types/Type";
3
3
  import { Container } from "./Container";
4
4
  import { InstanceWrapper } from "./InstanceWrapper";
5
+ import { ControllerWrapper } from "./ControllerWrapper";
5
6
  export declare class Module<TInput = any> {
6
7
  readonly container: Container;
7
- type: TInput;
8
+ readonly type: TInput;
8
9
  imports: Map<any, InstanceWrapper>;
9
- controllers: Map<any, InstanceWrapper>;
10
+ controllers: Map<any, ControllerWrapper>;
10
11
  providers: Map<any, InstanceWrapper>;
11
12
  exports: Set<any>;
12
13
  constructor(container: Container, type: TInput);
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Module = void 0;
4
4
  const InstanceWrapper_1 = require("./InstanceWrapper");
5
+ const ControllerWrapper_1 = require("./ControllerWrapper");
5
6
  const env_1 = require("../env");
6
7
  class Module {
7
8
  constructor(container, type) {
@@ -40,17 +41,8 @@ class Module {
40
41
  this.providers.set(wrapper.token, wrapper);
41
42
  }
42
43
  addController(type) {
43
- this.controllers.set(type, new InstanceWrapper_1.InstanceWrapper(this, type));
44
- for (const name of Object.getOwnPropertyNames(type.prototype)) {
45
- const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name);
46
- if (!descriptor) {
47
- continue;
48
- }
49
- const command = Reflect.getMetadata("command", descriptor.value);
50
- if (!command) {
51
- continue;
52
- }
53
- }
44
+ const controllerWrapper = new ControllerWrapper_1.ControllerWrapper(this, type);
45
+ this.controllers.set(type, controllerWrapper);
54
46
  }
55
47
  addExport(type) {
56
48
  const token = typeof type !== "string"
@@ -0,0 +1,23 @@
1
+ import { ArgMeta } from "../types/ArgMeta";
2
+ import { Type } from "../types/Type";
3
+ export declare class Route {
4
+ readonly type: Type;
5
+ readonly method: string;
6
+ description?: string;
7
+ args: {
8
+ type: "param" | "option";
9
+ name: string;
10
+ params: any;
11
+ }[];
12
+ argsMeta: ArgMeta[];
13
+ designTypes: any[];
14
+ commandNames: string[];
15
+ completions: {
16
+ name: string;
17
+ command?: string;
18
+ }[];
19
+ constructor(type: Type, method: string);
20
+ get isCommand(): boolean;
21
+ get isCompletion(): boolean;
22
+ getArgType(index: number): string | undefined;
23
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Route = void 0;
4
+ const env_1 = require("../env");
5
+ class Route {
6
+ constructor(type, method) {
7
+ this.type = type;
8
+ this.method = method;
9
+ this.args = [];
10
+ this.argsMeta = [];
11
+ this.designTypes = [];
12
+ this.commandNames = [];
13
+ this.completions = [];
14
+ const descriptor = Object.getOwnPropertyDescriptor(this.type.prototype, this.method);
15
+ if (!descriptor) {
16
+ return;
17
+ }
18
+ this.description = Reflect.getMetadata(env_1.COMMAND_DESCRIPTION_METADATA, descriptor.value) || "";
19
+ this.commandNames = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value) || [];
20
+ this.completions = Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [];
21
+ const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, this.type, this.method) || [], argsAliases = Reflect.getMetadata(env_1.ALIAS_METADATA, this.type, this.method) || {}, argsDescription = Reflect.getMetadata(env_1.ARGS_DESCRIPTION_METADATA, this.type, method) || {}, designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type.prototype, this.method) || [];
22
+ this.argsMeta = argsMeta;
23
+ this.designTypes = designTypes;
24
+ for (let i = 0; i < argsMeta.length; i++) {
25
+ const argMeta = argsMeta[i];
26
+ if (argMeta.type === "param") {
27
+ this.args[argMeta.index] = {
28
+ type: argMeta.type,
29
+ name: argMeta.name,
30
+ params: {
31
+ description: argsDescription[argMeta.index] || ""
32
+ }
33
+ };
34
+ }
35
+ if (argMeta.type === "option") {
36
+ const { type, alias, description } = argMeta.params || {};
37
+ this.args[argMeta.index] = {
38
+ type: argMeta.type,
39
+ name: argMeta.name,
40
+ params: Object.assign(Object.assign({}, argMeta.params), { type: this.getArgType(argMeta.index) || type, alias: argsAliases[argMeta.index] || alias, description: argsDescription[argMeta.index] || description })
41
+ };
42
+ }
43
+ }
44
+ }
45
+ get isCommand() {
46
+ return this.commandNames.length > 0;
47
+ }
48
+ get isCompletion() {
49
+ return this.completions.length > 0;
50
+ }
51
+ getArgType(index) {
52
+ switch (this.designTypes[index]) {
53
+ case String:
54
+ return "string";
55
+ case Boolean:
56
+ return "boolean";
57
+ case Number:
58
+ return "number";
59
+ default:
60
+ return undefined;
61
+ }
62
+ }
63
+ }
64
+ exports.Route = Route;
@@ -1,7 +1,7 @@
1
1
  import "reflect-metadata";
2
2
  import { Cli } from "@kearisp/cli";
3
3
  import { Container } from "./Container";
4
- import { InstanceWrapper } from "./InstanceWrapper";
4
+ import { ControllerWrapper } from "./ControllerWrapper";
5
5
  import { Module } from "./Module";
6
6
  export declare class Scanner {
7
7
  readonly container: Container;
@@ -13,6 +13,6 @@ export declare class Scanner {
13
13
  protected scanImports(module: Module): void;
14
14
  protected scanExports(module: Module): void;
15
15
  protected scanRoutes(): void;
16
- protected scanControllerRoutes(cli: Cli, controller: any, wrapper: InstanceWrapper): boolean;
16
+ protected scanControllerRoutes(cli: Cli, wrapper: ControllerWrapper): void;
17
17
  protected scanDynamicModules(): Promise<void>;
18
18
  }
@@ -85,115 +85,40 @@ class Scanner {
85
85
  }
86
86
  const cli = cliWrapper.instance;
87
87
  for (const [, module] of this.container.modules) {
88
- for (const [type, controller] of module.controllers) {
88
+ for (const [, controller] of module.controllers) {
89
89
  if (!controller.instance) {
90
90
  continue;
91
91
  }
92
- this.scanControllerRoutes(cli, type, controller);
92
+ this.scanControllerRoutes(cli, controller);
93
93
  }
94
94
  }
95
95
  }
96
- scanControllerRoutes(cli, controller, wrapper) {
97
- const controllerCommandNames = [];
98
- for (const name of Object.getOwnPropertyNames(controller.prototype)) {
99
- const descriptor = Object.getOwnPropertyDescriptor(controller.prototype, name);
100
- if (!descriptor) {
101
- continue;
102
- }
103
- const commandNames = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value) || [];
104
- if (commandNames.length === 0) {
105
- continue;
106
- }
107
- const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, controller, name) || [];
108
- const designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, controller.prototype, name) || [];
109
- const description = Reflect.getMetadata(env_1.COMMAND_DESCRIPTION_METADATA, descriptor.value);
110
- for (const commandName of commandNames) {
111
- controllerCommandNames.push(commandName);
96
+ scanControllerRoutes(cli, wrapper) {
97
+ for (const route of wrapper.commands) {
98
+ for (const commandName of route.commandNames) {
112
99
  const command = cli.command(commandName);
113
- if (description) {
100
+ if (route.description) {
114
101
  command.help({
115
- description
102
+ description: route.description
116
103
  });
117
104
  }
118
- argsMeta.forEach((argMeta) => {
119
- if (argMeta.type === "option") {
120
- command.option(argMeta.name, argMeta.params);
121
- }
122
- });
123
105
  command.action((input) => {
124
- const args = [];
125
- const params = Object.values(input.arguments());
126
- argsMeta.forEach((argMeta) => {
127
- switch (argMeta.type) {
128
- case "param":
129
- args[argMeta.index] = input.argument(argMeta.name);
130
- break;
131
- case "option":
132
- if (designTypes[argMeta.index] === Array) {
133
- args[argMeta.index] = input.options(argMeta.name);
134
- }
135
- else {
136
- args[argMeta.index] = input.option(argMeta.name);
137
- }
138
- break;
139
- }
140
- });
141
- return wrapper.instance[name](...args, ...params);
106
+ return wrapper.run(route, input);
142
107
  });
143
- }
144
- }
145
- const controllerCompletions = [];
146
- for (const method of Object.getOwnPropertyNames(controller.prototype)) {
147
- const descriptor = Object.getOwnPropertyDescriptor(controller.prototype, method);
148
- if (!descriptor) {
149
- continue;
150
- }
151
- const completions = Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [];
152
- if (completions.length === 0) {
153
- continue;
154
- }
155
- for (const completion of completions) {
156
- controllerCompletions.push(Object.assign(Object.assign({}, completion), { method }));
157
- }
158
- }
159
- controllerCompletions.sort((a, b) => {
160
- return a.command < b.command ? -1 : 1;
161
- });
162
- for (const completion of controllerCompletions) {
163
- const commandNames = completion.command
164
- ? [completion.command]
165
- : controllerCommandNames.filter((commandName) => {
166
- return !controllerCompletions.filter((c) => {
167
- return c.name === completion.name && typeof c.command !== "undefined";
168
- }).map((c) => {
169
- return c.method;
170
- }).includes(commandName);
171
- });
172
- const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, controller, completion.method) || [];
173
- const designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, controller.prototype, completion.method) || [];
174
- for (const commandName of commandNames) {
175
- cli.command(commandName).completion(completion.name, (input) => {
176
- const args = [];
177
- argsMeta.forEach((argMeta) => {
178
- switch (argMeta.type) {
179
- case "param":
180
- args[argMeta.index] = input.argument(argMeta.name);
181
- break;
182
- case "option":
183
- if (designTypes[argMeta.index] === Array) {
184
- args[argMeta.index] = input.options(argMeta.name);
185
- }
186
- else {
187
- args[argMeta.index] = input.option(argMeta.name);
188
- }
189
- break;
108
+ for (const arg of route.args) {
109
+ if (arg.type === "option") {
110
+ command.option(arg.name, arg.params);
111
+ }
112
+ command.completion(arg.name, (input) => {
113
+ const [completion] = wrapper.getCompletionCommands(arg.name, commandName);
114
+ if (!completion) {
115
+ return [];
190
116
  }
117
+ return wrapper.run(completion, input);
191
118
  });
192
- return wrapper.instance[completion.method](...args);
193
- });
119
+ }
194
120
  }
195
121
  }
196
- return true;
197
122
  }
198
123
  scanDynamicModules() {
199
124
  return __awaiter(this, void 0, void 0, function* () {
@@ -6,11 +6,11 @@ const env_1 = require("../env");
6
6
  const Completion = (name, command) => {
7
7
  return (_target, _propertyKey, descriptor) => {
8
8
  Reflect.defineMetadata(env_1.COMPLETION_METADATA, [
9
- ...Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [],
10
9
  {
11
10
  name,
12
11
  command
13
- }
12
+ },
13
+ ...Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || []
14
14
  ], descriptor.value);
15
15
  };
16
16
  };
@@ -1,5 +1,6 @@
1
1
  type Params = {
2
2
  command?: string;
3
+ description?: string;
3
4
  };
4
5
  export declare const Controller: (params?: Params) => ClassDecorator;
5
6
  export {};
@@ -2,12 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Controller = void 0;
4
4
  const Controller = (params) => {
5
- const { command } = params || {};
5
+ const { command, description } = params || {};
6
6
  return (target) => {
7
+ Reflect.defineMetadata("IS_CONTROLLER", true, target);
8
+ if (description) {
9
+ Reflect.defineMetadata("CONTROLLER_DESCRIPTION", description, target);
10
+ }
7
11
  if (!command) {
8
12
  return;
9
13
  }
10
- Reflect.defineMetadata("IS_CONTROLLER", true, target);
11
14
  // TODO:
12
15
  };
13
16
  };
@@ -1,2 +1,4 @@
1
1
  import "reflect-metadata";
2
- export declare const Description: (description: string) => MethodDecorator;
2
+ type UniversalDecorator = ClassDecorator & MethodDecorator & PropertyDecorator & ParameterDecorator;
3
+ export declare const Description: (description: string) => UniversalDecorator;
4
+ export {};
@@ -4,8 +4,27 @@ exports.Description = void 0;
4
4
  require("reflect-metadata");
5
5
  const env_1 = require("../env");
6
6
  const Description = (description) => {
7
- return (_target, _propertyKey, descriptor) => {
8
- Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, descriptor.value);
7
+ return (target, propertyKey, descriptorOrIndex) => {
8
+ // Class
9
+ if (typeof target === "function" && typeof propertyKey === "undefined" && typeof descriptorOrIndex === "undefined") {
10
+ Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, target);
11
+ return;
12
+ }
13
+ if (typeof target !== "object" || !propertyKey) {
14
+ return;
15
+ }
16
+ // Property
17
+ if (typeof descriptorOrIndex === "undefined") {
18
+ Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, target, propertyKey);
19
+ return;
20
+ }
21
+ // Method
22
+ if (typeof descriptorOrIndex !== "number") {
23
+ Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, descriptorOrIndex.value);
24
+ return;
25
+ }
26
+ // Parameter
27
+ Reflect.defineMetadata(env_1.ARGS_DESCRIPTION_METADATA, Object.assign(Object.assign({}, Reflect.getMetadata(env_1.ARGS_DESCRIPTION_METADATA, target.constructor, propertyKey) || {}), { [descriptorOrIndex]: description }), target.constructor, propertyKey);
9
28
  };
10
29
  };
11
30
  exports.Description = Description;
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
2
  import { Option as O } from "@kearisp/cli";
3
- type Params = Omit<O, "name">;
4
- export declare const Option: (name: string, params?: Partial<Params>) => ParameterDecorator;
3
+ type AliasOrParams = string | Omit<O, "name">;
4
+ export declare const Option: (name: string, params?: AliasOrParams) => ParameterDecorator;
5
5
  export {};
@@ -9,13 +9,13 @@ const Option = (name, params) => {
9
9
  return;
10
10
  }
11
11
  Reflect.defineMetadata(env_1.ARGS_METADATA, [
12
- ...Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, key) || [],
13
12
  {
14
13
  type: "option",
15
14
  name,
16
- params,
15
+ params: typeof params === "string" ? { alias: params } : params,
17
16
  index
18
- }
17
+ },
18
+ ...Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, key) || []
19
19
  ], target.constructor, key);
20
20
  };
21
21
  };
package/lib/env.d.ts CHANGED
@@ -6,6 +6,8 @@ export declare const COMMAND_METADATA = "command";
6
6
  export declare const COMMAND_DESCRIPTION_METADATA = "__COMMAND_DESCRIPTION__";
7
7
  export declare const COMPLETION_METADATA = "completion";
8
8
  export declare const ARGS_METADATA = "__ARGS__";
9
+ export declare const ALIAS_METADATA = "__ALIAS_METADATA__";
10
+ export declare const ARGS_DESCRIPTION_METADATA = "__ARGS_DESCRIPTION__";
9
11
  export declare const OPTION_META = "__OPTION_META__";
10
12
  export declare const PARAMTYPES_METADATA = "design:paramtypes";
11
13
  export declare const SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
package/lib/env.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_DESCRIPTION_METADATA = exports.COMMAND_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = void 0;
3
+ exports.MODULE_METADATA = exports.PLUGIN_NAME_METADATA = exports.PLUGIN_DIR_KEY = exports.INJECT_TOKEN_METADATA = exports.SELF_DECLARED_DEPS_METADATA = exports.PARAMTYPES_METADATA = exports.OPTION_META = exports.ARGS_DESCRIPTION_METADATA = exports.ALIAS_METADATA = exports.ARGS_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_DESCRIPTION_METADATA = exports.COMMAND_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE_METADATA = exports.IS_GLOBAL_METADATA = void 0;
4
4
  exports.IS_GLOBAL_METADATA = "IS_GLOBAL";
5
5
  exports.IS_MODULE_METADATA = "isModule";
6
6
  exports.INJECTABLE_WATERMARK = "__injectable__";
@@ -9,6 +9,8 @@ exports.COMMAND_METADATA = "command";
9
9
  exports.COMMAND_DESCRIPTION_METADATA = "__COMMAND_DESCRIPTION__";
10
10
  exports.COMPLETION_METADATA = "completion";
11
11
  exports.ARGS_METADATA = "__ARGS__";
12
+ exports.ALIAS_METADATA = "__ALIAS_METADATA__";
13
+ exports.ARGS_DESCRIPTION_METADATA = "__ARGS_DESCRIPTION__";
12
14
  exports.OPTION_META = "__OPTION_META__";
13
15
  exports.PARAMTYPES_METADATA = "design:paramtypes";
14
16
  exports.SELF_DECLARED_DEPS_METADATA = "self:paramtypes";
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- export { Cli } from "@kearisp/cli";
2
+ export { Cli, CommandNotFoundError } from "@kearisp/cli";
3
3
  export * from "./core";
4
4
  export * from "./decorators";
5
5
  export * from "./makes";
package/lib/index.js CHANGED
@@ -14,10 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.PLUGIN_DIR_KEY = exports.PLUGIN_NAME_METADATA = exports.MODULE_METADATA = exports.IS_MODULE_METADATA = exports.Cli = void 0;
17
+ exports.PLUGIN_DIR_KEY = exports.PLUGIN_NAME_METADATA = exports.MODULE_METADATA = exports.IS_MODULE_METADATA = exports.CommandNotFoundError = exports.Cli = void 0;
18
18
  require("reflect-metadata");
19
19
  var cli_1 = require("@kearisp/cli");
20
20
  Object.defineProperty(exports, "Cli", { enumerable: true, get: function () { return cli_1.Cli; } });
21
+ Object.defineProperty(exports, "CommandNotFoundError", { enumerable: true, get: function () { return cli_1.CommandNotFoundError; } });
21
22
  __exportStar(require("./core"), exports);
22
23
  __exportStar(require("./decorators"), exports);
23
24
  __exportStar(require("./makes"), exports);
@@ -7,25 +7,31 @@ type ProjectData = {
7
7
  /** @deprecated */
8
8
  src?: string;
9
9
  };
10
+ type PluginData = {
11
+ name: string;
12
+ env: "latest" | "beta";
13
+ };
10
14
  type PresetData = {
11
15
  name: string;
12
16
  source: PresetType;
13
17
  path?: string;
14
18
  };
15
- export type AppConfigProperties = Omit<PickProperties<AppConfig>, "logLevel"> & {
19
+ export type AppConfigProperties = Omit<PickProperties<AppConfig>, "logLevel" | "plugins"> & {
20
+ plugins?: (string | PluginData)[];
16
21
  logLevel?: AppConfig["logLevel"];
17
22
  };
18
23
  export declare abstract class AppConfig {
19
24
  debug?: boolean;
25
+ keystore?: string;
20
26
  logLevel: "off" | "info" | "warn" | "error";
21
- plugins?: string[];
27
+ plugins: PluginData[];
22
28
  presets?: PresetData[];
23
29
  projects?: ProjectData[];
24
30
  meta?: EnvConfig;
25
31
  env?: EnvConfig;
26
32
  protected constructor(data: AppConfigProperties);
27
- addPlugin(plugin: string): void;
28
- removePlugin(removePlugin: string): void;
33
+ addPlugin(name: string, env?: PluginData["env"]): void;
34
+ removePlugin(name: string): void;
29
35
  getProject(id: string): ProjectData | undefined;
30
36
  addProject(id: string, name: string, path: string): void;
31
37
  removeProject(id: string): void;
@@ -42,5 +48,7 @@ export declare abstract class AppConfig {
42
48
  unsetEnv(name: string): void;
43
49
  abstract save(): Promise<void>;
44
50
  toJson(): AppConfigProperties;
51
+ toJsString(): string;
52
+ toString(): string;
45
53
  }
46
54
  export {};
@@ -1,29 +1,50 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.AppConfig = void 0;
4
15
  const Preset_1 = require("./Preset");
5
16
  class AppConfig {
6
17
  constructor(data) {
7
18
  this.logLevel = "off";
8
- Object.assign(this, data);
19
+ const { plugins = [] } = data, rest = __rest(data, ["plugins"]);
20
+ Object.assign(this, rest);
21
+ this.plugins = plugins.map((plugin) => {
22
+ if (typeof plugin === "string") {
23
+ return {
24
+ name: plugin,
25
+ env: "latest"
26
+ };
27
+ }
28
+ return plugin;
29
+ });
9
30
  }
10
- addPlugin(plugin) {
11
- if (!this.plugins) {
12
- this.plugins = [];
13
- }
14
- if (this.plugins.includes(plugin)) {
31
+ addPlugin(name, env = "latest") {
32
+ const plugin = this.plugins.find((plugin) => plugin.name === name);
33
+ if (plugin) {
34
+ plugin.name = name;
35
+ plugin.env = env;
15
36
  return;
16
37
  }
17
- this.plugins.push(plugin);
38
+ this.plugins.push({
39
+ name,
40
+ env
41
+ });
18
42
  }
19
- removePlugin(removePlugin) {
20
- if (!this.plugins) {
21
- return;
22
- }
23
- this.plugins = this.plugins.filter((plugin) => plugin !== removePlugin);
43
+ removePlugin(name) {
24
44
  if (this.plugins.length === 0) {
25
- delete this.plugins;
45
+ return;
26
46
  }
47
+ this.plugins = this.plugins.filter((plugin) => plugin.name !== name);
27
48
  }
28
49
  getProject(id) {
29
50
  if (!this.projects) {
@@ -151,7 +172,8 @@ class AppConfig {
151
172
  const json = {
152
173
  debug: this.debug,
153
174
  logLevel: this.logLevel,
154
- plugins: this.plugins,
175
+ keystore: this.keystore,
176
+ plugins: this.plugins.length > 0 ? this.plugins : undefined,
155
177
  projects: this.projects,
156
178
  presets: this.presets,
157
179
  env: this.env,
@@ -164,5 +186,12 @@ class AppConfig {
164
186
  return res;
165
187
  }, {});
166
188
  }
189
+ toJsString() {
190
+ const json = JSON.stringify(this.toJson(), null, 4);
191
+ return `// Wocker config\nexports.config = ${json};`;
192
+ }
193
+ toString() {
194
+ return JSON.stringify(this.toJson(), null, 4);
195
+ }
167
196
  }
168
197
  exports.AppConfig = AppConfig;
@@ -14,8 +14,9 @@ export declare class FileSystem {
14
14
  readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>;
15
15
  readFile(path: string): Buffer;
16
16
  readJSON(...paths: string[]): any;
17
- writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions): Promise<void>;
17
+ writeFile(path: string, data: string | Buffer | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions): void;
18
18
  writeJSON(path: string, data: any, options?: WriteFileOptions): void;
19
+ appendFile(path: string, data: string | Uint8Array, options?: WriteFileOptions): void;
19
20
  rm(path: string, options?: RmOptions): void;
20
21
  createWriteStream(path: string, options?: BufferEncoding): fs.WriteStream;
21
22
  createReadStream(path: string, options?: BufferEncoding): fs.ReadStream;
@@ -114,30 +114,20 @@ class FileSystem {
114
114
  }
115
115
  writeFile(path, data, options) {
116
116
  const fullPath = this.path(path);
117
- return new Promise((resolve, reject) => {
118
- const callback = (err) => {
119
- if (err) {
120
- reject(err);
121
- return;
122
- }
123
- resolve(undefined);
124
- };
125
- if (options) {
126
- fs_1.default.writeFile(fullPath, data, options, callback);
127
- }
128
- else {
129
- fs_1.default.writeFile(fullPath, data, callback);
130
- }
131
- });
117
+ fs_1.default.writeFileSync(fullPath, data, options);
132
118
  }
133
119
  writeJSON(path, data, options) {
134
120
  const fullPath = this.path(path);
135
121
  const json = JSON.stringify(data, null, 4);
136
122
  fs_1.default.writeFileSync(fullPath, json, options);
137
123
  }
124
+ appendFile(path, data, options) {
125
+ const fullPath = this.path(path);
126
+ fs_1.default.appendFileSync(fullPath, data, options);
127
+ }
138
128
  rm(path, options) {
139
129
  const fullPath = this.path(path);
140
- fs_1.default.rmdirSync(fullPath, options);
130
+ fs_1.default.rmSync(fullPath, options);
141
131
  }
142
132
  createWriteStream(path, options) {
143
133
  return fs_1.default.createWriteStream(this.path(path), options);
@@ -0,0 +1,6 @@
1
+ export declare abstract class KeystoreProvider {
2
+ abstract get(key: string, defaultValue: string): Promise<string>;
3
+ abstract get(key: string, defaultValue?: string): Promise<string | undefined>;
4
+ abstract set(key: string, value: string): Promise<void>;
5
+ abstract delete(key: string): Promise<void>;
6
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeystoreProvider = void 0;
4
+ class KeystoreProvider {
5
+ }
6
+ exports.KeystoreProvider = KeystoreProvider;
@@ -1,16 +1,19 @@
1
1
  import { PickProperties } from "../types";
2
2
  type TextOption = {
3
- type: "string" | "number" | "int";
3
+ type: "text" | "string" | "number" | "int" | "password";
4
4
  message?: string;
5
5
  default?: string | number;
6
6
  };
7
7
  type ConfirmOption = {
8
8
  type: "boolean";
9
9
  message?: string;
10
+ required?: boolean;
10
11
  default?: boolean;
11
12
  };
12
13
  type SelectOption = {
13
14
  type: "select";
15
+ required?: boolean;
16
+ multiple?: boolean;
14
17
  options: string[] | {
15
18
  label?: string;
16
19
  value: string;
@@ -20,7 +23,7 @@ type SelectOption = {
20
23
  message?: string;
21
24
  default?: string;
22
25
  };
23
- type AnyOption = TextOption | ConfirmOption | SelectOption;
26
+ export type PresetVariableConfig = TextOption | ConfirmOption | SelectOption;
24
27
  export type PresetProperties = PickProperties<Preset>;
25
28
  export declare abstract class Preset {
26
29
  name: string;
@@ -30,10 +33,10 @@ export declare abstract class Preset {
30
33
  image?: string;
31
34
  dockerfile?: string;
32
35
  buildArgsOptions?: {
33
- [name: string]: AnyOption;
36
+ [name: string]: PresetVariableConfig;
34
37
  };
35
38
  envOptions?: {
36
- [name: string]: AnyOption;
39
+ [name: string]: PresetVariableConfig;
37
40
  };
38
41
  path?: string;
39
42
  volumes?: string[];
@@ -40,6 +40,9 @@ export declare abstract class Project {
40
40
  volumeUnmount(...volumes: string[]): void;
41
41
  addExtraHost(host: string, domain: string): void;
42
42
  removeExtraHost(host: string): void;
43
+ abstract getSecret(key: string, byDefault: string): Promise<string>;
44
+ abstract getSecret(key: string, byDefault?: string): Promise<string | undefined>;
45
+ abstract setSecret(key: string, value: string): Promise<void>;
43
46
  abstract save(): Promise<void>;
44
47
  toJSON(): ProjectProperties;
45
48
  }
@@ -5,6 +5,7 @@ export * from "./FileSystem";
5
5
  export * from "./FileSystemManager";
6
6
  export * from "./FS";
7
7
  export * from "./FSManager";
8
+ export * from "./KeystoreProvider";
8
9
  export * from "./Logger";
9
10
  export * from "./Preset";
10
11
  export * from "./Project";
@@ -21,6 +21,7 @@ __exportStar(require("./FileSystem"), exports);
21
21
  __exportStar(require("./FileSystemManager"), exports);
22
22
  __exportStar(require("./FS"), exports);
23
23
  __exportStar(require("./FSManager"), exports);
24
+ __exportStar(require("./KeystoreProvider"), exports);
24
25
  __exportStar(require("./Logger"), exports);
25
26
  __exportStar(require("./Preset"), exports);
26
27
  __exportStar(require("./Project"), exports);
@@ -1,12 +1,14 @@
1
1
  import { AppConfig } from "../makes";
2
2
  export declare abstract class AppConfigService {
3
- protected config?: AppConfig;
3
+ abstract get config(): AppConfig;
4
4
  get version(): string;
5
5
  isVersionGTE(version: string): boolean;
6
6
  abstract pwd(...parts: string[]): string;
7
7
  abstract setPWD(pwd: string): void;
8
8
  abstract dataPath(...args: string[]): string;
9
9
  abstract pluginsPath(...args: string[]): string;
10
+ /**
11
+ * @deprecated
12
+ */
10
13
  getConfig(): AppConfig;
11
- protected abstract loadConfig(): AppConfig;
12
14
  }
@@ -25,10 +25,10 @@ let AppConfigService = class AppConfigService {
25
25
  }
26
26
  return true;
27
27
  }
28
+ /**
29
+ * @deprecated
30
+ */
28
31
  getConfig() {
29
- if (!this.config) {
30
- this.config = this.loadConfig();
31
- }
32
32
  return this.config;
33
33
  }
34
34
  };
@@ -0,0 +1,9 @@
1
+ import { KeystoreProvider } from "../makes";
2
+ export declare abstract class KeystoreService {
3
+ abstract hasProvider(name: string): boolean;
4
+ abstract provider(name?: string): KeystoreProvider;
5
+ abstract get(key: string, defaultValue: string): Promise<string>;
6
+ abstract get(key: string, defaultValue?: string): Promise<string | undefined>;
7
+ abstract set(key: string, value: string): Promise<void>;
8
+ abstract registerProvider(name: string, provider: KeystoreProvider): void;
9
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.KeystoreService = void 0;
10
+ const decorators_1 = require("../decorators");
11
+ let KeystoreService = class KeystoreService {
12
+ };
13
+ exports.KeystoreService = KeystoreService;
14
+ exports.KeystoreService = KeystoreService = __decorate([
15
+ (0, decorators_1.Injectable)("KEYSTORE_SERVICE")
16
+ ], KeystoreService);
@@ -1,4 +1,3 @@
1
- import { Container } from "dockerode";
2
1
  import { Project } from "../makes/Project";
3
2
  type SearchParams = Partial<{
4
3
  id: string;
@@ -7,8 +6,7 @@ type SearchParams = Partial<{
7
6
  }>;
8
7
  export declare abstract class ProjectService {
9
8
  abstract cdProject(name: string): Promise<void>;
10
- abstract get(): Promise<Project>;
11
- abstract getContainer(): Promise<Container | null>;
9
+ abstract get(name?: string): Promise<Project>;
12
10
  abstract start(project: Project): Promise<void>;
13
11
  abstract stop(project: Project): Promise<void>;
14
12
  abstract save(project: Project): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  export * from "./AppConfigService";
2
2
  export * from "./AppEventsService";
3
3
  export * from "./DockerService";
4
+ export * from "./KeystoreService";
4
5
  export * from "./LogService";
5
6
  export * from "./PluginConfigService";
6
7
  export * from "./PresetService";
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AppConfigService"), exports);
18
18
  __exportStar(require("./AppEventsService"), exports);
19
19
  __exportStar(require("./DockerService"), exports);
20
+ __exportStar(require("./KeystoreService"), exports);
20
21
  __exportStar(require("./LogService"), exports);
21
22
  __exportStar(require("./PluginConfigService"), exports);
22
23
  __exportStar(require("./PresetService"), exports);
@@ -0,0 +1,6 @@
1
+ export type ArgMeta = {
2
+ index: number;
3
+ type: "param" | "option";
4
+ name: string;
5
+ params: any;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.21",
3
+ "version": "1.0.22-beta.1",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Core of the Wocker",
6
6
  "license": "MIT",
7
- "main": "lib/index.js",
8
- "types": "lib/index.d.ts",
7
+ "main": "./lib/index.js",
8
+ "types": "./lib/index.d.ts",
9
9
  "keywords": [
10
10
  "wocker"
11
11
  ],
@@ -18,25 +18,27 @@
18
18
  "url": "https://github.com/kearisp/wocker-core/issues"
19
19
  },
20
20
  "scripts": {
21
- "prepare": "npm run build",
21
+ "prepublishOnly": "npm run build",
22
22
  "build": "tsc --project tsconfig.build.json",
23
23
  "watch": "tsc -w --project tsconfig.build.json",
24
24
  "test": "jest --colors",
25
- "test-watch": "jest --colors --watchAll --coverage"
25
+ "test-watch": "jest --colors --watchAll --coverage",
26
+ "make-coverage-badge": "make-coverage-badge"
26
27
  },
27
28
  "dependencies": {
28
- "@kearisp/cli": "^2.0.7",
29
+ "@kearisp/cli": "^2.0.8",
29
30
  "fs": "^0.0.1-security",
30
31
  "path": "^0.12.7",
31
32
  "reflect-metadata": "^0.2.2"
32
33
  },
33
34
  "devDependencies": {
34
35
  "@types/dockerode": "^3.3.23",
35
- "@types/jest": "^29.5.12",
36
- "@types/node": "^20.11.7",
36
+ "@types/jest": "^29.5.14",
37
+ "@types/node": "^22.15.3",
37
38
  "jest": "^29.7.0",
38
- "ts-jest": "^29.2.4",
39
+ "make-coverage-badge": "^1.2.0",
40
+ "ts-jest": "^29.3.2",
39
41
  "ts-node": "^10.9.2",
40
- "typescript": "^5.5.4"
42
+ "typescript": "^5.8.3"
41
43
  }
42
44
  }