@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
@@ -0,0 +1,169 @@
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.PresetController = void 0;
27
+ const utils_1 = require("@wocker/utils");
28
+ const Path = __importStar(require("path"));
29
+ const env_1 = require("../env");
30
+ const utils_2 = require("../utils");
31
+ const makes_1 = require("../makes");
32
+ const services_1 = require("../services");
33
+ class PresetController extends makes_1.Controller {
34
+ constructor(di) {
35
+ super();
36
+ this.appConfigService = di.resolveService(services_1.AppConfigService);
37
+ this.appEventsService = di.resolveService(services_1.AppEventsService);
38
+ this.projectService = di.resolveService(services_1.ProjectService);
39
+ this.presetService = di.resolveService(services_1.PresetService);
40
+ this.dockerService = di.resolveService(services_1.DockerService);
41
+ }
42
+ install(cli) {
43
+ super.install(cli);
44
+ this.appConfigService.registerProjectType("preset", "Preset");
45
+ this.appEventsService.on("project:init", (project) => this.onInit(project));
46
+ this.appEventsService.on("project:beforeStart", (project) => this.onBeforeStart(project));
47
+ this.appEventsService.on("project:rebuild", (project) => this.onRebuild(project));
48
+ cli.command("preset:build <preset>")
49
+ .completion("preset", () => this.presets())
50
+ .option("rebuild", {
51
+ type: "boolean",
52
+ alias: "r",
53
+ description: "Rebuild image"
54
+ })
55
+ .action((options, preset) => this.build(options, preset));
56
+ }
57
+ async presets() {
58
+ const presets = await this.presetService.search();
59
+ return presets.map((preset) => {
60
+ return preset.name;
61
+ });
62
+ }
63
+ async onInit(project) {
64
+ if (project.type !== "preset") {
65
+ return;
66
+ }
67
+ const presets = await this.presetService.search();
68
+ if (presets.length === 0) {
69
+ throw new Error("No presets");
70
+ }
71
+ project.preset = await (0, utils_1.promptSelect)({
72
+ message: "Choose preset:",
73
+ options: presets.map((preset) => {
74
+ return {
75
+ label: preset.name,
76
+ value: preset.name
77
+ };
78
+ }),
79
+ default: project.preset
80
+ });
81
+ const preset = await this.presetService.get(project.preset);
82
+ if (!preset) {
83
+ throw new Error("Preset not found");
84
+ }
85
+ if (preset.buildArgsOptions) {
86
+ project.buildArgs = await (0, utils_1.promptConfig)(preset.buildArgsOptions, project.buildArgs);
87
+ }
88
+ if (preset.envOptions) {
89
+ project.env = await (0, utils_1.promptConfig)(preset.envOptions, project.env);
90
+ }
91
+ if (preset.volumeOptions) {
92
+ for (let volume of preset.volumeOptions) {
93
+ volume = (0, utils_2.injectVariables)(volume, {
94
+ ...project.buildArgs || {},
95
+ ...project.env || {}
96
+ });
97
+ const { destination, options } = (0, utils_2.volumeParse)(volume);
98
+ let projectVolume = project.getVolumeByDestination(destination);
99
+ const source = await (0, utils_1.promptText)({
100
+ message: "Volume",
101
+ suffix: `:${destination}`,
102
+ default: projectVolume ? (0, utils_2.volumeParse)(projectVolume).source : "./"
103
+ });
104
+ projectVolume = (0, utils_2.volumeFormat)({
105
+ source,
106
+ destination,
107
+ options
108
+ });
109
+ project.volumeMount(projectVolume);
110
+ }
111
+ }
112
+ if (preset.dockerfile) {
113
+ project.imageName = preset.getImageName(project.buildArgs);
114
+ }
115
+ }
116
+ async onRebuild(project) {
117
+ if (project.type !== "preset") {
118
+ return;
119
+ }
120
+ const preset = await this.presetService.get(project.preset);
121
+ if (!preset) {
122
+ throw new Error(`Preset ${project.preset} not found`);
123
+ }
124
+ const imageName = preset.getImageName(project.buildArgs || {});
125
+ const exists = await this.dockerService.imageExists(imageName);
126
+ if (exists) {
127
+ console.info(`Removing image: ${imageName}`);
128
+ await this.dockerService.imageRm(imageName);
129
+ }
130
+ }
131
+ async onBeforeStart(project) {
132
+ if (project.type !== "preset") {
133
+ return;
134
+ }
135
+ const preset = await this.presetService.get(project.preset);
136
+ if (preset.dockerfile) {
137
+ project.imageName = preset.getImageName(project.buildArgs);
138
+ if (!await this.dockerService.imageExists(project.imageName)) {
139
+ await this.dockerService.buildImage({
140
+ tag: project.imageName,
141
+ labels: {
142
+ presetName: preset.name
143
+ },
144
+ buildArgs: project.buildArgs,
145
+ context: Path.join(env_1.PRESETS_DIR, preset.name),
146
+ src: preset.dockerfile
147
+ });
148
+ }
149
+ }
150
+ }
151
+ async build(options, presetName) {
152
+ const preset = await this.presetService.get(presetName);
153
+ let buildArgs = {};
154
+ if (preset.buildArgsOptions) {
155
+ buildArgs = await (0, utils_1.promptGroup)(preset.buildArgsOptions);
156
+ }
157
+ const imageName = preset.getImageName(buildArgs);
158
+ await this.dockerService.buildImage({
159
+ tag: imageName,
160
+ labels: {
161
+ presetName: preset.name
162
+ },
163
+ buildArgs: buildArgs,
164
+ context: Path.join(env_1.PRESETS_DIR, preset.name),
165
+ src: preset.dockerfile
166
+ });
167
+ }
168
+ }
169
+ exports.PresetController = PresetController;
@@ -1,11 +1,14 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Controller } from "src/makes";
3
- import { AppConfigService, AppEventsService, ProjectService } from "src/services";
2
+ import { DI, Controller } from "../makes";
3
+ import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
4
4
  type InitOptions = {
5
5
  name?: string;
6
6
  type?: string;
7
7
  preset?: string;
8
8
  };
9
+ type ListOptions = {
10
+ all?: boolean;
11
+ };
9
12
  type StartOptions = {
10
13
  name?: string;
11
14
  rebuild?: boolean;
@@ -37,15 +40,20 @@ type ExecOptions = {
37
40
  name?: string;
38
41
  };
39
42
  declare class ProjectController extends Controller {
43
+ protected di: DI;
40
44
  protected appConfigService: AppConfigService;
41
45
  protected appEventsService: AppEventsService;
42
46
  protected projectService: ProjectService;
43
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
47
+ protected dockerService: DockerService;
48
+ constructor(di: DI);
44
49
  install(cli: Cli): void;
45
50
  protected getProjectNames(): Promise<string[]>;
51
+ protected getScripts(): Promise<string[]>;
46
52
  init(options: InitOptions): Promise<void>;
53
+ projectList(options: ListOptions): Promise<string>;
47
54
  start(options: StartOptions): Promise<void>;
48
55
  stop(options: StopOptions): Promise<void>;
56
+ run(script: string): Promise<void>;
49
57
  attach(options: AttachOptions): Promise<void>;
50
58
  configList(options: ConfigOptions): Promise<string>;
51
59
  configGet(options: ConfigOptions, key: string): Promise<string>;