@wocker/ws 1.0.12 → 1.0.13

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.
@@ -1,6 +1,4 @@
1
1
  export * from "./ElasticSearchPlugin";
2
- export * from "./LocaltunnelPlugin";
3
- export * from "./MaildevPlugin";
4
2
  export * from "./MongodbPlugin";
5
3
  export * from "./PageKitePlugin";
6
4
  export * from "./ProxmoxPlugin";
@@ -15,8 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./ElasticSearchPlugin"), exports);
18
- __exportStar(require("./LocaltunnelPlugin"), exports);
19
- __exportStar(require("./MaildevPlugin"), exports);
20
18
  __exportStar(require("./MongodbPlugin"), exports);
21
19
  __exportStar(require("./PageKitePlugin"), exports);
22
20
  __exportStar(require("./ProxmoxPlugin"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/ws",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Docker workspace for web projects",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@wocker/core": "^1.0.11",
29
- "@wocker/utils": "^1.0.4",
29
+ "@wocker/utils": "^1.0.5",
30
30
  "async-mutex": "^0.4.0",
31
31
  "axios": "^1.6.7",
32
32
  "chalk": "^2.4.2",
@@ -54,6 +54,6 @@
54
54
  "eslint-plugin-import": "^2.28.1",
55
55
  "eslint-plugin-node": "^11.1.0",
56
56
  "eslint-webpack-plugin": "^3.1.0",
57
- "typescript": "^5.5.2"
57
+ "typescript": "^5.5.4"
58
58
  }
59
59
  }
@@ -1,34 +0,0 @@
1
- import { Project } from "@wocker/core";
2
- import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
3
- type InitOptions = {
4
- name?: string;
5
- };
6
- type StartOptions = {
7
- name?: string;
8
- detach?: boolean;
9
- };
10
- type StopOptions = {
11
- name?: string;
12
- };
13
- type LogsOptions = {
14
- name?: string;
15
- detach?: boolean;
16
- };
17
- export declare class LocaltunnelPlugin {
18
- protected readonly appConfigService: AppConfigService;
19
- protected readonly appEventsService: AppEventsService;
20
- protected readonly projectService: ProjectService;
21
- protected readonly dockerService: DockerService;
22
- constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService);
23
- getIp(): Promise<string>;
24
- onProjectStart(project: Project): Promise<void>;
25
- onProjectStop(project: Project): Promise<void>;
26
- build(): Promise<void>;
27
- rebuild(): Promise<void>;
28
- init(options: InitOptions): Promise<void>;
29
- start(options: StartOptions): Promise<void>;
30
- stop(options: StopOptions): Promise<void>;
31
- restart(options: StartOptions): Promise<void>;
32
- logs(options: LogsOptions): Promise<void>;
33
- }
34
- export {};
@@ -1,231 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.LocaltunnelPlugin = void 0;
16
- const core_1 = require("@wocker/core");
17
- const utils_1 = require("@wocker/utils");
18
- const axios_1 = __importDefault(require("axios"));
19
- const makes_1 = require("../makes");
20
- const services_1 = require("../services");
21
- let LocaltunnelPlugin = class LocaltunnelPlugin {
22
- constructor(appConfigService, appEventsService, projectService, dockerService) {
23
- this.appConfigService = appConfigService;
24
- this.appEventsService = appEventsService;
25
- this.projectService = projectService;
26
- this.dockerService = dockerService;
27
- }
28
- async getIp() {
29
- const res = await axios_1.default.get("https://ipv4.icanhazip.com");
30
- return res.data.replace("\n", "");
31
- }
32
- async onProjectStart(project) {
33
- if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
34
- return;
35
- }
36
- let container = await this.dockerService.getContainer(`localtunnel-${project.name}`);
37
- if (container) {
38
- const { State: { Running } } = await container.inspect();
39
- if (Running) {
40
- console.info("Localtunnel is already running");
41
- return;
42
- }
43
- else {
44
- await this.dockerService.removeContainer(`localtunnel-${project.name}`);
45
- }
46
- }
47
- console.info("Localtunnel starting...");
48
- makes_1.Logger.info(`Localtunnel start: ${project.name}`);
49
- await this.build();
50
- const subdomain = project.getEnv("LOCALTUNNEL_SUBDOMAIN", project.name);
51
- container = await this.dockerService.createContainer({
52
- name: `localtunnel-${project.name}`,
53
- image: "ws-localtunnel",
54
- restart: "always",
55
- networkMode: "host",
56
- cmd: [
57
- "lt",
58
- `--port=80`,
59
- `--subdomain=${subdomain}`,
60
- "--print-requests"
61
- ]
62
- });
63
- const stream = await container.attach({
64
- logs: true,
65
- stream: true,
66
- hijack: true,
67
- stdin: true,
68
- stdout: true,
69
- stderr: true
70
- });
71
- stream.setEncoding("utf8");
72
- await container.start();
73
- const link = await new Promise((resolve, reject) => {
74
- let res = "";
75
- stream.on("data", (data) => {
76
- const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
77
- if (regLink.test(data.toString())) {
78
- const [link] = regLink.exec(data.toString());
79
- if (link.includes(".loca.lt")) {
80
- res = link;
81
- stream.end();
82
- }
83
- }
84
- });
85
- stream.on("end", () => resolve(res));
86
- stream.on("error", reject);
87
- });
88
- makes_1.Logger.info(`${project.name} localtunnel forwarding: ${link}`);
89
- const ip = await this.getIp();
90
- console.info(`IP: ${ip}`);
91
- console.info(`Forwarding: ${link}`);
92
- if (project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "false") === "true") {
93
- console.info("Skipping IP confirmation...");
94
- const res = await axios_1.default.get(link, {
95
- headers: {
96
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
97
- },
98
- validateStatus: () => true
99
- });
100
- const [path] = /\/continue\/[\w.]+/.exec(res.data) || [];
101
- if (path) {
102
- const sendData = new URLSearchParams({
103
- endpoint: ip
104
- });
105
- const res = await axios_1.default.post(`${link}${path}`, sendData.toString(), {
106
- headers: {
107
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
108
- "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
109
- }
110
- });
111
- if (res.status === 200) {
112
- console.info("IP confirmed");
113
- }
114
- }
115
- }
116
- }
117
- async onProjectStop(project) {
118
- if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
119
- return;
120
- }
121
- console.info("Localtunnel stopping...");
122
- await this.dockerService.removeContainer(`localtunnel-${project.name}`);
123
- }
124
- async build() {
125
- const exists = await this.dockerService.imageExists("ws-localtunnel");
126
- if (!exists) {
127
- await this.dockerService.buildImage({
128
- tag: "ws-localtunnel",
129
- context: this.appConfigService.pluginsPath("plugins/localtunnel"),
130
- src: "./Dockerfile"
131
- });
132
- }
133
- }
134
- async rebuild() {
135
- try {
136
- await this.dockerService.imageRm("ws-localtunnel");
137
- }
138
- catch (err) {
139
- console.info(err.message);
140
- }
141
- await this.build();
142
- }
143
- async init(options) {
144
- const { name } = options;
145
- if (name) {
146
- await this.projectService.cdProject(name);
147
- }
148
- const project = await this.projectService.get();
149
- const enabled = await (0, utils_1.promptConfirm)({
150
- message: "Enable localtunnel?",
151
- default: project.getEnv("LOCALTUNNEL_ENABLE", "false") === "true"
152
- });
153
- if (enabled) {
154
- const subdomain = await (0, utils_1.promptText)({
155
- message: "Subdomain",
156
- prefix: "https://",
157
- suffix: ".loca.lt",
158
- default: project.getEnv("LOCALTUNNEL_SUBDOMAIN")
159
- });
160
- if (!subdomain) {
161
- throw new Error("Subdomain can't be empty");
162
- }
163
- const autoConfirmIP = await (0, utils_1.promptConfirm)({
164
- message: "Do you want to skip the IP confirmation form automatically?",
165
- default: project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "true") === "true"
166
- });
167
- project.setEnv("LOCALTUNNEL_ENABLE", "true");
168
- project.setEnv("LOCALTUNNEL_SUBDOMAIN", subdomain);
169
- project.setEnv("LOCALTUNNEL_AUTO_CONFIRM", autoConfirmIP ? "true" : "false");
170
- }
171
- else {
172
- project.setEnv("LOCALTUNNEL_ENABLE", "false");
173
- }
174
- await project.save();
175
- }
176
- async start(options) {
177
- const { name, detach } = options;
178
- if (name) {
179
- await this.projectService.cdProject(name);
180
- }
181
- const project = await this.projectService.get();
182
- if (project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
183
- throw new Error(`Localtunnel is not initialized. Run "ws localtunnel:init${name ? ` -n=${name}` : ""}" first.`);
184
- }
185
- await this.onProjectStart(project);
186
- if (!detach) {
187
- await this.logs({ name });
188
- }
189
- }
190
- async stop(options) {
191
- const { name } = options;
192
- if (name) {
193
- await this.projectService.cdProject(name);
194
- }
195
- const project = await this.projectService.get();
196
- await this.onProjectStop(project);
197
- }
198
- async restart(options) {
199
- const { name } = options;
200
- await this.stop({ name });
201
- await this.start(options);
202
- }
203
- async logs(options) {
204
- const { name, } = options;
205
- if (name) {
206
- await this.projectService.cdProject(name);
207
- }
208
- const project = await this.projectService.get();
209
- const container = await this.dockerService.getContainer(`localtunnel-${project.name}`);
210
- const stream = await container.logs({
211
- follow: true,
212
- stderr: true,
213
- stdout: true,
214
- tail: 5
215
- });
216
- stream.on("data", (data) => {
217
- process.stdout.write(data);
218
- });
219
- stream.on("error", (data) => {
220
- process.stderr.write(data);
221
- });
222
- }
223
- };
224
- exports.LocaltunnelPlugin = LocaltunnelPlugin;
225
- exports.LocaltunnelPlugin = LocaltunnelPlugin = __decorate([
226
- (0, core_1.Controller)(),
227
- __metadata("design:paramtypes", [services_1.AppConfigService,
228
- services_1.AppEventsService,
229
- services_1.ProjectService,
230
- services_1.DockerService])
231
- ], LocaltunnelPlugin);
@@ -1,9 +0,0 @@
1
- import { DockerService, AppConfigService } from "../services";
2
- export declare class MaildevPlugin {
3
- protected readonly appConfigService: AppConfigService;
4
- protected readonly dockerService: DockerService;
5
- protected containerName: string;
6
- constructor(appConfigService: AppConfigService, dockerService: DockerService);
7
- start(): Promise<void>;
8
- stop(): Promise<void>;
9
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MaildevPlugin = void 0;
13
- const core_1 = require("@wocker/core");
14
- const services_1 = require("../services");
15
- let MaildevPlugin = class MaildevPlugin {
16
- constructor(appConfigService, dockerService) {
17
- this.appConfigService = appConfigService;
18
- this.dockerService = dockerService;
19
- this.containerName = "maildev.workspace";
20
- }
21
- async start() {
22
- console.log("Maildev starting...");
23
- const imageName = "ws-maildev";
24
- if (!await this.dockerService.imageExists(imageName)) {
25
- await this.dockerService.buildImage({
26
- tag: "ws-maildev",
27
- buildArgs: {},
28
- labels: {},
29
- context: this.appConfigService.pluginsPath("plugins/maildev"),
30
- src: "./Dockerfile"
31
- });
32
- }
33
- let container = await this.dockerService.createContainer({
34
- name: this.containerName,
35
- restart: "always",
36
- env: {
37
- VIRTUAL_HOST: "maildev.workspace"
38
- },
39
- ports: [
40
- "25:25"
41
- ],
42
- image: imageName
43
- });
44
- await container.start();
45
- }
46
- async stop() {
47
- console.log("Maildev stopping...");
48
- await this.dockerService.removeContainer(this.containerName);
49
- }
50
- };
51
- exports.MaildevPlugin = MaildevPlugin;
52
- exports.MaildevPlugin = MaildevPlugin = __decorate([
53
- (0, core_1.Controller)(),
54
- __metadata("design:paramtypes", [services_1.AppConfigService,
55
- services_1.DockerService])
56
- ], MaildevPlugin);
@@ -1,37 +0,0 @@
1
- FROM alpine:latest
2
-
3
- RUN apk update && apk upgrade && apk add --no-cache curl bash nodejs npm
4
-
5
- RUN npm install --quiet -g localtunnel
6
-
7
- SHELL ["/bin/bash", "-c"]
8
-
9
- ARG UID=1000
10
- ARG USER=user
11
-
12
- RUN adduser -D -u $UID $USER
13
-
14
- USER $USER
15
-
16
- RUN touch /home/$USER/.bashrc && chmod +x /home/$USER/.bashrc
17
-
18
- #ENV NODE_VERSION 16.13.0
19
- #ENV NVM_DIR /home/$USER/.nvm
20
-
21
- #RUN mkdir -p $NVM_DIR && \
22
- # curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
23
-
24
- #RUN echo "[ -s \"$NVM_DIR/nvm.sh\" ] && \. \"$NVM_DIR/nvm.sh\"" >> ~/.bashrc
25
- #RUN echo "[ -s \"$NVM_DIR/bash_completion\" ] && \. \"$NVM_DIR/bash_completion\"" >> ~/.bashrc
26
-
27
- #ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin
28
- #ENV PATH $NODE_PATH:$PATH
29
-
30
- #RUN source /home/$USER/.bashrc && \
31
- #RUN source $NVM_DIR/nvm.sh && \
32
- # nvm install $NODE_VERSION && \
33
- # nvm alias default $NODE_VERSION && \
34
- # nvm use default #&& \
35
- #npm install --quiet -g localtunnel
36
-
37
- #ENTRYPOINT ["lt"]
@@ -1,34 +0,0 @@
1
- FROM ubuntu:latest
2
-
3
- RUN apt-get update && apt-get upgrade -y && apt-get install -y curl bash
4
-
5
- SHELL ["/bin/bash", "-c"]
6
-
7
- ARG UID=1000
8
- ARG USER=user
9
-
10
- RUN useradd -m -u $UID $USER
11
-
12
- USER $USER
13
-
14
- RUN touch /home/$USER/.bashrc && chmod +x /home/$USER/.bashrc
15
-
16
- ENV NODE_VERSION 16.13.0
17
- ENV NVM_DIR /home/$USER/.nvm
18
-
19
- RUN mkdir -p $NVM_DIR && \
20
- curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
21
-
22
- RUN echo "[ -s \"$NVM_DIR/nvm.sh\" ] && \. \"$NVM_DIR/nvm.sh\"" >> ~/.bashrc
23
- RUN echo "[ -s \"$NVM_DIR/bash_completion\" ] && \. \"$NVM_DIR/bash_completion\"" >> ~/.bashrc
24
-
25
- ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin
26
- ENV PATH $NODE_PATH:$PATH
27
-
28
- RUN source $NVM_DIR/nvm.sh && \
29
- nvm install $NODE_VERSION && \
30
- nvm alias default $NODE_VERSION && \
31
- nvm use default && \
32
- npm install --quiet -g localtunnel
33
-
34
- ENTRYPOINT ["lt"]
@@ -1,3 +0,0 @@
1
- {
2
- "name": "localtunnel"
3
- }
@@ -1,5 +0,0 @@
1
- FROM djfarrelly/maildev
2
-
3
- LABEL maintainer="Kris Papercut <krispcut@gmail.com>"
4
-
5
- EXPOSE 80 25
@@ -1,3 +0,0 @@
1
- {
2
- "dockerfile": "./Dockerfile"
3
- }