@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Kris Papercut
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # Wocker
2
+
3
+ ###### Docker workspace for web projects
4
+
5
+ ## Requirements
6
+
7
+ - [node.js](https://nodejs.org)
8
+ - [docker](https://www.docker.com)
9
+
10
+
11
+ ## Usage
12
+
13
+ ### Installation
14
+
15
+ ```shell
16
+ npm i -g @wocker/ws
17
+ ```
18
+
19
+ ### Project initialization
20
+
21
+ ```text
22
+ 127.0.0.1 <domain>
23
+ ```
24
+
25
+ ```shell
26
+ cd /project-dir
27
+ ws init
28
+ ws domain:add <domain>
29
+ ```
30
+
31
+ ### Starting project container
32
+
33
+ ```shell
34
+ ws start -d
35
+ ```
36
+
37
+ Options:
38
+ - --detach, -d -
39
+
40
+ [//]: # (TODO)
41
+
42
+
43
+ ### Proxy
44
+
45
+ ```shell
46
+ ws proxy:start
47
+ ```
48
+
49
+ #### Logs
50
+
51
+ ```shell
52
+ ws proxy:logs
53
+ ```
54
+
55
+
56
+ ### Mariadb
57
+
58
+ #### Installation
59
+
60
+ To access the following services within the workspace, please add the following entries to your hosts file:
61
+
62
+ ```text
63
+ 127.0.0.1 maildev.workspace
64
+ 127.0.0.1 dbadmin-mariadb.workspace
65
+ ```
66
+
67
+
68
+ #### Start Mariadb
69
+
70
+ ```shell
71
+ ws maridb:start
72
+ ```
73
+
74
+ ### Backup db
75
+
76
+ The `mariadb:backup` command is used to create a backup of a MariaDB database.
77
+
78
+ ```shell
79
+ ws mariadb:backup [database]
80
+ ```
81
+
82
+ #### Backup Location
83
+
84
+ The backup file will be saved in the following directory:
85
+
86
+ > $WS_DIR/plugins/mariadb/dump/**\[dbname]**/yyyy-MM-dd HH-mm.sql
87
+
88
+
89
+ ### Delete backup
90
+
91
+ The `mariadb:delete-backup` command will remove file from `$WS_DIR` directory.
92
+
93
+ ```shell
94
+ ws mariadb:delete-backup [database] [filename]
95
+ ```
96
+
97
+ ### Dump
98
+
99
+ The `mariadb:dump` command is used to dump a MariaDB database to a file.
100
+
101
+ ```shell
102
+ ws mairadb:dump [database] > dump.sql
103
+ ```
104
+
105
+
106
+ ## Technologies
107
+
108
+ - [typescript](https://www.typescriptlang.org)
109
+ - [dockerode](https://npmjs.org/package/dockerode)
110
+
111
+
112
+ ## Environments
113
+
114
+ You can add `WS_DIR` into `.bashrc` for changing ws data path.
115
+
116
+ ```shell
117
+ export WS_DIR="$HOME/.workspace"
118
+ ```
119
+
120
+
121
+ ### Completion
122
+
123
+ ```bash
124
+ source <(ws completion script)
125
+ ```
126
+
127
+
128
+ ## Folders structure
129
+
130
+ ```text
131
+ ├── bin/
132
+ ├── plugins/
133
+ │ ├── localtunnel/
134
+ │ ├── maildev/
135
+ │ ├── mariadb/
136
+ │ └── ngrok/
137
+ ├── presets/
138
+ │ ├── apache/
139
+ │ ├── go/
140
+ │ ├── node/
141
+ │ └── shopify/
142
+ ├── plugins/
143
+ └── src/
144
+ ├── makes/
145
+ │ └── index.ts
146
+ ├── models/
147
+ │ └── index.ts
148
+ ├── types/
149
+ │ └── index.ts
150
+ ├── utils/
151
+ │ └── index.ts
152
+ ├── App.ts
153
+ ├── env.ts
154
+ └── index.ts
155
+ ```
package/bin/ws.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ const chalk = require("chalk");
4
+ const {app} = require("../lib/index.js");
5
+
6
+
7
+ app.run().then((res) => {
8
+ if(res) {
9
+ process.stdout.write(res);
10
+ }
11
+ }).catch((err) => {
12
+ console.error(chalk.red(err.message));
13
+ });
package/lib/App.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Controller, Plugin } from "src/makes";
3
+ import { AppConfigService } from "src/services";
4
+ export declare class App {
5
+ protected config: AppConfigService;
6
+ protected cli: Cli;
7
+ constructor(config: AppConfigService);
8
+ install(): void;
9
+ useController(controller: Controller): void;
10
+ usePlugin(plugin: Plugin): void;
11
+ setDebug(status: string): Promise<void>;
12
+ run(): Promise<string>;
13
+ }
package/lib/App.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.App = void 0;
7
+ var Path = _interopRequireWildcard(require("path"));
8
+ var _cli = require("@kearisp/cli");
9
+ var _env = require("./env");
10
+ var _utils = require("./utils");
11
+ var _makes = require("./makes");
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 App {
15
+ constructor(config) {
16
+ this.config = config;
17
+ this.cli = new _cli.Cli(_makes.Logger);
18
+ this.install();
19
+ }
20
+ install() {
21
+ this.cli.command("completion script").help(false).action(() => this.cli.completionScript());
22
+ this.cli.command("debug <status>").completion("status", () => ["on", "off"]).action(async (options, status) => this.setDebug(status));
23
+ }
24
+ useController(controller) {
25
+ controller.install(this.cli);
26
+ }
27
+ usePlugin(plugin) {
28
+ plugin.install(this.cli);
29
+ }
30
+ async setDebug(status) {
31
+ _makes.Logger.info(`Set debug ${status}`);
32
+ await (0, _utils.setConfig)({
33
+ debug: status === "on"
34
+ });
35
+ }
36
+ async run() {
37
+ const mapDir = Path.dirname(_env.MAP_PATH);
38
+ if (!_makes.FS.existsSync(mapDir)) {
39
+ await _makes.FS.mkdir(mapDir);
40
+ }
41
+ if (!_makes.FS.existsSync(_env.MAP_PATH)) {
42
+ await _makes.FS.writeJSON(_env.MAP_PATH, {
43
+ projects: []
44
+ });
45
+ }
46
+ if (!_makes.FS.existsSync(`${_env.DATA_DIR}/projects`)) {
47
+ await _makes.FS.mkdir(`${_env.DATA_DIR}/projects`);
48
+ }
49
+ return this.cli.run(process.argv);
50
+ }
51
+ }
52
+ exports.App = App;
@@ -0,0 +1,8 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Controller } from "src/makes";
3
+ declare class ImageController extends Controller {
4
+ constructor();
5
+ install(cli: Cli): void;
6
+ list(): Promise<string>;
7
+ }
8
+ export { ImageController };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ImageController = void 0;
7
+ var _cliTable = _interopRequireDefault(require("cli-table3"));
8
+ var _makes = require("../makes");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ class ImageController extends _makes.Controller {
11
+ constructor() {
12
+ super();
13
+ }
14
+ install(cli) {
15
+ super.install(cli);
16
+ cli.command("images").action(() => this.list());
17
+ }
18
+ async list() {
19
+ const images = await _makes.Docker.imageLs({});
20
+ const table = new _cliTable.default({
21
+ head: ["Name"]
22
+ });
23
+ for (const image of images) {
24
+ table.push([image.Id]);
25
+ }
26
+ return table.toString() + "\n";
27
+ }
28
+ }
29
+ exports.ImageController = ImageController;
@@ -0,0 +1,64 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { Controller } from "src/makes";
3
+ import { AppConfigService, AppEventsService, ProjectService } from "src/services";
4
+ type InitOptions = {
5
+ name?: string;
6
+ type?: string;
7
+ preset?: string;
8
+ };
9
+ type StartOptions = {
10
+ name?: string;
11
+ rebuild?: boolean;
12
+ detach?: boolean;
13
+ };
14
+ type StopOptions = {
15
+ name?: string;
16
+ };
17
+ type AttachOptions = {
18
+ name?: string;
19
+ };
20
+ type ConfigOptions = {
21
+ name?: string;
22
+ global?: boolean;
23
+ };
24
+ type BuildArgsOptions = {
25
+ name?: string;
26
+ };
27
+ type VolumeOptions = {
28
+ name?: string;
29
+ };
30
+ type LogsOptions = {
31
+ name?: string;
32
+ global?: boolean;
33
+ detach?: boolean;
34
+ follow?: boolean;
35
+ };
36
+ type ExecOptions = {
37
+ name?: string;
38
+ };
39
+ declare class ProjectController extends Controller {
40
+ protected appConfigService: AppConfigService;
41
+ protected appEventsService: AppEventsService;
42
+ protected projectService: ProjectService;
43
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
44
+ install(cli: Cli): void;
45
+ protected getProjectNames(): Promise<string[]>;
46
+ init(options: InitOptions): Promise<void>;
47
+ start(options: StartOptions): Promise<void>;
48
+ stop(options: StopOptions): Promise<void>;
49
+ attach(options: AttachOptions): Promise<void>;
50
+ configList(options: ConfigOptions): Promise<string>;
51
+ configGet(options: ConfigOptions, key: string): Promise<string>;
52
+ configSet(options: ConfigOptions, configs: string[]): Promise<void>;
53
+ configUnset(options: ConfigOptions, configs: string[]): Promise<void>;
54
+ buildArgsList(options: BuildArgsOptions): Promise<string>;
55
+ buildArgsGet(options: BuildArgsOptions, args: string[]): Promise<string>;
56
+ buildArgsSet(options: BuildArgsOptions, args: string[]): Promise<void>;
57
+ buildArgsUnset(options: BuildArgsOptions, args: string[]): Promise<void>;
58
+ volumeList(options: VolumeOptions): Promise<string>;
59
+ volumeMount(options: VolumeOptions, volumes: string[]): Promise<void>;
60
+ volumeUnmount(options: VolumeOptions, volumes: string[]): Promise<void>;
61
+ logs(options: LogsOptions): Promise<void>;
62
+ exec(options: ExecOptions, command: string[]): Promise<void>;
63
+ }
64
+ export { ProjectController };