@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,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Preset = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _md = _interopRequireDefault(require("md5"));
9
- var _env = require("../env");
10
- var _makes = require("../makes");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
- class Preset {
15
- constructor(data) {
16
- if (data) {
17
- for (const i in data) {
18
- this[i] = data[i];
19
- }
20
- }
21
- }
22
- getImageArgs(project) {
23
- if (!this.buildArgsOptions) {
24
- return {};
25
- }
26
- return Object.keys(this.buildArgsOptions).reduce((buildArgs, key) => {
27
- buildArgs[key] = project.buildArgs[key];
28
- return buildArgs;
29
- }, {});
30
- }
31
- getImageName(buildArgs) {
32
- const rawValues = [];
33
- const hashValues = [];
34
- Object.keys(buildArgs).forEach(key => {
35
- const {
36
- [key]: {
37
- hash = true
38
- } = {}
39
- } = this.buildArgsOptions || {};
40
- const value = buildArgs[key];
41
- if (hash) {
42
- hashValues.push(value);
43
- } else {
44
- rawValues.push(value);
45
- }
46
- });
47
- const version = [...rawValues, (0, _md.default)(hashValues.join(",")).substr(0, 6)].filter(value => {
48
- return !!value;
49
- }).join("-");
50
- return `ws-preset-${this.name}:${version}`;
51
- }
52
- static async get(name) {
53
- const data = await _makes.FS.readJSON(Path.join(_env.PRESETS_DIR, name, "config.json"));
54
- return new Preset({
55
- name,
56
- ...data
57
- });
58
- }
59
- }
60
- exports.Preset = Preset;
@@ -1,151 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Project = exports.PROJECT_TYPE_IMAGE = exports.PROJECT_TYPE_DOCKERFILE = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _makes = require("../makes");
9
- var _utils = require("../utils");
10
- var _env = require("../env");
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- class Project {
14
- setEnv(name, value) {
15
- this.env = {
16
- ...(this.env || {}),
17
- [name]: typeof value === "boolean" ? value ? "true" : "false" : value
18
- };
19
- }
20
- getEnv(name, defaultValue) {
21
- const {
22
- [name]: value = defaultValue
23
- } = this.env || {};
24
- return value;
25
- }
26
- unsetEnv(name) {
27
- if (this.env && this.env[name]) {
28
- delete this.env[name];
29
- }
30
- }
31
- getMeta(name, defaultValue) {
32
- const {
33
- [name]: value = defaultValue
34
- } = this.meta || {};
35
- return value;
36
- }
37
- setMeta(name, value) {
38
- if (!this.meta) {
39
- this.meta = {};
40
- }
41
- this.meta[name] = value;
42
- }
43
- volumeMount(...volumes) {
44
- if (volumes.length === 0) {
45
- return;
46
- }
47
- const [volume, ...restVolumes] = volumes;
48
- const {
49
- destination
50
- } = (0, _utils.volumeParse)(volume);
51
- this.volumes = [...(this.volumes || []).filter(v => {
52
- return v !== this.getVolumeByDestination(destination);
53
- }), volume];
54
- this.volumeMount(...restVolumes);
55
- }
56
- getVolumeBySource(source) {
57
- return (this.volumes || []).find(volume => {
58
- return (0, _utils.volumeParse)(volume).source === source;
59
- });
60
- }
61
- getVolumeByDestination(destination) {
62
- return (this.volumes || []).find(volume => {
63
- return (0, _utils.volumeParse)(volume).destination === destination;
64
- });
65
- }
66
- volumeUnmount(...volumes) {
67
- this.volumes = this.volumes.filter(mounted => {
68
- return !volumes.includes(mounted);
69
- });
70
- }
71
- static async get(id) {
72
- //
73
- }
74
- async save() {
75
- if (!this.name) {
76
- throw new Error("Project should has a name");
77
- }
78
- if (!this.path) {
79
- throw new Error("Project should has a path");
80
- }
81
- if (!this.id) {
82
- this.id = this.name;
83
- }
84
- const projectDirPath = Path.join(_env.DATA_DIR, "projects", this.name);
85
- if (!_makes.FS.existsSync(projectDirPath)) {
86
- await _makes.FS.mkdir(projectDirPath);
87
- }
88
- const configPath = Path.join(_env.DATA_DIR, "projects", this.id, "config.json");
89
- await _makes.FS.writeJSON(configPath, this);
90
- const config = await (0, _utils.getConfig)();
91
- await (0, _utils.setConfig)({
92
- ...config,
93
- projects: [...(config.projects || []).filter(project => {
94
- return project.id !== this.id;
95
- }).filter(project => {
96
- return project.src !== this.path;
97
- }), {
98
- id: this.id,
99
- src: this.path
100
- }]
101
- });
102
- }
103
- static fromObject(data) {
104
- const project = new Project();
105
- for (const i in data) {
106
- project[i] = data[i];
107
- }
108
- return project;
109
- }
110
- static async search(params = {}) {
111
- const {
112
- id,
113
- name,
114
- src
115
- } = params;
116
- const map = await _makes.FS.readJSON(_env.MAP_PATH);
117
- const mapProjects = map.projects.filter(config => {
118
- if (id) {
119
- return config.id === id;
120
- }
121
- return true;
122
- }).filter(config => {
123
- if (src) {
124
- return config.src === src;
125
- }
126
- return true;
127
- });
128
- const projects = [];
129
- for (const i in mapProjects) {
130
- const projectConfig = await _makes.FS.readJSON(Path.join(_env.DATA_DIR, "projects", mapProjects[i].id, "config.json"));
131
- const project = Project.fromObject({
132
- ...projectConfig,
133
- id: projectConfig.id
134
- });
135
- if (name && project.name !== name) {
136
- continue;
137
- }
138
- projects.push(project);
139
- }
140
- return projects;
141
- }
142
- static async searchOne(params = {}) {
143
- const [project] = await Project.search(params);
144
- return project || null;
145
- }
146
- }
147
- exports.Project = Project;
148
- const PROJECT_TYPE_DOCKERFILE = "dockerfile";
149
- exports.PROJECT_TYPE_DOCKERFILE = PROJECT_TYPE_DOCKERFILE;
150
- const PROJECT_TYPE_IMAGE = "image";
151
- exports.PROJECT_TYPE_IMAGE = PROJECT_TYPE_IMAGE;
@@ -1,2 +0,0 @@
1
- export * from "./Preset";
2
- export * from "./Project";
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Preset = require("./Preset");
7
- Object.keys(_Preset).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _Preset[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _Preset[key];
14
- }
15
- });
16
- });
17
- var _Project = require("./Project");
18
- Object.keys(_Project).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _Project[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _Project[key];
25
- }
26
- });
27
- });
@@ -1,25 +0,0 @@
1
- import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
3
- declare class MariadbPlugin extends Plugin {
4
- protected dbDir: string;
5
- protected user: string;
6
- protected password: string;
7
- constructor();
8
- install(cli: Cli): void;
9
- protected getDatabases(): Promise<string[]>;
10
- protected getDumpDatabases(): Promise<string[]>;
11
- protected getDumpFiles(database?: string): Promise<string[]>;
12
- start(): Promise<void>;
13
- protected startMariadb(): Promise<void>;
14
- protected startAdmin(): Promise<void>;
15
- stop(): Promise<void>;
16
- protected stopMariadb(): Promise<void>;
17
- protected stopAdmin(): Promise<void>;
18
- exec(options: any, command: string[]): Promise<void>;
19
- backup(database?: string): Promise<void>;
20
- deleteBackup(options: any, database?: string, filename?: string): Promise<void>;
21
- restore(options: any, database?: string, filename?: string): Promise<void>;
22
- dump(options: any, database?: string): Promise<void>;
23
- import(options: any, database?: string): Promise<void>;
24
- }
25
- export { MariadbPlugin };
@@ -1,297 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.MariadbPlugin = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _format = _interopRequireDefault(require("date-fns/format"));
9
- var _env = require("../env");
10
- var _makes = require("../makes");
11
- var _utils = require("../utils");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- 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); }
14
- 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; }
15
- class MariadbPlugin extends _makes.Plugin {
16
- user = "root";
17
- password = "toor";
18
- constructor() {
19
- super("mariadb");
20
- this.dbDir = Path.join(_env.DATA_DIR, "db/mariadb");
21
- // this.dataDir = Path.join(PLUGINS_DIR, "mariadb");
22
- }
23
-
24
- install(cli) {
25
- super.install(cli);
26
- cli.command("mariadb:start").action(() => this.start());
27
- cli.command("mariadb:stop").action(() => this.stop());
28
- cli.command("mariadb:backup [database]").completion("database", () => this.getDatabases()).action((options, database) => this.backup(database));
29
- cli.command("mariadb:delete-backup [database] [filename]").option("yes", {
30
- type: "boolean",
31
- alias: "y"
32
- }).completion("database", () => this.getDumpDatabases()).completion("filename", (options, database) => this.getDumpFiles(database)).action((options, database, filename) => this.deleteBackup(options, database, filename));
33
- cli.command("mariadb:restore [database] [filename]").completion("database", () => this.getDumpDatabases()).completion("filename", (options, database) => this.getDumpFiles(database)).action((options, database, filename) => this.restore(options, database, filename));
34
- cli.command("mariadb:import <database>").completion("database", () => this.getDatabases()).action((options, database) => this.import(options, database));
35
- cli.command("mariadb:dump <database>").completion("database", () => this.getDatabases()).action((options, database) => this.dump(options, database));
36
- cli.command("mariadb:exec [...command]").action((options, command) => this.exec(options, command));
37
- }
38
- async getDatabases() {
39
- const stream = await _makes.Docker.exec("mariadb.workspace", ["mysql", `-u${this.user}`, `-p${this.password}`, "-e", "SHOW DATABASES;"], false);
40
- let res = "";
41
- stream.on("data", data => {
42
- res += (0, _utils.demuxOutput)(data).toString();
43
- });
44
- await new Promise((resolve, reject) => {
45
- stream.on("end", resolve);
46
- stream.on("error", reject);
47
- });
48
- return res.split(/\r?\n/).filter(database => {
49
- return !/Database$/.test(database);
50
- }).filter(database => {
51
- return !/_schema/.test(database);
52
- }).filter(database => {
53
- return !!database;
54
- });
55
- }
56
- async getDumpDatabases() {
57
- return _makes.FS.readdir(this.dataPath("dump"));
58
- }
59
- async getDumpFiles(database) {
60
- if (!database) {
61
- return [];
62
- }
63
- const dirPath = this.dataPath("dump", database);
64
- if (!_makes.FS.existsSync(dirPath)) {
65
- return [];
66
- }
67
- return _makes.FS.readdirFiles(dirPath);
68
- }
69
- async start() {
70
- await this.startMariadb();
71
- await this.startAdmin();
72
- }
73
- async startMariadb() {
74
- console.info("Mariadb starting...");
75
- await _makes.Docker.pullImage("mariadb:10.5");
76
- await _makes.Docker.containerRun({
77
- name: "mariadb.workspace",
78
- restart: "always",
79
- ports: ["3306:3306"],
80
- env: {
81
- MYSQL_ROOT_PASSWORD: "toor"
82
- },
83
- volumes: [`${this.dbDir}:/var/lib/mysql`],
84
- image: "mariadb:10.5"
85
- });
86
- }
87
- async startAdmin() {
88
- console.info("Phpmyadmin starting...");
89
- const configPath = "conf/config.user.inc.php";
90
- if (!_makes.FS.existsSync(this.dataPath(configPath))) {
91
- await _makes.FS.mkdir(Path.dirname(this.dataPath(configPath)), {
92
- recursive: true
93
- });
94
- await _makes.FS.copyFile(this.pluginPath("admin", configPath), this.dataPath(configPath));
95
- }
96
- await _makes.FS.mkdir(this.dataPath("save"), {
97
- recursive: true
98
- });
99
- await _makes.FS.mkdir(this.dataPath("upload"), {
100
- recursive: true
101
- });
102
- await _makes.Docker.pullImage("phpmyadmin/phpmyadmin:latest");
103
- await _makes.Docker.containerRun({
104
- name: "dbadmin-mariadb.workspace",
105
- restart: "always",
106
- env: {
107
- PMA_USER: "root",
108
- PMA_PASSWORD: "toor",
109
- VIRTUAL_HOST: "dbadmin-mariadb.workspace",
110
- VIRTUAL_PORT: "80"
111
- },
112
- volumes: [`${this.dataPath("conf/config.user.inc.php")}:/etc/phpmyadmin/config.user.inc.php`, `${this.dataPath("save")}:/etc/phpmyadmin/save`, `${this.dataPath("upload")}:/etc/phpmyadmin/upload`],
113
- links: ["mariadb.workspace:db"],
114
- image: "phpmyadmin/phpmyadmin:latest"
115
- });
116
- }
117
- async stop() {
118
- await this.stopMariadb();
119
- await this.stopAdmin();
120
- }
121
- async stopMariadb() {
122
- console.info("Mariadb stopping...");
123
- const container = await _makes.Docker.getContainer("mariadb.workspace");
124
- if (container) {
125
- try {
126
- await container.stop();
127
- } catch (err) {
128
- _makes.Logger.warning(err.message, {
129
- class: "MariadbPlugin"
130
- });
131
- }
132
- try {
133
- await container.remove();
134
- } catch (err) {
135
- _makes.Logger.warning(err.message, {
136
- class: "MariadbPlugin"
137
- });
138
- }
139
- }
140
- }
141
- async stopAdmin() {
142
- console.info("Phpmyadmin stopping...");
143
- const container = await _makes.Docker.getContainer("dbadmin-mariadb.workspace");
144
- if (container) {
145
- try {
146
- await container.stop();
147
- } catch (err) {
148
- _makes.Logger.warning(err.message, {
149
- class: "MariadbPlugin"
150
- });
151
- }
152
- try {
153
- await container.remove();
154
- } catch (err) {
155
- _makes.Logger.warning(err.message, {
156
- class: "MariadbPlugin"
157
- });
158
- }
159
- }
160
- }
161
- async exec(options, command) {
162
- await _makes.Docker.exec("mariadb.workspace", command);
163
- }
164
- async backup(database) {
165
- if (!database) {
166
- database = await (0, _utils.promptSelect)({
167
- message: "Database",
168
- options: await this.getDatabases()
169
- });
170
- }
171
- const date = (0, _format.default)(new Date(), "yyyy-MM-dd HH-mm");
172
- const filePath = this.dataPath("dump", database, `${date}.sql`);
173
- if (!_makes.FS.existsSync(Path.dirname(filePath))) {
174
- _makes.FS.mkdirSync(Path.dirname(filePath), {
175
- recursive: true
176
- });
177
- }
178
- const file = _makes.FS.createWriteStream(filePath);
179
- const stream = await _makes.Docker.exec("mariadb.workspace", ["mysqldump", "--add-drop-table", `-u${this.user}`, `-p${this.password}`, database], false);
180
- stream.on("data", data => {
181
- file.write((0, _utils.demuxOutput)(data));
182
- });
183
- }
184
- async deleteBackup(options, database, filename) {
185
- const {
186
- yes
187
- } = options;
188
- if (!database) {
189
- const dumps = await this.getDumpDatabases();
190
- if (dumps.length === 0) {
191
- throw new Error("No dump databases");
192
- }
193
- database = await (0, _utils.promptSelect)({
194
- message: "Database",
195
- options: dumps
196
- });
197
- }
198
- if (!filename) {
199
- const files = await _makes.FS.readdirFiles(this.dataPath("dump", database));
200
- if (files.length === 0) {
201
- throw new Error(`No backups for ${database}`);
202
- }
203
- filename = await (0, _utils.promptSelect)({
204
- message: "File",
205
- options: files
206
- });
207
- }
208
- if (!yes) {
209
- const confirm = await (0, _utils.promptConfirm)({
210
- message: `Delete ${filename}`,
211
- default: false
212
- });
213
- if (!confirm) {
214
- return;
215
- }
216
- }
217
- const filePath = this.dataPath("dump", database, filename);
218
- await _makes.FS.rm(filePath);
219
- const otherFiles = await _makes.FS.readdir(this.dataPath("dump", database));
220
- if (otherFiles.length === 0) {
221
- await _makes.FS.rm(this.dataPath("dump", database), {
222
- force: true,
223
- recursive: true
224
- });
225
- }
226
- }
227
- async restore(options, database, filename) {
228
- if (!database) {
229
- const dumps = await _makes.FS.readdir(this.dataPath("dump"));
230
- if (dumps.length === 0) {
231
- throw new Error("No dumps found");
232
- }
233
- database = await (0, _utils.promptSelect)({
234
- message: "Database",
235
- options: dumps
236
- });
237
- }
238
- if (!database) {
239
- throw new Error("Need database name");
240
- }
241
- const dirs = await _makes.FS.readdir(this.dataPath("dump", database));
242
- if (!filename) {
243
- filename = await (0, _utils.promptSelect)({
244
- message: "File",
245
- options: dirs
246
- });
247
- }
248
- const path = this.dataPath("dump", database, filename);
249
- const file = _makes.FS.createReadStream(path);
250
- const stream = await _makes.Docker.exec("mariadb.workspace", ["mysql", "-uroot", "-ptoor", database], false);
251
- file.on("data", data => {
252
- stream.write(data);
253
- });
254
- file.on("end", () => {
255
- stream.write("exit\n");
256
- });
257
- stream.on("error", data => {
258
- process.stderr.write((0, _utils.demuxOutput)(data));
259
- stream.write("exit\n");
260
- file.close();
261
- });
262
- }
263
- async dump(options, database) {
264
- const date = (0, _format.default)(new Date(), "yyyy-MM-dd HH-mm");
265
- const dirPath = this.dataPath("dump", database);
266
- const filePath = this.dataPath("dump", database, `${date}.sql`);
267
- if (!_makes.FS.existsSync(dirPath)) {
268
- _makes.FS.mkdirSync(dirPath, {
269
- recursive: true
270
- });
271
- }
272
-
273
- // const filePath = Path.join(DATA_DIR, `${database} ${date}.sql`);
274
- // console.log(filePath);
275
-
276
- const file = _makes.FS.createWriteStream(filePath);
277
- const stream = await _makes.Docker.exec("mariadb.workspace", ["mysqldump", "-uroot", "-ptoor", database]);
278
- stream.pipe(file);
279
- }
280
- async import(options, database) {
281
- const container = await _makes.Docker.getContainer("mariadb.workspace");
282
- const exec = await container.exec({
283
- AttachStdin: true,
284
- AttachStdout: true,
285
- AttachStderr: true,
286
- Tty: process.stdin.isTTY,
287
- Cmd: ["mysql", `-u${this.user}`, `-p${this.password}`, database]
288
- });
289
- const stream = await exec.start({
290
- hijack: true,
291
- stdin: true,
292
- Tty: process.stdin.isTTY
293
- });
294
- await _makes.Docker.attachStream(stream);
295
- }
296
- }
297
- exports.MariadbPlugin = MariadbPlugin;
@@ -1,19 +0,0 @@
1
- import { Cli } from "@kearisp/cli";
2
- import { Plugin } from "src/makes";
3
- import { Project } from "src/models";
4
- import { AppConfigService, AppEventsService } from "src/services";
5
- type BuildOptions = {
6
- rebuild?: boolean;
7
- };
8
- declare class PresetPlugin extends Plugin {
9
- protected appConfigService: AppConfigService;
10
- protected appEventsService: AppEventsService;
11
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService);
12
- install(cli: Cli): void;
13
- presets(): Promise<string[]>;
14
- protected onInit(project: Project): Promise<void>;
15
- protected onRebuild(project: Project): Promise<void>;
16
- protected onBeforeStart(project: Project): Promise<void>;
17
- build(options: BuildOptions, presetName: string): Promise<void>;
18
- }
19
- export { PresetPlugin };