@wocker/core 1.0.9 → 1.0.11

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 (41) hide show
  1. package/lib/decorators/Command.d.ts +1 -0
  2. package/lib/decorators/Command.js +1 -0
  3. package/lib/decorators/Completion.d.ts +1 -0
  4. package/lib/decorators/Completion.js +1 -0
  5. package/lib/decorators/Description.d.ts +2 -0
  6. package/lib/decorators/Description.js +11 -0
  7. package/lib/decorators/Module.js +3 -1
  8. package/lib/decorators/Param.d.ts +2 -1
  9. package/lib/decorators/Param.js +14 -1
  10. package/lib/decorators/Plugin.js +1 -1
  11. package/lib/decorators/index.d.ts +2 -0
  12. package/lib/decorators/index.js +2 -0
  13. package/lib/env.d.ts +1 -0
  14. package/lib/env.js +2 -1
  15. package/lib/makes/ApplicationContext.d.ts +3 -3
  16. package/lib/makes/ApplicationContext.js +5 -2
  17. package/lib/makes/Config.d.ts +4 -2
  18. package/lib/makes/Config.js +8 -2
  19. package/lib/makes/Container.d.ts +0 -1
  20. package/lib/makes/Container.js +9 -7
  21. package/lib/makes/FS.d.ts +3 -2
  22. package/lib/makes/FS.js +27 -10
  23. package/lib/makes/FSManager.d.ts +4 -4
  24. package/lib/makes/FSManager.js +14 -14
  25. package/lib/makes/Factory.d.ts +1 -2
  26. package/lib/makes/Factory.js +12 -12
  27. package/lib/makes/FileSystem.d.ts +16 -0
  28. package/lib/makes/FileSystem.js +90 -0
  29. package/lib/makes/InstanceWrapper.d.ts +2 -2
  30. package/lib/makes/InstanceWrapper.js +2 -5
  31. package/lib/makes/Logger.d.ts +1 -1
  32. package/lib/makes/Module.js +8 -3
  33. package/lib/makes/Preset.d.ts +4 -11
  34. package/lib/makes/Preset.js +0 -28
  35. package/lib/makes/Project.d.ts +3 -1
  36. package/lib/makes/Project.js +17 -0
  37. package/lib/makes/index.d.ts +1 -1
  38. package/lib/makes/index.js +1 -1
  39. package/package.json +11 -6
  40. package/lib/makes/DI.d.ts +0 -7
  41. package/lib/makes/DI.js +0 -27
@@ -1 +1,2 @@
1
+ import "reflect-metadata";
1
2
  export declare const Command: (command: string) => MethodDecorator;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Command = void 0;
4
+ require("reflect-metadata");
4
5
  const env_1 = require("../env");
5
6
  const Command = (command) => {
6
7
  return (target, key, descriptor) => {
@@ -1 +1,2 @@
1
+ import "reflect-metadata";
1
2
  export declare const Completion: (name: string, command?: string) => MethodDecorator;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Completion = void 0;
4
+ require("reflect-metadata");
4
5
  const Completion = (name, command) => {
5
6
  return (target, propertyKey, descriptor) => {
6
7
  Reflect.defineMetadata("completion", [
@@ -0,0 +1,2 @@
1
+ import "reflect-metadata";
2
+ export declare const Description: (description: string) => MethodDecorator;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Description = void 0;
4
+ require("reflect-metadata");
5
+ const env_1 = require("../env");
6
+ const Description = (description) => {
7
+ return (target, propertyKey, descriptor) => {
8
+ Reflect.defineMetadata(env_1.COMMAND_DESCRIPTION_METADATA, description, descriptor);
9
+ };
10
+ };
11
+ exports.Description = Description;
@@ -5,8 +5,10 @@ const env_1 = require("../env");
5
5
  const Module = (config) => {
6
6
  const { [env_1.PLUGIN_NAME_METADATA]: name, [env_1.MODULE_METADATA.CONTROLLERS]: controllers = [], [env_1.MODULE_METADATA.PROVIDERS]: providers = [], [env_1.MODULE_METADATA.IMPORTS]: imports = [], [env_1.MODULE_METADATA.EXPORTS]: exports = [] } = config;
7
7
  return (target) => {
8
+ if (name) {
9
+ Reflect.defineMetadata(env_1.PLUGIN_NAME_METADATA, name, target);
10
+ }
8
11
  Reflect.defineMetadata("isModule", true, target);
9
- Reflect.defineMetadata(env_1.PLUGIN_NAME_METADATA, name, target);
10
12
  Reflect.defineMetadata(env_1.MODULE_METADATA.IMPORTS, imports, target);
11
13
  Reflect.defineMetadata(env_1.MODULE_METADATA.CONTROLLERS, controllers, target);
12
14
  Reflect.defineMetadata(env_1.MODULE_METADATA.PROVIDERS, providers, target);
@@ -1 +1,2 @@
1
- export declare const Param: (name: string) => MethodDecorator;
1
+ import "reflect-metadata";
2
+ export declare const Param: (name: string) => ParameterDecorator;
@@ -1,8 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Param = void 0;
4
+ require("reflect-metadata");
5
+ const env_1 = require("../env");
4
6
  const Param = (name) => {
5
- return (target, propertyKey, descriptor) => {
7
+ return (target, propertyKey, parameterIndex) => {
8
+ if (!propertyKey) {
9
+ return;
10
+ }
11
+ Reflect.defineMetadata(env_1.ARGS_METADATA, [
12
+ ...Reflect.getMetadata(env_1.ARGS_METADATA, target.constructor, propertyKey) || [],
13
+ {
14
+ type: "param",
15
+ name,
16
+ index: parameterIndex
17
+ }
18
+ ], target.constructor, propertyKey);
6
19
  };
7
20
  };
8
21
  exports.Param = Param;
@@ -18,7 +18,7 @@ const Plugin = (config) => {
18
18
  const { name } = config, rest = __rest(config, ["name"]);
19
19
  return (target) => {
20
20
  Reflect.defineMetadata("isPlugin", true, target);
21
- Reflect.defineMetadata(env_1.PLUGIN_NAME_METADATA, true, target);
21
+ Reflect.defineMetadata(env_1.PLUGIN_NAME_METADATA, name, target);
22
22
  (0, Module_1.Module)(rest)(target);
23
23
  };
24
24
  };
@@ -1,8 +1,10 @@
1
1
  export * from "./Command";
2
2
  export * from "./Completion";
3
3
  export * from "./Controller";
4
+ export * from "./Description";
4
5
  export * from "./Inject";
5
6
  export * from "./Injectable";
6
7
  export * from "./Module";
7
8
  export * from "./Option";
9
+ export * from "./Param";
8
10
  export * from "./Plugin";
@@ -17,8 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Command"), exports);
18
18
  __exportStar(require("./Completion"), exports);
19
19
  __exportStar(require("./Controller"), exports);
20
+ __exportStar(require("./Description"), exports);
20
21
  __exportStar(require("./Inject"), exports);
21
22
  __exportStar(require("./Injectable"), exports);
22
23
  __exportStar(require("./Module"), exports);
23
24
  __exportStar(require("./Option"), exports);
25
+ __exportStar(require("./Param"), exports);
24
26
  __exportStar(require("./Plugin"), exports);
package/lib/env.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare const IS_MODULE = "IS_MODULE";
2
2
  export declare const INJECTABLE_WATERMARK = "__injectable__";
3
3
  export declare const ARGS_META = "__ARGS__";
4
4
  export declare const COMMAND_METADATA = "command";
5
+ export declare const COMMAND_DESCRIPTION_METADATA = "__COMMAND_DESCRIPTION__";
5
6
  export declare const COMPLETION_METADATA = "completion";
6
7
  export declare const ARGS_METADATA = "__ARGS__";
7
8
  export declare const OPTION_META = "__OPTION_META__";
package/lib/env.js CHANGED
@@ -1,10 +1,11 @@
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_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE = 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_METADATA = exports.COMPLETION_METADATA = exports.COMMAND_DESCRIPTION_METADATA = exports.COMMAND_METADATA = exports.ARGS_META = exports.INJECTABLE_WATERMARK = exports.IS_MODULE = void 0;
4
4
  exports.IS_MODULE = "IS_MODULE";
5
5
  exports.INJECTABLE_WATERMARK = "__injectable__";
6
6
  exports.ARGS_META = "__ARGS__";
7
7
  exports.COMMAND_METADATA = "command";
8
+ exports.COMMAND_DESCRIPTION_METADATA = "__COMMAND_DESCRIPTION__";
8
9
  exports.COMPLETION_METADATA = "completion";
9
10
  exports.ARGS_METADATA = "__ARGS__";
10
11
  exports.OPTION_META = "__OPTION_META__";
@@ -1,9 +1,9 @@
1
1
  import { Type } from "../types/Type";
2
2
  import { Container } from "./Container";
3
3
  export declare class ApplicationContext {
4
- protected module: any;
5
- protected container: Container;
4
+ protected readonly module: any;
5
+ protected readonly container: Container;
6
6
  constructor(module: any, container: Container);
7
7
  get<TInput = any, TResult = TInput>(typeOrToken: Type<TInput> | Function | string | symbol): TResult;
8
- run(args: string[]): Promise<any>;
8
+ run(args: string[]): Promise<string>;
9
9
  }
@@ -17,8 +17,11 @@ class ApplicationContext {
17
17
  this.container = container;
18
18
  }
19
19
  get(typeOrToken) {
20
- var _a;
21
- const res = (_a = this.container.getModule(this.module)) === null || _a === void 0 ? void 0 : _a.get(typeOrToken);
20
+ const module = this.container.getModule(this.module);
21
+ if (!module) {
22
+ throw new Error("Module not found");
23
+ }
24
+ const res = module.get(typeOrToken);
22
25
  if (!res) {
23
26
  throw new Error("Instance not found");
24
27
  }
@@ -1,5 +1,7 @@
1
1
  import { EnvConfig, PickProperties } from "../types";
2
- export type ConfigProperties = PickProperties<Config>;
2
+ export type ConfigProperties = Omit<PickProperties<Config>, "logLevel"> & {
3
+ logLevel?: Config["logLevel"];
4
+ };
3
5
  export declare abstract class Config {
4
6
  debug?: boolean;
5
7
  logLevel: "off" | "info" | "warn" | "error";
@@ -13,7 +15,7 @@ export declare abstract class Config {
13
15
  env?: EnvConfig;
14
16
  protected constructor(data: ConfigProperties);
15
17
  addPlugin(plugin: string): void;
16
- removePlugin(plugin: string): void;
18
+ removePlugin(removePlugin: string): void;
17
19
  setProject(id: string, path: string): void;
18
20
  getMeta(name: string, defaultValue: string): string;
19
21
  setMeta(name: string, value: string): void;
@@ -9,10 +9,16 @@ class Config {
9
9
  Object.assign(this, data);
10
10
  }
11
11
  addPlugin(plugin) {
12
+ if (!this.plugins) {
13
+ this.plugins = [];
14
+ }
15
+ if (this.plugins.includes(plugin)) {
16
+ return;
17
+ }
12
18
  this.plugins.push(plugin);
13
19
  }
14
- removePlugin(plugin) {
15
- this.plugins = this.plugins.filter((plugin) => plugin !== plugin);
20
+ removePlugin(removePlugin) {
21
+ this.plugins = this.plugins.filter((plugin) => plugin !== removePlugin);
16
22
  }
17
23
  setProject(id, path) {
18
24
  this.projects = [
@@ -4,5 +4,4 @@ export declare class Container {
4
4
  hasModule(type: any): boolean;
5
5
  getModule(type: any): Module | undefined;
6
6
  addModule(type: any, module: Module): void;
7
- addController(moduleType: any, type: any): void;
8
7
  }
@@ -4,6 +4,15 @@ exports.Container = void 0;
4
4
  class Container {
5
5
  constructor() {
6
6
  this.modules = new Map();
7
+ // public addController(moduleType: any, type: any): void {
8
+ // const module = this.getModule(moduleType);
9
+ //
10
+ // if(!module) {
11
+ // return;
12
+ // }
13
+ //
14
+ // module.addController(type);
15
+ // }
7
16
  }
8
17
  hasModule(type) {
9
18
  return this.modules.has(type);
@@ -14,12 +23,5 @@ class Container {
14
23
  addModule(type, module) {
15
24
  this.modules.set(type, module);
16
25
  }
17
- addController(moduleType, type) {
18
- const module = this.getModule(moduleType);
19
- if (!module) {
20
- return;
21
- }
22
- module.addController(type);
23
- }
24
26
  }
25
27
  exports.Container = Container;
package/lib/makes/FS.d.ts CHANGED
@@ -8,12 +8,13 @@ type ReadFileOptions = Abortable & {
8
8
  encoding?: BufferEncoding;
9
9
  flag?: string;
10
10
  };
11
- declare class FS {
11
+ export declare class FS {
12
12
  static mkdir(path: PathLike, options?: MakeDirectoryOptions): Promise<unknown>;
13
13
  static readFile(filePath: PathOrFileDescriptor, options?: ReadFileOptions): Promise<string | Buffer>;
14
14
  static writeFile(filePath: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<unknown>;
15
15
  static readJSON(...paths: string[]): Promise<any>;
16
16
  static writeJSON(filePath: PathOrFileDescriptor, data: any, options?: WriteFileOptions): Promise<void>;
17
+ static readdir(path: PathLike): Promise<string[]>;
17
18
  static rm(path: PathLike, options?: RmOptions): Promise<void>;
18
19
  }
19
- export { FS };
20
+ export {};
package/lib/makes/FS.js CHANGED
@@ -31,15 +31,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
34
37
  Object.defineProperty(exports, "__esModule", { value: true });
35
38
  exports.FS = void 0;
36
- const fs_1 = require("fs");
39
+ const fs_1 = __importDefault(require("fs"));
37
40
  const Path = __importStar(require("path"));
38
41
  class FS {
39
42
  static mkdir(path, options) {
40
43
  return __awaiter(this, void 0, void 0, function* () {
41
44
  return new Promise((resolve, reject) => {
42
- (0, fs_1.mkdir)(path, options, (err) => {
45
+ fs_1.default.mkdir(path, options, (err) => {
43
46
  if (err) {
44
47
  reject(err);
45
48
  return;
@@ -52,7 +55,7 @@ class FS {
52
55
  static readFile(filePath, options) {
53
56
  return __awaiter(this, void 0, void 0, function* () {
54
57
  return new Promise((resolve, reject) => {
55
- (0, fs_1.readFile)(filePath, options, (err, res) => {
58
+ fs_1.default.readFile(filePath, options, (err, res) => {
56
59
  if (err) {
57
60
  reject(err);
58
61
  return;
@@ -73,10 +76,10 @@ class FS {
73
76
  resolve(undefined);
74
77
  };
75
78
  if (options) {
76
- (0, fs_1.writeFile)(filePath, data, options, callback);
79
+ fs_1.default.writeFile(filePath, data, options, callback);
77
80
  }
78
81
  else {
79
- (0, fs_1.writeFile)(filePath, data, callback);
82
+ fs_1.default.writeFile(filePath, data, callback);
80
83
  }
81
84
  });
82
85
  });
@@ -85,7 +88,7 @@ class FS {
85
88
  return __awaiter(this, void 0, void 0, function* () {
86
89
  const res = yield new Promise((resolve, reject) => {
87
90
  const filePath = Path.join(...paths);
88
- (0, fs_1.readFile)(filePath, (err, data) => {
91
+ fs_1.default.readFile(filePath, (err, data) => {
89
92
  if (err) {
90
93
  reject(err);
91
94
  return;
@@ -108,14 +111,28 @@ class FS {
108
111
  resolve(undefined);
109
112
  };
110
113
  if (options) {
111
- (0, fs_1.writeFile)(filePath, json, options, callback);
114
+ fs_1.default.writeFile(filePath, json, options, callback);
112
115
  }
113
116
  else {
114
- (0, fs_1.writeFile)(filePath, json, callback);
117
+ fs_1.default.writeFile(filePath, json, callback);
115
118
  }
116
119
  });
117
120
  });
118
121
  }
122
+ static readdir(path) {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ return new Promise((resolve, reject) => {
125
+ fs_1.default.readdir(path, (err, files) => {
126
+ if (!err) {
127
+ resolve(files);
128
+ }
129
+ else {
130
+ reject(err);
131
+ }
132
+ });
133
+ });
134
+ });
135
+ }
119
136
  static rm(path, options) {
120
137
  return __awaiter(this, void 0, void 0, function* () {
121
138
  return new Promise((resolve, reject) => {
@@ -127,10 +144,10 @@ class FS {
127
144
  resolve(undefined);
128
145
  };
129
146
  if (options) {
130
- (0, fs_1.rm)(path, options, callback);
147
+ fs_1.default.rm(path, options, callback);
131
148
  }
132
149
  else {
133
- (0, fs_1.rm)(path, callback);
150
+ fs_1.default.rm(path, callback);
134
151
  }
135
152
  });
136
153
  });
@@ -1,8 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import fs, { createReadStream, MakeDirectoryOptions, RmOptions } from "fs";
3
- declare class FSManager {
4
- protected source: string;
5
- protected destination: string;
3
+ import { FileSystem } from "./FileSystem";
4
+ export declare class FSManager {
5
+ readonly source: FileSystem;
6
+ readonly destination: FileSystem;
6
7
  constructor(source: string, destination: string);
7
8
  path(...parts: string[]): string;
8
9
  mkdir(path: string, options?: MakeDirectoryOptions): Promise<unknown>;
@@ -15,4 +16,3 @@ declare class FSManager {
15
16
  createWriteStream(...parts: string[]): fs.WriteStream;
16
17
  createReadStream(path: string, options?: Parameters<typeof createReadStream>[1]): fs.ReadStream;
17
18
  }
18
- export { FSManager };
@@ -34,18 +34,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.FSManager = void 0;
36
36
  const fs_1 = __importStar(require("fs"));
37
- const Path = __importStar(require("path"));
37
+ const FileSystem_1 = require("./FileSystem");
38
38
  class FSManager {
39
39
  constructor(source, destination) {
40
- this.source = source;
41
- this.destination = destination;
40
+ this.source = new FileSystem_1.FileSystem(source);
41
+ this.destination = new FileSystem_1.FileSystem(destination);
42
42
  }
43
43
  path(...parts) {
44
- return Path.join(this.destination, ...parts);
44
+ return this.destination.path(...parts);
45
45
  }
46
46
  mkdir(path_1) {
47
47
  return __awaiter(this, arguments, void 0, function* (path, options = {}) {
48
- const fullPath = Path.join(this.destination, path);
48
+ const fullPath = this.path(path);
49
49
  return new Promise((resolve, reject) => {
50
50
  (0, fs_1.mkdir)(fullPath, options, (err) => {
51
51
  if (err) {
@@ -59,7 +59,7 @@ class FSManager {
59
59
  }
60
60
  readdir(path) {
61
61
  return __awaiter(this, void 0, void 0, function* () {
62
- const filePath = Path.join(this.destination, path);
62
+ const filePath = this.path(path);
63
63
  return new Promise((resolve, reject) => {
64
64
  (0, fs_1.readdir)(filePath, (err, files) => {
65
65
  if (err) {
@@ -72,16 +72,16 @@ class FSManager {
72
72
  });
73
73
  }
74
74
  exists(path) {
75
- const fullPath = Path.join(this.destination, path);
75
+ const fullPath = this.path(path);
76
76
  return (0, fs_1.existsSync)(fullPath);
77
77
  }
78
78
  copy(path) {
79
- const destination = Path.join(this.destination, path);
79
+ const destination = this.path(path);
80
80
  if ((0, fs_1.existsSync)(destination)) {
81
81
  return Promise.resolve();
82
82
  }
83
83
  return new Promise((resolve, reject) => {
84
- (0, fs_1.copyFile)(Path.join(this.source, path), destination, (err) => {
84
+ (0, fs_1.copyFile)(this.source.path(path), destination, (err) => {
85
85
  if (err) {
86
86
  reject(err);
87
87
  return;
@@ -92,7 +92,7 @@ class FSManager {
92
92
  }
93
93
  readJSON(path) {
94
94
  return __awaiter(this, void 0, void 0, function* () {
95
- const filePath = Path.join(this.destination, ...path);
95
+ const filePath = this.path(path);
96
96
  const res = yield new Promise((resolve, reject) => {
97
97
  (0, fs_1.readFile)(filePath, (err, data) => {
98
98
  if (err) {
@@ -108,7 +108,7 @@ class FSManager {
108
108
  writeJSON(path, data) {
109
109
  return __awaiter(this, void 0, void 0, function* () {
110
110
  const json = JSON.stringify(data, null, 4);
111
- const filePath = Path.join(this.destination, path);
111
+ const filePath = this.path(path);
112
112
  return new Promise((resolve, reject) => {
113
113
  (0, fs_1.writeFile)(filePath, json, (err) => {
114
114
  if (err) {
@@ -122,7 +122,7 @@ class FSManager {
122
122
  }
123
123
  rm(path_1) {
124
124
  return __awaiter(this, arguments, void 0, function* (path, options = {}) {
125
- const filePath = Path.join(this.destination, path);
125
+ const filePath = this.path(path);
126
126
  return new Promise((resolve, reject) => {
127
127
  fs_1.default.rm(filePath, options, (err) => {
128
128
  if (err) {
@@ -135,11 +135,11 @@ class FSManager {
135
135
  });
136
136
  }
137
137
  createWriteStream(...parts) {
138
- const filePath = Path.join(this.destination, ...parts);
138
+ const filePath = this.path(...parts);
139
139
  return (0, fs_1.createWriteStream)(filePath);
140
140
  }
141
141
  createReadStream(path, options) {
142
- const filePath = Path.join(this.destination, path);
142
+ const filePath = this.path(path);
143
143
  return (0, fs_1.createReadStream)(filePath, options);
144
144
  }
145
145
  }
@@ -12,9 +12,8 @@ export declare class Factory {
12
12
  scanModuleDependencies(module: Module): Promise<void>;
13
13
  scanDynamicModules(): Promise<void>;
14
14
  scanRoutes(): Promise<void>;
15
- log(...args: any[]): void;
16
15
  init(): Promise<void>;
17
- run(args: string[]): Promise<any>;
16
+ run(args: string[]): Promise<string>;
18
17
  getContainer(): Container;
19
18
  static create(module: any): Promise<ApplicationContext>;
20
19
  }
@@ -58,8 +58,10 @@ class Factory {
58
58
  scanModuleDependencies(module) {
59
59
  return __awaiter(this, void 0, void 0, function* () {
60
60
  const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || [];
61
+ // Logger.info(module.type.name, providers);
61
62
  module.addProvider(cli_1.Cli, this.cli);
62
63
  providers.forEach((providerType) => {
64
+ // Logger.info(" ->", (providerType as any).name);
63
65
  module.addProvider(providerType);
64
66
  });
65
67
  const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || [];
@@ -115,6 +117,9 @@ class Factory {
115
117
  });
116
118
  const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || [];
117
119
  const command = this.cli.command(commandName);
120
+ command.help({
121
+ description: "Des"
122
+ });
118
123
  for (const argMeta of argsMeta) {
119
124
  if (argMeta.type === "option") {
120
125
  command.option(argMeta.name, argMeta.params);
@@ -136,11 +141,15 @@ class Factory {
136
141
  for (const controllerCommand of controllerCommands) {
137
142
  const { command: commandName, method, argsMeta } = controllerCommand;
138
143
  this.cli.command(commandName)
139
- .action((options, ...params) => {
144
+ .action((input) => {
140
145
  const args = [];
146
+ const params = Object.values(input.arguments());
141
147
  argsMeta.forEach((argMeta) => {
142
- if (argMeta.type === "option") {
143
- args[argMeta.index] = options[argMeta.name];
148
+ if (argMeta.type === "param") {
149
+ args[argMeta.index] = input.argument(argMeta.name);
150
+ }
151
+ else if (argMeta.type === "option") {
152
+ args[argMeta.index] = input.option(argMeta.name);
144
153
  }
145
154
  });
146
155
  return controller.instance[method](...args, ...params);
@@ -166,15 +175,6 @@ class Factory {
166
175
  }
167
176
  });
168
177
  }
169
- log(...args) {
170
- for (const [, module] of this.container.modules) {
171
- module.providers.forEach((provider) => {
172
- if (provider.instance.info) {
173
- provider.instance.info(...args);
174
- }
175
- });
176
- }
177
- }
178
178
  init() {
179
179
  return __awaiter(this, void 0, void 0, function* () {
180
180
  for (const [, module] of this.container.modules) {
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import * as fs from "fs";
3
+ type ReaddirOptions = fs.ObjectEncodingOptions & {
4
+ recursive?: boolean | undefined;
5
+ };
6
+ export declare class FileSystem {
7
+ protected readonly source: string;
8
+ constructor(source: string);
9
+ path(...parts: string[]): string;
10
+ exists(...parts: string[]): boolean;
11
+ stat(...parts: string[]): fs.Stats;
12
+ mkdir(path: string, options?: fs.MakeDirectoryOptions): void;
13
+ readdir(...parts: string[]): Promise<unknown>;
14
+ readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>;
15
+ }
16
+ export {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.FileSystem = void 0;
36
+ const fs = __importStar(require("fs"));
37
+ const Path = __importStar(require("path"));
38
+ class FileSystem {
39
+ constructor(source) {
40
+ this.source = source;
41
+ }
42
+ path(...parts) {
43
+ return Path.join(this.source, ...parts);
44
+ }
45
+ exists(...parts) {
46
+ const fullPath = this.path(...parts);
47
+ return fs.existsSync(fullPath);
48
+ }
49
+ stat(...parts) {
50
+ const fullPath = this.path(...parts);
51
+ return fs.statSync(fullPath);
52
+ }
53
+ mkdir(path, options) {
54
+ const fullPath = this.path(path);
55
+ fs.mkdirSync(fullPath, options);
56
+ }
57
+ readdir(...parts) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const fullPath = this.path(...parts);
60
+ return new Promise((resolve, reject) => {
61
+ fs.readdir(fullPath, (err, files) => {
62
+ if (err) {
63
+ reject(err);
64
+ return;
65
+ }
66
+ resolve(files);
67
+ });
68
+ });
69
+ });
70
+ }
71
+ readdirFiles() {
72
+ return __awaiter(this, arguments, void 0, function* (path = "", options) {
73
+ const fullPath = this.path(path);
74
+ return new Promise((resolve, reject) => {
75
+ fs.readdir(fullPath, options, (err, files) => {
76
+ if (err) {
77
+ reject(err);
78
+ return;
79
+ }
80
+ files = files.filter((path) => {
81
+ const stat = this.stat(path);
82
+ return stat.isFile();
83
+ });
84
+ resolve(files);
85
+ });
86
+ });
87
+ });
88
+ }
89
+ }
90
+ exports.FileSystem = FileSystem;
@@ -1,10 +1,10 @@
1
+ import "reflect-metadata";
1
2
  import { Module } from "./Module";
2
3
  export declare class InstanceWrapper {
3
4
  private readonly module;
4
- private readonly token;
5
5
  private readonly provider;
6
6
  private _instance?;
7
- constructor(module: Module, token: any, provider: any, _instance?: any);
7
+ constructor(module: Module, provider: any, _instance?: any);
8
8
  get instance(): any;
9
9
  set instance(instance: any);
10
10
  }
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InstanceWrapper = void 0;
4
+ require("reflect-metadata");
4
5
  const env_1 = require("../env");
5
6
  class InstanceWrapper {
6
- constructor(module, token, provider, _instance) {
7
+ constructor(module, provider, _instance) {
7
8
  this.module = module;
8
- this.token = token;
9
9
  this.provider = provider;
10
10
  this._instance = _instance;
11
11
  }
12
12
  get instance() {
13
- if (!this.provider) {
14
- return null;
15
- }
16
13
  if (!this._instance) {
17
14
  const types = [
18
15
  ...Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.provider) || []
@@ -1,4 +1,4 @@
1
- import { LogService } from "../services/LogService";
1
+ import { LogService } from "../services";
2
2
  export declare class Logger {
3
3
  static install(ls: LogService): void;
4
4
  static log(...data: any[]): void;
@@ -34,19 +34,24 @@ class Module {
34
34
  }
35
35
  addProvider(provider, instance) {
36
36
  if ("provide" in provider && "useValue" in provider) {
37
- const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.provide, provider.provide, provider.useValue);
37
+ const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.provide, provider.useValue);
38
+ this.providers.set(provider.provide, wrapper);
39
+ return;
40
+ }
41
+ if ("provide" in provider && "useClass" in provider) {
42
+ const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.useClass);
38
43
  this.providers.set(provider.provide, wrapper);
39
44
  return;
40
45
  }
41
46
  const token = Reflect.getMetadata("INJECT_TOKEN", provider) || provider;
42
- const wrapper = new InstanceWrapper_1.InstanceWrapper(this, token, provider, instance);
47
+ const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider, instance);
43
48
  this.providers.set(token, wrapper);
44
49
  }
45
50
  addInjection() {
46
51
  //
47
52
  }
48
53
  addController(type) {
49
- this.controllers.set(type, new InstanceWrapper_1.InstanceWrapper(this, type, type));
54
+ this.controllers.set(type, new InstanceWrapper_1.InstanceWrapper(this, type));
50
55
  for (const name of Object.getOwnPropertyNames(type.prototype)) {
51
56
  const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name);
52
57
  if (!descriptor) {
@@ -1,6 +1,3 @@
1
- import { DI } from "./DI";
2
- import { PresetServiceSearchOptions as SearchOptions } from "../services/PresetService";
3
- import { EnvConfig } from "../types";
4
1
  type TextOption = {
5
2
  type: "string" | "number" | "int";
6
3
  message?: string;
@@ -23,7 +20,7 @@ type SelectOption = {
23
20
  default?: string;
24
21
  };
25
22
  type AnyOption = TextOption | ConfirmOption | SelectOption;
26
- declare class Preset {
23
+ export declare abstract class Preset {
27
24
  id: string;
28
25
  name: string;
29
26
  version: string;
@@ -36,11 +33,7 @@ declare class Preset {
36
33
  };
37
34
  volumes?: string[];
38
35
  volumeOptions?: string[];
39
- constructor(data: any);
40
- save(): Promise<void>;
41
- getImageName(buildArgs?: EnvConfig): string;
42
- static install(di: DI): void;
43
- static search(options: SearchOptions): Promise<any[]>;
44
- static searchOne(options: SearchOptions): Promise<any>;
36
+ protected constructor(data: any);
37
+ abstract save(): Promise<void>;
45
38
  }
46
- export { Preset };
39
+ export {};
@@ -1,17 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Preset = void 0;
13
- const PresetService_1 = require("../services/PresetService");
14
- let _di;
15
4
  class Preset {
16
5
  constructor(data) {
17
6
  this.id = data.id;
@@ -23,22 +12,5 @@ class Preset {
23
12
  this.volumes = data.volumes;
24
13
  this.volumeOptions = data.volumeOptions;
25
14
  }
26
- save() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return _di.resolveService(PresetService_1.PresetService).save(this);
29
- });
30
- }
31
- getImageName(buildArgs) {
32
- return _di.resolveService(PresetService_1.PresetService).getImageName(this, buildArgs);
33
- }
34
- static install(di) {
35
- _di = di;
36
- }
37
- static search(options) {
38
- return _di.resolveService(PresetService_1.PresetService).search(options);
39
- }
40
- static searchOne(options) {
41
- return _di.resolveService(PresetService_1.PresetService).searchOne(options);
42
- }
43
15
  }
44
16
  exports.Preset = Preset;
@@ -1,4 +1,5 @@
1
1
  import { PickProperties, EnvConfig } from "../types";
2
+ export type ProjectProperties = Omit<PickProperties<Project>, "containerName">;
2
3
  export declare abstract class Project {
3
4
  id: string;
4
5
  name: string;
@@ -13,7 +14,7 @@ export declare abstract class Project {
13
14
  ports?: string[];
14
15
  volumes?: string[];
15
16
  metadata?: EnvConfig;
16
- protected constructor(data: PickProperties<Project>);
17
+ protected constructor(data: ProjectProperties);
17
18
  get containerName(): string;
18
19
  hasEnv(name: string): boolean;
19
20
  getEnv(name: string, defaultValue?: string): string | undefined;
@@ -28,6 +29,7 @@ export declare abstract class Project {
28
29
  volumeMount(...volumes: string[]): void;
29
30
  volumeUnmount(...volumes: string[]): void;
30
31
  abstract save(): Promise<void>;
32
+ toJSON(): ProjectProperties;
31
33
  }
32
34
  export declare const PROJECT_TYPE_DOCKERFILE = "dockerfile";
33
35
  export declare const PROJECT_TYPE_IMAGE = "image";
@@ -106,6 +106,23 @@ class Project {
106
106
  return !volumes.includes(mounted);
107
107
  });
108
108
  }
109
+ toJSON() {
110
+ return {
111
+ id: this.id,
112
+ name: this.name,
113
+ type: this.type,
114
+ path: this.path,
115
+ preset: this.preset,
116
+ imageName: this.imageName,
117
+ dockerfile: this.dockerfile,
118
+ scripts: this.scripts,
119
+ buildArgs: this.buildArgs,
120
+ env: this.env,
121
+ ports: this.ports,
122
+ volumes: this.volumes,
123
+ metadata: this.metadata
124
+ };
125
+ }
109
126
  }
110
127
  exports.Project = Project;
111
128
  exports.PROJECT_TYPE_DOCKERFILE = "dockerfile";
@@ -1,6 +1,6 @@
1
1
  export * from "./Config";
2
2
  export * from "./Container";
3
- export * from "./DI";
3
+ export * from "./FileSystem";
4
4
  export * from "./FS";
5
5
  export * from "./FSManager";
6
6
  export * from "./Logger";
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Config"), exports);
18
18
  __exportStar(require("./Container"), exports);
19
- __exportStar(require("./DI"), exports);
19
+ __exportStar(require("./FileSystem"), exports);
20
20
  __exportStar(require("./FS"), exports);
21
21
  __exportStar(require("./FSManager"), exports);
22
22
  __exportStar(require("./Logger"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Core of wocker",
6
6
  "license": "MIT",
@@ -19,19 +19,24 @@
19
19
  },
20
20
  "scripts": {
21
21
  "prepare": "npm run build",
22
- "watch": "tsc -w",
23
- "build": "tsc",
24
- "test": "echo \"Error: no test specified\" && exit 1"
22
+ "build": "tsc --project tsconfig.build.json",
23
+ "watch": "tsc -w --project tsconfig.build.json",
24
+ "watch:test": "jest --colors --watchAll --coverage",
25
+ "test": "jest --colors"
25
26
  },
26
27
  "dependencies": {
27
- "@kearisp/cli": "^1.0.7",
28
+ "@kearisp/cli": "^2.0.4",
28
29
  "fs": "^0.0.1-security",
29
30
  "path": "^0.12.7",
30
31
  "reflect-metadata": "^0.2.1"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/dockerode": "^3.3.23",
35
+ "@types/jest": "^29.5.12",
34
36
  "@types/node": "^20.11.7",
35
- "typescript": "^5.4.4"
37
+ "jest": "^29.7.0",
38
+ "ts-jest": "^29.1.2",
39
+ "ts-node": "^10.9.2",
40
+ "typescript": "^5.4.5"
36
41
  }
37
42
  }
package/lib/makes/DI.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import "reflect-metadata";
2
- declare class DI {
3
- private services;
4
- resolveService<T>(key: any): T;
5
- registerService(key: any, service: any): void;
6
- }
7
- export { DI };
package/lib/makes/DI.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DI = void 0;
4
- require("reflect-metadata");
5
- class DI {
6
- constructor() {
7
- this.services = new Map();
8
- }
9
- resolveService(key) {
10
- let res = this.services.get(key);
11
- if (!res) {
12
- const types = Reflect.getMetadata("design:paramtypes", key);
13
- if (types && types.length > 0) {
14
- types.forEach((type) => {
15
- this.resolveService(type);
16
- });
17
- }
18
- res = new key(this);
19
- this.services.set(key, res);
20
- }
21
- return res;
22
- }
23
- registerService(key, service) {
24
- this.services.set(key, service);
25
- }
26
- }
27
- exports.DI = DI;