@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,164 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PresetPlugin = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _env = require("../env");
9
- var _makes = require("../makes");
10
- var _models = require("../models");
11
- var _utils = require("../utils");
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; }
14
- class PresetPlugin extends _makes.Plugin {
15
- constructor(appConfigService, appEventsService) {
16
- super("preset");
17
- this.appConfigService = appConfigService;
18
- this.appEventsService = appEventsService;
19
- this.pluginDir = Path.join(_env.ROOT_DIR, "presets");
20
- }
21
- install(cli) {
22
- super.install(cli);
23
- this.appConfigService.registerProjectType("preset", "Preset");
24
- this.appEventsService.on("project:init", project => this.onInit(project));
25
- this.appEventsService.on("project:rebuild", project => this.onRebuild(project));
26
- this.appEventsService.on("project:beforeStart", project => this.onBeforeStart(project));
27
- cli.command("preset:build <preset>").completion("preset", () => this.presets()).option("rebuild", {
28
- alias: "r",
29
- type: "boolean",
30
- description: "Rebuild image"
31
- }).action((options, preset) => this.build(options, preset));
32
- }
33
- async presets() {
34
- return _makes.FS.readdir(this.pluginPath());
35
- }
36
- async onInit(project) {
37
- if (project.type !== "preset") {
38
- return;
39
- }
40
- const presetName = await (0, _utils.promptSelect)({
41
- message: "Select preset",
42
- options: await _makes.FS.readdir(_env.PRESETS_DIR),
43
- default: project.getEnv("PRESET_NAME")
44
- });
45
- const preset = await _models.Preset.get(presetName);
46
- project.setEnv("PRESET_NAME", presetName);
47
- if (preset.buildArgsOptions) {
48
- project.buildArgs = await (0, _utils.promptGroup)(project.buildArgs || {}, preset.buildArgsOptions);
49
- }
50
- if (preset.envOptions) {
51
- project.env = await (0, _utils.promptGroup)(project.env || {}, preset.envOptions);
52
- }
53
- if (preset.volumeOptions) {
54
- for (let volume of preset.volumeOptions) {
55
- volume = (0, _utils.injectVariables)(volume, {
56
- ...(project.buildArgs || {}),
57
- ...(project.env || {})
58
- });
59
- const {
60
- destination,
61
- options
62
- } = (0, _utils.volumeParse)(volume);
63
- let projectVolume = project.getVolumeByDestination(destination);
64
- const source = await (0, _utils.promptText)({
65
- message: "Volume",
66
- suffix: `:${destination}`,
67
- default: projectVolume ? (0, _utils.volumeParse)(projectVolume).source : "./"
68
- });
69
- projectVolume = (0, _utils.volumeFormat)({
70
- source,
71
- destination,
72
- options
73
- });
74
- project.volumeMount(projectVolume);
75
- }
76
- }
77
- if (preset.dockerfile) {
78
- project.imageName = preset.getImageName(project.buildArgs);
79
- }
80
- }
81
- async onRebuild(project) {
82
- if (project.type !== "preset") {
83
- return;
84
- }
85
- const presetName = project.getEnv("PRESET_NAME");
86
- const preset = await _models.Preset.get(presetName);
87
- if (!preset) {
88
- throw new Error(`Preset ${presetName} not found`);
89
- }
90
- const imageName = preset.getImageName(project.buildArgs || {});
91
- const exists = await _makes.Docker.imageExists(imageName);
92
- if (exists) {
93
- console.info(`Removing image: ${imageName}`);
94
- await _makes.Docker.imageRm(imageName);
95
- }
96
- }
97
- async onBeforeStart(project) {
98
- if (project.type !== "preset") {
99
- return;
100
- }
101
- const presetName = project.getEnv("PRESET_NAME");
102
- const preset = await _models.Preset.get(presetName);
103
- const config = await _makes.FS.readJSON(this.pluginPath(project.getEnv("PRESET_NAME"), "config.json"));
104
-
105
- // if(preset.volumes) {
106
- // project.volumeMount(...preset.volumes);
107
- // }
108
-
109
- // if(preset.image) {
110
- // project.imageName = config.image;
111
- //
112
- // return;
113
- // }
114
-
115
- if (preset.dockerfile) {
116
- project.imageName = preset.getImageName(project.buildArgs);
117
- _makes.Logger.info(project.imageName);
118
- if (!(await _makes.Docker.imageExists(project.imageName))) {
119
- const stream = await _makes.Docker.imageBuild2({
120
- tag: project.imageName,
121
- context: this.pluginPath(presetName),
122
- src: config.dockerfile,
123
- labels: {
124
- presetName
125
- },
126
- buildArgs: project.buildArgs
127
- });
128
- await (0, _utils.followProgress)(stream);
129
- }
130
- }
131
- }
132
- async build(options, presetName) {
133
- const {
134
- rebuild
135
- } = options;
136
- const preset = await _models.Preset.get(presetName);
137
- const presetPath = this.pluginPath(presetName);
138
- let buildArgs = {};
139
- if (preset.buildArgsOptions) {
140
- buildArgs = await (0, _utils.promptGroup)(buildArgs, preset.buildArgsOptions);
141
- }
142
- const imageName = preset.getImageName(buildArgs);
143
- _makes.Logger.info("Image name:", imageName);
144
- _makes.Logger.info("Build args:", buildArgs);
145
- if (rebuild) {
146
- const exists = await _makes.Docker.imageExists(imageName);
147
- if (exists) {
148
- await _makes.Docker.imageRm(imageName);
149
- }
150
- }
151
- const stream = await _makes.Docker.imageBuild2({
152
- tag: imageName,
153
- context: presetPath,
154
- src: preset.dockerfile,
155
- labels: {
156
- presetName,
157
- ...buildArgs
158
- },
159
- buildArgs
160
- });
161
- await (0, _utils.followProgress)(stream);
162
- }
163
- }
164
- exports.PresetPlugin = PresetPlugin;
@@ -1,12 +0,0 @@
1
- import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
3
- type ProjectListOptions = {
4
- all?: boolean;
5
- };
6
- declare class ProjectPlugin extends Plugin {
7
- constructor();
8
- install(cli: Cli): void;
9
- projectList(options: ProjectListOptions): Promise<string>;
10
- init(): Promise<void>;
11
- }
12
- export { ProjectPlugin };
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ProjectPlugin = void 0;
7
- var _cliTable = _interopRequireDefault(require("cli-table3"));
8
- var _makes = require("../makes");
9
- var _models = require("../models");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- class ProjectPlugin extends _makes.Plugin {
12
- constructor() {
13
- super("project");
14
- }
15
- install(cli) {
16
- super.install(cli);
17
- cli.command("ps").option("all", {
18
- type: "boolean",
19
- alias: "a",
20
- description: "All projects"
21
- }).action(options => this.projectList(options));
22
- }
23
- async projectList(options) {
24
- const {
25
- all
26
- } = options;
27
- const projects = await _models.Project.search();
28
- const table = new _cliTable.default({
29
- head: ["Name", "Type", "Status"],
30
- colAligns: ["left", "center"]
31
- });
32
- for (const i in projects) {
33
- const project = projects[i];
34
- const container = await _makes.Docker.getContainer(`${project.name}.workspace`);
35
- if (!container) {
36
- if (all) {
37
- table.push([project.name, project.type, "-"]);
38
- }
39
- continue;
40
- }
41
- const {
42
- State: {
43
- Status = "Stopped"
44
- } = {}
45
- } = await container.inspect();
46
- table.push([project.name, project.type, Status]);
47
- }
48
- return table.toString();
49
- }
50
- async init() {
51
- //
52
- }
53
- }
54
- exports.ProjectPlugin = ProjectPlugin;
@@ -1,257 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ProxyPlugin = void 0;
7
- var _chalk = _interopRequireDefault(require("chalk"));
8
- var _cliTable = _interopRequireDefault(require("cli-table3"));
9
- var _makes = require("../makes");
10
- var _models = require("../models");
11
- var _utils = require("../utils");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- class ProxyPlugin extends _makes.Plugin {
14
- containerName = "proxy.workspace";
15
- constructor(appConfigService, appEventsService, projectService) {
16
- super("proxy");
17
- this.appConfigService = appConfigService;
18
- this.appEventsService = appEventsService;
19
- this.projectService = projectService;
20
- }
21
- install(cli) {
22
- super.install(cli);
23
- this.appEventsService.on("project:beforeStart", project => this.onProjectStart(project));
24
- cli.command("proxy:init").option("http-port", {
25
- type: "number",
26
- description: "Http port"
27
- }).option("https-port", {
28
- type: "number",
29
- description: "Https port"
30
- }).action(options => this.init(options));
31
- cli.command("proxy:start").action(() => this.start());
32
- cli.command("proxy:stop").action(() => this.stop());
33
- cli.command("proxy:restart").action(() => this.restart());
34
- cli.command("proxy:logs").action(() => this.logs());
35
- cli.command("domains").option("name", {
36
- type: "string",
37
- alias: "n"
38
- }).completion("name", () => this.getProjectNames()).action(options => this.domainList(options));
39
- cli.command("domain:add [...domains]").option("name", {
40
- type: "string",
41
- alias: "n"
42
- }).completion("name", () => this.getProjectNames()).action((options, domains) => this.addDomain(options, domains));
43
- cli.command("domain:remove [...domains]").option("name", {
44
- type: "string",
45
- alias: "n"
46
- }).completion("name", () => this.getProjectNames()).action((options, domains) => this.removeDomain(options, domains));
47
- cli.command("domain:set [...domains]").option("name", {
48
- type: "string",
49
- alias: "n"
50
- }).completion("name", () => this.getProjectNames()).action((options, domains) => this.setDomains(options, domains));
51
- cli.command("domain:clear").option("name", {
52
- type: "string",
53
- alias: "n"
54
- }).action(options => this.clearDomains(options));
55
- }
56
- async getProjectNames() {
57
- const projects = await _models.Project.search();
58
- return projects.map(project => {
59
- return project.name;
60
- });
61
- }
62
- async onProjectStart(project) {
63
- await this.createNetwork();
64
- if (!project.getEnv("VIRTUAL_HOST")) {
65
- project.setEnv("VIRTUAL_HOST", `${project.name}.workspace`);
66
- }
67
- }
68
- async createNetwork() {
69
- const networks = await _makes.Docker.docker.listNetworks();
70
- const workspaceNetwork = networks.find(network => network.Name === "workspace");
71
- if (!workspaceNetwork) {
72
- console.info("Creating \"workspace\" network.");
73
- await _makes.Docker.docker.createNetwork({
74
- Name: "workspace"
75
- });
76
- }
77
- }
78
- async init(options) {
79
- let {
80
- "http-port": httpPort,
81
- "https-port": httpsPort
82
- } = options;
83
- _makes.Logger.log(typeof httpPort, typeof httpsPort);
84
- if (typeof httpPort === "undefined" || isNaN(httpPort)) {
85
- httpPort = await (0, _utils.promptText)({
86
- required: true,
87
- label: "Http port",
88
- type: "integer",
89
- default: await this.appConfigService.getEnvVariable("PROXY_HTTP_PORT", "80")
90
- });
91
- }
92
- await this.appConfigService.setEnvVariable("PROXY_HTTP_PORT", httpPort);
93
- if (typeof httpsPort === "undefined" || httpsPort === null) {
94
- httpsPort = await (0, _utils.promptText)({
95
- required: true,
96
- label: "Https port",
97
- type: "integer",
98
- default: await this.appConfigService.getEnvVariable("PROXY_HTTPS_PORT", "443")
99
- });
100
- }
101
- await this.appConfigService.setEnvVariable("PROXY_HTTPS_PORT", httpsPort);
102
- }
103
- async start() {
104
- console.info("Proxy starting...");
105
- await _makes.Docker.pullImage("nginxproxy/nginx-proxy");
106
- const httpPort = await this.appConfigService.getEnvVariable("PROXY_HTTP_PORT", "80");
107
- const httpsPort = await this.appConfigService.getEnvVariable("PROXY_HTTPS_PORT", "443");
108
- const container = await _makes.Docker.createContainer({
109
- name: this.containerName,
110
- image: "nginxproxy/nginx-proxy",
111
- restart: "always",
112
- volumes: ["/var/run/docker.sock:/tmp/docker.sock:ro", `${this.certsPath()}:/etc/nginx/certs`],
113
- ports: [`${httpPort}:${httpPort}`, `${httpsPort}:${httpsPort}`],
114
- env: {
115
- DEFAULT_HOST: "index.workspace",
116
- HTTP_PORT: httpPort,
117
- HTTPS_PORT: httpsPort
118
- }
119
- });
120
- await container.start();
121
- }
122
- async stop() {
123
- console.info("Proxy stopping...");
124
- const container = await _makes.Docker.getContainer(this.containerName);
125
- if (container) {
126
- try {
127
- await container.stop();
128
- } catch (err) {
129
- //
130
- }
131
- try {
132
- await container.remove();
133
- } catch (err) {
134
- //
135
- }
136
- }
137
- }
138
- async restart() {
139
- await this.stop();
140
- await this.start();
141
- }
142
- async logs() {
143
- const container = await _makes.Docker.getContainer(this.containerName);
144
- if (container) {
145
- const stream = await container.logs({
146
- follow: true,
147
- stdout: true,
148
- stderr: true
149
- });
150
- stream.on("data", data => {
151
- process.stdout.write((0, _utils.demuxOutput)(data));
152
- });
153
- }
154
- }
155
- async domainList(options) {
156
- const {
157
- name
158
- } = options;
159
- const project = await _models.Project.searchOne(name ? {
160
- name
161
- } : {
162
- src: this.appConfigService.getPWD()
163
- });
164
- if (!project) {
165
- throw new Error("Project not found");
166
- }
167
- const table = new _cliTable.default({
168
- head: [_chalk.default.yellow("Domain")]
169
- });
170
- const domains = project.getEnv("VIRTUAL_HOST", "").split(",");
171
- for (const domain of domains) {
172
- table.push([domain]);
173
- }
174
- return table.toString();
175
- }
176
- async addDomain(options, addDomains) {
177
- const {
178
- name
179
- } = options;
180
- if (name) {
181
- await this.projectService.cdProject(name);
182
- }
183
- const project = await this.projectService.get();
184
- if (!project) {
185
- throw new Error("Project not found");
186
- }
187
- let domains = project.getEnv("VIRTUAL_HOST", "").split(",").filter(domain => {
188
- return !!domain;
189
- });
190
- domains = [...domains, ...addDomains.filter(domain => {
191
- return !domains.find(existDomain => {
192
- return existDomain === domain;
193
- });
194
- })];
195
- project.setEnv("VIRTUAL_HOST", domains.join(","));
196
- await project.save();
197
- const container = await _makes.Docker.getContainer(`${project.name}.workspace`);
198
- if (container) {
199
- await this.projectService.stop();
200
- await this.projectService.start();
201
- }
202
- }
203
- async removeDomain(options, removeDomains) {
204
- const {
205
- name
206
- } = options;
207
- const project = await _models.Project.searchOne(name ? {
208
- name
209
- } : {
210
- src: this.appConfigService.getPWD()
211
- });
212
- if (!project) {
213
- throw new Error("Project not found");
214
- }
215
- let domains = project.getEnv("VIRTUAL_HOST", "").split(",").filter(domain => {
216
- return !!domain;
217
- });
218
- domains = domains.filter(domain => {
219
- return !removeDomains.find(removeDomain => {
220
- return removeDomain === domain;
221
- });
222
- });
223
- project.setEnv("VIRTUAL_HOST", domains.join(","));
224
- await project.save();
225
- }
226
- async setDomains(options, domains) {
227
- const {
228
- name
229
- } = options;
230
- const project = await _models.Project.searchOne(name ? {
231
- name
232
- } : {
233
- src: this.appConfigService.getPWD()
234
- });
235
- if (!project) {
236
- throw new Error("Project not found");
237
- }
238
- project.setEnv("VIRTUAL_HOST", domains.join(","));
239
- await project.save();
240
- }
241
- async clearDomains(options) {
242
- const {
243
- name
244
- } = options;
245
- const project = await _models.Project.searchOne(name ? {
246
- name
247
- } : {
248
- src: this.appConfigService.getPWD()
249
- });
250
- if (!project) {
251
- throw new Error("Project not found");
252
- }
253
- project.unsetEnv("VIRTUAL_HOST");
254
- await project.save();
255
- }
256
- }
257
- exports.ProxyPlugin = ProxyPlugin;
@@ -1,36 +0,0 @@
1
- import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
3
- import { Project } from "src/models";
4
- import { AppConfigService, AppEventsService, ProjectService } from "src/services";
5
- type InitOptions = {
6
- name?: string;
7
- };
8
- type StartOptions = {
9
- name?: string;
10
- rebuild?: boolean;
11
- detach?: boolean;
12
- };
13
- type StopOptions = {
14
- name?: string;
15
- };
16
- type LogsOptions = {
17
- name?: string;
18
- detach?: boolean;
19
- };
20
- declare class ServeoPlugin extends Plugin {
21
- protected appConfigService: AppConfigService;
22
- protected appEventsService: AppEventsService;
23
- protected projectService: ProjectService;
24
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
25
- install(cli: Cli): void;
26
- onProjectStart(project: Project): Promise<void>;
27
- onProjectStop(project: Project): Promise<void>;
28
- init(options: InitOptions): Promise<void>;
29
- start(options: StartOptions): Promise<void>;
30
- stop(options: StopOptions): Promise<void>;
31
- restart(options: StartOptions): Promise<void>;
32
- build(): Promise<void>;
33
- rebuild(): Promise<void>;
34
- logs(options: LogsOptions): Promise<void>;
35
- }
36
- export { ServeoPlugin };