@wocker/core 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/lib/controllers/ProjectController.d.ts +9 -0
- package/lib/controllers/ProjectController.js +33 -0
- package/lib/decorators/Controller.d.ts +4 -0
- package/lib/decorators/Controller.js +28 -0
- package/lib/decorators/Inject.d.ts +1 -0
- package/lib/decorators/Inject.js +8 -0
- package/lib/decorators/Injectable.d.ts +4 -0
- package/lib/decorators/Injectable.js +18 -0
- package/lib/decorators/Module.d.ts +9 -0
- package/lib/decorators/Module.js +30 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +30 -0
- package/lib/makes/Controller.d.ts +5 -0
- package/lib/makes/Controller.js +9 -0
- package/lib/makes/DI.d.ts +8 -0
- package/lib/makes/DI.js +27 -0
- package/lib/makes/FS.d.ts +7 -0
- package/lib/makes/FS.js +44 -0
- package/lib/makes/Plugin.d.ts +6 -0
- package/lib/makes/Plugin.js +10 -0
- package/lib/models/Project.d.ts +36 -0
- package/lib/models/Project.js +104 -0
- package/lib/services/AppConfigInterface.d.ts +0 -0
- package/lib/services/AppConfigInterface.js +1 -0
- package/lib/services/AppConfigService.d.ts +24 -0
- package/lib/services/AppConfigService.js +94 -0
- package/lib/services/AppEventsService.d.ts +10 -0
- package/lib/services/AppEventsService.js +40 -0
- package/lib/services/ConfigService.d.ts +9 -0
- package/lib/services/ConfigService.js +43 -0
- package/lib/services/DockerInterface.d.ts +2 -0
- package/lib/services/DockerInterface.js +3 -0
- package/lib/services/ProjectService.d.ts +15 -0
- package/lib/services/ProjectService.js +45 -0
- package/lib/services/ProjectServiceInterface.d.ts +8 -0
- package/lib/services/ProjectServiceInterface.js +35 -0
- package/lib/types/AppConfig.d.ts +10 -0
- package/lib/types/AppConfig.js +2 -0
- package/lib/types/EnvConfig.d.ts +3 -0
- package/lib/types/EnvConfig.js +2 -0
- package/lib/utils/volumeFormat.d.ts +6 -0
- package/lib/utils/volumeFormat.js +8 -0
- package/lib/utils/volumeParse.d.ts +2 -0
- package/lib/utils/volumeParse.js +13 -0
- package/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Kris Papercut
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @wocker/core
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Cli } from "@kearisp/cli";
|
|
2
|
+
import { ConfigService } from "../services/ConfigService";
|
|
3
|
+
import { Controller } from "../makes/Controller";
|
|
4
|
+
export declare class ProjectController extends Controller {
|
|
5
|
+
protected configService: ConfigService;
|
|
6
|
+
constructor(configService: ConfigService);
|
|
7
|
+
install(cli: Cli): void;
|
|
8
|
+
test(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProjectController = void 0;
|
|
13
|
+
const Injectable_1 = require("../decorators/Injectable");
|
|
14
|
+
const ConfigService_1 = require("../services/ConfigService");
|
|
15
|
+
const Controller_1 = require("../makes/Controller");
|
|
16
|
+
let ProjectController = class ProjectController extends Controller_1.Controller {
|
|
17
|
+
constructor(configService) {
|
|
18
|
+
super();
|
|
19
|
+
this.configService = configService;
|
|
20
|
+
}
|
|
21
|
+
install(cli) {
|
|
22
|
+
super.install(cli);
|
|
23
|
+
cli.command("test").action(() => this.test());
|
|
24
|
+
}
|
|
25
|
+
test() {
|
|
26
|
+
return this.configService.dataPath("data");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.ProjectController = ProjectController;
|
|
30
|
+
exports.ProjectController = ProjectController = __decorate([
|
|
31
|
+
(0, Injectable_1.Injectable)(),
|
|
32
|
+
__metadata("design:paramtypes", [ConfigService_1.ConfigService])
|
|
33
|
+
], ProjectController);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Controller = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DI_1 = require("../makes/DI");
|
|
6
|
+
const di = new DI_1.DI();
|
|
7
|
+
const Controller = () => {
|
|
8
|
+
// return (Target: any) => {
|
|
9
|
+
// const types = Reflect.getMetadata("design:paramtypes", Target);
|
|
10
|
+
//
|
|
11
|
+
// const params = types.map((type: any) => {
|
|
12
|
+
// return di.resolveService(type);
|
|
13
|
+
// });
|
|
14
|
+
// };
|
|
15
|
+
return (Target) => {
|
|
16
|
+
const types = Reflect.getMetadata("design:paramtypes", Target);
|
|
17
|
+
const params = types.map((type) => {
|
|
18
|
+
return di.resolveService(type);
|
|
19
|
+
});
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
return class extends Target {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...params);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.Controller = Controller;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Inject: () => (target: any) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Injectable = void 0;
|
|
4
|
+
const Injectable = (ddi) => {
|
|
5
|
+
return (Target) => {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
return class extends Target {
|
|
8
|
+
constructor(di) {
|
|
9
|
+
const types = Reflect.getMetadata("design:paramtypes", Target);
|
|
10
|
+
const params = types.map((type) => {
|
|
11
|
+
return (di).resolveService(type);
|
|
12
|
+
});
|
|
13
|
+
super(...params);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.Injectable = Injectable;
|
|
@@ -0,0 +1,30 @@
|
|
|
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.Module = void 0;
|
|
13
|
+
const DI_1 = require("../makes/DI");
|
|
14
|
+
const Module = (options) => {
|
|
15
|
+
const { services = [] } = options;
|
|
16
|
+
const di = new DI_1.DI();
|
|
17
|
+
for (const service of services) {
|
|
18
|
+
//
|
|
19
|
+
}
|
|
20
|
+
return (Target) => {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
return class extends Target {
|
|
23
|
+
run(parts) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.Module = Module;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Cli } from "@kearisp/cli";
|
|
2
|
+
export * from "./decorators/Inject";
|
|
3
|
+
export * from "./decorators/Injectable";
|
|
4
|
+
export * from "./makes/Controller";
|
|
5
|
+
export * from "./makes/DI";
|
|
6
|
+
export * from "./makes/Plugin";
|
|
7
|
+
export * from "./models/Project";
|
|
8
|
+
export * from "./services/AppConfigService";
|
|
9
|
+
export * from "./services/AppEventsService";
|
|
10
|
+
export * from "./services/ProjectService";
|
|
11
|
+
export * from "./services/ProjectServiceInterface";
|
|
12
|
+
export * from "./types/AppConfig";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
exports.Cli = void 0;
|
|
18
|
+
var cli_1 = require("@kearisp/cli");
|
|
19
|
+
Object.defineProperty(exports, "Cli", { enumerable: true, get: function () { return cli_1.Cli; } });
|
|
20
|
+
__exportStar(require("./decorators/Inject"), exports);
|
|
21
|
+
__exportStar(require("./decorators/Injectable"), exports);
|
|
22
|
+
__exportStar(require("./makes/Controller"), exports);
|
|
23
|
+
__exportStar(require("./makes/DI"), exports);
|
|
24
|
+
__exportStar(require("./makes/Plugin"), exports);
|
|
25
|
+
__exportStar(require("./models/Project"), exports);
|
|
26
|
+
__exportStar(require("./services/AppConfigService"), exports);
|
|
27
|
+
__exportStar(require("./services/AppEventsService"), exports);
|
|
28
|
+
__exportStar(require("./services/ProjectService"), exports);
|
|
29
|
+
__exportStar(require("./services/ProjectServiceInterface"), exports);
|
|
30
|
+
__exportStar(require("./types/AppConfig"), exports);
|
package/lib/makes/DI.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
const params = types ? types.map((type) => {
|
|
14
|
+
return this.resolveService(type);
|
|
15
|
+
}) : [];
|
|
16
|
+
res = new key(this);
|
|
17
|
+
this.services.set(key, res);
|
|
18
|
+
}
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
21
|
+
registerService(key, service) {
|
|
22
|
+
this.services.set(key, service);
|
|
23
|
+
}
|
|
24
|
+
use() {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.DI = DI;
|
package/lib/makes/FS.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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.FS = void 0;
|
|
13
|
+
const fs_1 = require("fs");
|
|
14
|
+
class FS {
|
|
15
|
+
static readJSON(filePath) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const res = yield new Promise((resolve, reject) => {
|
|
18
|
+
(0, fs_1.readFile)(filePath, (err, data) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
reject(err);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
resolve(data);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
return JSON.parse(res.toString());
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
static writeJSON(filePath, data) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const json = JSON.stringify(data, null, 4);
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
(0, fs_1.writeFile)(filePath, json, (err) => {
|
|
34
|
+
if (err) {
|
|
35
|
+
reject(err);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
resolve(undefined);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.FS = FS;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Plugin = void 0;
|
|
4
|
+
const Controller_1 = require("./Controller");
|
|
5
|
+
class Plugin extends Controller_1.Controller {
|
|
6
|
+
install(cli) {
|
|
7
|
+
super.install(cli);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.Plugin = Plugin;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { DI } from "../makes/DI";
|
|
3
|
+
import { EnvConfig } from "../types/EnvConfig";
|
|
4
|
+
type SearchOptions = {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
path: string;
|
|
8
|
+
};
|
|
9
|
+
declare class Project {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
path: string;
|
|
14
|
+
imageName?: string;
|
|
15
|
+
dockerfile?: string;
|
|
16
|
+
env: EnvConfig;
|
|
17
|
+
buildArgs?: EnvConfig;
|
|
18
|
+
volumes?: string[];
|
|
19
|
+
static di?: DI;
|
|
20
|
+
constructor(data: any);
|
|
21
|
+
getEnv(name: string, defaultValue?: string): string | undefined;
|
|
22
|
+
setEnv(name: string, value: string | boolean): void;
|
|
23
|
+
unsetEnv(name: string): void;
|
|
24
|
+
volumeMount(...volumes: string[]): void;
|
|
25
|
+
getVolumeBySource(source: string): string | undefined;
|
|
26
|
+
getVolumeByDestination(destination: string): string | undefined;
|
|
27
|
+
volumeUnmount(...volumes: string[]): void;
|
|
28
|
+
save(): Promise<void>;
|
|
29
|
+
static install(di: DI): void;
|
|
30
|
+
static fromObject(data: any): Project;
|
|
31
|
+
static search(params?: Partial<SearchOptions>): Promise<Project[]>;
|
|
32
|
+
static searchOne(params: Partial<SearchOptions>): Promise<Project | null>;
|
|
33
|
+
}
|
|
34
|
+
export { Project };
|
|
35
|
+
export declare const PROJECT_TYPE_DOCKERFILE = "dockerfile";
|
|
36
|
+
export declare const PROJECT_TYPE_IMAGE = "image";
|
|
@@ -0,0 +1,104 @@
|
|
|
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.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
|
+
const volumeParse_1 = require("../utils/volumeParse");
|
|
17
|
+
let appConfig;
|
|
18
|
+
let projectService;
|
|
19
|
+
class Project {
|
|
20
|
+
constructor(data) {
|
|
21
|
+
this.id = data.id;
|
|
22
|
+
this.name = data.name;
|
|
23
|
+
this.type = data.type;
|
|
24
|
+
this.path = data.path;
|
|
25
|
+
this.imageName = data.imageName;
|
|
26
|
+
this.env = data.env || {};
|
|
27
|
+
this.buildArgs = data.buildArgs;
|
|
28
|
+
}
|
|
29
|
+
getEnv(name, defaultValue) {
|
|
30
|
+
const { [name]: value = defaultValue } = this.env;
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
setEnv(name, value) {
|
|
34
|
+
this.env = Object.assign(Object.assign({}, this.env), { [name]: typeof value === "boolean"
|
|
35
|
+
? (value ? "true" : "false")
|
|
36
|
+
: value });
|
|
37
|
+
}
|
|
38
|
+
unsetEnv(name) {
|
|
39
|
+
if (name in this.env) {
|
|
40
|
+
delete this.env[name];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
volumeMount(...volumes) {
|
|
44
|
+
if (volumes.length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const [volume, ...restVolumes] = volumes;
|
|
48
|
+
const { destination } = (0, volumeParse_1.volumeParse)(volume);
|
|
49
|
+
this.volumes = [
|
|
50
|
+
...(this.volumes || []).filter((v) => {
|
|
51
|
+
return v !== this.getVolumeByDestination(destination);
|
|
52
|
+
}),
|
|
53
|
+
volume
|
|
54
|
+
];
|
|
55
|
+
this.volumeMount(...restVolumes);
|
|
56
|
+
}
|
|
57
|
+
getVolumeBySource(source) {
|
|
58
|
+
return (this.volumes || []).find((volume) => {
|
|
59
|
+
return (0, volumeParse_1.volumeParse)(volume).source === source;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
getVolumeByDestination(destination) {
|
|
63
|
+
return (this.volumes || []).find((volume) => {
|
|
64
|
+
return (0, volumeParse_1.volumeParse)(volume).destination === destination;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
volumeUnmount(...volumes) {
|
|
68
|
+
this.volumes = (this.volumes || []).filter((mounted) => {
|
|
69
|
+
return !volumes.includes(mounted);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
save() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
if (!projectService) {
|
|
75
|
+
throw new Error("Dependency is missing");
|
|
76
|
+
}
|
|
77
|
+
yield projectService.save(this);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
static install(di) {
|
|
81
|
+
appConfig = di.resolveService(AppConfigService_1.AppConfigService);
|
|
82
|
+
projectService = di.resolveService(ProjectService_1.ProjectService);
|
|
83
|
+
}
|
|
84
|
+
static fromObject(data) {
|
|
85
|
+
return new Project(data);
|
|
86
|
+
}
|
|
87
|
+
static search(params = {}) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
if (!projectService) {
|
|
90
|
+
throw new Error("Dependency is missing");
|
|
91
|
+
}
|
|
92
|
+
return projectService.search(params);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
static searchOne(params) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const [project] = yield Project.search(params);
|
|
98
|
+
return project || null;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.Project = Project;
|
|
103
|
+
exports.PROJECT_TYPE_DOCKERFILE = "dockerfile";
|
|
104
|
+
exports.PROJECT_TYPE_IMAGE = "image";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AppConfig } from "../types/AppConfig";
|
|
2
|
+
type TypeMap = {
|
|
3
|
+
[type: string]: string;
|
|
4
|
+
};
|
|
5
|
+
declare class AppConfigService {
|
|
6
|
+
protected DATA_DIR: string;
|
|
7
|
+
protected PLUGINS_DIR: string;
|
|
8
|
+
protected MAP_PATH: string;
|
|
9
|
+
protected pwd: string;
|
|
10
|
+
protected mapTypes: TypeMap;
|
|
11
|
+
constructor(DATA_DIR: string, PLUGINS_DIR: string, MAP_PATH: string);
|
|
12
|
+
dataPath(...args: string[]): string;
|
|
13
|
+
pluginsPath(...args: string[]): string;
|
|
14
|
+
getData(): string;
|
|
15
|
+
getPWD(): string;
|
|
16
|
+
setPWD(pwd: string): void;
|
|
17
|
+
getAppConfig(): Promise<AppConfig>;
|
|
18
|
+
setProject(): Promise<void>;
|
|
19
|
+
getAllEnvVariables(): Promise<AppConfig["env"]>;
|
|
20
|
+
getEnvVariable(name: string, defaultValue?: string): Promise<string | undefined>;
|
|
21
|
+
setProjectConfig(id: string, path: string): Promise<void>;
|
|
22
|
+
getProjectTypes(): TypeMap;
|
|
23
|
+
}
|
|
24
|
+
export { AppConfigService };
|
|
@@ -0,0 +1,94 @@
|
|
|
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.AppConfigService = void 0;
|
|
36
|
+
const Path = __importStar(require("path"));
|
|
37
|
+
const FS = __importStar(require("fs"));
|
|
38
|
+
class AppConfigService {
|
|
39
|
+
constructor(DATA_DIR, PLUGINS_DIR, MAP_PATH) {
|
|
40
|
+
this.DATA_DIR = DATA_DIR;
|
|
41
|
+
this.PLUGINS_DIR = PLUGINS_DIR;
|
|
42
|
+
this.MAP_PATH = MAP_PATH;
|
|
43
|
+
this.mapTypes = {
|
|
44
|
+
image: "Image",
|
|
45
|
+
dockerfile: "Dockerfile"
|
|
46
|
+
};
|
|
47
|
+
this.pwd = (process.cwd() || process.env.PWD);
|
|
48
|
+
}
|
|
49
|
+
dataPath(...args) {
|
|
50
|
+
return Path.join(this.DATA_DIR, ...args);
|
|
51
|
+
}
|
|
52
|
+
pluginsPath(...args) {
|
|
53
|
+
return Path.join(this.PLUGINS_DIR, ...args);
|
|
54
|
+
}
|
|
55
|
+
getData() {
|
|
56
|
+
return "Test";
|
|
57
|
+
}
|
|
58
|
+
getPWD() {
|
|
59
|
+
return this.pwd;
|
|
60
|
+
}
|
|
61
|
+
setPWD(pwd) {
|
|
62
|
+
this.pwd = pwd;
|
|
63
|
+
}
|
|
64
|
+
getAppConfig() {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const content = yield FS.promises.readFile(this.MAP_PATH);
|
|
67
|
+
return JSON.parse(content.toString());
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
setProject() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
//
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
getAllEnvVariables() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return {};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getEnvVariable(name, defaultValue) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
return undefined;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
setProjectConfig(id, path) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
throw new Error("");
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getProjectTypes() {
|
|
91
|
+
return this.mapTypes;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.AppConfigService = AppConfigService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type EventHandle = (...args: any[]) => Promise<void> | void;
|
|
2
|
+
declare class AppEventsService {
|
|
3
|
+
protected handles: ({
|
|
4
|
+
[event: string]: EventHandle[];
|
|
5
|
+
});
|
|
6
|
+
on(event: string, handle: EventHandle): () => void;
|
|
7
|
+
off(event: string, handle: EventHandle): void;
|
|
8
|
+
emit(event: string, ...args: any[]): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export { EventHandle as AppEventHandle, AppEventsService };
|
|
@@ -0,0 +1,40 @@
|
|
|
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.AppEventsService = void 0;
|
|
13
|
+
class AppEventsService {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.handles = {};
|
|
16
|
+
}
|
|
17
|
+
on(event, handle) {
|
|
18
|
+
this.handles[event] = [
|
|
19
|
+
...this.handles[event] || [],
|
|
20
|
+
handle
|
|
21
|
+
];
|
|
22
|
+
return () => {
|
|
23
|
+
this.handles[event] = this.handles[event].filter((filterHandle) => {
|
|
24
|
+
return filterHandle !== handle;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
off(event, handle) {
|
|
29
|
+
//
|
|
30
|
+
}
|
|
31
|
+
emit(event, ...args) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const handles = this.handles[event] || [];
|
|
34
|
+
for (const i in handles) {
|
|
35
|
+
yield handles[i](...args);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.AppEventsService = AppEventsService;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare class ConfigService {
|
|
2
|
+
protected DATA_DIR: string;
|
|
3
|
+
protected PLUGINS_DIR: string;
|
|
4
|
+
constructor(DATA_DIR: string, PLUGINS_DIR: string);
|
|
5
|
+
dataPath(...args: string[]): string;
|
|
6
|
+
pluginsPath(...args: string[]): string;
|
|
7
|
+
getData(): string;
|
|
8
|
+
}
|
|
9
|
+
export { ConfigService };
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ConfigService = void 0;
|
|
27
|
+
const Path = __importStar(require("path"));
|
|
28
|
+
class ConfigService {
|
|
29
|
+
constructor(DATA_DIR, PLUGINS_DIR) {
|
|
30
|
+
this.DATA_DIR = DATA_DIR;
|
|
31
|
+
this.PLUGINS_DIR = PLUGINS_DIR;
|
|
32
|
+
}
|
|
33
|
+
dataPath(...args) {
|
|
34
|
+
return Path.join(this.DATA_DIR, ...args);
|
|
35
|
+
}
|
|
36
|
+
pluginsPath(...args) {
|
|
37
|
+
return Path.join(this.PLUGINS_DIR, ...args);
|
|
38
|
+
}
|
|
39
|
+
getData() {
|
|
40
|
+
return "Test";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ConfigService = ConfigService;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Project } from "../models/Project";
|
|
2
|
+
type SearchParams = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
};
|
|
7
|
+
declare class ProjectService {
|
|
8
|
+
cdProject(name: string): Promise<void>;
|
|
9
|
+
get(): Promise<Project>;
|
|
10
|
+
start(project: Project): Promise<void>;
|
|
11
|
+
stop(project: Project): Promise<void>;
|
|
12
|
+
save(project: Project): Promise<void>;
|
|
13
|
+
search(params?: Partial<SearchParams>): Promise<Project[]>;
|
|
14
|
+
}
|
|
15
|
+
export { ProjectService, SearchParams as ProjectServiceSearchParams };
|
|
@@ -0,0 +1,45 @@
|
|
|
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.ProjectService = void 0;
|
|
13
|
+
class ProjectService {
|
|
14
|
+
cdProject(name) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
throw new Error("Project not found");
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
get() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
throw new Error("Project not found");
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
start(project) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
throw new Error("Project not found");
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
stop(project) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
throw new Error("Project not found");
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
save(project) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
throw new Error("Dependency is missing");
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
search(params = {}) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
throw new Error("Dependency is missing");
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ProjectService = ProjectService;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Project } from "../models/Project";
|
|
2
|
+
declare class ProjectServiceInterface {
|
|
3
|
+
cdProject(name: string): Promise<void>;
|
|
4
|
+
get(): Promise<Project>;
|
|
5
|
+
start(project: Project): Promise<void>;
|
|
6
|
+
stop(project: Project): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export { ProjectServiceInterface };
|
|
@@ -0,0 +1,35 @@
|
|
|
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.ProjectServiceInterface = void 0;
|
|
13
|
+
class ProjectServiceInterface {
|
|
14
|
+
cdProject(name) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
throw new Error("Project not found");
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
get() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
throw new Error("Project not found");
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
start(project) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
throw new Error("Project not found");
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
stop(project) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
throw new Error("Project not found");
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ProjectServiceInterface = ProjectServiceInterface;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.volumeFormat = void 0;
|
|
4
|
+
const volumeFormat = (volume) => {
|
|
5
|
+
const { source, destination, options } = volume;
|
|
6
|
+
return `${source}:${destination}` + (options ? `:${options}` : "");
|
|
7
|
+
};
|
|
8
|
+
exports.volumeFormat = volumeFormat;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.volumeParse = void 0;
|
|
4
|
+
const volumeParse = (volume) => {
|
|
5
|
+
const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
|
|
6
|
+
const [, source, destination, options] = regVolume.exec(volume) || [];
|
|
7
|
+
return {
|
|
8
|
+
source,
|
|
9
|
+
destination,
|
|
10
|
+
options
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.volumeParse = volumeParse;
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wocker/core",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Wocker Core",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"author": "Kris Papercut <krispcut@gmail.com>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prepare": "npm run build",
|
|
11
|
+
"watch": "tsc -w",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@kearisp/cli": "^1.0.2",
|
|
17
|
+
"fs": "^0.0.1-security",
|
|
18
|
+
"path": "^0.12.7",
|
|
19
|
+
"reflect-metadata": "^0.1.13"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^20.8.9",
|
|
23
|
+
"typescript": "^5.2.2"
|
|
24
|
+
}
|
|
25
|
+
}
|