@wocker/ws 1.0.2 → 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 (100) hide show
  1. package/README.md +1 -1
  2. package/lib/App.d.ts +4 -3
  3. package/lib/App.js +98 -77
  4. package/lib/controllers/ImageController.d.ts +2 -2
  5. package/lib/controllers/ImageController.js +27 -27
  6. package/lib/controllers/PluginController.d.ts +2 -2
  7. package/lib/controllers/PluginController.js +78 -56
  8. package/lib/controllers/PresetController.d.ts +3 -1
  9. package/lib/controllers/PresetController.js +155 -136
  10. package/lib/controllers/ProjectController.d.ts +5 -5
  11. package/lib/controllers/ProjectController.js +653 -603
  12. package/lib/controllers/ProxyController.d.ts +4 -1
  13. package/lib/controllers/ProxyController.js +269 -245
  14. package/lib/controllers/index.js +19 -58
  15. package/lib/env.js +33 -15
  16. package/lib/index.d.ts +2 -0
  17. package/lib/index.js +30 -16
  18. package/lib/makes/Controller.js +4 -8
  19. package/lib/makes/DI.d.ts +7 -0
  20. package/lib/makes/DI.js +27 -0
  21. package/lib/makes/Docker.js +298 -382
  22. package/lib/makes/FS.js +328 -304
  23. package/lib/makes/LineConvertStream.js +37 -40
  24. package/lib/makes/Logger.d.ts +9 -1
  25. package/lib/makes/Logger.js +22 -11
  26. package/lib/makes/Model.js +8 -12
  27. package/lib/makes/MySQL.js +6 -27
  28. package/lib/makes/Plugin.d.ts +1 -1
  29. package/lib/makes/Plugin.js +55 -37
  30. package/lib/makes/Preset.d.ts +46 -0
  31. package/lib/makes/Preset.js +33 -0
  32. package/lib/makes/Project.d.ts +45 -0
  33. package/lib/makes/Project.js +127 -0
  34. package/lib/makes/Repository.js +18 -21
  35. package/lib/makes/index.d.ts +3 -0
  36. package/lib/makes/index.js +23 -69
  37. package/lib/plugins/ElasticSearchPlugin.d.ts +3 -1
  38. package/lib/plugins/ElasticSearchPlugin.js +66 -66
  39. package/lib/plugins/LocaltunnelPlugin.d.ts +2 -2
  40. package/lib/plugins/LocaltunnelPlugin.js +256 -257
  41. package/lib/plugins/MaildevPlugin.d.ts +2 -2
  42. package/lib/plugins/MaildevPlugin.js +45 -44
  43. package/lib/plugins/MongodbPlugin.d.ts +2 -2
  44. package/lib/plugins/MongodbPlugin.js +303 -248
  45. package/lib/plugins/NgrokPlugin.d.ts +2 -2
  46. package/lib/plugins/NgrokPlugin.js +221 -231
  47. package/lib/plugins/PageKitePlugin.d.ts +2 -2
  48. package/lib/plugins/PageKitePlugin.js +150 -149
  49. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  50. package/lib/plugins/PostgresPlugin.js +115 -89
  51. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  52. package/lib/plugins/ProxmoxPlugin.js +50 -38
  53. package/lib/plugins/RedisPlugin.d.ts +3 -1
  54. package/lib/plugins/RedisPlugin.js +73 -72
  55. package/lib/plugins/index.js +25 -103
  56. package/lib/services/AppConfigService.d.ts +3 -3
  57. package/lib/services/AppConfigService.js +162 -157
  58. package/lib/services/AppEventsService.js +26 -24
  59. package/lib/services/DockerService.d.ts +37 -2
  60. package/lib/services/DockerService.js +185 -205
  61. package/lib/services/LogService.d.ts +3 -2
  62. package/lib/services/LogService.js +33 -34
  63. package/lib/services/PluginService.d.ts +2 -1
  64. package/lib/services/PluginService.js +11 -14
  65. package/lib/services/PresetService.d.ts +8 -3
  66. package/lib/services/PresetService.js +60 -59
  67. package/lib/services/ProjectService.d.ts +11 -4
  68. package/lib/services/ProjectService.js +140 -129
  69. package/lib/services/index.js +21 -80
  70. package/lib/types/Config.d.ts +4 -3
  71. package/lib/types/Config.js +1 -4
  72. package/lib/types/EnvConfig.js +1 -4
  73. package/lib/types/index.js +16 -25
  74. package/lib/utils/buildOptions.js +5 -8
  75. package/lib/utils/demuxOutput.js +16 -20
  76. package/lib/utils/escapeRegExp.js +4 -7
  77. package/lib/utils/exec.js +38 -39
  78. package/lib/utils/fetch.js +46 -30
  79. package/lib/utils/followProgress.js +66 -77
  80. package/lib/utils/format-size-units.js +16 -16
  81. package/lib/utils/get-config.d.ts +1 -1
  82. package/lib/utils/get-config.js +13 -16
  83. package/lib/utils/get-cursor-position.js +22 -29
  84. package/lib/utils/image-build.js +35 -23
  85. package/lib/utils/index.js +32 -191
  86. package/lib/utils/injectVariables.js +10 -13
  87. package/lib/utils/parse-table.js +20 -23
  88. package/lib/utils/set-config.d.ts +1 -1
  89. package/lib/utils/set-config.js +12 -15
  90. package/lib/utils/spawn.js +17 -20
  91. package/lib/utils/tty.js +2 -6
  92. package/lib/utils/volumeFormat.js +5 -12
  93. package/lib/utils/volumeParse.js +10 -13
  94. package/package.json +13 -39
  95. package/presets/bun/Dockerfile +11 -0
  96. package/presets/bun/config.json +3 -0
  97. package/presets/node/Dockerfile +4 -2
  98. package/presets/php-apache/Dockerfile +3 -2
  99. package/.github/workflows/publish.yml +0 -31
  100. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
@@ -1,265 +1,320 @@
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.MongodbPlugin = void 0;
7
- var _core = require("@wocker/core");
8
- var _utils = require("@wocker/utils");
9
- var Path = _interopRequireWildcard(require("path"));
10
- var dateFns = _interopRequireWildcard(require("date-fns"));
11
- var _env = require("../env");
12
- var _makes = require("../makes");
13
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
- class MongodbPlugin extends _makes.Plugin {
16
- container = "mongodb.workspace";
17
- adminContainer = "dbadmin-mongodb.workspace";
18
- constructor(di) {
19
- super("mongodb");
20
- this.dockerService = di.resolveService(_core.DockerService);
21
- this.dataDir = Path.join(_env.DATA_DIR, "db/mongodb");
22
- }
23
- install(cli) {
24
- super.install(cli);
25
- cli.command("mongodb:start").action(() => {
26
- return this.start();
27
- });
28
- cli.command("mongodb:stop").action(() => {
29
- return this.stop();
30
- });
31
- cli.command("mongodb:restart").action(() => {
32
- return this.restart();
33
- });
34
- cli.command("mongodb:backup [database]").completion("database", () => {
35
- return this.getDatabases();
36
- }).action((options, database) => {
37
- return this.backup(database);
38
- });
39
- cli.command("mongodb:restore [database] [filename]").completion("database", () => {
40
- const dumpPath = this.dataPath("dump");
41
- return _makes.FS.readdir(dumpPath);
42
- }).completion("filename", (options, database) => {
43
- if (!database) {
44
- return [];
45
- }
46
- const dirPath = this.dataPath("dump", database);
47
- if (!_makes.FS.existsSync(dirPath)) {
48
- return [];
49
- }
50
- return _makes.FS.readdir(dirPath);
51
- }).action((options, database, filename) => {
52
- return this.restore(database, filename);
53
- });
54
- cli.command("mongodb:delete-backup [database] [filename]").option("yes", {
55
- type: "boolean",
56
- alias: "y"
57
- }).completion("database", () => {
58
- return this.getDatabasesDumps();
59
- }).completion("filename", (options, database) => {
60
- if (!database) {
61
- return [];
62
- }
63
- const dumpPath = this.dataPath("dump", database);
64
- if (!_makes.FS.existsSync(dumpPath)) {
65
- return [];
66
- }
67
- return _makes.FS.readdirFiles(dumpPath);
68
- }).action((options, database, filename) => {
69
- return this.deleteBackup(database, filename, options.yes);
70
- });
71
- }
72
- async getDatabases() {
73
- const stream = await _makes.Docker.exec(this.container, ["mongosh", "--username", "root", "--password", "toor", "--quiet", "--eval", "db.getMongo().getDBNames().forEach(function(i){print(i)})"], false);
74
- let res = "";
75
- stream.on("data", data => {
76
- res += (0, _utils.demuxOutput)(data).toString();
77
- });
78
- await new Promise((resolve, reject) => {
79
- stream.on("end", resolve);
80
- stream.on("error", reject);
81
- });
82
- return res.split(/\r?\n/).filter(database => {
83
- return !!database;
84
- });
85
- }
86
- async getDatabasesDumps() {
87
- const dumpDir = this.dataPath("dump");
88
- return _makes.FS.readdir(dumpDir);
89
- }
90
- async start() {
91
- console.log("Mongidb starting...");
92
- await _makes.Docker.pullImage("mongo:latest");
93
- const container = await this.dockerService.createContainer({
94
- name: this.container,
95
- restart: "always",
96
- image: "mongo:latest",
97
- volumes: [`${this.dataPath()}:/data/db`],
98
- ports: ["27017:27017"],
99
- env: {
100
- MONGO_INITDB_ROOT_USERNAME: "root",
101
- MONGO_INITDB_ROOT_PASSWORD: "toor",
102
- MONGO_ROOT_USER: "root",
103
- MONGO_ROOT_PASSWORD: "toor"
104
- }
105
- });
106
- await container.start();
107
- await this.startAdmin();
108
- }
109
- async startAdmin() {
110
- console.log("Mongodb Admin starting...");
111
- await _makes.Docker.pullImage("mongo-express:latest");
112
- const container = await this.dockerService.createContainer({
113
- name: this.adminContainer,
114
- restart: "always",
115
- env: {
116
- ME_CONFIG_MONGODB_SERVER: this.container,
117
- ME_CONFIG_MONGODB_PORT: "27017",
118
- MONGO_ROOT_USER: "root",
119
- MONGO_ROOT_PASSWORD: "toor",
120
- ME_CONFIG_MONGODB_ADMINUSERNAME: "root",
121
- ME_CONFIG_MONGODB_ADMINPASSWORD: "toor",
122
- ME_CONFIG_MONGODB_ENABLE_ADMIN: "true",
123
- ME_CONFIG_MONGODB_AUTH_DATABASE: "admin",
124
- ME_CONFIG_MONGODB_AUTH_USERNAME: "root",
125
- ME_CONFIG_MONGODB_AUTH_PASSWORD: "toor",
126
- VIRTUAL_HOST: this.adminContainer,
127
- VIRTUAL_PORT: "8081"
128
- },
129
- image: "mongo-express:latest"
130
- });
131
- await container.start();
132
- }
133
- async stop() {
134
- await this.stopDB();
135
- await this.stopAdmin();
136
- }
137
- async stopDB() {
138
- console.log("Mongodb stopping...");
139
- const container = await this.dockerService.getContainer(this.container);
140
- if (container) {
141
- try {
142
- await container.stop();
143
- await container.remove();
144
- } catch (err) {
145
- _makes.Logger.error(err.message);
146
- }
147
- }
148
- }
149
- async stopAdmin() {
150
- console.log("Mongodb Admin stopping...");
151
- await this.dockerService.removeContainer(this.adminContainer);
152
- }
153
- async restart() {
154
- await this.stop();
155
- await this.start();
156
- }
157
- async backup(database) {
158
- if (!database) {
159
- database = await (0, _utils.promptSelect)({
160
- message: "Database",
161
- options: await this.getDatabases()
162
- });
27
+ const utils_1 = require("@wocker/utils");
28
+ const Path = __importStar(require("path"));
29
+ const dateFns = __importStar(require("date-fns"));
30
+ const env_1 = require("../env");
31
+ const makes_1 = require("../makes");
32
+ const services_1 = require("../services");
33
+ class MongodbPlugin extends makes_1.Plugin {
34
+ constructor(di) {
35
+ super("mongodb");
36
+ this.container = "mongodb.workspace";
37
+ this.adminContainer = "dbadmin-mongodb.workspace";
38
+ this.dockerService = di.resolveService(services_1.DockerService);
39
+ this.dataDir = Path.join(env_1.DATA_DIR, "db/mongodb");
163
40
  }
164
- const date = dateFns.format(new Date(), "yyyy-MM-dd HH-mm");
165
- const dirPath = this.dataPath("dump", database);
166
- const filePath = this.dataPath("dump", database, `${date}.gz`);
167
- if (!_makes.FS.existsSync(dirPath)) {
168
- _makes.FS.mkdirSync(dirPath, {
169
- recursive: true
170
- });
41
+ install(cli) {
42
+ super.install(cli);
43
+ cli.command("mongodb:start").action(() => {
44
+ return this.start();
45
+ });
46
+ cli.command("mongodb:stop").action(() => {
47
+ return this.stop();
48
+ });
49
+ cli.command("mongodb:restart").action(() => {
50
+ return this.restart();
51
+ });
52
+ cli.command("mongodb:backup [database]")
53
+ .completion("database", () => {
54
+ return this.getDatabases();
55
+ })
56
+ .action((options, database) => {
57
+ return this.backup(database);
58
+ });
59
+ cli.command("mongodb:restore [database] [filename]")
60
+ .completion("database", () => {
61
+ const dumpPath = this.dataPath("dump");
62
+ return makes_1.FS.readdir(dumpPath);
63
+ })
64
+ .completion("filename", (options, database) => {
65
+ if (!database) {
66
+ return [];
67
+ }
68
+ const dirPath = this.dataPath("dump", database);
69
+ if (!makes_1.FS.existsSync(dirPath)) {
70
+ return [];
71
+ }
72
+ return makes_1.FS.readdir(dirPath);
73
+ })
74
+ .action((options, database, filename) => {
75
+ return this.restore(database, filename);
76
+ });
77
+ cli.command("mongodb:delete-backup [database] [filename]")
78
+ .option("yes", {
79
+ type: "boolean",
80
+ alias: "y"
81
+ })
82
+ .completion("database", () => {
83
+ return this.getDatabasesDumps();
84
+ })
85
+ .completion("filename", (options, database) => {
86
+ if (!database) {
87
+ return [];
88
+ }
89
+ const dumpPath = this.dataPath("dump", database);
90
+ if (!makes_1.FS.existsSync(dumpPath)) {
91
+ return [];
92
+ }
93
+ return makes_1.FS.readdirFiles(dumpPath);
94
+ })
95
+ .action((options, database, filename) => {
96
+ return this.deleteBackup(database, filename, options.yes);
97
+ });
171
98
  }
172
- const stream = await _makes.Docker.exec(this.container, ["mongodump", "--authenticationDatabase", "admin", "--host", `${this.container}:27017`, "--username", "root", "--password", "toor", "--db", database, "--archive", "--gzip"], false);
173
- const file = _makes.FS.createWriteStream(filePath);
174
- stream.on("data", data => {
175
- file.write((0, _utils.demuxOutput)(data));
176
- });
177
- await new Promise((resolve, reject) => {
178
- stream.on("end", resolve);
179
- stream.on("error", reject);
180
- });
181
- }
182
- async deleteBackup(database, filename, yes) {
183
- if (!database) {
184
- database = await (0, _utils.promptSelect)({
185
- message: "Database",
186
- options: await this.getDatabasesDumps()
187
- });
99
+ async getDatabases() {
100
+ const stream = await makes_1.Docker.exec(this.container, [
101
+ "mongosh",
102
+ "--username", "root",
103
+ "--password", "toor",
104
+ "--quiet",
105
+ "--eval", "db.getMongo().getDBNames().forEach(function(i){print(i)})"
106
+ ], false);
107
+ let res = "";
108
+ stream.on("data", (data) => {
109
+ res += (0, utils_1.demuxOutput)(data).toString();
110
+ });
111
+ await new Promise((resolve, reject) => {
112
+ stream.on("end", resolve);
113
+ stream.on("error", reject);
114
+ });
115
+ return res.split(/\r?\n/).filter((database) => {
116
+ return !!database;
117
+ });
188
118
  }
189
- if (!database) {
190
- throw new Error("No database");
119
+ async getDatabasesDumps() {
120
+ const dumpDir = this.dataPath("dump");
121
+ return makes_1.FS.readdir(dumpDir);
191
122
  }
192
- const dirPath = this.dataPath("dump", database);
193
- if (!_makes.FS.existsSync(dirPath)) {
194
- throw new Error(`Backups dir for database "${database}" not found`);
123
+ async start() {
124
+ console.log("Mongidb starting...");
125
+ await makes_1.Docker.pullImage("mongo:latest");
126
+ const container = await this.dockerService.createContainer({
127
+ name: this.container,
128
+ restart: "always",
129
+ image: "mongo:latest",
130
+ volumes: [
131
+ `${this.dataPath()}:/data/db`
132
+ ],
133
+ ports: ["27017:27017"],
134
+ env: {
135
+ MONGO_INITDB_ROOT_USERNAME: "root",
136
+ MONGO_INITDB_ROOT_PASSWORD: "toor",
137
+ MONGO_ROOT_USER: "root",
138
+ MONGO_ROOT_PASSWORD: "toor"
139
+ }
140
+ });
141
+ await container.start();
142
+ await this.startAdmin();
195
143
  }
196
- if (!filename) {
197
- const files = await _makes.FS.readdirFiles(dirPath);
198
- if (files.length === 0) {
199
- throw new Error(`No backups for ${database}`);
200
- }
201
- filename = await (0, _utils.promptSelect)({
202
- message: "File",
203
- options: files
204
- });
144
+ async startAdmin() {
145
+ console.log("Mongodb Admin starting...");
146
+ await makes_1.Docker.pullImage("mongo-express:latest");
147
+ const container = await this.dockerService.createContainer({
148
+ name: this.adminContainer,
149
+ restart: "always",
150
+ env: {
151
+ ME_CONFIG_MONGODB_SERVER: this.container,
152
+ ME_CONFIG_MONGODB_PORT: "27017",
153
+ MONGO_ROOT_USER: "root",
154
+ MONGO_ROOT_PASSWORD: "toor",
155
+ ME_CONFIG_MONGODB_ADMINUSERNAME: "root",
156
+ ME_CONFIG_MONGODB_ADMINPASSWORD: "toor",
157
+ ME_CONFIG_MONGODB_ENABLE_ADMIN: "true",
158
+ ME_CONFIG_MONGODB_AUTH_DATABASE: "admin",
159
+ ME_CONFIG_MONGODB_AUTH_USERNAME: "root",
160
+ ME_CONFIG_MONGODB_AUTH_PASSWORD: "toor",
161
+ VIRTUAL_HOST: this.adminContainer,
162
+ VIRTUAL_PORT: "8081"
163
+ },
164
+ image: "mongo-express:latest"
165
+ });
166
+ await container.start();
205
167
  }
206
- const filePath = this.dataPath("dump", database, filename);
207
- if (!_makes.FS.existsSync(filePath)) {
208
- throw new Error(`Backup "${filename}" not found`);
168
+ async stop() {
169
+ await this.stopDB();
170
+ await this.stopAdmin();
209
171
  }
210
- if (!yes) {
211
- yes = await (0, _utils.promptConfirm)({
212
- message: `Delete ${filename}?`,
213
- default: false
214
- });
172
+ async stopDB() {
173
+ console.log("Mongodb stopping...");
174
+ const container = await this.dockerService.getContainer(this.container);
175
+ if (container) {
176
+ try {
177
+ await container.stop();
178
+ await container.remove();
179
+ }
180
+ catch (err) {
181
+ makes_1.Logger.error(err.message);
182
+ }
183
+ }
215
184
  }
216
- if (!yes) {
217
- return;
185
+ async stopAdmin() {
186
+ console.log("Mongodb Admin stopping...");
187
+ await this.dockerService.removeContainer(this.adminContainer);
218
188
  }
219
- await _makes.FS.rm(filePath);
220
- const otherFiles = await _makes.FS.readdir(dirPath);
221
- if (otherFiles.length === 0) {
222
- await _makes.FS.rm(dirPath, {
223
- force: true,
224
- recursive: true
225
- });
189
+ async restart() {
190
+ await this.stop();
191
+ await this.start();
226
192
  }
227
- }
228
- async restore(database, filename) {
229
- if (!database) {
230
- const dumps = await _makes.FS.readdir(this.dataPath("dump"));
231
- if (dumps.length === 0) {
232
- throw new Error("No dumps found");
233
- }
234
- database = await (0, _utils.promptSelect)({
235
- message: "Database",
236
- options: dumps
237
- });
193
+ async backup(database) {
194
+ if (!database) {
195
+ database = await (0, utils_1.promptSelect)({
196
+ message: "Database",
197
+ options: await this.getDatabases()
198
+ });
199
+ }
200
+ const date = dateFns.format(new Date(), "yyyy-MM-dd HH-mm");
201
+ const dirPath = this.dataPath("dump", database);
202
+ const filePath = this.dataPath("dump", database, `${date}.gz`);
203
+ if (!makes_1.FS.existsSync(dirPath)) {
204
+ makes_1.FS.mkdirSync(dirPath, {
205
+ recursive: true
206
+ });
207
+ }
208
+ const stream = await makes_1.Docker.exec(this.container, [
209
+ "mongodump",
210
+ "--authenticationDatabase", "admin",
211
+ "--host", `${this.container}:27017`,
212
+ "--username", "root",
213
+ "--password", "toor",
214
+ "--db", database,
215
+ "--archive",
216
+ "--gzip"
217
+ ], false);
218
+ const file = makes_1.FS.createWriteStream(filePath);
219
+ stream.on("data", (data) => {
220
+ file.write((0, utils_1.demuxOutput)(data));
221
+ });
222
+ await new Promise((resolve, reject) => {
223
+ stream.on("end", resolve);
224
+ stream.on("error", reject);
225
+ });
238
226
  }
239
- if (!database) {
240
- throw new Error("Need database name");
227
+ async deleteBackup(database, filename, yes) {
228
+ if (!database) {
229
+ database = await (0, utils_1.promptSelect)({
230
+ message: "Database",
231
+ options: await this.getDatabasesDumps()
232
+ });
233
+ }
234
+ if (!database) {
235
+ throw new Error("No database");
236
+ }
237
+ const dirPath = this.dataPath("dump", database);
238
+ if (!makes_1.FS.existsSync(dirPath)) {
239
+ throw new Error(`Backups dir for database "${database}" not found`);
240
+ }
241
+ if (!filename) {
242
+ const files = await makes_1.FS.readdirFiles(dirPath);
243
+ if (files.length === 0) {
244
+ throw new Error(`No backups for ${database}`);
245
+ }
246
+ filename = await (0, utils_1.promptSelect)({
247
+ message: "File",
248
+ options: files
249
+ });
250
+ }
251
+ const filePath = this.dataPath("dump", database, filename);
252
+ if (!makes_1.FS.existsSync(filePath)) {
253
+ throw new Error(`Backup "${filename}" not found`);
254
+ }
255
+ if (!yes) {
256
+ yes = await (0, utils_1.promptConfirm)({
257
+ message: `Delete ${filename}?`,
258
+ default: false
259
+ });
260
+ }
261
+ if (!yes) {
262
+ return;
263
+ }
264
+ await makes_1.FS.rm(filePath);
265
+ const otherFiles = await makes_1.FS.readdir(dirPath);
266
+ if (otherFiles.length === 0) {
267
+ await makes_1.FS.rm(dirPath, {
268
+ force: true,
269
+ recursive: true
270
+ });
271
+ }
241
272
  }
242
- if (!filename) {
243
- const filenames = await _makes.FS.readdir(this.dataPath("dump", database));
244
- filename = await (0, _utils.promptSelect)({
245
- message: "File",
246
- options: filenames
247
- });
273
+ async restore(database, filename) {
274
+ if (!database) {
275
+ const dumps = await makes_1.FS.readdir(this.dataPath("dump"));
276
+ if (dumps.length === 0) {
277
+ throw new Error("No dumps found");
278
+ }
279
+ database = await (0, utils_1.promptSelect)({
280
+ message: "Database",
281
+ options: dumps
282
+ });
283
+ }
284
+ if (!database) {
285
+ throw new Error("Need database name");
286
+ }
287
+ if (!filename) {
288
+ const filenames = await makes_1.FS.readdir(this.dataPath("dump", database));
289
+ filename = await (0, utils_1.promptSelect)({
290
+ message: "File",
291
+ options: filenames
292
+ });
293
+ }
294
+ const path = this.dataPath("dump", database, filename);
295
+ const file = makes_1.FS.createReadStream(path);
296
+ const stream = await makes_1.Docker.exec(this.container, [
297
+ "mongorestore",
298
+ "--authenticationDatabase", "admin",
299
+ "--host", `${this.container}:27017`,
300
+ "--username", "root",
301
+ "--password", "toor",
302
+ "--db", database,
303
+ "--drop",
304
+ "--gzip",
305
+ "--archive"
306
+ ], false);
307
+ file.on("data", (data) => {
308
+ stream.write(data);
309
+ });
310
+ file.on("end", () => {
311
+ throw new Error("File end");
312
+ });
313
+ stream.on("error", (err) => {
314
+ file.close();
315
+ throw err;
316
+ });
317
+ console.log(path);
248
318
  }
249
- const path = this.dataPath("dump", database, filename);
250
- const file = _makes.FS.createReadStream(path);
251
- const stream = await _makes.Docker.exec(this.container, ["mongorestore", "--authenticationDatabase", "admin", "--host", `${this.container}:27017`, "--username", "root", "--password", "toor", "--db", database, "--drop", "--gzip", "--archive"], false);
252
- file.on("data", data => {
253
- stream.write(data);
254
- });
255
- file.on("end", () => {
256
- throw new Error("File end");
257
- });
258
- stream.on("error", err => {
259
- file.close();
260
- throw err;
261
- });
262
- console.log(path);
263
- }
264
319
  }
265
- exports.MongodbPlugin = MongodbPlugin;
320
+ exports.MongodbPlugin = MongodbPlugin;
@@ -1,6 +1,6 @@
1
- import { DI, Project, AppEventsService, ProjectService } from "@wocker/core";
2
1
  import { Cli } from "@kearisp/cli";
3
- import { Plugin } from "src/makes";
2
+ import { DI, Plugin, Project } from "../makes";
3
+ import { AppEventsService, ProjectService } from "../services";
4
4
  type StartOptions = {
5
5
  name?: string;
6
6
  detach?: string;