@wocker/core 1.0.1 → 1.0.3

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/Injectable.d.ts +1 -1
  2. package/lib/decorators/Injectable.js +1 -1
  3. package/lib/index.d.ts +7 -1
  4. package/lib/index.js +7 -1
  5. package/lib/makes/DI.d.ts +0 -1
  6. package/lib/makes/DI.js +5 -5
  7. package/lib/makes/FSManager.d.ts +18 -0
  8. package/lib/makes/FSManager.js +146 -0
  9. package/lib/makes/Logger.d.ts +9 -0
  10. package/lib/makes/Logger.js +23 -0
  11. package/lib/models/Preset.d.ts +46 -0
  12. package/lib/models/Preset.js +44 -0
  13. package/lib/models/Project.d.ts +5 -1
  14. package/lib/models/Project.js +12 -1
  15. package/lib/services/AppConfigService.d.ts +14 -18
  16. package/lib/services/AppConfigService.js +0 -88
  17. package/lib/services/AppEventsService.d.ts +5 -8
  18. package/lib/services/AppEventsService.js +0 -34
  19. package/lib/services/DockerService.d.ts +48 -0
  20. package/lib/services/DockerService.js +6 -0
  21. package/lib/services/LogService.d.ts +7 -0
  22. package/lib/services/LogService.js +6 -0
  23. package/lib/services/PresetService.d.ts +13 -0
  24. package/lib/{decorators/Module.js → services/PresetService.js} +9 -18
  25. package/lib/services/ProjectService.d.ts +10 -9
  26. package/lib/services/ProjectService.js +3 -27
  27. package/lib/types/AppConfig.d.ts +1 -0
  28. package/package.json +5 -4
  29. package/lib/controllers/ProjectController.d.ts +0 -9
  30. package/lib/controllers/ProjectController.js +0 -33
  31. package/lib/decorators/Controller.d.ts +0 -4
  32. package/lib/decorators/Controller.js +0 -28
  33. package/lib/decorators/Module.d.ts +0 -9
  34. package/lib/services/AppConfigInterface.d.ts +0 -0
  35. package/lib/services/AppConfigInterface.js +0 -1
  36. package/lib/services/ConfigService.d.ts +0 -9
  37. package/lib/services/ConfigService.js +0 -43
  38. package/lib/services/DockerInterface.d.ts +0 -2
  39. package/lib/services/DockerInterface.js +0 -3
  40. package/lib/services/ProjectServiceInterface.d.ts +0 -8
  41. package/lib/services/ProjectServiceInterface.js +0 -35
@@ -1,4 +1,4 @@
1
1
  import { DI } from "../makes/DI";
2
- export declare const Injectable: (ddi?: DI) => <T extends new (...rest: any[]) => {}>(Target: T) => {
2
+ export declare const Injectable: () => <T extends new (...rest: any[]) => {}>(Target: T) => {
3
3
  new (di: DI): {};
4
4
  } & T;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Injectable = void 0;
4
- const Injectable = (ddi) => {
4
+ const Injectable = () => {
5
5
  return (Target) => {
6
6
  // @ts-ignore
7
7
  return class extends Target {
package/lib/index.d.ts CHANGED
@@ -3,10 +3,16 @@ export * from "./decorators/Inject";
3
3
  export * from "./decorators/Injectable";
4
4
  export * from "./makes/Controller";
5
5
  export * from "./makes/DI";
6
+ export * from "./makes/FSManager";
7
+ export * from "./makes/Logger";
6
8
  export * from "./makes/Plugin";
9
+ export * from "./models/Preset";
7
10
  export * from "./models/Project";
8
11
  export * from "./services/AppConfigService";
9
12
  export * from "./services/AppEventsService";
13
+ export * from "./services/DockerService";
14
+ export * from "./services/LogService";
15
+ export * from "./services/PresetService";
10
16
  export * from "./services/ProjectService";
11
- export * from "./services/ProjectServiceInterface";
12
17
  export * from "./types/AppConfig";
18
+ export * from "./types/EnvConfig";
package/lib/index.js CHANGED
@@ -21,10 +21,16 @@ __exportStar(require("./decorators/Inject"), exports);
21
21
  __exportStar(require("./decorators/Injectable"), exports);
22
22
  __exportStar(require("./makes/Controller"), exports);
23
23
  __exportStar(require("./makes/DI"), exports);
24
+ __exportStar(require("./makes/FSManager"), exports);
25
+ __exportStar(require("./makes/Logger"), exports);
24
26
  __exportStar(require("./makes/Plugin"), exports);
27
+ __exportStar(require("./models/Preset"), exports);
25
28
  __exportStar(require("./models/Project"), exports);
26
29
  __exportStar(require("./services/AppConfigService"), exports);
27
30
  __exportStar(require("./services/AppEventsService"), exports);
31
+ __exportStar(require("./services/DockerService"), exports);
32
+ __exportStar(require("./services/LogService"), exports);
33
+ __exportStar(require("./services/PresetService"), exports);
28
34
  __exportStar(require("./services/ProjectService"), exports);
29
- __exportStar(require("./services/ProjectServiceInterface"), exports);
30
35
  __exportStar(require("./types/AppConfig"), exports);
36
+ __exportStar(require("./types/EnvConfig"), exports);
package/lib/makes/DI.d.ts CHANGED
@@ -3,6 +3,5 @@ declare class DI {
3
3
  private services;
4
4
  resolveService<T>(key: any): T;
5
5
  registerService(key: any, service: any): void;
6
- use(): void;
7
6
  }
8
7
  export { DI };
package/lib/makes/DI.js CHANGED
@@ -10,9 +10,11 @@ class DI {
10
10
  let res = this.services.get(key);
11
11
  if (!res) {
12
12
  const types = Reflect.getMetadata("design:paramtypes", key);
13
- const params = types ? types.map((type) => {
14
- return this.resolveService(type);
15
- }) : [];
13
+ if (types && types.length > 0) {
14
+ types.forEach((type) => {
15
+ this.resolveService(type);
16
+ });
17
+ }
16
18
  res = new key(this);
17
19
  this.services.set(key, res);
18
20
  }
@@ -21,7 +23,5 @@ class DI {
21
23
  registerService(key, service) {
22
24
  this.services.set(key, service);
23
25
  }
24
- use() {
25
- }
26
26
  }
27
27
  exports.DI = DI;
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ import fs, { createReadStream, MakeDirectoryOptions, RmOptions } from "fs";
3
+ declare class FSManager {
4
+ protected source: string;
5
+ protected destination: string;
6
+ constructor(source: string, destination: string);
7
+ path(...parts: string[]): string;
8
+ mkdir(path: string, options?: MakeDirectoryOptions): Promise<unknown>;
9
+ readdir(path: string): Promise<string[]>;
10
+ exists(path: string): boolean;
11
+ copy(path: string): Promise<void>;
12
+ readJSON(path: string): Promise<any>;
13
+ writeJSON(path: string, data: any): Promise<void>;
14
+ rm(path: string, options?: RmOptions): Promise<unknown>;
15
+ createWriteStream(...parts: string[]): fs.WriteStream;
16
+ createReadStream(path: string, options?: Parameters<typeof createReadStream>[1]): fs.ReadStream;
17
+ }
18
+ export { FSManager };
@@ -0,0 +1,146 @@
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.FSManager = void 0;
36
+ const fs_1 = __importStar(require("fs"));
37
+ const Path = __importStar(require("path"));
38
+ class FSManager {
39
+ constructor(source, destination) {
40
+ this.source = source;
41
+ this.destination = destination;
42
+ }
43
+ path(...parts) {
44
+ return Path.join(this.destination, ...parts);
45
+ }
46
+ mkdir(path, options = {}) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const fullPath = Path.join(this.destination, path);
49
+ return new Promise((resolve, reject) => {
50
+ (0, fs_1.mkdir)(fullPath, options, (err) => {
51
+ if (err) {
52
+ reject(err);
53
+ return;
54
+ }
55
+ resolve(undefined);
56
+ });
57
+ });
58
+ });
59
+ }
60
+ readdir(path) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const filePath = Path.join(this.destination, path);
63
+ return new Promise((resolve, reject) => {
64
+ (0, fs_1.readdir)(filePath, (err, files) => {
65
+ if (err) {
66
+ reject(err);
67
+ return;
68
+ }
69
+ resolve(files);
70
+ });
71
+ });
72
+ });
73
+ }
74
+ exists(path) {
75
+ const fullPath = Path.join(this.destination, path);
76
+ return (0, fs_1.existsSync)(fullPath);
77
+ }
78
+ copy(path) {
79
+ const destination = Path.join(this.destination, path);
80
+ if ((0, fs_1.existsSync)(destination)) {
81
+ return Promise.resolve();
82
+ }
83
+ return new Promise((resolve, reject) => {
84
+ (0, fs_1.copyFile)(Path.join(this.source, path), destination, (err) => {
85
+ if (err) {
86
+ reject(err);
87
+ return;
88
+ }
89
+ resolve(undefined);
90
+ });
91
+ });
92
+ }
93
+ readJSON(path) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ const filePath = Path.join(this.destination, ...path);
96
+ const res = yield new Promise((resolve, reject) => {
97
+ (0, fs_1.readFile)(filePath, (err, data) => {
98
+ if (err) {
99
+ reject(err);
100
+ return;
101
+ }
102
+ resolve(data);
103
+ });
104
+ });
105
+ return JSON.parse(res.toString());
106
+ });
107
+ }
108
+ writeJSON(path, data) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const json = JSON.stringify(data, null, 4);
111
+ const filePath = Path.join(this.destination, path);
112
+ return new Promise((resolve, reject) => {
113
+ (0, fs_1.writeFile)(filePath, json, (err) => {
114
+ if (err) {
115
+ reject(err);
116
+ return;
117
+ }
118
+ resolve(undefined);
119
+ });
120
+ });
121
+ });
122
+ }
123
+ rm(path, options = {}) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const filePath = Path.join(this.destination, path);
126
+ return new Promise((resolve, reject) => {
127
+ fs_1.default.rm(filePath, options, (err) => {
128
+ if (err) {
129
+ reject(err);
130
+ return;
131
+ }
132
+ resolve(undefined);
133
+ });
134
+ });
135
+ });
136
+ }
137
+ createWriteStream(...parts) {
138
+ const filePath = Path.join(this.destination, ...parts);
139
+ return (0, fs_1.createWriteStream)(filePath);
140
+ }
141
+ createReadStream(path, options) {
142
+ const filePath = Path.join(this.destination, path);
143
+ return (0, fs_1.createReadStream)(filePath, options);
144
+ }
145
+ }
146
+ exports.FSManager = FSManager;
@@ -0,0 +1,9 @@
1
+ import { DI } from "./DI";
2
+ declare class Logger {
3
+ static install(di: DI): void;
4
+ static log(...data: any[]): void;
5
+ static info(...data: any[]): void;
6
+ static warning(...data: any[]): void;
7
+ static error(...data: any[]): void;
8
+ }
9
+ export { Logger };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ const LogService_1 = require("../services/LogService");
5
+ let _di;
6
+ class Logger {
7
+ static install(di) {
8
+ _di = di;
9
+ }
10
+ static log(...data) {
11
+ _di.resolveService(LogService_1.LogService).log(...data);
12
+ }
13
+ static info(...data) {
14
+ _di.resolveService(LogService_1.LogService).info(...data);
15
+ }
16
+ static warning(...data) {
17
+ _di.resolveService(LogService_1.LogService).warning(...data);
18
+ }
19
+ static error(...data) {
20
+ _di.resolveService(LogService_1.LogService).error(...data);
21
+ }
22
+ }
23
+ exports.Logger = Logger;
@@ -0,0 +1,46 @@
1
+ import { DI } from "../makes/DI";
2
+ import { PresetServiceSearchOptions as SearchOptions } from "../services/PresetService";
3
+ import { EnvConfig } from "../types/EnvConfig";
4
+ type TextOption = {
5
+ type: "string" | "number" | "int";
6
+ message?: string;
7
+ default?: string | number;
8
+ };
9
+ type ConfirmOption = {
10
+ type: "boolean";
11
+ message?: string;
12
+ default?: boolean;
13
+ };
14
+ type SelectOption = {
15
+ type: "select";
16
+ options: string[] | {
17
+ label?: string;
18
+ value: string;
19
+ }[] | {
20
+ [name: string]: string;
21
+ };
22
+ message?: string;
23
+ default?: string;
24
+ };
25
+ type AnyOption = TextOption | ConfirmOption | SelectOption;
26
+ declare class Preset {
27
+ id: string;
28
+ name: string;
29
+ version: string;
30
+ dockerfile?: string;
31
+ buildArgsOptions?: {
32
+ [name: string]: AnyOption;
33
+ };
34
+ envOptions?: {
35
+ [name: string]: AnyOption;
36
+ };
37
+ volumes?: string[];
38
+ 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<Preset[]>;
44
+ static searchOne(options: SearchOptions): Promise<Preset | null | undefined>;
45
+ }
46
+ export { Preset };
@@ -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.Preset = void 0;
13
+ const PresetService_1 = require("../services/PresetService");
14
+ let _di;
15
+ class Preset {
16
+ constructor(data) {
17
+ this.id = data.id;
18
+ this.name = data.name;
19
+ this.version = data.version;
20
+ this.dockerfile = data.dockerfile;
21
+ this.buildArgsOptions = data.buildArgsOptions;
22
+ this.envOptions = data.envOptions;
23
+ this.volumes = data.volumes;
24
+ this.volumeOptions = data.volumeOptions;
25
+ }
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
+ }
44
+ exports.Preset = Preset;
@@ -11,13 +11,17 @@ declare class Project {
11
11
  name: string;
12
12
  type: string;
13
13
  path: string;
14
+ preset?: string;
14
15
  imageName?: string;
15
16
  dockerfile?: string;
16
- env: EnvConfig;
17
+ scripts?: string[];
17
18
  buildArgs?: EnvConfig;
19
+ env: EnvConfig;
18
20
  volumes?: string[];
21
+ ports?: string[];
19
22
  static di?: DI;
20
23
  constructor(data: any);
24
+ hasEnv(name: string): boolean;
21
25
  getEnv(name: string, defaultValue?: string): string | undefined;
22
26
  setEnv(name: string, value: string | boolean): void;
23
27
  unsetEnv(name: string): void;
@@ -22,9 +22,20 @@ class Project {
22
22
  this.name = data.name;
23
23
  this.type = data.type;
24
24
  this.path = data.path;
25
+ this.preset = data.preset;
26
+ this.dockerfile = data.dockerfile;
25
27
  this.imageName = data.imageName;
26
- this.env = data.env || {};
28
+ this.scripts = data.scripts;
27
29
  this.buildArgs = data.buildArgs;
30
+ this.env = data.env || {};
31
+ this.ports = data.ports;
32
+ this.volumes = data.volumes;
33
+ }
34
+ hasEnv(name) {
35
+ if (!this.env) {
36
+ return false;
37
+ }
38
+ return this.env.hasOwnProperty(name);
28
39
  }
29
40
  getEnv(name, defaultValue) {
30
41
  const { [name]: value = defaultValue } = this.env;
@@ -2,23 +2,19 @@ import { AppConfig } from "../types/AppConfig";
2
2
  type TypeMap = {
3
3
  [type: string]: string;
4
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;
5
+ declare abstract class AppConfigService {
6
+ abstract dataPath(...args: string[]): string;
7
+ abstract pluginsPath(...args: string[]): string;
8
+ abstract getPWD(): string;
9
+ abstract setPWD(pwd: string): void;
10
+ abstract getAppConfig(): Promise<AppConfig>;
11
+ abstract getAllEnvVariables(): Promise<AppConfig["env"]>;
12
+ abstract getEnvVariable(name: string, defaultValue?: string): Promise<string | undefined>;
13
+ abstract setEnvVariable(name: string, value: string | number): Promise<void>;
14
+ abstract setProjectConfig(id: string, path: string): Promise<void>;
15
+ abstract getProjectTypes(): TypeMap;
16
+ abstract registerProjectType(name: string, title?: string): void;
17
+ abstract activatePlugin(name: string): Promise<void>;
18
+ abstract deactivatePlugin(name: string): Promise<void>;
23
19
  }
24
20
  export { AppConfigService };
@@ -1,94 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
35
3
  exports.AppConfigService = void 0;
36
- const Path = __importStar(require("path"));
37
- const FS = __importStar(require("fs"));
38
4
  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
5
  }
94
6
  exports.AppConfigService = AppConfigService;
@@ -1,10 +1,7 @@
1
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>;
2
+ declare abstract class AppEventsService {
3
+ abstract on(event: string, handle: EventHandle): void;
4
+ abstract off(event: string, handle: EventHandle): void;
5
+ abstract emit(event: string, ...args: any[]): Promise<void>;
9
6
  }
10
- export { EventHandle as AppEventHandle, AppEventsService };
7
+ export { AppEventsService, EventHandle as AppEventHandle };
@@ -1,40 +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.AppEventsService = void 0;
13
4
  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
5
  }
40
6
  exports.AppEventsService = AppEventsService;
@@ -0,0 +1,48 @@
1
+ /// <reference types="node" />
2
+ import { Container } from "dockerode";
3
+ declare namespace DockerServiceParams {
4
+ type CreateContainer = {
5
+ name: string;
6
+ image: string;
7
+ restart?: "always";
8
+ projectId?: string;
9
+ tty?: boolean;
10
+ ulimits?: {
11
+ [key: string]: {
12
+ hard?: number;
13
+ soft?: number;
14
+ };
15
+ };
16
+ links?: string[];
17
+ env?: {
18
+ [key: string]: string;
19
+ };
20
+ networkMode?: string;
21
+ extraHosts?: any;
22
+ volumes?: string[];
23
+ ports?: string[];
24
+ cmd?: string[];
25
+ };
26
+ type BuildImage = {
27
+ tag: string;
28
+ buildArgs?: {
29
+ [key: string]: string;
30
+ };
31
+ labels?: {
32
+ [key: string]: string;
33
+ };
34
+ context: string;
35
+ src: string;
36
+ };
37
+ }
38
+ declare abstract class DockerService {
39
+ abstract createContainer(params: DockerServiceParams.CreateContainer): Promise<Container>;
40
+ abstract getContainer(name: string): Promise<Container | null>;
41
+ abstract removeContainer(name: string): Promise<void>;
42
+ abstract buildImage(params: DockerServiceParams.BuildImage): Promise<any>;
43
+ abstract imageExists(tag: string): Promise<boolean>;
44
+ abstract imageRm(tag: string): Promise<void>;
45
+ abstract pullImage(tag: string): Promise<void>;
46
+ abstract attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
47
+ }
48
+ export { DockerService, DockerServiceParams };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DockerService = void 0;
4
+ class DockerService {
5
+ }
6
+ exports.DockerService = DockerService;
@@ -0,0 +1,7 @@
1
+ declare abstract class LogService {
2
+ abstract log(...data: any[]): void;
3
+ abstract info(...data: any[]): void;
4
+ abstract warning(...data: any[]): void;
5
+ abstract error(...data: any[]): void;
6
+ }
7
+ export { LogService };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogService = void 0;
4
+ class LogService {
5
+ }
6
+ exports.LogService = LogService;
@@ -0,0 +1,13 @@
1
+ import { Preset } from "../models/Preset";
2
+ import { EnvConfig } from "../types/EnvConfig";
3
+ type SearchOptions = Partial<{
4
+ name: string;
5
+ }>;
6
+ declare abstract class PresetService {
7
+ abstract getImageName(preset: Preset, buildArgs?: EnvConfig): string;
8
+ abstract save(preset: Preset): Promise<void>;
9
+ abstract get(name: string): Promise<Preset | null>;
10
+ abstract search(options?: SearchOptions): Promise<Preset[]>;
11
+ searchOne(options?: SearchOptions): Promise<Preset | null | undefined>;
12
+ }
13
+ export { PresetService, SearchOptions as PresetServiceSearchOptions };
@@ -9,22 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
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
- //
12
+ exports.PresetService = void 0;
13
+ class PresetService {
14
+ searchOne(options) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const [preset] = yield this.search(options);
17
+ return preset || null;
18
+ });
19
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;
20
+ }
21
+ exports.PresetService = PresetService;
@@ -1,15 +1,16 @@
1
1
  import { Project } from "../models/Project";
2
- type SearchParams = {
2
+ type SearchParams = Partial<{
3
3
  id: string;
4
4
  name: string;
5
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[]>;
6
+ }>;
7
+ declare abstract class ProjectService {
8
+ abstract cdProject(name: string): Promise<void>;
9
+ abstract get(): Promise<Project>;
10
+ abstract start(project: Project): Promise<void>;
11
+ abstract stop(project: Project): Promise<void>;
12
+ abstract save(project: Project): Promise<void>;
13
+ abstract search(params: SearchParams): Promise<Project[]>;
14
+ searchOne(params?: SearchParams): Promise<Project | null>;
14
15
  }
15
16
  export { ProjectService, SearchParams as ProjectServiceSearchParams };
@@ -11,34 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ProjectService = void 0;
13
13
  class ProjectService {
14
- cdProject(name) {
14
+ searchOne(params = {}) {
15
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");
16
+ const [project] = yield this.search(params);
17
+ return project || null;
42
18
  });
43
19
  }
44
20
  }
@@ -2,6 +2,7 @@ import { EnvConfig } from "./EnvConfig";
2
2
  export type AppConfig = {
3
3
  debug?: boolean;
4
4
  env: EnvConfig;
5
+ plugins: string[];
5
6
  projects: {
6
7
  id: string;
7
8
  name?: string;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
+ "author": "Kris Papercut <krispcut@gmail.com>",
4
5
  "description": "Wocker Core",
6
+ "license": "MIT",
5
7
  "main": "lib/index.js",
6
8
  "types": "lib/index.d.ts",
7
- "author": "Kris Papercut <krispcut@gmail.com>",
8
- "license": "MIT",
9
9
  "scripts": {
10
10
  "prepare": "npm run build",
11
11
  "watch": "tsc -w",
@@ -13,12 +13,13 @@
13
13
  "test": "echo \"Error: no test specified\" && exit 1"
14
14
  },
15
15
  "dependencies": {
16
- "@kearisp/cli": "^1.0.2",
16
+ "@kearisp/cli": "^1.0.3",
17
17
  "fs": "^0.0.1-security",
18
18
  "path": "^0.12.7",
19
19
  "reflect-metadata": "^0.1.13"
20
20
  },
21
21
  "devDependencies": {
22
+ "@types/dockerode": "^3.3.23",
22
23
  "@types/node": "^20.8.9",
23
24
  "typescript": "^5.2.2"
24
25
  }
@@ -1,9 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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);
@@ -1,4 +0,0 @@
1
- import "reflect-metadata";
2
- export declare const Controller: () => <T extends new (...rest: any[]) => {}>(Target: T) => {
3
- new (): {};
4
- } & T;
@@ -1,28 +0,0 @@
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;
@@ -1,9 +0,0 @@
1
- type Options = {
2
- services: any[];
3
- };
4
- export declare const Module: (options: Options) => <T extends new () => {}>(Target: T) => {
5
- new (): {
6
- run(parts: string[]): Promise<void>;
7
- };
8
- } & T;
9
- export {};
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,9 +0,0 @@
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 };
@@ -1,43 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- declare class DockerInterface {
2
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- class DockerInterface {
3
- }
@@ -1,8 +0,0 @@
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 };
@@ -1,35 +0,0 @@
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;