@wocker/ws 1.0.1 → 1.0.2
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.
- package/.github/workflows/publish.yml +31 -0
- package/README.md +11 -137
- package/bin/ws.js +7 -3
- package/lib/App.d.ts +7 -5
- package/lib/App.js +45 -11
- package/lib/controllers/ImageController.d.ts +3 -1
- package/lib/controllers/ImageController.js +3 -1
- package/lib/controllers/PluginController.d.ts +14 -0
- package/lib/controllers/PluginController.js +62 -0
- package/lib/controllers/PresetController.d.ts +19 -0
- package/lib/controllers/PresetController.js +150 -0
- package/lib/controllers/ProjectController.d.ts +13 -5
- package/lib/controllers/ProjectController.js +92 -25
- package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +9 -11
- package/lib/{plugins/ProxyPlugin.js → controllers/ProxyController.js} +120 -128
- package/lib/controllers/index.d.ts +3 -0
- package/lib/controllers/index.js +33 -0
- package/lib/env.js +9 -16
- package/lib/index.js +11 -24
- package/lib/makes/Docker.js +11 -25
- package/lib/makes/FS.d.ts +1 -1
- package/lib/makes/FS.js +13 -10
- package/lib/makes/Logger.d.ts +1 -7
- package/lib/makes/Logger.js +6 -33
- package/lib/makes/Plugin.js +2 -2
- package/lib/plugins/ElasticSearchPlugin.d.ts +16 -0
- package/lib/plugins/ElasticSearchPlugin.js +72 -0
- package/lib/plugins/LocaltunnelPlugin.d.ts +3 -3
- package/lib/plugins/LocaltunnelPlugin.js +17 -15
- package/lib/plugins/MaildevPlugin.d.ts +3 -1
- package/lib/plugins/MaildevPlugin.js +8 -5
- package/lib/plugins/MongodbPlugin.d.ts +5 -3
- package/lib/plugins/MongodbPlugin.js +10 -16
- package/lib/plugins/NgrokPlugin.d.ts +2 -3
- package/lib/plugins/NgrokPlugin.js +7 -6
- package/lib/plugins/PageKitePlugin.d.ts +2 -3
- package/lib/plugins/PageKitePlugin.js +8 -6
- package/lib/plugins/PostgresPlugin.js +5 -4
- package/lib/plugins/ProxmoxPlugin.js +2 -2
- package/lib/plugins/RedisPlugin.d.ts +8 -2
- package/lib/plugins/RedisPlugin.js +57 -20
- package/lib/plugins/index.d.ts +2 -6
- package/lib/plugins/index.js +11 -66
- package/lib/services/AppConfigService.d.ts +14 -4
- package/lib/services/AppConfigService.js +88 -3
- package/lib/services/AppEventsService.d.ts +5 -8
- package/lib/services/AppEventsService.js +2 -3
- package/lib/services/DockerService.d.ts +16 -0
- package/lib/services/DockerService.js +220 -0
- package/lib/services/LogService.d.ts +11 -0
- package/lib/services/LogService.js +39 -0
- package/lib/services/PluginService.d.ts +10 -0
- package/lib/services/PluginService.js +18 -0
- package/lib/services/PresetService.d.ts +9 -0
- package/lib/services/PresetService.js +63 -0
- package/lib/services/ProjectService.d.ts +8 -7
- package/lib/services/ProjectService.js +64 -12
- package/lib/services/index.d.ts +4 -0
- package/lib/services/index.js +44 -0
- package/lib/utils/demuxOutput.js +0 -2
- package/lib/utils/exec.d.ts +1 -1
- package/lib/utils/exec.js +4 -5
- package/lib/utils/fetch.js +3 -4
- package/lib/utils/image-build.js +2 -2
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/index.js +0 -44
- package/lib/utils/injectVariables.js +1 -1
- package/package.json +13 -13
- package/presets/node/config.json +9 -7
- package/presets/php-apache/Dockerfile +37 -36
- package/presets/php-apache/config.json +10 -15
- package/presets/php-fpm/Dockerfile +21 -0
- package/presets/php-fpm/config.json +25 -0
- package/lib/models/Preset.d.ts +0 -19
- package/lib/models/Preset.js +0 -60
- package/lib/models/Project.d.ts +0 -38
- package/lib/models/Project.js +0 -151
- package/lib/models/index.d.ts +0 -2
- package/lib/models/index.js +0 -27
- package/lib/plugins/MariadbPlugin.d.ts +0 -25
- package/lib/plugins/MariadbPlugin.js +0 -297
- package/lib/plugins/PresetPlugin.d.ts +0 -19
- package/lib/plugins/PresetPlugin.js +0 -164
- package/lib/plugins/ProjectPlugin.d.ts +0 -12
- package/lib/plugins/ProjectPlugin.js +0 -54
- package/lib/plugins/ServeoPlugin.d.ts +0 -36
- package/lib/plugins/ServeoPlugin.js +0 -260
- package/lib/plugins/TestPlugin.d.ts +0 -10
- package/lib/plugins/TestPlugin.js +0 -75
- package/lib/utils/promptConfirm.d.ts +0 -6
- package/lib/utils/promptConfirm.js +0 -21
- package/lib/utils/promptGroup.d.ts +0 -16
- package/lib/utils/promptGroup.js +0 -39
- package/lib/utils/promptSelect.d.ts +0 -12
- package/lib/utils/promptSelect.js +0 -47
- package/lib/utils/promptText.d.ts +0 -13
- package/lib/utils/promptText.js +0 -53
- package/plugins/serveo/Dockerfile +0 -17
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types:
|
|
6
|
+
- published
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: publish
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout code
|
|
14
|
+
uses: actions/checkout@v3
|
|
15
|
+
|
|
16
|
+
- name: Set up Node.js
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: '18'
|
|
20
|
+
registry-url: 'https://registry.npmjs.org'
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: npm install
|
|
24
|
+
|
|
25
|
+
- name: Build
|
|
26
|
+
run: npm run build
|
|
27
|
+
|
|
28
|
+
- name: Publish to NPM
|
|
29
|
+
env:
|
|
30
|
+
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
|
|
31
|
+
run: npm publish
|
package/README.md
CHANGED
|
@@ -1,155 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wocker/ws
|
|
2
2
|
|
|
3
3
|
###### Docker workspace for web projects
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
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,15 @@
|
|
|
1
|
+
import { DI, Controller } from "@wocker/core";
|
|
1
2
|
import { Cli } from "@kearisp/cli";
|
|
2
|
-
import { Controller, Plugin } from "src/makes";
|
|
3
3
|
import { AppConfigService } from "src/services";
|
|
4
4
|
export declare class App {
|
|
5
|
-
protected
|
|
5
|
+
protected di: DI;
|
|
6
6
|
protected cli: Cli;
|
|
7
|
-
|
|
7
|
+
protected appConfigService: AppConfigService;
|
|
8
|
+
constructor();
|
|
8
9
|
install(): void;
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
use(Constructor: {
|
|
11
|
+
new (...params: any[]): Controller;
|
|
12
|
+
}): void;
|
|
11
13
|
setDebug(status: string): Promise<void>;
|
|
12
14
|
run(): Promise<string>;
|
|
13
15
|
}
|
package/lib/App.js
CHANGED
|
@@ -4,31 +4,52 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.App = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _core = require("@wocker/core");
|
|
8
8
|
var _cli = require("@kearisp/cli");
|
|
9
|
+
var Path = _interopRequireWildcard(require("path"));
|
|
9
10
|
var _env = require("./env");
|
|
10
11
|
var _utils = require("./utils");
|
|
11
12
|
var _makes = require("./makes");
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
var _services = require("./services");
|
|
14
|
+
var _controllers = require("./controllers");
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
14
17
|
class App {
|
|
15
|
-
constructor(
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
+
constructor() {
|
|
19
|
+
this.di = new _core.DI();
|
|
20
|
+
this.appConfigService = new _services.AppConfigService();
|
|
21
|
+
this.di.registerService(_core.AppConfigService, this.appConfigService);
|
|
22
|
+
this.di.registerService(_core.AppEventsService, new _services.AppEventsService());
|
|
23
|
+
this.di.registerService(_core.DockerService, new _services.DockerService(this.di));
|
|
24
|
+
this.di.registerService(_core.PresetService, new _services.PresetService(this.di));
|
|
25
|
+
this.di.registerService(_services.PluginService, new _services.PluginService(this.di));
|
|
26
|
+
this.di.registerService(_core.ProjectService, new _services.ProjectService(this.di));
|
|
27
|
+
this.di.registerService(_core.LogService, new _services.LogService(this.di));
|
|
28
|
+
this.di.registerService(_cli.Cli, this.cli);
|
|
29
|
+
this.cli = new _cli.Cli(_core.Logger);
|
|
30
|
+
_core.Preset.install(this.di);
|
|
31
|
+
_core.Project.install(this.di);
|
|
32
|
+
_core.Logger.install(this.di);
|
|
18
33
|
this.install();
|
|
34
|
+
this.use(_controllers.ImageController);
|
|
35
|
+
this.use(_controllers.PluginController);
|
|
36
|
+
this.use(_controllers.PresetController);
|
|
37
|
+
this.use(_controllers.ProjectController);
|
|
38
|
+
this.use(_controllers.ProxyController);
|
|
19
39
|
}
|
|
20
40
|
install() {
|
|
21
41
|
this.cli.command("completion script").help(false).action(() => this.cli.completionScript());
|
|
42
|
+
this.cli.command("log [...items]").action((options, items) => {
|
|
43
|
+
_core.Logger.log(...items);
|
|
44
|
+
});
|
|
22
45
|
this.cli.command("debug <status>").completion("status", () => ["on", "off"]).action(async (options, status) => this.setDebug(status));
|
|
23
46
|
}
|
|
24
|
-
|
|
47
|
+
use(Constructor) {
|
|
48
|
+
const controller = new Constructor(this.di);
|
|
25
49
|
controller.install(this.cli);
|
|
26
50
|
}
|
|
27
|
-
usePlugin(plugin) {
|
|
28
|
-
plugin.install(this.cli);
|
|
29
|
-
}
|
|
30
51
|
async setDebug(status) {
|
|
31
|
-
|
|
52
|
+
_core.Logger.info(`Set debug ${status}`);
|
|
32
53
|
await (0, _utils.setConfig)({
|
|
33
54
|
debug: status === "on"
|
|
34
55
|
});
|
|
@@ -46,6 +67,19 @@ class App {
|
|
|
46
67
|
if (!_makes.FS.existsSync(`${_env.DATA_DIR}/projects`)) {
|
|
47
68
|
await _makes.FS.mkdir(`${_env.DATA_DIR}/projects`);
|
|
48
69
|
}
|
|
70
|
+
const {
|
|
71
|
+
plugins = []
|
|
72
|
+
} = await this.appConfigService.getAppConfig();
|
|
73
|
+
for (const plugin of plugins) {
|
|
74
|
+
try {
|
|
75
|
+
const {
|
|
76
|
+
default: Plugin
|
|
77
|
+
} = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(plugin);
|
|
78
|
+
this.use(Plugin);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
_core.Logger.error(err.message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
49
83
|
return this.cli.run(process.argv);
|
|
50
84
|
}
|
|
51
85
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { AppConfigService, DI } from "@wocker/core";
|
|
1
2
|
import { Cli } from "@kearisp/cli";
|
|
2
3
|
import { Controller } from "src/makes";
|
|
3
4
|
declare class ImageController extends Controller {
|
|
4
|
-
|
|
5
|
+
protected appConfigService: AppConfigService;
|
|
6
|
+
constructor(di: DI);
|
|
5
7
|
install(cli: Cli): void;
|
|
6
8
|
list(): Promise<string>;
|
|
7
9
|
}
|
|
@@ -4,12 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ImageController = void 0;
|
|
7
|
+
var _core = require("@wocker/core");
|
|
7
8
|
var _cliTable = _interopRequireDefault(require("cli-table3"));
|
|
8
9
|
var _makes = require("../makes");
|
|
9
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
11
|
class ImageController extends _makes.Controller {
|
|
11
|
-
constructor() {
|
|
12
|
+
constructor(di) {
|
|
12
13
|
super();
|
|
14
|
+
this.appConfigService = di.resolveService(_core.AppConfigService);
|
|
13
15
|
}
|
|
14
16
|
install(cli) {
|
|
15
17
|
super.install(cli);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DI, AppConfigService, Controller } from "@wocker/core";
|
|
2
|
+
import { Cli } from "@kearisp/cli";
|
|
3
|
+
import { PluginService } from "src/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,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PluginController = void 0;
|
|
7
|
+
var _core = require("@wocker/core");
|
|
8
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
|
+
var _services = require("../services");
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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 PluginController extends _core.Controller {
|
|
16
|
+
constructor(di) {
|
|
17
|
+
super();
|
|
18
|
+
this.appConfigService = di.resolveService(_core.AppConfigService);
|
|
19
|
+
this.pluginService = di.resolveService(_services.PluginService);
|
|
20
|
+
}
|
|
21
|
+
install(cli) {
|
|
22
|
+
super.install(cli);
|
|
23
|
+
cli.command("plugin:add <name>").action((options, name) => this.add(options, name));
|
|
24
|
+
cli.command("plugin:remove <name>").action((options, name) => this.remove(options, name));
|
|
25
|
+
}
|
|
26
|
+
async add(options, addName) {
|
|
27
|
+
const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(addName) || [];
|
|
28
|
+
const fullName = `${prefix}${name}${suffix}`;
|
|
29
|
+
try {
|
|
30
|
+
const {
|
|
31
|
+
default: Plugin
|
|
32
|
+
} = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(fullName);
|
|
33
|
+
this.pluginService.use(Plugin);
|
|
34
|
+
await this.appConfigService.activatePlugin(fullName);
|
|
35
|
+
console.info(`Plugin ${fullName} activated`);
|
|
36
|
+
return;
|
|
37
|
+
} catch (err) {
|
|
38
|
+
_core.Logger.error(err.message);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const res = await _axios.default.get(`https://registry.npmjs.org/${encodeURIComponent(fullName)}`, {
|
|
42
|
+
validateStatus: () => true
|
|
43
|
+
});
|
|
44
|
+
if (res.status !== 200) {
|
|
45
|
+
console.error(_chalk.default.red(`Plugin ${fullName} not found`));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
console.info(`Installing ${fullName}`);
|
|
49
|
+
await (0, _utils.exec)(`npm install -g ${fullName}`);
|
|
50
|
+
await this.appConfigService.activatePlugin(fullName);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
_core.Logger.error(err.message);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async remove(options, removeName) {
|
|
56
|
+
const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(removeName) || [];
|
|
57
|
+
const fullName = `${prefix}${name}${suffix}`;
|
|
58
|
+
await this.appConfigService.deactivatePlugin(fullName);
|
|
59
|
+
console.info(`Plugin ${fullName} deactivated`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.PluginController = PluginController;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DI, Controller, Cli, AppConfigService, AppEventsService, ProjectService, PresetService, DockerService, Project } from "@wocker/core";
|
|
2
|
+
type BuildParams = {
|
|
3
|
+
rebuild?: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare class PresetController extends Controller {
|
|
6
|
+
protected appConfigService: AppConfigService;
|
|
7
|
+
protected appEventsService: AppEventsService;
|
|
8
|
+
protected projectService: ProjectService;
|
|
9
|
+
protected presetService: PresetService;
|
|
10
|
+
protected dockerService: DockerService;
|
|
11
|
+
constructor(di: DI);
|
|
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: BuildParams, presetName: string): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export { PresetController };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PresetController = void 0;
|
|
7
|
+
var _core = require("@wocker/core");
|
|
8
|
+
var _utils = require("@wocker/utils");
|
|
9
|
+
var Path = _interopRequireWildcard(require("path"));
|
|
10
|
+
var _env = require("../env");
|
|
11
|
+
var _utils2 = require("../utils");
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
class PresetController extends _core.Controller {
|
|
15
|
+
constructor(di) {
|
|
16
|
+
super();
|
|
17
|
+
this.appConfigService = di.resolveService(_core.AppConfigService);
|
|
18
|
+
this.appEventsService = di.resolveService(_core.AppEventsService);
|
|
19
|
+
this.projectService = di.resolveService(_core.ProjectService);
|
|
20
|
+
this.presetService = di.resolveService(_core.PresetService);
|
|
21
|
+
this.dockerService = di.resolveService(_core.DockerService);
|
|
22
|
+
}
|
|
23
|
+
install(cli) {
|
|
24
|
+
super.install(cli);
|
|
25
|
+
this.appConfigService.registerProjectType("preset", "Preset");
|
|
26
|
+
this.appEventsService.on("project:init", project => this.onInit(project));
|
|
27
|
+
this.appEventsService.on("project:beforeStart", project => this.onBeforeStart(project));
|
|
28
|
+
this.appEventsService.on("project:rebuild", project => this.onRebuild(project));
|
|
29
|
+
cli.command("preset:build <preset>").completion("preset", () => this.presets()).option("rebuild", {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
alias: "r",
|
|
32
|
+
description: "Rebuild image"
|
|
33
|
+
}).action((options, preset) => this.build(options, preset));
|
|
34
|
+
}
|
|
35
|
+
async presets() {
|
|
36
|
+
const presets = await this.presetService.search();
|
|
37
|
+
return presets.map(preset => {
|
|
38
|
+
return preset.name;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async onInit(project) {
|
|
42
|
+
if (project.type !== "preset") {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const presets = await this.presetService.search();
|
|
46
|
+
if (presets.length === 0) {
|
|
47
|
+
throw new Error("No presets");
|
|
48
|
+
}
|
|
49
|
+
project.preset = await (0, _utils.promptSelect)({
|
|
50
|
+
message: "Choose preset:",
|
|
51
|
+
options: presets.map(preset => {
|
|
52
|
+
return {
|
|
53
|
+
label: preset.name,
|
|
54
|
+
value: preset.name
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
default: project.preset
|
|
58
|
+
});
|
|
59
|
+
const preset = await this.presetService.get(project.preset);
|
|
60
|
+
if (!preset) {
|
|
61
|
+
throw new Error("Preset not found");
|
|
62
|
+
}
|
|
63
|
+
if (preset.buildArgsOptions) {
|
|
64
|
+
project.buildArgs = await (0, _utils.promptConfig)(preset.buildArgsOptions, project.buildArgs);
|
|
65
|
+
}
|
|
66
|
+
if (preset.envOptions) {
|
|
67
|
+
project.env = await (0, _utils.promptConfig)(preset.envOptions, project.env);
|
|
68
|
+
}
|
|
69
|
+
if (preset.volumeOptions) {
|
|
70
|
+
for (let volume of preset.volumeOptions) {
|
|
71
|
+
volume = (0, _utils2.injectVariables)(volume, {
|
|
72
|
+
...(project.buildArgs || {}),
|
|
73
|
+
...(project.env || {})
|
|
74
|
+
});
|
|
75
|
+
const {
|
|
76
|
+
destination,
|
|
77
|
+
options
|
|
78
|
+
} = (0, _utils2.volumeParse)(volume);
|
|
79
|
+
let projectVolume = project.getVolumeByDestination(destination);
|
|
80
|
+
const source = await (0, _utils.promptText)({
|
|
81
|
+
message: "Volume",
|
|
82
|
+
suffix: `:${destination}`,
|
|
83
|
+
default: projectVolume ? (0, _utils2.volumeParse)(projectVolume).source : "./"
|
|
84
|
+
});
|
|
85
|
+
projectVolume = (0, _utils2.volumeFormat)({
|
|
86
|
+
source,
|
|
87
|
+
destination,
|
|
88
|
+
options
|
|
89
|
+
});
|
|
90
|
+
project.volumeMount(projectVolume);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (preset.dockerfile) {
|
|
94
|
+
project.imageName = preset.getImageName(project.buildArgs);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async onRebuild(project) {
|
|
98
|
+
if (project.type !== "preset") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const preset = await this.presetService.get(project.preset);
|
|
102
|
+
if (!preset) {
|
|
103
|
+
throw new Error(`Preset ${project.preset} not found`);
|
|
104
|
+
}
|
|
105
|
+
const imageName = preset.getImageName(project.buildArgs || {});
|
|
106
|
+
const exists = await this.dockerService.imageExists(imageName);
|
|
107
|
+
if (exists) {
|
|
108
|
+
console.info(`Removing image: ${imageName}`);
|
|
109
|
+
await this.dockerService.imageRm(imageName);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async onBeforeStart(project) {
|
|
113
|
+
if (project.type !== "preset") {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const preset = await this.presetService.get(project.preset);
|
|
117
|
+
if (preset.dockerfile) {
|
|
118
|
+
project.imageName = preset.getImageName(project.buildArgs);
|
|
119
|
+
if (!(await this.dockerService.imageExists(project.imageName))) {
|
|
120
|
+
await this.dockerService.buildImage({
|
|
121
|
+
tag: project.imageName,
|
|
122
|
+
labels: {
|
|
123
|
+
presetName: preset.name
|
|
124
|
+
},
|
|
125
|
+
buildArgs: project.buildArgs,
|
|
126
|
+
context: Path.join(_env.PRESETS_DIR, preset.name),
|
|
127
|
+
src: preset.dockerfile
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async build(options, presetName) {
|
|
133
|
+
const preset = await this.presetService.get(presetName);
|
|
134
|
+
let buildArgs = {};
|
|
135
|
+
if (preset.buildArgsOptions) {
|
|
136
|
+
buildArgs = await (0, _utils.promptGroup)(preset.buildArgsOptions);
|
|
137
|
+
}
|
|
138
|
+
const imageName = preset.getImageName(buildArgs);
|
|
139
|
+
await this.dockerService.buildImage({
|
|
140
|
+
tag: imageName,
|
|
141
|
+
labels: {
|
|
142
|
+
presetName: preset.name
|
|
143
|
+
},
|
|
144
|
+
buildArgs: buildArgs,
|
|
145
|
+
context: Path.join(_env.PRESETS_DIR, preset.name),
|
|
146
|
+
src: preset.dockerfile
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.PresetController = PresetController;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { DI, AppConfigService as CoreAppConfigService, AppEventsService as CoreAppEventsService, ProjectService as CoreProjectService, DockerService } from "@wocker/core";
|
|
1
2
|
import { Cli } from "@kearisp/cli";
|
|
2
3
|
import { Controller } from "src/makes";
|
|
3
|
-
import { AppConfigService, AppEventsService, ProjectService } from "src/services";
|
|
4
4
|
type InitOptions = {
|
|
5
5
|
name?: string;
|
|
6
6
|
type?: string;
|
|
7
7
|
preset?: string;
|
|
8
8
|
};
|
|
9
|
+
type ListOptions = {
|
|
10
|
+
all?: boolean;
|
|
11
|
+
};
|
|
9
12
|
type StartOptions = {
|
|
10
13
|
name?: string;
|
|
11
14
|
rebuild?: boolean;
|
|
@@ -37,15 +40,20 @@ type ExecOptions = {
|
|
|
37
40
|
name?: string;
|
|
38
41
|
};
|
|
39
42
|
declare class ProjectController extends Controller {
|
|
40
|
-
protected
|
|
41
|
-
protected
|
|
42
|
-
protected
|
|
43
|
-
|
|
43
|
+
protected di: DI;
|
|
44
|
+
protected appConfigService: CoreAppConfigService;
|
|
45
|
+
protected appEventsService: CoreAppEventsService;
|
|
46
|
+
protected projectService: CoreProjectService;
|
|
47
|
+
protected dockerService: DockerService;
|
|
48
|
+
constructor(di: DI);
|
|
44
49
|
install(cli: Cli): void;
|
|
45
50
|
protected getProjectNames(): Promise<string[]>;
|
|
51
|
+
protected getScripts(): Promise<string[]>;
|
|
46
52
|
init(options: InitOptions): Promise<void>;
|
|
53
|
+
projectList(options: ListOptions): Promise<string>;
|
|
47
54
|
start(options: StartOptions): Promise<void>;
|
|
48
55
|
stop(options: StopOptions): Promise<void>;
|
|
56
|
+
run(script: string): Promise<void>;
|
|
49
57
|
attach(options: AttachOptions): Promise<void>;
|
|
50
58
|
configList(options: ConfigOptions): Promise<string>;
|
|
51
59
|
configGet(options: ConfigOptions, key: string): Promise<string>;
|