@wocker/core 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/lib/decorators/Command.d.ts +1 -0
- package/lib/decorators/Command.js +10 -0
- package/lib/decorators/Completion.d.ts +1 -0
- package/lib/decorators/Completion.js +15 -0
- package/lib/decorators/Controller.d.ts +5 -0
- package/lib/decorators/Controller.js +14 -0
- package/lib/decorators/Inject.d.ts +1 -1
- package/lib/decorators/Inject.js +10 -2
- package/lib/decorators/Injectable.d.ts +1 -4
- package/lib/decorators/Injectable.js +7 -12
- package/lib/decorators/Module.d.ts +15 -0
- package/lib/decorators/Module.js +16 -0
- package/lib/decorators/Option.d.ts +4 -0
- package/lib/decorators/Option.js +21 -0
- package/lib/decorators/Param.d.ts +1 -0
- package/lib/decorators/Param.js +8 -0
- package/lib/decorators/index.d.ts +7 -0
- package/lib/decorators/index.js +23 -0
- package/lib/env.d.ts +18 -0
- package/lib/env.js +22 -0
- package/lib/index.d.ts +5 -17
- package/lib/index.js +8 -18
- package/lib/makes/Container.d.ts +8 -0
- package/lib/makes/Container.js +25 -0
- package/lib/makes/FS.d.ts +15 -3
- package/lib/makes/FS.js +99 -4
- package/lib/makes/FSManager.js +4 -4
- package/lib/makes/Factory.d.ts +17 -0
- package/lib/makes/Factory.js +201 -0
- package/lib/makes/InstanceWrapper.d.ts +10 -0
- package/lib/makes/InstanceWrapper.js +41 -0
- package/lib/makes/Logger.d.ts +4 -5
- package/lib/makes/Logger.js +8 -9
- package/lib/makes/Module.d.ts +17 -0
- package/lib/makes/Module.js +63 -0
- package/lib/makes/Plugin.d.ts +1 -3
- package/lib/makes/Plugin.js +2 -3
- package/lib/{models → makes}/Preset.d.ts +4 -4
- package/lib/{models → makes}/Project.d.ts +14 -10
- package/lib/{models → makes}/Project.js +60 -24
- package/lib/makes/Scanner.d.ts +4 -0
- package/lib/makes/Scanner.js +9 -0
- package/lib/makes/index.d.ts +9 -0
- package/lib/makes/index.js +25 -0
- package/lib/services/AppConfigService.d.ts +1 -1
- package/lib/services/AppConfigService.js +12 -2
- package/lib/services/AppEventsService.d.ts +2 -2
- package/lib/services/AppEventsService.js +12 -2
- package/lib/services/DockerService.d.ts +13 -1
- package/lib/services/DockerService.js +12 -2
- package/lib/services/LogService.d.ts +2 -3
- package/lib/services/LogService.js +12 -2
- package/lib/services/PluginConfigService.d.ts +5 -0
- package/lib/services/PluginConfigService.js +64 -0
- package/lib/services/PresetService.d.ts +6 -7
- package/lib/services/ProjectService.d.ts +5 -3
- package/lib/services/ProjectService.js +14 -4
- package/lib/services/index.d.ts +7 -0
- package/lib/services/index.js +23 -0
- package/lib/types/Abstract.d.ts +3 -0
- package/lib/types/Abstract.js +2 -0
- package/lib/types/InjectionToken.d.ts +3 -0
- package/lib/types/InjectionToken.js +2 -0
- package/lib/types/PickProperties.d.ts +3 -0
- package/lib/types/PickProperties.js +2 -0
- package/lib/types/Provider.d.ts +12 -0
- package/lib/types/Provider.js +2 -0
- package/lib/types/Type.d.ts +3 -0
- package/lib/types/Type.js +2 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +19 -0
- package/package.json +17 -6
- package/lib/makes/Controller.d.ts +0 -5
- package/lib/makes/Controller.js +0 -9
- /package/lib/{models → makes}/Preset.js +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Factory = void 0;
|
|
13
|
+
const cli_1 = require("@kearisp/cli");
|
|
14
|
+
const Container_1 = require("./Container");
|
|
15
|
+
const Module_1 = require("./Module");
|
|
16
|
+
const env_1 = require("../env");
|
|
17
|
+
class Factory {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.routes = [];
|
|
20
|
+
this.container = new Container_1.Container();
|
|
21
|
+
this.cli = new cli_1.Cli();
|
|
22
|
+
}
|
|
23
|
+
scan(moduleType) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
if (this.container.modules.has(moduleType)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
yield this.scanModules(moduleType);
|
|
29
|
+
yield this.scanDependencies();
|
|
30
|
+
yield this.scanDynamicModules();
|
|
31
|
+
yield this.scanRoutes();
|
|
32
|
+
yield this.init();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
scanModules(moduleType, parent) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (this.container.hasModule(moduleType)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const module = new Module_1.Module(moduleType, parent);
|
|
41
|
+
this.container.addModule(moduleType, module);
|
|
42
|
+
const modules = Reflect.getMetadata(env_1.MODULE_METADATA.IMPORTS, moduleType) || [];
|
|
43
|
+
for (const subModuleType of modules) {
|
|
44
|
+
yield this.scanModules(subModuleType, module);
|
|
45
|
+
}
|
|
46
|
+
// const exports = Reflect.getMetadata(MODULE_METADATA.EXPORTS, moduleType) || [];
|
|
47
|
+
return module;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
scanDependencies() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
for (const [, module] of this.container.modules) {
|
|
53
|
+
yield this.scanModuleDependencies(module);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
scanModuleDependencies(module) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const providers = Reflect.getMetadata(env_1.MODULE_METADATA.PROVIDERS, module.type) || [];
|
|
60
|
+
module.addProvider(cli_1.Cli, this.cli);
|
|
61
|
+
providers.forEach((providerType) => {
|
|
62
|
+
module.addProvider(providerType);
|
|
63
|
+
});
|
|
64
|
+
const controllers = Reflect.getMetadata(env_1.MODULE_METADATA.CONTROLLERS, module.type) || [];
|
|
65
|
+
controllers.forEach((controller) => {
|
|
66
|
+
module.addController(controller);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
scanDynamicModules() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
for (const [moduleType, module] of this.container.modules) {
|
|
73
|
+
if (moduleType.prototype.load) {
|
|
74
|
+
const { imports } = yield moduleType.prototype.load(this.container);
|
|
75
|
+
for (const type of imports) {
|
|
76
|
+
const isModule = Reflect.getMetadata("isModule", type);
|
|
77
|
+
if (!isModule) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const subModule = yield this.scanModules(type, module);
|
|
81
|
+
if (subModule) {
|
|
82
|
+
yield this.scanModuleDependencies(subModule);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
scanRoutes() {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
for (const [, module] of this.container.modules) {
|
|
92
|
+
for (const [type, controller] of module.controllers) {
|
|
93
|
+
const controllerCommands = [];
|
|
94
|
+
const controllerCompletions = [];
|
|
95
|
+
for (const name of Object.getOwnPropertyNames(type.prototype)) {
|
|
96
|
+
const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name);
|
|
97
|
+
if (!descriptor) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const commandName = Reflect.getMetadata(env_1.COMMAND_METADATA, descriptor.value);
|
|
101
|
+
const completions = (Reflect.getMetadata(env_1.COMPLETION_METADATA, descriptor.value) || []).map((completion) => {
|
|
102
|
+
return Object.assign(Object.assign({}, completion), { method: name });
|
|
103
|
+
});
|
|
104
|
+
if (completions.length > 0) {
|
|
105
|
+
controllerCompletions.push(...completions);
|
|
106
|
+
}
|
|
107
|
+
if (commandName) {
|
|
108
|
+
controllerCommands.push({
|
|
109
|
+
command: commandName,
|
|
110
|
+
controller,
|
|
111
|
+
method: name,
|
|
112
|
+
argsMeta: Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || []
|
|
113
|
+
});
|
|
114
|
+
const argsMeta = Reflect.getMetadata(env_1.ARGS_METADATA, type, name) || [];
|
|
115
|
+
const command = this.cli.command(commandName);
|
|
116
|
+
for (const argMeta of argsMeta) {
|
|
117
|
+
if (argMeta.type === "option") {
|
|
118
|
+
command.option(argMeta.name, argMeta.params);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// command.action((options, ...params) => {
|
|
122
|
+
// const args: any[] = [];
|
|
123
|
+
//
|
|
124
|
+
// argsMeta.forEach((argMeta: any) => {
|
|
125
|
+
// if(argMeta.type === "option") {
|
|
126
|
+
// args[argMeta.index] = options[argMeta.name];
|
|
127
|
+
// }
|
|
128
|
+
// });
|
|
129
|
+
//
|
|
130
|
+
// return controller.instance[name](...args, ...params);
|
|
131
|
+
// });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const controllerCommand of controllerCommands) {
|
|
135
|
+
const { command: commandName, method, argsMeta } = controllerCommand;
|
|
136
|
+
this.cli.command(commandName)
|
|
137
|
+
.action((options, ...params) => {
|
|
138
|
+
const args = [];
|
|
139
|
+
argsMeta.forEach((argMeta) => {
|
|
140
|
+
if (argMeta.type === "option") {
|
|
141
|
+
args[argMeta.index] = options[argMeta.name];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return controller.instance[method](...args, ...params);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
for (const controllerCompletion of controllerCompletions) {
|
|
148
|
+
const { name, command: commandName, method } = controllerCompletion;
|
|
149
|
+
if (!commandName) {
|
|
150
|
+
for (const route of controllerCommands) {
|
|
151
|
+
const { command } = route;
|
|
152
|
+
this.cli.command(command).completion(name, () => {
|
|
153
|
+
return controller.instance[method]();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.cli.command(commandName).completion(name, () => {
|
|
159
|
+
return controller.instance[method]();
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
log(...args) {
|
|
168
|
+
for (const [, module] of this.container.modules) {
|
|
169
|
+
module.providers.forEach((provider) => {
|
|
170
|
+
if (provider.instance.info) {
|
|
171
|
+
provider.instance.info(...args);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
init() {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
for (const [, module] of this.container.modules) {
|
|
179
|
+
module.providers.forEach((provider) => {
|
|
180
|
+
provider.instance;
|
|
181
|
+
});
|
|
182
|
+
module.controllers.forEach((controller) => {
|
|
183
|
+
controller.instance;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
run(args) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
return this.cli.run(args);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
static create(module) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
const factory = new this();
|
|
196
|
+
yield factory.scan(module);
|
|
197
|
+
return factory;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.Factory = Factory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Module } from "./Module";
|
|
2
|
+
export declare class InstanceWrapper {
|
|
3
|
+
private readonly module;
|
|
4
|
+
private readonly token;
|
|
5
|
+
private readonly provider;
|
|
6
|
+
private _instance?;
|
|
7
|
+
constructor(module: Module, token: any, provider: any, _instance?: any);
|
|
8
|
+
get instance(): any;
|
|
9
|
+
set instance(instance: any);
|
|
10
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InstanceWrapper = void 0;
|
|
4
|
+
const env_1 = require("../env");
|
|
5
|
+
class InstanceWrapper {
|
|
6
|
+
constructor(module, token, provider, _instance) {
|
|
7
|
+
this.module = module;
|
|
8
|
+
this.token = token;
|
|
9
|
+
this.provider = provider;
|
|
10
|
+
this._instance = _instance;
|
|
11
|
+
}
|
|
12
|
+
get instance() {
|
|
13
|
+
if (!this.provider) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (!this._instance) {
|
|
17
|
+
const types = [
|
|
18
|
+
...Reflect.getMetadata(env_1.PARAMTYPES_METADATA, this.provider) || []
|
|
19
|
+
];
|
|
20
|
+
const selfTypes = Reflect.getMetadata(env_1.SELF_DECLARED_DEPS_METADATA, this.provider) || [];
|
|
21
|
+
if (selfTypes.length > 0) {
|
|
22
|
+
selfTypes.forEach(({ index, token }) => {
|
|
23
|
+
types[index] = token;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const params = types.map((type) => {
|
|
27
|
+
const wrapper = this.module.getWrapper(type);
|
|
28
|
+
if (!wrapper) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return wrapper.instance;
|
|
32
|
+
});
|
|
33
|
+
this._instance = new this.provider(...params);
|
|
34
|
+
}
|
|
35
|
+
return this._instance;
|
|
36
|
+
}
|
|
37
|
+
set instance(instance) {
|
|
38
|
+
this._instance = instance;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.InstanceWrapper = InstanceWrapper;
|
package/lib/makes/Logger.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare class Logger {
|
|
3
|
-
static install(
|
|
1
|
+
import { LogService } from "../services/LogService";
|
|
2
|
+
export declare class Logger {
|
|
3
|
+
static install(ls: LogService): void;
|
|
4
4
|
static log(...data: any[]): void;
|
|
5
5
|
static info(...data: any[]): void;
|
|
6
|
-
static
|
|
6
|
+
static warn(...data: any[]): void;
|
|
7
7
|
static error(...data: any[]): void;
|
|
8
8
|
}
|
|
9
|
-
export { Logger };
|
package/lib/makes/Logger.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Logger = void 0;
|
|
4
|
-
|
|
5
|
-
let _di;
|
|
4
|
+
let loggerService;
|
|
6
5
|
class Logger {
|
|
7
|
-
static install(
|
|
8
|
-
|
|
6
|
+
static install(ls) {
|
|
7
|
+
loggerService = ls;
|
|
9
8
|
}
|
|
10
9
|
static log(...data) {
|
|
11
|
-
|
|
10
|
+
loggerService.log(...data);
|
|
12
11
|
}
|
|
13
12
|
static info(...data) {
|
|
14
|
-
|
|
13
|
+
loggerService.info(...data);
|
|
15
14
|
}
|
|
16
|
-
static
|
|
17
|
-
|
|
15
|
+
static warn(...data) {
|
|
16
|
+
loggerService.warn(...data);
|
|
18
17
|
}
|
|
19
18
|
static error(...data) {
|
|
20
|
-
|
|
19
|
+
loggerService.error(...data);
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
exports.Logger = Logger;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Provider } from "../types/Provider";
|
|
2
|
+
import { InstanceWrapper } from "./InstanceWrapper";
|
|
3
|
+
export declare class Module {
|
|
4
|
+
type: any;
|
|
5
|
+
parent?: Module | undefined;
|
|
6
|
+
imports: Set<any>;
|
|
7
|
+
controllers: Map<any, InstanceWrapper>;
|
|
8
|
+
providers: Map<any, InstanceWrapper>;
|
|
9
|
+
exports: Map<any, any>;
|
|
10
|
+
constructor(type: any, parent?: Module | undefined);
|
|
11
|
+
get<T = any>(type: any): T;
|
|
12
|
+
getWrapper(type: any): InstanceWrapper | undefined;
|
|
13
|
+
addImport(module: any): void;
|
|
14
|
+
addProvider(provider: Provider, instance?: any): void;
|
|
15
|
+
addInjection(): void;
|
|
16
|
+
addController(type: any): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = void 0;
|
|
4
|
+
const InstanceWrapper_1 = require("./InstanceWrapper");
|
|
5
|
+
const env_1 = require("../env");
|
|
6
|
+
class Module {
|
|
7
|
+
constructor(type, parent) {
|
|
8
|
+
this.type = type;
|
|
9
|
+
this.parent = parent;
|
|
10
|
+
this.imports = new Set();
|
|
11
|
+
this.controllers = new Map();
|
|
12
|
+
this.providers = new Map();
|
|
13
|
+
this.exports = new Map();
|
|
14
|
+
}
|
|
15
|
+
get(type) {
|
|
16
|
+
const wrapper = this.getWrapper(type);
|
|
17
|
+
if (!wrapper) {
|
|
18
|
+
throw new Error("Provider not found");
|
|
19
|
+
}
|
|
20
|
+
return wrapper.instance;
|
|
21
|
+
}
|
|
22
|
+
getWrapper(type) {
|
|
23
|
+
const token = typeof type !== "string"
|
|
24
|
+
? Reflect.getMetadata(env_1.INJECT_TOKEN_METADATA, type) || type
|
|
25
|
+
: type;
|
|
26
|
+
const wrapper = this.providers.get(token);
|
|
27
|
+
if (!wrapper && this.parent) {
|
|
28
|
+
return this.parent.getWrapper(type);
|
|
29
|
+
}
|
|
30
|
+
return wrapper;
|
|
31
|
+
}
|
|
32
|
+
addImport(module) {
|
|
33
|
+
this.imports.add(module);
|
|
34
|
+
}
|
|
35
|
+
addProvider(provider, instance) {
|
|
36
|
+
if ("provide" in provider && "useValue" in provider) {
|
|
37
|
+
const wrapper = new InstanceWrapper_1.InstanceWrapper(this, provider.provide, provider.provide, provider.useValue);
|
|
38
|
+
this.providers.set(provider.provide, wrapper);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const token = Reflect.getMetadata("INJECT_TOKEN", provider) || provider;
|
|
42
|
+
const wrapper = new InstanceWrapper_1.InstanceWrapper(this, token, provider, instance);
|
|
43
|
+
this.providers.set(token, wrapper);
|
|
44
|
+
}
|
|
45
|
+
addInjection() {
|
|
46
|
+
//
|
|
47
|
+
}
|
|
48
|
+
addController(type) {
|
|
49
|
+
this.controllers.set(type, new InstanceWrapper_1.InstanceWrapper(this, type, type));
|
|
50
|
+
for (const name of Object.getOwnPropertyNames(type.prototype)) {
|
|
51
|
+
const descriptor = Object.getOwnPropertyDescriptor(type.prototype, name);
|
|
52
|
+
if (!descriptor) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const command = Reflect.getMetadata("command", descriptor.value);
|
|
56
|
+
if (!command) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
// console.log(">", name, command);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Module = Module;
|
package/lib/makes/Plugin.d.ts
CHANGED
package/lib/makes/Plugin.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Plugin = void 0;
|
|
4
|
-
|
|
5
|
-
class Plugin extends Controller_1.Controller {
|
|
4
|
+
class Plugin {
|
|
6
5
|
install(cli) {
|
|
7
|
-
|
|
6
|
+
//
|
|
8
7
|
}
|
|
9
8
|
}
|
|
10
9
|
exports.Plugin = Plugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DI } from "
|
|
1
|
+
import { DI } from "./DI";
|
|
2
2
|
import { PresetServiceSearchOptions as SearchOptions } from "../services/PresetService";
|
|
3
|
-
import { EnvConfig } from "../types
|
|
3
|
+
import { EnvConfig } from "../types";
|
|
4
4
|
type TextOption = {
|
|
5
5
|
type: "string" | "number" | "int";
|
|
6
6
|
message?: string;
|
|
@@ -40,7 +40,7 @@ declare class Preset {
|
|
|
40
40
|
save(): Promise<void>;
|
|
41
41
|
getImageName(buildArgs?: EnvConfig): string;
|
|
42
42
|
static install(di: DI): void;
|
|
43
|
-
static search(options: SearchOptions): Promise<
|
|
44
|
-
static searchOne(options: SearchOptions): Promise<
|
|
43
|
+
static search(options: SearchOptions): Promise<any[]>;
|
|
44
|
+
static searchOne(options: SearchOptions): Promise<any>;
|
|
45
45
|
}
|
|
46
46
|
export { Preset };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import { DI } from "
|
|
3
|
-
import { EnvConfig } from "../types/EnvConfig";
|
|
1
|
+
import { PickProperties, EnvConfig } from "../types";
|
|
2
|
+
import { DI } from "./DI";
|
|
4
3
|
type SearchOptions = {
|
|
5
4
|
id: string;
|
|
6
5
|
name: string;
|
|
7
6
|
path: string;
|
|
8
7
|
};
|
|
9
|
-
declare class Project {
|
|
8
|
+
export declare class Project {
|
|
10
9
|
id: string;
|
|
11
10
|
name: string;
|
|
12
11
|
type: string;
|
|
@@ -16,18 +15,23 @@ declare class Project {
|
|
|
16
15
|
dockerfile?: string;
|
|
17
16
|
scripts?: string[];
|
|
18
17
|
buildArgs?: EnvConfig;
|
|
19
|
-
env
|
|
20
|
-
volumes?: string[];
|
|
18
|
+
env?: EnvConfig;
|
|
21
19
|
ports?: string[];
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
volumes?: string[];
|
|
21
|
+
metadata?: EnvConfig;
|
|
22
|
+
protected constructor(data: PickProperties<Project>);
|
|
23
|
+
get containerName(): string;
|
|
24
24
|
hasEnv(name: string): boolean;
|
|
25
25
|
getEnv(name: string, defaultValue?: string): string | undefined;
|
|
26
26
|
setEnv(name: string, value: string | boolean): void;
|
|
27
27
|
unsetEnv(name: string): void;
|
|
28
|
-
|
|
28
|
+
hasMeta(name: string): boolean;
|
|
29
|
+
getMeta<D = string | undefined>(name: string, defaultValue?: D): D;
|
|
30
|
+
setMeta(name: string, value: string | boolean): void;
|
|
31
|
+
unsetMeta(name: string): void;
|
|
29
32
|
getVolumeBySource(source: string): string | undefined;
|
|
30
33
|
getVolumeByDestination(destination: string): string | undefined;
|
|
34
|
+
volumeMount(...volumes: string[]): void;
|
|
31
35
|
volumeUnmount(...volumes: string[]): void;
|
|
32
36
|
save(): Promise<void>;
|
|
33
37
|
static install(di: DI): void;
|
|
@@ -35,6 +39,6 @@ declare class Project {
|
|
|
35
39
|
static search(params?: Partial<SearchOptions>): Promise<Project[]>;
|
|
36
40
|
static searchOne(params: Partial<SearchOptions>): Promise<Project | null>;
|
|
37
41
|
}
|
|
38
|
-
export { Project };
|
|
39
42
|
export declare const PROJECT_TYPE_DOCKERFILE = "dockerfile";
|
|
40
43
|
export declare const PROJECT_TYPE_IMAGE = "image";
|
|
44
|
+
export {};
|
|
@@ -10,11 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PROJECT_TYPE_IMAGE = exports.PROJECT_TYPE_DOCKERFILE = exports.Project = void 0;
|
|
13
|
-
require("reflect-metadata");
|
|
14
|
-
const AppConfigService_1 = require("../services/AppConfigService");
|
|
15
|
-
const ProjectService_1 = require("../services/ProjectService");
|
|
16
13
|
const volumeParse_1 = require("../utils/volumeParse");
|
|
17
|
-
|
|
14
|
+
const services_1 = require("../services");
|
|
18
15
|
let projectService;
|
|
19
16
|
class Project {
|
|
20
17
|
constructor(data) {
|
|
@@ -23,13 +20,18 @@ class Project {
|
|
|
23
20
|
this.type = data.type;
|
|
24
21
|
this.path = data.path;
|
|
25
22
|
this.preset = data.preset;
|
|
26
|
-
this.dockerfile = data.dockerfile;
|
|
27
23
|
this.imageName = data.imageName;
|
|
24
|
+
this.dockerfile = data.dockerfile;
|
|
28
25
|
this.scripts = data.scripts;
|
|
29
26
|
this.buildArgs = data.buildArgs;
|
|
30
|
-
this.env = data.env
|
|
27
|
+
this.env = data.env;
|
|
31
28
|
this.ports = data.ports;
|
|
32
29
|
this.volumes = data.volumes;
|
|
30
|
+
this.metadata = data.metadata;
|
|
31
|
+
Object.assign(this, data);
|
|
32
|
+
}
|
|
33
|
+
get containerName() {
|
|
34
|
+
return `${this.name}.workspace`;
|
|
33
35
|
}
|
|
34
36
|
hasEnv(name) {
|
|
35
37
|
if (!this.env) {
|
|
@@ -38,18 +40,63 @@ class Project {
|
|
|
38
40
|
return this.env.hasOwnProperty(name);
|
|
39
41
|
}
|
|
40
42
|
getEnv(name, defaultValue) {
|
|
41
|
-
const { [name]: value = defaultValue } = this.env;
|
|
43
|
+
const { [name]: value = defaultValue } = this.env || {};
|
|
42
44
|
return value;
|
|
43
45
|
}
|
|
44
46
|
setEnv(name, value) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (!this.env) {
|
|
48
|
+
this.env = {};
|
|
49
|
+
}
|
|
50
|
+
this.env[name] = typeof value === "boolean"
|
|
51
|
+
? (value ? "true" : "false")
|
|
52
|
+
: value;
|
|
48
53
|
}
|
|
49
54
|
unsetEnv(name) {
|
|
55
|
+
if (!this.env) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
50
58
|
if (name in this.env) {
|
|
51
59
|
delete this.env[name];
|
|
52
60
|
}
|
|
61
|
+
if (Object.keys(this.env).length === 0) {
|
|
62
|
+
delete this.env;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
hasMeta(name) {
|
|
66
|
+
return !!this.metadata && this.metadata.hasOwnProperty(name);
|
|
67
|
+
}
|
|
68
|
+
getMeta(name, defaultValue) {
|
|
69
|
+
const { [name]: value = defaultValue } = this.metadata || {};
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
setMeta(name, value) {
|
|
73
|
+
if (!this.metadata) {
|
|
74
|
+
this.metadata = {};
|
|
75
|
+
}
|
|
76
|
+
this.metadata[name] = typeof value === "boolean"
|
|
77
|
+
? (value ? "true" : "false")
|
|
78
|
+
: value;
|
|
79
|
+
}
|
|
80
|
+
unsetMeta(name) {
|
|
81
|
+
if (!this.metadata) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (name in this.metadata) {
|
|
85
|
+
delete this.metadata[name];
|
|
86
|
+
}
|
|
87
|
+
if (Object.keys(this.metadata).length === 0) {
|
|
88
|
+
delete this.metadata;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
getVolumeBySource(source) {
|
|
92
|
+
return (this.volumes || []).find((volume) => {
|
|
93
|
+
return (0, volumeParse_1.volumeParse)(volume).source === source;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getVolumeByDestination(destination) {
|
|
97
|
+
return (this.volumes || []).find((volume) => {
|
|
98
|
+
return (0, volumeParse_1.volumeParse)(volume).destination === destination;
|
|
99
|
+
});
|
|
53
100
|
}
|
|
54
101
|
volumeMount(...volumes) {
|
|
55
102
|
if (volumes.length === 0) {
|
|
@@ -65,16 +112,6 @@ class Project {
|
|
|
65
112
|
];
|
|
66
113
|
this.volumeMount(...restVolumes);
|
|
67
114
|
}
|
|
68
|
-
getVolumeBySource(source) {
|
|
69
|
-
return (this.volumes || []).find((volume) => {
|
|
70
|
-
return (0, volumeParse_1.volumeParse)(volume).source === source;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
getVolumeByDestination(destination) {
|
|
74
|
-
return (this.volumes || []).find((volume) => {
|
|
75
|
-
return (0, volumeParse_1.volumeParse)(volume).destination === destination;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
115
|
volumeUnmount(...volumes) {
|
|
79
116
|
this.volumes = (this.volumes || []).filter((mounted) => {
|
|
80
117
|
return !volumes.includes(mounted);
|
|
@@ -89,14 +126,13 @@ class Project {
|
|
|
89
126
|
});
|
|
90
127
|
}
|
|
91
128
|
static install(di) {
|
|
92
|
-
|
|
93
|
-
projectService = di.resolveService(ProjectService_1.ProjectService);
|
|
129
|
+
projectService = di.resolveService(services_1.ProjectService);
|
|
94
130
|
}
|
|
95
131
|
static fromObject(data) {
|
|
96
132
|
return new Project(data);
|
|
97
133
|
}
|
|
98
|
-
static search(
|
|
99
|
-
return __awaiter(this,
|
|
134
|
+
static search() {
|
|
135
|
+
return __awaiter(this, arguments, void 0, function* (params = {}) {
|
|
100
136
|
if (!projectService) {
|
|
101
137
|
throw new Error("Dependency is missing");
|
|
102
138
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Container"), exports);
|
|
18
|
+
__exportStar(require("./DI"), exports);
|
|
19
|
+
__exportStar(require("./FS"), exports);
|
|
20
|
+
__exportStar(require("./FSManager"), exports);
|
|
21
|
+
__exportStar(require("./Logger"), exports);
|
|
22
|
+
__exportStar(require("./Plugin"), exports);
|
|
23
|
+
__exportStar(require("./Preset"), exports);
|
|
24
|
+
__exportStar(require("./Project"), exports);
|
|
25
|
+
__exportStar(require("./Factory"), exports);
|