@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
package/README.md CHANGED
@@ -1,155 +1,29 @@
1
- # Wocker
1
+ # @wocker/ws
2
2
 
3
3
  ###### Docker workspace for web projects
4
4
 
5
- ## Requirements
5
+ ## Installation
6
6
 
7
- - [node.js](https://nodejs.org)
8
- - [docker](https://www.docker.com)
9
-
10
-
11
- ## Usage
12
-
13
- ### Installation
7
+ **Note:** It is recommended to install Wocker globally to ensure accessibility from any directory in your terminal.
14
8
 
15
9
  ```shell
16
10
  npm i -g @wocker/ws
17
11
  ```
18
12
 
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
13
 
121
14
  ### Completion
122
15
 
16
+ Wocker comes with shell completion support to enhance your development workflow. To enable shell completion, run the following command:
17
+
123
18
  ```bash
124
19
  source <(ws completion script)
125
20
  ```
126
21
 
22
+ This will enable tab completion for `ws` commands, providing a more convenient and efficient way to interact with the tool.
127
23
 
128
- ## Folders structure
129
24
 
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
- ```
25
+ ## Documentation
26
+
27
+ Wocker is a powerful tool for managing your web project's Docker workspace. It provides a convenient and efficient way to set up and manage your Docker containers.
28
+
29
+ For more information and detailed usage, please refer to the [documentation](https://kearisp.github.io/wocker).
package/bin/ws.js CHANGED
@@ -4,10 +4,14 @@ const chalk = require("chalk");
4
4
  const {app} = require("../lib/index.js");
5
5
 
6
6
 
7
- app.run().then((res) => {
8
- if(res) {
9
- process.stdout.write(res);
7
+ app.run(process.argv).then((res) => {
8
+ if(!res) {
9
+ return;
10
10
  }
11
+
12
+ process.stdout.write(res);
11
13
  }).catch((err) => {
12
14
  console.error(chalk.red(err.message));
15
+
16
+ // throw err;
13
17
  });
package/lib/App.d.ts CHANGED
@@ -1,13 +1,16 @@
1
+ import { Controller } from "@wocker/core";
1
2
  import { Cli } from "@kearisp/cli";
2
- import { Controller, Plugin } from "src/makes";
3
- import { AppConfigService } from "src/services";
3
+ import { DI } from "./makes";
4
+ import { AppConfigService } from "./services";
4
5
  export declare class App {
5
- protected config: AppConfigService;
6
+ protected di: DI;
6
7
  protected cli: Cli;
7
- constructor(config: AppConfigService);
8
+ protected appConfigService: AppConfigService;
9
+ constructor();
8
10
  install(): void;
9
- useController(controller: Controller): void;
10
- usePlugin(plugin: Plugin): void;
11
- setDebug(status: string): Promise<void>;
11
+ use(Constructor: {
12
+ new (...params: any[]): Controller;
13
+ }): void;
14
+ setDebug(status: string): Promise<string>;
12
15
  run(): Promise<string>;
13
16
  }
package/lib/App.js CHANGED
@@ -1,52 +1,107 @@
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.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; }
27
+ const cli_1 = require("@kearisp/cli");
28
+ const Path = __importStar(require("path"));
29
+ const env_1 = require("./env");
30
+ const utils_1 = require("./utils");
31
+ const makes_1 = require("./makes");
32
+ const services_1 = require("./services");
33
+ const controllers_1 = require("./controllers");
14
34
  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);
35
+ constructor() {
36
+ this.di = new makes_1.DI();
37
+ this.appConfigService = new services_1.AppConfigService();
38
+ this.di.registerService(services_1.AppConfigService, this.appConfigService);
39
+ this.di.registerService(services_1.AppEventsService, new services_1.AppEventsService());
40
+ this.di.registerService(services_1.DockerService, new services_1.DockerService(this.di));
41
+ this.di.registerService(services_1.PresetService, new services_1.PresetService(this.di));
42
+ this.di.registerService(services_1.PluginService, new services_1.PluginService(this.di));
43
+ this.di.registerService(services_1.ProjectService, new services_1.ProjectService(this.di));
44
+ this.di.registerService(services_1.LogService, new services_1.LogService(this.di));
45
+ this.di.registerService(cli_1.Cli, this.cli);
46
+ this.cli = new cli_1.Cli(makes_1.Logger);
47
+ makes_1.Preset.install(this.di);
48
+ makes_1.Project.install(this.di);
49
+ makes_1.Logger.install(this.di);
50
+ this.install();
51
+ this.use(controllers_1.ImageController);
52
+ this.use(controllers_1.PluginController);
53
+ this.use(controllers_1.PresetController);
54
+ this.use(controllers_1.ProjectController);
55
+ this.use(controllers_1.ProxyController);
56
+ }
57
+ install() {
58
+ this.cli.command("completion script")
59
+ .help(false)
60
+ .action(() => this.cli.completionScript());
61
+ this.cli.command("log [...items]")
62
+ .action((options, items) => {
63
+ makes_1.Logger.log(...items);
64
+ return "";
65
+ });
66
+ this.cli.command("debug <status>")
67
+ .completion("status", () => ["on", "off"])
68
+ .action(async (options, status) => this.setDebug(status));
69
+ }
70
+ use(Constructor) {
71
+ const controller = new Constructor(this.di);
72
+ controller.install(this.cli);
40
73
  }
41
- if (!_makes.FS.existsSync(_env.MAP_PATH)) {
42
- await _makes.FS.writeJSON(_env.MAP_PATH, {
43
- projects: []
44
- });
74
+ async setDebug(status) {
75
+ makes_1.Logger.info(`Set debug ${status}`);
76
+ await (0, utils_1.setConfig)({
77
+ debug: status === "on"
78
+ });
79
+ return "";
45
80
  }
46
- if (!_makes.FS.existsSync(`${_env.DATA_DIR}/projects`)) {
47
- await _makes.FS.mkdir(`${_env.DATA_DIR}/projects`);
81
+ async run() {
82
+ const mapDir = Path.dirname(env_1.MAP_PATH);
83
+ if (!makes_1.FS.existsSync(mapDir)) {
84
+ await makes_1.FS.mkdir(mapDir);
85
+ }
86
+ if (!makes_1.FS.existsSync(env_1.MAP_PATH)) {
87
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, {
88
+ projects: []
89
+ });
90
+ }
91
+ if (!makes_1.FS.existsSync(`${env_1.DATA_DIR}/projects`)) {
92
+ await makes_1.FS.mkdir(`${env_1.DATA_DIR}/projects`);
93
+ }
94
+ const { plugins = [] } = await this.appConfigService.getAppConfig();
95
+ for (const plugin of plugins) {
96
+ try {
97
+ const { default: Plugin } = await Promise.resolve(`${plugin}`).then(s => __importStar(require(s)));
98
+ this.use(Plugin);
99
+ }
100
+ catch (err) {
101
+ makes_1.Logger.error(err.message);
102
+ }
103
+ }
104
+ return this.cli.run(process.argv);
48
105
  }
49
- return this.cli.run(process.argv);
50
- }
51
106
  }
52
- exports.App = App;
107
+ exports.App = App;
@@ -1,7 +1,9 @@
1
1
  import { Cli } from "@kearisp/cli";
2
- import { Controller } from "src/makes";
2
+ import { DI, Controller } from "../makes";
3
+ import { AppConfigService } from "../services";
3
4
  declare class ImageController extends Controller {
4
- constructor();
5
+ protected appConfigService: AppConfigService;
6
+ constructor(di: DI);
5
7
  install(cli: Cli): void;
6
8
  list(): Promise<string>;
7
9
  }
@@ -1,29 +1,31 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
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]);
7
+ const cli_table3_1 = __importDefault(require("cli-table3"));
8
+ const makes_1 = require("../makes");
9
+ const services_1 = require("../services");
10
+ class ImageController extends makes_1.Controller {
11
+ constructor(di) {
12
+ super();
13
+ this.appConfigService = di.resolveService(services_1.AppConfigService);
14
+ }
15
+ install(cli) {
16
+ super.install(cli);
17
+ cli.command("images")
18
+ .action(() => this.list());
19
+ }
20
+ async list() {
21
+ const images = await makes_1.Docker.imageLs({});
22
+ const table = new cli_table3_1.default({
23
+ head: ["Name"]
24
+ });
25
+ for (const image of images) {
26
+ table.push([image.Id]);
27
+ }
28
+ return table.toString() + "\n";
25
29
  }
26
- return table.toString() + "\n";
27
- }
28
30
  }
29
- exports.ImageController = ImageController;
31
+ exports.ImageController = ImageController;
@@ -0,0 +1,14 @@
1
+ import { Cli } from "@kearisp/cli";
2
+ import { DI, Controller } from "../makes";
3
+ import { AppConfigService, PluginService } from "../services";
4
+ type AddOptions = {};
5
+ type RemoveOptions = {};
6
+ declare class PluginController extends Controller {
7
+ protected appConfigService: AppConfigService;
8
+ protected pluginService: PluginService;
9
+ constructor(di: DI);
10
+ install(cli: Cli): void;
11
+ add(options: AddOptions, addName: string): Promise<void>;
12
+ remove(options: RemoveOptions, removeName: string): Promise<void>;
13
+ }
14
+ export { PluginController };
@@ -0,0 +1,84 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.PluginController = void 0;
30
+ const axios_1 = __importDefault(require("axios"));
31
+ const chalk_1 = __importDefault(require("chalk"));
32
+ const makes_1 = require("../makes");
33
+ const services_1 = require("../services");
34
+ const utils_1 = require("../utils");
35
+ class PluginController extends makes_1.Controller {
36
+ constructor(di) {
37
+ super();
38
+ this.appConfigService = di.resolveService(services_1.AppConfigService);
39
+ this.pluginService = di.resolveService(services_1.PluginService);
40
+ }
41
+ install(cli) {
42
+ super.install(cli);
43
+ cli.command("plugin:add <name>")
44
+ .action((options, name) => this.add(options, name));
45
+ cli.command("plugin:remove <name>")
46
+ .action((options, name) => this.remove(options, name));
47
+ }
48
+ async add(options, addName) {
49
+ const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(addName) || [];
50
+ const fullName = `${prefix}${name}${suffix}`;
51
+ try {
52
+ const { default: Plugin } = await Promise.resolve(`${fullName}`).then(s => __importStar(require(s)));
53
+ this.pluginService.use(Plugin);
54
+ await this.appConfigService.activatePlugin(fullName);
55
+ console.info(`Plugin ${fullName} activated`);
56
+ return;
57
+ }
58
+ catch (err) {
59
+ makes_1.Logger.error(err.message);
60
+ }
61
+ try {
62
+ const res = await axios_1.default.get(`https://registry.npmjs.org/${encodeURIComponent(fullName)}`, {
63
+ validateStatus: () => true
64
+ });
65
+ if (res.status !== 200) {
66
+ console.error(chalk_1.default.red(`Plugin ${fullName} not found`));
67
+ return;
68
+ }
69
+ console.info(`Installing ${fullName}`);
70
+ await (0, utils_1.exec)(`npm install -g ${fullName}`);
71
+ await this.appConfigService.activatePlugin(fullName);
72
+ }
73
+ catch (err) {
74
+ makes_1.Logger.error(err.message);
75
+ }
76
+ }
77
+ async remove(options, removeName) {
78
+ const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(removeName) || [];
79
+ const fullName = `${prefix}${name}${suffix}`;
80
+ await this.appConfigService.deactivatePlugin(fullName);
81
+ console.info(`Plugin ${fullName} deactivated`);
82
+ }
83
+ }
84
+ exports.PluginController = PluginController;
@@ -0,0 +1,21 @@
1
+ import { Cli } from "@wocker/core";
2
+ import { DI, Controller, Project } from "../makes";
3
+ import { AppConfigService, AppEventsService, ProjectService, PresetService, DockerService } from "../services";
4
+ type BuildParams = {
5
+ rebuild?: boolean;
6
+ };
7
+ declare class PresetController extends Controller {
8
+ protected appConfigService: AppConfigService;
9
+ protected appEventsService: AppEventsService;
10
+ protected projectService: ProjectService;
11
+ protected presetService: PresetService;
12
+ protected dockerService: DockerService;
13
+ constructor(di: DI);
14
+ install(cli: Cli): void;
15
+ presets(): Promise<string[]>;
16
+ protected onInit(project: Project): Promise<void>;
17
+ protected onRebuild(project: Project): Promise<void>;
18
+ protected onBeforeStart(project: Project): Promise<void>;
19
+ build(options: BuildParams, presetName: string): Promise<void>;
20
+ }
21
+ export { PresetController };