@wocker/core 1.0.21-beta.3 → 1.0.22-beta.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.
Files changed (37) hide show
  1. package/lib/core/ApplicationContext.js +22 -0
  2. package/lib/core/ControllerWrapper.d.ts +13 -0
  3. package/lib/core/ControllerWrapper.js +85 -0
  4. package/lib/core/InstanceWrapper.d.ts +3 -3
  5. package/lib/core/InstanceWrapper.js +4 -1
  6. package/lib/core/Module.d.ts +3 -2
  7. package/lib/core/Module.js +3 -11
  8. package/lib/core/Route.d.ts +10 -0
  9. package/lib/core/Route.js +32 -0
  10. package/lib/core/RouteCompletion.d.ts +5 -0
  11. package/lib/core/RouteCompletion.js +11 -0
  12. package/lib/core/Scanner.d.ts +2 -2
  13. package/lib/core/Scanner.js +20 -99
  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 +27 -2
  18. package/lib/index.d.ts +1 -1
  19. package/lib/index.js +2 -1
  20. package/lib/makes/AppConfig.d.ts +12 -4
  21. package/lib/makes/AppConfig.js +43 -14
  22. package/lib/makes/FileSystem.d.ts +2 -1
  23. package/lib/makes/FileSystem.js +6 -16
  24. package/lib/makes/KeystoreProvider.d.ts +6 -0
  25. package/lib/makes/KeystoreProvider.js +6 -0
  26. package/lib/makes/Preset.d.ts +7 -4
  27. package/lib/makes/Project.d.ts +3 -0
  28. package/lib/makes/index.d.ts +1 -0
  29. package/lib/makes/index.js +1 -0
  30. package/lib/services/AppConfigService.d.ts +4 -2
  31. package/lib/services/AppConfigService.js +3 -3
  32. package/lib/services/KeystoreService.d.ts +9 -0
  33. package/lib/services/KeystoreService.js +16 -0
  34. package/lib/services/ProjectService.d.ts +1 -3
  35. package/lib/services/index.d.ts +1 -0
  36. package/lib/services/index.js +1 -0
  37. package/package.json +12 -10
@@ -30,6 +30,28 @@ 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
+ const description = container.getDescription();
37
+ if (!description) {
38
+ continue;
39
+ }
40
+ console.info(`${description}:`);
41
+ const routes = container.getRoutes();
42
+ const spaceLength = routes.reduce((space, route) => {
43
+ return Math.max(space, route.command.length + 2);
44
+ }, 0);
45
+ for (const route of routes) {
46
+ if (!route.description) {
47
+ continue;
48
+ }
49
+ const space = " ".repeat(Math.max(0, spaceLength - route.command.length));
50
+ console.info(` ${route.command} ${space} ${route.description}`);
51
+ }
52
+ console.info("");
53
+ }
54
+ });
33
55
  return cli.run(args);
34
56
  });
35
57
  }
@@ -0,0 +1,13 @@
1
+ import "reflect-metadata";
2
+ import { InstanceWrapper } from "./InstanceWrapper";
3
+ import { Module } from "./Module";
4
+ import { Type } from "../types/Type";
5
+ import { Route } from "./Route";
6
+ import { RouteCompletion } from "./RouteCompletion";
7
+ export declare class ControllerWrapper<TInput = any> extends InstanceWrapper {
8
+ readonly type: Type<TInput>;
9
+ constructor(module: Module, type: Type<TInput>);
10
+ getDescription(): string | undefined;
11
+ getRoutes(): Route[];
12
+ getCompletions(): RouteCompletion[];
13
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ControllerWrapper = void 0;
4
+ require("reflect-metadata");
5
+ const env_1 = require("../env");
6
+ const InstanceWrapper_1 = require("./InstanceWrapper");
7
+ const Route_1 = require("./Route");
8
+ const RouteCompletion_1 = require("./RouteCompletion");
9
+ class ControllerWrapper extends InstanceWrapper_1.InstanceWrapper {
10
+ constructor(module, type) {
11
+ super(module, type);
12
+ }
13
+ getDescription() {
14
+ return Reflect.getMetadata("CONTROLLER_DESCRIPTION", this.type);
15
+ // || this.type.prototype.constructor.name;
16
+ }
17
+ getRoutes() {
18
+ const routes = [];
19
+ if (!this.type) {
20
+ return [];
21
+ }
22
+ for (const method of Object.getOwnPropertyNames(this.type.prototype)) {
23
+ const descriptor = Object.getOwnPropertyDescriptor(this.type.prototype, method);
24
+ if (!descriptor) {
25
+ continue;
26
+ }
27
+ const commandNames = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value) || [];
28
+ if (commandNames.length === 0) {
29
+ continue;
30
+ }
31
+ const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, this.type, method) || [];
32
+ const designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type.prototype, method) || [];
33
+ const description = Reflect.getMetadata(env_1.COMMAND_DESCRIPTION_METADATA, descriptor.value);
34
+ for (const commandName of commandNames) {
35
+ const route = new Route_1.Route(method, commandName, argsMeta, designTypes, description);
36
+ routes.push(route);
37
+ }
38
+ }
39
+ return routes;
40
+ }
41
+ getCompletions() {
42
+ const routes = [], allCommandNames = [], allCompletions = [];
43
+ if (!this.type) {
44
+ return routes;
45
+ }
46
+ for (const method of Object.getOwnPropertyNames(this.type.prototype)) {
47
+ const descriptor = Object.getOwnPropertyDescriptor(this.type.prototype, method);
48
+ if (!descriptor) {
49
+ continue;
50
+ }
51
+ const commandNames = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value) || [];
52
+ if (commandNames.length > 0) {
53
+ allCommandNames.push(...commandNames);
54
+ }
55
+ const completionsData = Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || [];
56
+ if (completionsData.length > 0) {
57
+ for (const completionData of completionsData) {
58
+ allCompletions.push(Object.assign(Object.assign({}, completionData), { method }));
59
+ }
60
+ }
61
+ }
62
+ allCompletions.sort((a, b) => {
63
+ return a.command < b.command ? -1 : 1;
64
+ });
65
+ for (const data of allCompletions) {
66
+ const commandNames = data.command
67
+ ? [data.command]
68
+ : allCommandNames.filter((commandName) => {
69
+ return !allCompletions.filter((c) => {
70
+ return c.name === data.name && typeof c.command !== "undefined";
71
+ }).map((c) => {
72
+ return c.method;
73
+ }).includes(commandName);
74
+ });
75
+ const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, this.type, data.method) || [];
76
+ const designTypes = Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.type.prototype, data.method) || [];
77
+ for (const commandName of commandNames) {
78
+ const route = new RouteCompletion_1.RouteCompletion(data.method, data.name, commandName, argsMeta, designTypes);
79
+ routes.push(route);
80
+ }
81
+ }
82
+ return routes;
83
+ }
84
+ }
85
+ 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,10 @@
1
+ import { CommandInput } from "@kearisp/cli";
2
+ export declare class Route {
3
+ readonly method: string;
4
+ readonly command: string;
5
+ readonly argsMeta: any[];
6
+ readonly designTypes: any[];
7
+ readonly description?: string | undefined;
8
+ constructor(method: string, command: string, argsMeta: any[], designTypes: any[], description?: string | undefined);
9
+ getArgs(input: CommandInput): any[];
10
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Route = void 0;
4
+ class Route {
5
+ constructor(method, command, argsMeta, designTypes, description) {
6
+ this.method = method;
7
+ this.command = command;
8
+ this.argsMeta = argsMeta;
9
+ this.designTypes = designTypes;
10
+ this.description = description;
11
+ }
12
+ getArgs(input) {
13
+ const args = [];
14
+ this.argsMeta.forEach((argMeta) => {
15
+ switch (argMeta.type) {
16
+ case "param":
17
+ args[argMeta.index] = input.argument(argMeta.name);
18
+ break;
19
+ case "option":
20
+ if (this.designTypes[argMeta.index] === Array) {
21
+ args[argMeta.index] = input.options(argMeta.name);
22
+ }
23
+ else {
24
+ args[argMeta.index] = input.option(argMeta.name);
25
+ }
26
+ break;
27
+ }
28
+ });
29
+ return args;
30
+ }
31
+ }
32
+ exports.Route = Route;
@@ -0,0 +1,5 @@
1
+ import { Route } from "./Route";
2
+ export declare class RouteCompletion extends Route {
3
+ readonly name: string;
4
+ constructor(method: string, name: string, command: string, argsMeta: any[], designTypes: any[]);
5
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouteCompletion = void 0;
4
+ const Route_1 = require("./Route");
5
+ class RouteCompletion extends Route_1.Route {
6
+ constructor(method, name, command, argsMeta, designTypes) {
7
+ super(method, command, argsMeta, designTypes);
8
+ this.name = name;
9
+ }
10
+ }
11
+ exports.RouteCompletion = RouteCompletion;
@@ -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,36 @@ 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);
112
- const command = cli.command(commandName);
113
- if (description) {
114
- command.help({
115
- description
116
- });
117
- }
118
- argsMeta.forEach((argMeta) => {
119
- if (argMeta.type === "option") {
120
- command.option(argMeta.name, argMeta.params);
121
- }
96
+ scanControllerRoutes(cli, wrapper) {
97
+ for (const route of wrapper.getRoutes()) {
98
+ const command = cli.command(route.command);
99
+ if (route.description) {
100
+ command.help({
101
+ description: route.description
122
102
  });
123
- 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);
142
- });
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
103
  }
104
+ route.argsMeta.forEach((argMeta) => {
105
+ if (argMeta.type === "option") {
106
+ command.option(argMeta.name, argMeta.params);
107
+ }
108
+ });
109
+ command.action((input) => {
110
+ return wrapper.instance[route.method](...route.getArgs(input));
111
+ });
158
112
  }
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;
190
- }
191
- });
192
- return wrapper.instance[completion.method](...args);
193
- });
194
- }
113
+ for (const completion of wrapper.getCompletions()) {
114
+ cli.command(completion.command).completion(completion.name, (input) => {
115
+ return wrapper.instance[completion.method](...completion.getArgs(input));
116
+ });
195
117
  }
196
- return true;
197
118
  }
198
119
  scanDynamicModules() {
199
120
  return __awaiter(this, void 0, void 0, function* () {
@@ -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,33 @@ 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.COMMAND_DESCRIPTION_METADATA, [
28
+ {
29
+ index: descriptorOrIndex,
30
+ description
31
+ },
32
+ ...Reflect.getMetadata(env_1.COMMAND_DESCRIPTION_METADATA, target.constructor, propertyKey) || []
33
+ ], target.constructor, propertyKey);
9
34
  };
10
35
  };
11
36
  exports.Description = Description;
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);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.21-beta.3",
3
+ "version": "1.0.22-beta.0",
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
  }