@wocker/ws 1.0.7 → 1.0.8

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 (96) hide show
  1. package/bin/ws.js +1 -1
  2. package/lib/App.d.ts +1 -6
  3. package/lib/App.js +1 -27
  4. package/lib/AppModule.d.ts +6 -0
  5. package/lib/AppModule.js +97 -0
  6. package/lib/controllers/CompletionController.d.ts +6 -0
  7. package/lib/controllers/CompletionController.js +32 -0
  8. package/lib/controllers/ImageController.d.ts +5 -8
  9. package/lib/controllers/ImageController.js +27 -12
  10. package/lib/controllers/PluginController.d.ts +9 -13
  11. package/lib/controllers/PluginController.js +56 -18
  12. package/lib/controllers/PresetController.d.ts +9 -15
  13. package/lib/controllers/PresetController.js +41 -22
  14. package/lib/controllers/ProjectController.d.ts +27 -69
  15. package/lib/controllers/ProjectController.js +336 -261
  16. package/lib/controllers/ProxyController.d.ts +15 -25
  17. package/lib/controllers/ProxyController.js +142 -96
  18. package/lib/controllers/index.d.ts +1 -0
  19. package/lib/controllers/index.js +1 -0
  20. package/lib/index.d.ts +0 -1
  21. package/lib/index.js +0 -11
  22. package/lib/main.d.ts +3 -0
  23. package/lib/main.js +11 -0
  24. package/lib/makes/Logger.d.ts +2 -2
  25. package/lib/makes/Logger.js +19 -8
  26. package/lib/makes/Preset.d.ts +3 -4
  27. package/lib/makes/Preset.js +19 -8
  28. package/lib/makes/index.d.ts +0 -6
  29. package/lib/makes/index.js +0 -6
  30. package/lib/plugins/ElasticSearchPlugin.d.ts +5 -6
  31. package/lib/plugins/ElasticSearchPlugin.js +19 -8
  32. package/lib/plugins/LocaltunnelPlugin.d.ts +8 -8
  33. package/lib/plugins/LocaltunnelPlugin.js +25 -10
  34. package/lib/plugins/MaildevPlugin.d.ts +5 -6
  35. package/lib/plugins/MaildevPlugin.js +21 -8
  36. package/lib/plugins/MongodbPlugin.d.ts +5 -5
  37. package/lib/plugins/MongodbPlugin.js +26 -11
  38. package/lib/plugins/NgrokPlugin.d.ts +7 -6
  39. package/lib/plugins/NgrokPlugin.js +32 -17
  40. package/lib/plugins/PageKitePlugin.d.ts +10 -8
  41. package/lib/plugins/PageKitePlugin.js +36 -20
  42. package/lib/plugins/ProxmoxPlugin.d.ts +8 -5
  43. package/lib/plugins/ProxmoxPlugin.js +25 -9
  44. package/lib/plugins/RedisPlugin.d.ts +4 -6
  45. package/lib/plugins/RedisPlugin.js +19 -8
  46. package/lib/plugins/index.d.ts +0 -2
  47. package/lib/plugins/index.js +0 -2
  48. package/lib/services/AppConfigService.d.ts +3 -3
  49. package/lib/services/AppConfigService.js +16 -2
  50. package/lib/services/AppEventsService.d.ts +1 -2
  51. package/lib/services/AppEventsService.js +11 -2
  52. package/lib/services/DockerService.d.ts +9 -39
  53. package/lib/services/DockerService.js +122 -4
  54. package/lib/services/LogService.d.ts +3 -5
  55. package/lib/services/LogService.js +19 -4
  56. package/lib/services/PluginService.d.ts +4 -9
  57. package/lib/services/PluginService.js +18 -8
  58. package/lib/services/PresetService.d.ts +5 -5
  59. package/lib/services/PresetService.js +11 -2
  60. package/lib/services/ProjectService.d.ts +9 -6
  61. package/lib/services/ProjectService.js +62 -31
  62. package/lib/utils/get-config.d.ts +2 -2
  63. package/lib/utils/index.d.ts +0 -1
  64. package/lib/utils/index.js +0 -1
  65. package/lib/utils/set-config.d.ts +2 -2
  66. package/package.json +4 -4
  67. package/presets/node/config.json +1 -1
  68. package/presets/php-fpm/Dockerfile +1 -1
  69. package/lib/decorators/Inject.d.ts +0 -1
  70. package/lib/decorators/Inject.js +0 -8
  71. package/lib/decorators/Injectable.d.ts +0 -4
  72. package/lib/decorators/Injectable.js +0 -17
  73. package/lib/decorators/index.d.ts +0 -1
  74. package/lib/decorators/index.js +0 -17
  75. package/lib/makes/Controller.d.ts +0 -5
  76. package/lib/makes/Controller.js +0 -8
  77. package/lib/makes/DI.d.ts +0 -7
  78. package/lib/makes/DI.js +0 -27
  79. package/lib/makes/Docker.d.ts +0 -58
  80. package/lib/makes/Docker.js +0 -320
  81. package/lib/makes/Plugin.d.ts +0 -13
  82. package/lib/makes/Plugin.js +0 -61
  83. package/lib/makes/Project.d.ts +0 -45
  84. package/lib/makes/Project.js +0 -127
  85. package/lib/makes/Repository.d.ts +0 -11
  86. package/lib/makes/Repository.js +0 -22
  87. package/lib/plugins/PostgresPlugin.d.ts +0 -16
  88. package/lib/plugins/PostgresPlugin.js +0 -121
  89. package/lib/types/Config.d.ts +0 -12
  90. package/lib/types/Config.js +0 -2
  91. package/lib/types/EnvConfig.d.ts +0 -3
  92. package/lib/types/EnvConfig.js +0 -2
  93. package/lib/types/index.d.ts +0 -2
  94. package/lib/types/index.js +0 -18
  95. package/lib/utils/demuxOutput.d.ts +0 -2
  96. package/lib/utils/demuxOutput.js +0 -19
@@ -1,4 +1,4 @@
1
- import { DI, Project } from "../makes";
1
+ import { Project, PickProperties } from "@wocker/core";
2
2
  import { DockerService, AppConfigService, AppEventsService } from "../services";
3
3
  type SearchParams = Partial<{
4
4
  id: string;
@@ -6,16 +6,19 @@ type SearchParams = Partial<{
6
6
  path: string;
7
7
  }>;
8
8
  declare class ProjectService {
9
- protected appConfigService: AppConfigService;
10
- protected appEventsService: AppEventsService;
11
- protected dockerService: DockerService;
12
- constructor(di: DI);
9
+ protected readonly appConfigService: AppConfigService;
10
+ protected readonly appEventsService: AppEventsService;
11
+ protected readonly dockerService: DockerService;
12
+ constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, dockerService: DockerService);
13
+ fromObject(data: Partial<PickProperties<Project>>): Project;
14
+ getById(id: string): Promise<Project>;
13
15
  cdProject(name: string): Promise<void>;
14
16
  get(): Promise<Project>;
15
17
  getContainer(): Promise<import("dockerode").Container>;
16
- start(): Promise<void>;
18
+ start(restart?: boolean): Promise<void>;
17
19
  stop(): Promise<void>;
18
20
  save(project: Project): Promise<void>;
19
21
  search(params?: Partial<SearchParams>): Promise<Project[]>;
22
+ searchOne(params?: Partial<SearchParams>): Promise<Project | null>;
20
23
  }
21
24
  export { ProjectService };
@@ -15,6 +15,12 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ 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;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
18
24
  var __importStar = (this && this.__importStar) || function (mod) {
19
25
  if (mod && mod.__esModule) return mod;
20
26
  var result = {};
@@ -22,19 +28,38 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
28
  __setModuleDefault(result, mod);
23
29
  return result;
24
30
  };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", { value: true });
26
35
  exports.ProjectService = void 0;
36
+ const core_1 = require("@wocker/core");
27
37
  const Path = __importStar(require("path"));
28
38
  const makes_1 = require("../makes");
29
39
  const services_1 = require("../services");
30
- class ProjectService {
31
- constructor(di) {
32
- this.appConfigService = di.resolveService(services_1.AppConfigService);
33
- this.appEventsService = di.resolveService(services_1.AppEventsService);
34
- this.dockerService = di.resolveService(services_1.DockerService);
40
+ let ProjectService = class ProjectService {
41
+ constructor(appConfigService, appEventsService, dockerService) {
42
+ this.appConfigService = appConfigService;
43
+ this.appEventsService = appEventsService;
44
+ this.dockerService = dockerService;
45
+ }
46
+ fromObject(data) {
47
+ return new class extends core_1.Project {
48
+ constructor(projectService, data) {
49
+ super(data);
50
+ this.projectService = projectService;
51
+ }
52
+ async save() {
53
+ await this.projectService.save(this);
54
+ }
55
+ }(this, data);
56
+ }
57
+ async getById(id) {
58
+ const data = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", id, "config.json"));
59
+ return this.fromObject(data);
35
60
  }
36
61
  async cdProject(name) {
37
- const project = await makes_1.Project.searchOne({
62
+ const project = await this.searchOne({
38
63
  name
39
64
  });
40
65
  if (!project) {
@@ -43,7 +68,7 @@ class ProjectService {
43
68
  this.appConfigService.setPWD(project.path);
44
69
  }
45
70
  async get() {
46
- const project = await makes_1.Project.searchOne({
71
+ const project = await this.searchOne({
47
72
  path: this.appConfigService.getPWD()
48
73
  });
49
74
  if (!project) {
@@ -55,15 +80,15 @@ class ProjectService {
55
80
  const project = await this.get();
56
81
  return this.dockerService.getContainer(project.containerName);
57
82
  }
58
- async start() {
83
+ async start(restart) {
59
84
  const project = await this.get();
60
85
  if (project.type === "dockerfile") {
61
86
  project.imageName = `project-${project.name}:develop`;
62
- const images = await makes_1.Docker.imageLs({
87
+ const images = await this.dockerService.imageLs({
63
88
  tag: project.imageName
64
89
  });
65
90
  if (images.length === 0) {
66
- await makes_1.Docker.imageBuild2({
91
+ await this.dockerService.buildImage({
67
92
  tag: project.imageName,
68
93
  context: this.appConfigService.getPWD(),
69
94
  src: project.dockerfile
@@ -72,8 +97,12 @@ class ProjectService {
72
97
  }
73
98
  await this.appEventsService.emit("project:beforeStart", project);
74
99
  let container = await this.dockerService.getContainer(project.containerName);
100
+ if (container && restart) {
101
+ container = null;
102
+ await this.dockerService.removeContainer(project.containerName);
103
+ }
75
104
  if (!container) {
76
- container = await makes_1.Docker.createContainer({
105
+ container = await this.dockerService.createContainer({
77
106
  name: project.containerName,
78
107
  image: project.imageName,
79
108
  env: {
@@ -88,24 +117,20 @@ class ProjectService {
88
117
  ports: project.ports || []
89
118
  });
90
119
  }
91
- else {
92
- process.stdout.write("Container already exists\n");
93
- }
94
- if (container) {
95
- const { State: { Status } } = await container.inspect();
96
- if (Status === "created" || Status === "exited") {
97
- await container.start();
98
- await this.appEventsService.emit("project:start", project);
99
- }
120
+ const { State: { Status } } = await container.inspect();
121
+ if (Status === "created" || Status === "exited") {
122
+ await container.start();
123
+ await this.appEventsService.emit("project:start", project);
100
124
  }
101
125
  }
102
126
  async stop() {
103
127
  const project = await this.get();
104
- const container = await makes_1.Docker.getContainer(project.containerName);
105
- if (container) {
106
- await this.appEventsService.emit("project:stop", project);
107
- await makes_1.Docker.removeContainer(`${project.name}.workspace`);
128
+ const container = await this.dockerService.getContainer(project.containerName);
129
+ if (!container) {
130
+ return;
108
131
  }
132
+ await this.appEventsService.emit("project:stop", project);
133
+ await this.dockerService.removeContainer(project.containerName);
109
134
  }
110
135
  async save(project) {
111
136
  if (!project.name) {
@@ -138,17 +163,23 @@ class ProjectService {
138
163
  if (path && config.src !== path) {
139
164
  continue;
140
165
  }
141
- const projectData = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", config.id, "config.json"));
142
- if (name && projectData.name !== name) {
166
+ const project = await this.getById(config.id);
167
+ if (name && project.name !== name) {
143
168
  continue;
144
169
  }
145
- const project = makes_1.Project.fromObject({
146
- id: config.id,
147
- ...projectData
148
- });
149
170
  projects.push(project);
150
171
  }
151
172
  return projects;
152
173
  }
153
- }
174
+ async searchOne(params = {}) {
175
+ const [project] = await this.search(params);
176
+ return project || null;
177
+ }
178
+ };
154
179
  exports.ProjectService = ProjectService;
180
+ exports.ProjectService = ProjectService = __decorate([
181
+ (0, core_1.Injectable)("PROJECT_SERVICE"),
182
+ __metadata("design:paramtypes", [services_1.AppConfigService,
183
+ services_1.AppEventsService,
184
+ services_1.DockerService])
185
+ ], ProjectService);
@@ -1,2 +1,2 @@
1
- import { Config } from "../types";
2
- export declare const getConfig: () => Promise<Config>;
1
+ import { AppConfig } from "@wocker/core";
2
+ export declare const getConfig: () => Promise<AppConfig>;
@@ -1,5 +1,4 @@
1
1
  export * from "./buildOptions";
2
- export * from "./demuxOutput";
3
2
  export * from "./escapeRegExp";
4
3
  export * from "./exec";
5
4
  export * from "./fetch";
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./buildOptions"), exports);
18
- __exportStar(require("./demuxOutput"), exports);
19
18
  __exportStar(require("./escapeRegExp"), exports);
20
19
  __exportStar(require("./exec"), exports);
21
20
  __exportStar(require("./fetch"), exports);
@@ -1,2 +1,2 @@
1
- import { Config } from "../types";
2
- export declare const setConfig: (data: Partial<Config>) => Promise<Config>;
1
+ import { AppConfig } from "@wocker/core";
2
+ export declare const setConfig: (data: Partial<AppConfig>) => Promise<AppConfig>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocker/ws",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Docker workspace for web projects",
6
6
  "license": "MIT",
@@ -25,9 +25,9 @@
25
25
  "lint": "eslint \"**/*.{js,jsx,ts,tsx}\""
26
26
  },
27
27
  "dependencies": {
28
- "@kearisp/cli": "^1.0.6",
29
- "@wocker/core": "^1.0.4",
30
- "@wocker/utils": "^1.0.2",
28
+ "@kearisp/cli": "^1.0.7",
29
+ "@wocker/core": "^1.0.8",
30
+ "@wocker/utils": "^1.0.3",
31
31
  "async-mutex": "^0.4.0",
32
32
  "axios": "^1.6.7",
33
33
  "chalk": "^2.4.2",
@@ -33,7 +33,7 @@
33
33
  ]
34
34
  }
35
35
  },
36
- "volumes": [
36
+ "volumeOptions": [
37
37
  "./:/usr/app"
38
38
  ]
39
39
  }
@@ -164,7 +164,7 @@ ARG NGINX_DOCUMENT_ROOT=/var/www
164
164
  WORKDIR $WORKDIR
165
165
 
166
166
  ADD etc/nginx/sites-available/default.conf /tmp/default.conf.txt
167
- RUN envsubst '\${NGINX_DOCUMENT_ROOT}' < /tmp/default.conf.txt > /etc/nginx/sites-available/default.conf
167
+ RUN envsubst '\${NGINX_DOCUMENT_ROOT}' < /tmp/default.conf.txt > /etc/nginx/sites-available/default
168
168
 
169
169
  EXPOSE 80
170
170
  EXPOSE 9000
@@ -1 +0,0 @@
1
- export declare const Inject: () => (target: any) => void;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Inject = void 0;
4
- const Inject = () => {
5
- return (target) => {
6
- };
7
- };
8
- exports.Inject = Inject;
@@ -1,4 +0,0 @@
1
- import { DI } from "../makes";
2
- export declare const Injectable: () => <T extends new (...rest: any[]) => {}>(Target: T) => {
3
- new (di: DI): {};
4
- } & T;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Injectable = void 0;
4
- const Injectable = () => {
5
- return (Target) => {
6
- return class extends Target {
7
- constructor(di) {
8
- const types = Reflect.getMetadata("design:paramtypes", Target);
9
- const params = types.map((type) => {
10
- return (di).resolveService(type);
11
- });
12
- super(...params);
13
- }
14
- };
15
- };
16
- };
17
- exports.Injectable = Injectable;
@@ -1 +0,0 @@
1
- export * from "./Injectable";
@@ -1,17 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Injectable"), exports);
@@ -1,5 +0,0 @@
1
- import { Cli } from "@kearisp/cli";
2
- declare class Controller {
3
- install(cli: Cli): void;
4
- }
5
- export { Controller };
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Controller = void 0;
4
- class Controller {
5
- install() {
6
- }
7
- }
8
- exports.Controller = Controller;
package/lib/makes/DI.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import "reflect-metadata";
2
- declare class DI {
3
- private services;
4
- resolveService<T>(key: any): T;
5
- registerService(key: any, service: any): void;
6
- }
7
- export { DI };
package/lib/makes/DI.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DI = void 0;
4
- require("reflect-metadata");
5
- class DI {
6
- constructor() {
7
- this.services = new Map();
8
- }
9
- resolveService(key) {
10
- let res = this.services.get(key);
11
- if (!res) {
12
- const types = Reflect.getMetadata("design:paramtypes", key);
13
- if (types && types.length > 0) {
14
- types.forEach((type) => {
15
- this.resolveService(type);
16
- });
17
- }
18
- res = new key(this);
19
- this.services.set(key, res);
20
- }
21
- return res;
22
- }
23
- registerService(key, service) {
24
- this.services.set(key, service);
25
- }
26
- }
27
- exports.DI = DI;
@@ -1,58 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import Dockerode from "dockerode";
4
- type ContainerRunOptions = {
5
- name: string;
6
- image: string;
7
- restart?: "always";
8
- projectId?: string;
9
- tty?: boolean;
10
- links?: string[];
11
- env?: {
12
- [key: string]: string;
13
- };
14
- networkMode?: string;
15
- extraHosts?: any;
16
- volumes?: string[];
17
- ports?: string[];
18
- cmd?: string[];
19
- };
20
- type ImageBuildOptions = {
21
- tag: string;
22
- buildArgs?: {
23
- [key: string]: string;
24
- };
25
- labels?: {
26
- [key: string]: string;
27
- };
28
- context: string;
29
- src: string;
30
- };
31
- declare class Docker {
32
- static docker: Dockerode;
33
- static exec(name: string, args: string[], tty?: boolean): Promise<import("stream").Duplex>;
34
- static getImage(name: string): Promise<Dockerode.Image>;
35
- static getContainer(name: any): Promise<Dockerode.Container>;
36
- static removeContainer(name: string): Promise<void>;
37
- static getContainerList(options?: {
38
- name?: string;
39
- projectId?: string;
40
- }): Promise<Dockerode.ContainerInfo[]>;
41
- static attach(name: string): Promise<void>;
42
- static attachStream(stream: NodeJS.ReadWriteStream): Promise<void>;
43
- static imageExists(tag: string): Promise<boolean>;
44
- static imageLs(options?: {
45
- tag?: string;
46
- reference?: string;
47
- labels?: {
48
- [key: string]: string;
49
- };
50
- }): Promise<Dockerode.ImageInfo[]>;
51
- static imageBuild(options: ImageBuildOptions): Promise<void>;
52
- static imageBuild2(options: ImageBuildOptions): Promise<NodeJS.ReadableStream>;
53
- static imageRm(name: string): Promise<void>;
54
- static pullImage(tag: string): Promise<void>;
55
- static createContainer(options: ContainerRunOptions): Promise<Dockerode.Container>;
56
- static containerRun(options: ContainerRunOptions, attach?: boolean): Promise<Dockerode.Container>;
57
- }
58
- export { Docker };