@wocker/ws 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +155 -0
  3. package/bin/ws.js +13 -0
  4. package/lib/App.d.ts +13 -0
  5. package/lib/App.js +52 -0
  6. package/lib/controllers/ImageController.d.ts +8 -0
  7. package/lib/controllers/ImageController.js +29 -0
  8. package/lib/controllers/ProjectController.d.ts +64 -0
  9. package/lib/controllers/ProjectController.js +561 -0
  10. package/lib/controllers/index.d.ts +2 -0
  11. package/lib/controllers/index.js +27 -0
  12. package/lib/env.d.ts +7 -0
  13. package/lib/env.js +24 -0
  14. package/lib/index.d.ts +3 -0
  15. package/lib/index.js +31 -0
  16. package/lib/makes/Controller.d.ts +5 -0
  17. package/lib/makes/Controller.js +12 -0
  18. package/lib/makes/Docker.d.ts +58 -0
  19. package/lib/makes/Docker.js +418 -0
  20. package/lib/makes/FS.d.ts +37 -0
  21. package/lib/makes/FS.js +317 -0
  22. package/lib/makes/LineConvertStream.d.ts +13 -0
  23. package/lib/makes/LineConvertStream.js +45 -0
  24. package/lib/makes/Logger.d.ts +7 -0
  25. package/lib/makes/Logger.js +39 -0
  26. package/lib/makes/Model.d.ts +5 -0
  27. package/lib/makes/Model.js +16 -0
  28. package/lib/makes/MySQL.d.ts +15 -0
  29. package/lib/makes/MySQL.js +31 -0
  30. package/lib/makes/Plugin.d.ts +13 -0
  31. package/lib/makes/Plugin.js +43 -0
  32. package/lib/makes/Repository.d.ts +11 -0
  33. package/lib/makes/Repository.js +25 -0
  34. package/lib/makes/index.d.ts +6 -0
  35. package/lib/makes/index.js +71 -0
  36. package/lib/models/Preset.d.ts +19 -0
  37. package/lib/models/Preset.js +60 -0
  38. package/lib/models/Project.d.ts +38 -0
  39. package/lib/models/Project.js +151 -0
  40. package/lib/models/index.d.ts +2 -0
  41. package/lib/models/index.js +27 -0
  42. package/lib/plugins/LocaltunnelPlugin.d.ts +36 -0
  43. package/lib/plugins/LocaltunnelPlugin.js +273 -0
  44. package/lib/plugins/MaildevPlugin.d.ts +10 -0
  45. package/lib/plugins/MaildevPlugin.js +45 -0
  46. package/lib/plugins/MariadbPlugin.d.ts +25 -0
  47. package/lib/plugins/MariadbPlugin.js +297 -0
  48. package/lib/plugins/MongodbPlugin.d.ts +20 -0
  49. package/lib/plugins/MongodbPlugin.js +271 -0
  50. package/lib/plugins/NgrokPlugin.d.ts +37 -0
  51. package/lib/plugins/NgrokPlugin.js +248 -0
  52. package/lib/plugins/PageKitePlugin.d.ts +31 -0
  53. package/lib/plugins/PageKitePlugin.js +158 -0
  54. package/lib/plugins/PostgresPlugin.d.ts +16 -0
  55. package/lib/plugins/PostgresPlugin.js +94 -0
  56. package/lib/plugins/PresetPlugin.d.ts +19 -0
  57. package/lib/plugins/PresetPlugin.js +164 -0
  58. package/lib/plugins/ProjectPlugin.d.ts +12 -0
  59. package/lib/plugins/ProjectPlugin.js +54 -0
  60. package/lib/plugins/ProxmoxPlugin.d.ts +9 -0
  61. package/lib/plugins/ProxmoxPlugin.js +55 -0
  62. package/lib/plugins/ProxyPlugin.d.ts +33 -0
  63. package/lib/plugins/ProxyPlugin.js +257 -0
  64. package/lib/plugins/RedisPlugin.d.ts +10 -0
  65. package/lib/plugins/RedisPlugin.js +42 -0
  66. package/lib/plugins/ServeoPlugin.d.ts +36 -0
  67. package/lib/plugins/ServeoPlugin.js +260 -0
  68. package/lib/plugins/TestPlugin.d.ts +10 -0
  69. package/lib/plugins/TestPlugin.js +75 -0
  70. package/lib/plugins/index.d.ts +14 -0
  71. package/lib/plugins/index.js +159 -0
  72. package/lib/services/AppConfigService.d.ts +18 -0
  73. package/lib/services/AppConfigService.js +77 -0
  74. package/lib/services/AppEventsService.d.ts +13 -0
  75. package/lib/services/AppEventsService.js +29 -0
  76. package/lib/services/ProjectService.d.ts +13 -0
  77. package/lib/services/ProjectService.js +91 -0
  78. package/lib/services/index.d.ts +3 -0
  79. package/lib/services/index.js +38 -0
  80. package/lib/types/Config.d.ts +11 -0
  81. package/lib/types/Config.js +5 -0
  82. package/lib/types/EnvConfig.d.ts +3 -0
  83. package/lib/types/EnvConfig.js +5 -0
  84. package/lib/types/index.d.ts +2 -0
  85. package/lib/types/index.js +27 -0
  86. package/lib/utils/buildOptions.d.ts +1 -0
  87. package/lib/utils/buildOptions.js +12 -0
  88. package/lib/utils/demuxOutput.d.ts +2 -0
  89. package/lib/utils/demuxOutput.js +25 -0
  90. package/lib/utils/escapeRegExp.d.ts +2 -0
  91. package/lib/utils/escapeRegExp.js +10 -0
  92. package/lib/utils/exec.d.ts +2 -0
  93. package/lib/utils/exec.js +44 -0
  94. package/lib/utils/fetch.d.ts +5 -0
  95. package/lib/utils/fetch.js +37 -0
  96. package/lib/utils/followProgress.d.ts +6 -0
  97. package/lib/utils/followProgress.js +80 -0
  98. package/lib/utils/format-size-units.d.ts +1 -0
  99. package/lib/utils/format-size-units.js +19 -0
  100. package/lib/utils/get-config.d.ts +2 -0
  101. package/lib/utils/get-config.js +20 -0
  102. package/lib/utils/get-cursor-position.d.ts +4 -0
  103. package/lib/utils/get-cursor-position.js +34 -0
  104. package/lib/utils/image-build.d.ts +13 -0
  105. package/lib/utils/image-build.js +34 -0
  106. package/lib/utils/index.d.ts +21 -0
  107. package/lib/utils/index.js +236 -0
  108. package/lib/utils/injectVariables.d.ts +5 -0
  109. package/lib/utils/injectVariables.js +17 -0
  110. package/lib/utils/parse-table.d.ts +2 -0
  111. package/lib/utils/parse-table.js +27 -0
  112. package/lib/utils/promptConfirm.d.ts +6 -0
  113. package/lib/utils/promptConfirm.js +21 -0
  114. package/lib/utils/promptGroup.d.ts +16 -0
  115. package/lib/utils/promptGroup.js +39 -0
  116. package/lib/utils/promptSelect.d.ts +12 -0
  117. package/lib/utils/promptSelect.js +47 -0
  118. package/lib/utils/promptText.d.ts +13 -0
  119. package/lib/utils/promptText.js +53 -0
  120. package/lib/utils/set-config.d.ts +2 -0
  121. package/lib/utils/set-config.js +18 -0
  122. package/lib/utils/spawn.d.ts +2 -0
  123. package/lib/utils/spawn.js +24 -0
  124. package/lib/utils/tty.d.ts +2 -0
  125. package/lib/utils/tty.js +10 -0
  126. package/lib/utils/volumeFormat.d.ts +6 -0
  127. package/lib/utils/volumeFormat.js +15 -0
  128. package/lib/utils/volumeParse.d.ts +2 -0
  129. package/lib/utils/volumeParse.js +16 -0
  130. package/package.json +90 -0
  131. package/plugins/localtunnel/Dockerfile +37 -0
  132. package/plugins/localtunnel/Ubuntu.dockerfile +34 -0
  133. package/plugins/localtunnel/config.json +3 -0
  134. package/plugins/maildev/Dockerfile +5 -0
  135. package/plugins/maildev/config.json +3 -0
  136. package/plugins/mariadb/admin/conf/config.user.inc.php +9 -0
  137. package/plugins/ngrok/Dockerfile +2 -0
  138. package/plugins/pagekite/Dockerfile +3 -0
  139. package/plugins/proxmox/Dockerfile +35 -0
  140. package/plugins/proxy/Dockerfile +7 -0
  141. package/plugins/proxy/config.json +3 -0
  142. package/plugins/serveo/Dockerfile +17 -0
  143. package/presets/apache/.docker/apache2/apache2.conf +230 -0
  144. package/presets/apache/.docker/apache2/mods-available/mpm_prefork.conf +16 -0
  145. package/presets/apache/.docker/apache2/sites-available/000-default.conf.conf +21 -0
  146. package/presets/apache/Dockerfile +110 -0
  147. package/presets/apache/bin/compare-version +3 -0
  148. package/presets/apache/config.json +47 -0
  149. package/presets/go/Dockerfile +19 -0
  150. package/presets/go/config.json +13 -0
  151. package/presets/node/Dockerfile +37 -0
  152. package/presets/node/config.json +36 -0
  153. package/presets/php-apache/Dockerfile +133 -0
  154. package/presets/php-apache/bin/compare-version +3 -0
  155. package/presets/php-apache/config.json +56 -0
  156. package/presets/php-apache/etc/apache2/apache2.conf +230 -0
  157. package/presets/php-apache/etc/apache2/mods-available/mpm_prefork.conf +16 -0
  158. package/presets/php-apache/etc/apache2/sites-available/000-default.conf +21 -0
  159. package/presets/shopify/Dockerfile +160 -0
  160. package/presets/shopify/bin/compare-version +3 -0
  161. package/presets/shopify/config.json +24 -0
  162. package/presets/shopify/etc/apache2/apache2.conf +230 -0
  163. package/presets/shopify/etc/apache2/mods-available/mpm_prefork.conf +16 -0
  164. package/presets/shopify/etc/apache2/sites-available/000-default.conf +21 -0
@@ -0,0 +1,164 @@
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;
@@ -0,0 +1,12 @@
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 };
@@ -0,0 +1,54 @@
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;
@@ -0,0 +1,9 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Plugin } from "src/makes";
3
+ export declare class ProxmoxPlugin extends Plugin {
4
+ protected configDir: string;
5
+ constructor();
6
+ install(cli: Cli): void;
7
+ up(): Promise<void>;
8
+ down(): Promise<void>;
9
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ProxmoxPlugin = void 0;
7
+ var Path = _interopRequireWildcard(require("path"));
8
+ var _makes = require("../makes");
9
+ var _utils = require("../utils");
10
+ 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); }
11
+ 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; }
12
+ class ProxmoxPlugin extends _makes.Plugin {
13
+ constructor() {
14
+ super("proxmox");
15
+ this.configDir = Path.join(__dirname, "../../services/proxmox");
16
+ }
17
+ install(cli) {
18
+ super.install(cli);
19
+ }
20
+ async up() {
21
+ const container = await _makes.Docker.getContainer("proxmox.workspace");
22
+ if (container) {
23
+ await this.down();
24
+ }
25
+ await (0, _utils.exec)(`
26
+ docker build \
27
+ --tag "ws-proxmox" \
28
+ --file "${this.pluginPath("./Dockerfile")}" \
29
+ ${this.pluginPath()}
30
+ `);
31
+
32
+ // --add-host=""
33
+
34
+ await (0, _utils.exec)(`
35
+ docker run -d \
36
+ --name proxmox.workspace \
37
+ --network workspace \
38
+ -e VIRTUAL_HOST=proxmox.workspace \
39
+ -p 8006:8006 \
40
+ ws-proxmox
41
+ `);
42
+ }
43
+ async down() {
44
+ await (0, _utils.exec)("docker stop proxmox.workspace").catch(() => {
45
+ //
46
+ });
47
+ await (0, _utils.exec)("docker rm proxmox.workspace").catch(() => {
48
+ //
49
+ });
50
+ await (0, _utils.exec)("docker image rm ws-proxmox").catch(() => {
51
+ //
52
+ });
53
+ }
54
+ }
55
+ exports.ProxmoxPlugin = ProxmoxPlugin;
@@ -0,0 +1,33 @@
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
+ "http-port"?: number;
7
+ "https-port"?: number;
8
+ };
9
+ type DomainsOptions = {
10
+ name?: string;
11
+ };
12
+ declare class ProxyPlugin extends Plugin {
13
+ protected appConfigService: AppConfigService;
14
+ protected appEventsService: AppEventsService;
15
+ protected projectService: ProjectService;
16
+ protected containerName: string;
17
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
18
+ install(cli: Cli): void;
19
+ getProjectNames(): Promise<string[]>;
20
+ onProjectStart(project: Project): Promise<void>;
21
+ createNetwork(): Promise<void>;
22
+ init(options: InitOptions): Promise<void>;
23
+ start(): Promise<void>;
24
+ stop(): Promise<void>;
25
+ restart(): Promise<void>;
26
+ logs(): Promise<void>;
27
+ domainList(options: DomainsOptions): Promise<string>;
28
+ addDomain(options: DomainsOptions, addDomains: string[]): Promise<void>;
29
+ removeDomain(options: DomainsOptions, removeDomains: string[]): Promise<void>;
30
+ setDomains(options: DomainsOptions, domains: string[]): Promise<void>;
31
+ clearDomains(options: DomainsOptions): Promise<void>;
32
+ }
33
+ export { ProxyPlugin };
@@ -0,0 +1,257 @@
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;
@@ -0,0 +1,10 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Plugin } from "src/makes";
3
+ declare class RedisPlugin extends Plugin {
4
+ protected container: string;
5
+ constructor();
6
+ install(cli: Cli): void;
7
+ up(): Promise<void>;
8
+ down(): Promise<void>;
9
+ }
10
+ export { RedisPlugin };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RedisPlugin = void 0;
7
+ var _makes = require("../makes");
8
+ class RedisPlugin extends _makes.Plugin {
9
+ container = "redis.workspace";
10
+ constructor() {
11
+ super("redis");
12
+ }
13
+ install(cli) {
14
+ super.install(cli);
15
+ cli.command("redis:start").action(() => this.up());
16
+ cli.command("redis:stop").action(() => this.down());
17
+ }
18
+ async up() {
19
+ console.log("Redis up...");
20
+ await _makes.Docker.pullImage("redis");
21
+ const container = await _makes.Docker.createContainer({
22
+ name: this.container,
23
+ restart: "always",
24
+ env: {
25
+ VIRTUAL_HOST: this.container
26
+ },
27
+ volumes: [`${this.dataPath()}:/data`],
28
+ ports: ["6379:6379"],
29
+ image: "redis"
30
+ });
31
+ await container.start();
32
+ }
33
+ async down() {
34
+ console.log("Redis down...");
35
+ const container = await _makes.Docker.getContainer(this.container);
36
+ await container.stop().catch(() => {
37
+ //
38
+ });
39
+ await container.remove();
40
+ }
41
+ }
42
+ exports.RedisPlugin = RedisPlugin;
@@ -0,0 +1,36 @@
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 };