@wocker/ws 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 (136) hide show
  1. package/README.md +11 -137
  2. package/bin/ws.js +7 -3
  3. package/lib/App.d.ts +10 -7
  4. package/lib/App.js +99 -44
  5. package/lib/controllers/ImageController.d.ts +4 -2
  6. package/lib/controllers/ImageController.js +27 -25
  7. package/lib/controllers/PluginController.d.ts +14 -0
  8. package/lib/controllers/PluginController.js +84 -0
  9. package/lib/controllers/PresetController.d.ts +21 -0
  10. package/lib/controllers/PresetController.js +169 -0
  11. package/lib/controllers/ProjectController.d.ts +11 -3
  12. package/lib/controllers/ProjectController.js +653 -536
  13. package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +12 -11
  14. package/lib/controllers/ProxyController.js +273 -0
  15. package/lib/controllers/index.d.ts +3 -0
  16. package/lib/controllers/index.js +19 -25
  17. package/lib/env.js +33 -22
  18. package/lib/index.d.ts +2 -0
  19. package/lib/index.js +29 -28
  20. package/lib/makes/Controller.js +4 -8
  21. package/lib/makes/DI.d.ts +7 -0
  22. package/lib/makes/DI.js +27 -0
  23. package/lib/makes/Docker.js +299 -397
  24. package/lib/makes/FS.d.ts +1 -1
  25. package/lib/makes/FS.js +328 -301
  26. package/lib/makes/LineConvertStream.js +37 -40
  27. package/lib/makes/Logger.d.ts +5 -3
  28. package/lib/makes/Logger.js +18 -34
  29. package/lib/makes/Model.js +8 -12
  30. package/lib/makes/MySQL.js +6 -27
  31. package/lib/makes/Plugin.d.ts +1 -1
  32. package/lib/makes/Plugin.js +55 -37
  33. package/lib/makes/Preset.d.ts +46 -0
  34. package/lib/makes/Preset.js +33 -0
  35. package/lib/{models → makes}/Project.d.ts +23 -16
  36. package/lib/makes/Project.js +127 -0
  37. package/lib/makes/Repository.js +18 -21
  38. package/lib/makes/index.d.ts +3 -0
  39. package/lib/makes/index.js +23 -69
  40. package/lib/plugins/ElasticSearchPlugin.d.ts +18 -0
  41. package/lib/plugins/ElasticSearchPlugin.js +72 -0
  42. package/lib/plugins/LocaltunnelPlugin.d.ts +4 -4
  43. package/lib/plugins/LocaltunnelPlugin.js +256 -255
  44. package/lib/plugins/MaildevPlugin.d.ts +4 -2
  45. package/lib/plugins/MaildevPlugin.js +45 -41
  46. package/lib/plugins/MongodbPlugin.d.ts +6 -4
  47. package/lib/plugins/MongodbPlugin.js +303 -254
  48. package/lib/plugins/NgrokPlugin.d.ts +3 -4
  49. package/lib/plugins/NgrokPlugin.js +221 -230
  50. package/lib/plugins/PageKitePlugin.d.ts +3 -4
  51. package/lib/plugins/PageKitePlugin.js +150 -147
  52. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  53. package/lib/plugins/PostgresPlugin.js +115 -88
  54. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  55. package/lib/plugins/ProxmoxPlugin.js +50 -38
  56. package/lib/plugins/RedisPlugin.d.ts +10 -2
  57. package/lib/plugins/RedisPlugin.js +77 -39
  58. package/lib/plugins/index.d.ts +2 -6
  59. package/lib/plugins/index.js +25 -158
  60. package/lib/services/AppConfigService.d.ts +13 -3
  61. package/lib/services/AppConfigService.js +161 -71
  62. package/lib/services/AppEventsService.d.ts +5 -8
  63. package/lib/services/AppEventsService.js +26 -25
  64. package/lib/services/DockerService.d.ts +51 -0
  65. package/lib/services/DockerService.js +200 -0
  66. package/lib/services/LogService.d.ts +12 -0
  67. package/lib/services/LogService.js +38 -0
  68. package/lib/services/PluginService.d.ts +11 -0
  69. package/lib/services/PluginService.js +15 -0
  70. package/lib/services/PresetService.d.ts +14 -0
  71. package/lib/services/PresetService.js +64 -0
  72. package/lib/services/ProjectService.d.ts +12 -4
  73. package/lib/services/ProjectService.js +141 -78
  74. package/lib/services/index.d.ts +4 -0
  75. package/lib/services/index.js +21 -36
  76. package/lib/types/Config.d.ts +4 -3
  77. package/lib/types/Config.js +1 -4
  78. package/lib/types/EnvConfig.js +1 -4
  79. package/lib/types/index.js +16 -25
  80. package/lib/utils/buildOptions.js +5 -8
  81. package/lib/utils/demuxOutput.js +16 -22
  82. package/lib/utils/escapeRegExp.js +4 -7
  83. package/lib/utils/exec.d.ts +1 -1
  84. package/lib/utils/exec.js +38 -40
  85. package/lib/utils/fetch.js +45 -30
  86. package/lib/utils/followProgress.js +66 -77
  87. package/lib/utils/format-size-units.js +16 -16
  88. package/lib/utils/get-config.d.ts +1 -1
  89. package/lib/utils/get-config.js +13 -16
  90. package/lib/utils/get-cursor-position.js +22 -29
  91. package/lib/utils/image-build.js +35 -23
  92. package/lib/utils/index.d.ts +0 -4
  93. package/lib/utils/index.js +32 -235
  94. package/lib/utils/injectVariables.js +10 -13
  95. package/lib/utils/parse-table.js +20 -23
  96. package/lib/utils/set-config.d.ts +1 -1
  97. package/lib/utils/set-config.js +12 -15
  98. package/lib/utils/spawn.js +17 -20
  99. package/lib/utils/tty.js +2 -6
  100. package/lib/utils/volumeFormat.js +5 -12
  101. package/lib/utils/volumeParse.js +10 -13
  102. package/package.json +21 -47
  103. package/presets/bun/Dockerfile +11 -0
  104. package/presets/bun/config.json +3 -0
  105. package/presets/node/Dockerfile +4 -2
  106. package/presets/node/config.json +9 -7
  107. package/presets/php-apache/Dockerfile +40 -38
  108. package/presets/php-apache/config.json +10 -15
  109. package/presets/php-fpm/Dockerfile +21 -0
  110. package/presets/php-fpm/config.json +25 -0
  111. package/lib/models/Preset.d.ts +0 -19
  112. package/lib/models/Preset.js +0 -60
  113. package/lib/models/Project.js +0 -151
  114. package/lib/models/index.d.ts +0 -2
  115. package/lib/models/index.js +0 -27
  116. package/lib/plugins/MariadbPlugin.d.ts +0 -25
  117. package/lib/plugins/MariadbPlugin.js +0 -297
  118. package/lib/plugins/PresetPlugin.d.ts +0 -19
  119. package/lib/plugins/PresetPlugin.js +0 -164
  120. package/lib/plugins/ProjectPlugin.d.ts +0 -12
  121. package/lib/plugins/ProjectPlugin.js +0 -54
  122. package/lib/plugins/ProxyPlugin.js +0 -257
  123. package/lib/plugins/ServeoPlugin.d.ts +0 -36
  124. package/lib/plugins/ServeoPlugin.js +0 -260
  125. package/lib/plugins/TestPlugin.d.ts +0 -10
  126. package/lib/plugins/TestPlugin.js +0 -75
  127. package/lib/utils/promptConfirm.d.ts +0 -6
  128. package/lib/utils/promptConfirm.js +0 -21
  129. package/lib/utils/promptGroup.d.ts +0 -16
  130. package/lib/utils/promptGroup.js +0 -39
  131. package/lib/utils/promptSelect.d.ts +0 -12
  132. package/lib/utils/promptSelect.js +0 -47
  133. package/lib/utils/promptText.d.ts +0 -13
  134. package/lib/utils/promptText.js +0 -53
  135. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
  136. package/plugins/serveo/Dockerfile +0 -17
@@ -1,45 +1,42 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.LineConvertStream = void 0;
7
- var _stream = require("stream");
8
- var _asyncMutex = require("async-mutex");
9
- class LineConvertStream extends _stream.Readable {
10
- buf = "";
11
- mutex = new _asyncMutex.Mutex();
12
- constructor(stream) {
13
- super();
14
- this.stream = stream;
15
- this.stream.on("data", chunk => this.process(chunk));
16
- this.stream.on("end", () => {
17
- this.push(null);
18
- });
19
- this.stream.on("close", () => {
20
- this.destroy();
21
- });
22
- }
23
- _read(size) {
24
- //
25
- }
26
- async process(chunk) {
27
- await this.mutex.acquire();
28
- this.buf += chunk.toString();
29
- try {
30
- let pos;
31
- while ((pos = this.buf.indexOf("\n")) >= 0) {
32
- if (pos === 0) {
33
- this.buf = this.buf.slice(0);
34
- continue;
4
+ const stream_1 = require("stream");
5
+ const async_mutex_1 = require("async-mutex");
6
+ class LineConvertStream extends stream_1.Readable {
7
+ constructor(stream) {
8
+ super();
9
+ this.buf = "";
10
+ this.mutex = new async_mutex_1.Mutex();
11
+ this.stream = stream;
12
+ this.stream.on("data", (chunk) => this.process(chunk));
13
+ this.stream.on("end", () => {
14
+ this.push(null);
15
+ });
16
+ this.stream.on("close", () => {
17
+ this.destroy();
18
+ });
19
+ }
20
+ _read(size) {
21
+ }
22
+ async process(chunk) {
23
+ await this.mutex.acquire();
24
+ this.buf += chunk.toString();
25
+ try {
26
+ let pos;
27
+ while ((pos = this.buf.indexOf("\n")) >= 0) {
28
+ if (pos === 0) {
29
+ this.buf = this.buf.slice(0);
30
+ continue;
31
+ }
32
+ const line = this.buf.slice(0, pos);
33
+ this.buf = this.buf.slice(pos + 1);
34
+ this.push(line);
35
+ }
36
+ }
37
+ finally {
38
+ this.mutex.release();
35
39
  }
36
- const line = this.buf.slice(0, pos);
37
- this.buf = this.buf.slice(pos + 1);
38
- this.push(line);
39
- }
40
- } finally {
41
- this.mutex.release();
42
40
  }
43
- }
44
41
  }
45
- exports.LineConvertStream = LineConvertStream;
42
+ exports.LineConvertStream = LineConvertStream;
@@ -1,7 +1,9 @@
1
- export declare class Logger {
1
+ import { DI } from "./DI";
2
+ declare class Logger {
3
+ static install(di: DI): void;
2
4
  static log(...data: any[]): void;
3
5
  static info(...data: any[]): void;
4
- static warning(...data: any[]): void;
6
+ static warn(...data: any[]): void;
5
7
  static error(...data: any[]): void;
6
- static _log(type: string, ...data: any[]): void;
7
8
  }
9
+ export { Logger };
@@ -1,39 +1,23 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Logger = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _format = _interopRequireDefault(require("date-fns/format"));
9
- var _env = require("../env");
10
- var _FS = require("./FS");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
4
+ const LogService_1 = require("../services/LogService");
5
+ let _di;
14
6
  class Logger {
15
- static log(...data) {
16
- Logger._log("log", ...data);
17
- }
18
- static info(...data) {
19
- Logger._log("info", ...data);
20
- }
21
- static warning(...data) {
22
- Logger._log("warning", ...data);
23
- }
24
- static error(...data) {
25
- Logger._log("error", ...data);
26
- }
27
- static _log(type, ...data) {
28
- const time = (0, _format.default)(new Date(), "yyyy-MM-dd hh:mm:ss");
29
- const logPath = Path.join(_env.DATA_DIR, "ws.log");
30
- const logData = data.map(item => {
31
- return typeof item !== "string" ? JSON.stringify(item) : item;
32
- }).join(" ");
33
- if (!_FS.FS.existsSync(logPath)) {
34
- _FS.FS.writeFileSync(logPath, "");
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 warn(...data) {
17
+ _di.resolveService(LogService_1.LogService).warn(...data);
18
+ }
19
+ static error(...data) {
20
+ _di.resolveService(LogService_1.LogService).error(...data);
35
21
  }
36
- _FS.FS.appendFileSync(logPath, `[${time}] ${type}: ${logData}\n`);
37
- }
38
22
  }
39
- exports.Logger = Logger;
23
+ exports.Logger = Logger;
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Model = void 0;
7
4
  class Model {
8
- attributes = {};
9
- constructor(attributes = {}) {
10
- this.attributes = attributes;
11
- }
12
- async save() {
13
- //
14
- }
5
+ constructor(attributes = {}) {
6
+ this.attributes = {};
7
+ this.attributes = attributes;
8
+ }
9
+ async save() {
10
+ }
15
11
  }
16
- exports.Model = Model;
12
+ exports.Model = Model;
@@ -1,31 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.MySQL = void 0;
7
- // import {createConnection} from "mysql";
8
-
9
4
  class MySQL {
10
- constructor(options) {
11
- // this.connection = createConnection(options);
12
- }
13
- async query(sql) {
14
- // this.connection.connect();
15
- //
16
- // const res = await new Promise((resolve, reject) => {
17
- // this.connection.query(sql, (err, res) => {
18
- // if(err) {
19
- // return reject(err);
20
- // }
21
- //
22
- // return resolve(res);
23
- // });
24
- // });
25
- //
26
- // this.connection.end();
27
- //
28
- // return res;
29
- }
5
+ constructor(options) {
6
+ }
7
+ async query(sql) {
8
+ }
30
9
  }
31
- exports.MySQL = MySQL;
10
+ exports.MySQL = MySQL;
@@ -1,5 +1,5 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Controller } from "src/makes/Controller";
2
+ import { Controller } from "../makes/Controller";
3
3
  declare class Plugin extends Controller {
4
4
  protected certsDir: string;
5
5
  protected dataDir: string;
@@ -1,43 +1,61 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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;
5
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 });
6
26
  exports.Plugin = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _env = require("../env");
9
- var _Controller = require("./Controller");
10
- var _FS = require("./FS");
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- class Plugin extends _Controller.Controller {
14
- constructor(name) {
15
- super();
16
- this.certsDir = Path.join(_env.DATA_DIR, "certs");
17
- this.dataDir = Path.join(_env.DATA_DIR, "plugins", name);
18
- this.pluginDir = Path.join(_env.PLUGINS_DIR, name);
19
- }
20
- install(cli) {
21
- super.install(cli);
22
- if (!_FS.FS.existsSync(this.certsDir)) {
23
- _FS.FS.mkdirSync(this.certsDir, {
24
- recursive: true
25
- });
27
+ const Path = __importStar(require("path"));
28
+ const env_1 = require("../env");
29
+ const Controller_1 = require("../makes/Controller");
30
+ const FS_1 = require("../makes/FS");
31
+ class Plugin extends Controller_1.Controller {
32
+ constructor(name) {
33
+ super();
34
+ this.certsDir = Path.join(env_1.DATA_DIR, "certs");
35
+ this.dataDir = Path.join(env_1.DATA_DIR, "plugins", name);
36
+ this.pluginDir = Path.join(env_1.PLUGINS_DIR, name);
37
+ }
38
+ install(cli) {
39
+ super.install(cli);
40
+ if (!FS_1.FS.existsSync(this.certsDir)) {
41
+ FS_1.FS.mkdirSync(this.certsDir, {
42
+ recursive: true
43
+ });
44
+ }
45
+ if (!FS_1.FS.existsSync(this.dataDir)) {
46
+ FS_1.FS.mkdirSync(this.dataDir, {
47
+ recursive: true
48
+ });
49
+ }
50
+ }
51
+ certsPath(...paths) {
52
+ return Path.join(this.certsDir, ...paths);
53
+ }
54
+ dataPath(...paths) {
55
+ return Path.join(this.dataDir, ...paths);
26
56
  }
27
- if (!_FS.FS.existsSync(this.dataDir)) {
28
- _FS.FS.mkdirSync(this.dataDir, {
29
- recursive: true
30
- });
57
+ pluginPath(...paths) {
58
+ return Path.join(this.pluginDir, ...paths);
31
59
  }
32
- }
33
- certsPath(...paths) {
34
- return Path.join(this.certsDir, ...paths);
35
- }
36
- dataPath(...paths) {
37
- return Path.join(this.dataDir, ...paths);
38
- }
39
- pluginPath(...paths) {
40
- return Path.join(this.pluginDir, ...paths);
41
- }
42
60
  }
43
- exports.Plugin = Plugin;
61
+ exports.Plugin = Plugin;
@@ -0,0 +1,46 @@
1
+ import { EnvConfig } from "../types";
2
+ import { DI } from "../makes";
3
+ import { PresetServiceSearchOptions as SearchOptions } from "../services/PresetService";
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>;
45
+ }
46
+ export { Preset };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Preset = void 0;
4
+ const PresetService_1 = require("../services/PresetService");
5
+ let _di;
6
+ class Preset {
7
+ constructor(data) {
8
+ this.id = data.id;
9
+ this.name = data.name;
10
+ this.version = data.version;
11
+ this.dockerfile = data.dockerfile;
12
+ this.buildArgsOptions = data.buildArgsOptions;
13
+ this.envOptions = data.envOptions;
14
+ this.volumes = data.volumes;
15
+ this.volumeOptions = data.volumeOptions;
16
+ }
17
+ async save() {
18
+ return _di.resolveService(PresetService_1.PresetService).save(this);
19
+ }
20
+ getImageName(buildArgs) {
21
+ return _di.resolveService(PresetService_1.PresetService).getImageName(this, buildArgs);
22
+ }
23
+ static install(di) {
24
+ _di = di;
25
+ }
26
+ static search(options) {
27
+ return _di.resolveService(PresetService_1.PresetService).search(options);
28
+ }
29
+ static searchOne(options) {
30
+ return _di.resolveService(PresetService_1.PresetService).searchOne(options);
31
+ }
32
+ }
33
+ exports.Preset = Preset;
@@ -1,38 +1,45 @@
1
- import { EnvConfig } from "src/types";
1
+ import "reflect-metadata";
2
+ import { DI } from "../makes/DI";
3
+ import { EnvConfig } from "../types";
2
4
  type SearchOptions = {
3
5
  id: string;
4
6
  name: string;
5
- src: string;
7
+ path: string;
6
8
  };
7
- export declare class Project {
9
+ declare class Project {
8
10
  id: string;
9
- type: string;
10
11
  name: string;
12
+ type: string;
11
13
  path: string;
12
- dockerfile?: string;
14
+ preset?: string;
13
15
  imageName?: string;
16
+ dockerfile?: string;
17
+ scripts?: string[];
14
18
  buildArgs?: EnvConfig;
15
- env?: EnvConfig;
16
- domains?: string[];
19
+ env: EnvConfig;
20
+ ports?: string[];
17
21
  volumes?: string[];
18
- meta?: {
19
- [key: string]: string;
20
- };
22
+ metadata?: EnvConfig;
23
+ constructor(data: any);
24
+ get containerName(): string;
25
+ hasEnv(name: string): boolean;
26
+ getEnv(name: string, defaultValue?: string): string | undefined;
21
27
  setEnv(name: string, value: string | boolean): void;
22
- getEnv(name: string, defaultValue?: string): string;
23
28
  unsetEnv(name: string): void;
24
- getMeta(name: string, defaultValue?: string): string | undefined;
25
- setMeta(name: string, value: string): void;
29
+ hasMeta(name: string): boolean;
30
+ getMeta<D = string | undefined>(name: string, defaultValue?: D): D;
31
+ setMeta(name: string, value: string | boolean): void;
32
+ unsetMeta(name: string): void;
26
33
  volumeMount(...volumes: string[]): void;
27
34
  getVolumeBySource(source: string): string | undefined;
28
35
  getVolumeByDestination(destination: string): string | undefined;
29
36
  volumeUnmount(...volumes: string[]): void;
30
- static get(id: string): Promise<void>;
31
37
  save(): Promise<void>;
38
+ static install(di: DI): void;
32
39
  static fromObject(data: any): Project;
33
40
  static search(params?: Partial<SearchOptions>): Promise<Project[]>;
34
- static searchOne(params?: Partial<SearchOptions>): Promise<Project | null>;
41
+ static searchOne(params: Partial<SearchOptions>): Promise<Project | null>;
35
42
  }
43
+ export { Project };
36
44
  export declare const PROJECT_TYPE_DOCKERFILE = "dockerfile";
37
45
  export declare const PROJECT_TYPE_IMAGE = "image";
38
- export {};
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROJECT_TYPE_IMAGE = exports.PROJECT_TYPE_DOCKERFILE = exports.Project = void 0;
4
+ require("reflect-metadata");
5
+ const ProjectService_1 = require("../services/ProjectService");
6
+ const volumeParse_1 = require("../utils/volumeParse");
7
+ let projectService;
8
+ class Project {
9
+ constructor(data) {
10
+ this.id = data.id;
11
+ this.name = data.name;
12
+ this.type = data.type;
13
+ this.path = data.path;
14
+ this.preset = data.preset;
15
+ this.dockerfile = data.dockerfile;
16
+ this.imageName = data.imageName;
17
+ this.scripts = data.scripts;
18
+ this.buildArgs = data.buildArgs;
19
+ this.env = data.env || {};
20
+ this.ports = data.ports;
21
+ this.volumes = data.volumes;
22
+ this.metadata = data.metadata;
23
+ }
24
+ get containerName() {
25
+ return `${this.name}.workspace`;
26
+ }
27
+ hasEnv(name) {
28
+ if (!this.env) {
29
+ return false;
30
+ }
31
+ return this.env.hasOwnProperty(name);
32
+ }
33
+ getEnv(name, defaultValue) {
34
+ const { [name]: value = defaultValue } = this.env;
35
+ return value;
36
+ }
37
+ setEnv(name, value) {
38
+ this.env = {
39
+ ...this.env,
40
+ [name]: typeof value === "boolean"
41
+ ? (value ? "true" : "false")
42
+ : value
43
+ };
44
+ }
45
+ unsetEnv(name) {
46
+ if (name in this.env) {
47
+ delete this.env[name];
48
+ }
49
+ }
50
+ hasMeta(name) {
51
+ return !!this.metadata && this.metadata.hasOwnProperty(name);
52
+ }
53
+ getMeta(name, defaultValue) {
54
+ const { [name]: value = defaultValue } = this.metadata || {};
55
+ return value;
56
+ }
57
+ setMeta(name, value) {
58
+ if (!this.metadata) {
59
+ this.metadata = {};
60
+ }
61
+ this.metadata[name] = typeof value === "boolean"
62
+ ? (value ? "true" : "false")
63
+ : value;
64
+ }
65
+ unsetMeta(name) {
66
+ if (this.metadata && name in this.metadata) {
67
+ delete this.metadata[name];
68
+ }
69
+ if (this.metadata && Object.keys(this.metadata).length === 0) {
70
+ delete this.metadata;
71
+ }
72
+ }
73
+ volumeMount(...volumes) {
74
+ if (volumes.length === 0) {
75
+ return;
76
+ }
77
+ const [volume, ...restVolumes] = volumes;
78
+ const { destination } = (0, volumeParse_1.volumeParse)(volume);
79
+ this.volumes = [
80
+ ...(this.volumes || []).filter((v) => {
81
+ return v !== this.getVolumeByDestination(destination);
82
+ }),
83
+ volume
84
+ ];
85
+ this.volumeMount(...restVolumes);
86
+ }
87
+ getVolumeBySource(source) {
88
+ return (this.volumes || []).find((volume) => {
89
+ return (0, volumeParse_1.volumeParse)(volume).source === source;
90
+ });
91
+ }
92
+ getVolumeByDestination(destination) {
93
+ return (this.volumes || []).find((volume) => {
94
+ return (0, volumeParse_1.volumeParse)(volume).destination === destination;
95
+ });
96
+ }
97
+ volumeUnmount(...volumes) {
98
+ this.volumes = (this.volumes || []).filter((mounted) => {
99
+ return !volumes.includes(mounted);
100
+ });
101
+ }
102
+ async save() {
103
+ if (!projectService) {
104
+ throw new Error("Dependency is missing");
105
+ }
106
+ await projectService.save(this);
107
+ }
108
+ static install(di) {
109
+ projectService = di.resolveService(ProjectService_1.ProjectService);
110
+ }
111
+ static fromObject(data) {
112
+ return new Project(data);
113
+ }
114
+ static async search(params = {}) {
115
+ if (!projectService) {
116
+ throw new Error("Dependency is missing");
117
+ }
118
+ return projectService.search(params);
119
+ }
120
+ static async searchOne(params) {
121
+ const [project] = await Project.search(params);
122
+ return project || null;
123
+ }
124
+ }
125
+ exports.Project = Project;
126
+ exports.PROJECT_TYPE_DOCKERFILE = "dockerfile";
127
+ exports.PROJECT_TYPE_IMAGE = "image";
@@ -1,25 +1,22 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Repository = void 0;
7
4
  class Repository {
8
- async create(data) {
9
- return null;
10
- }
11
- async update(id, record) {
12
- return null;
13
- }
14
- async byId(id) {
15
- return null;
16
- }
17
- async search(params) {
18
- return [];
19
- }
20
- async searchOne(params) {
21
- const [item] = await this.search(params);
22
- return item;
23
- }
5
+ async create(data) {
6
+ return null;
7
+ }
8
+ async update(id, record) {
9
+ return null;
10
+ }
11
+ async byId(id) {
12
+ return null;
13
+ }
14
+ async search(params) {
15
+ return [];
16
+ }
17
+ async searchOne(params) {
18
+ const [item] = await this.search(params);
19
+ return item;
20
+ }
24
21
  }
25
- exports.Repository = Repository;
22
+ exports.Repository = Repository;
@@ -1,6 +1,9 @@
1
1
  export * from "./Controller";
2
+ export * from "./DI";
2
3
  export * from "./Docker";
3
4
  export * from "./FS";
4
5
  export * from "./Logger";
5
6
  export * from "./Plugin";
7
+ export * from "./Preset";
8
+ export * from "./Project";
6
9
  export * from "./Repository";