@wocker/ws 1.0.10 → 1.0.11

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.
@@ -11,6 +11,7 @@ export declare class PresetController {
11
11
  protected onInit(project: Project): Promise<void>;
12
12
  protected onRebuild(project: Project): Promise<void>;
13
13
  protected onBeforeStart(project: Project): Promise<void>;
14
+ add(preset: string): Promise<void>;
14
15
  eject(name?: string): Promise<void>;
15
16
  build(rebuild: boolean, presetName: string): Promise<void>;
16
17
  }
@@ -122,7 +122,7 @@ let PresetController = class PresetController {
122
122
  if (!preset) {
123
123
  throw new Error(`Preset ${project.preset} not found`);
124
124
  }
125
- const imageName = preset.getImageName(project.buildArgs || {});
125
+ const imageName = this.presetService.getImageName(preset, project.buildArgs || {});
126
126
  const exists = await this.dockerService.imageExists(imageName);
127
127
  if (exists) {
128
128
  console.info(`Removing image: ${imageName}`);
@@ -135,7 +135,7 @@ let PresetController = class PresetController {
135
135
  }
136
136
  const preset = await this.presetService.get(project.preset);
137
137
  if (preset.dockerfile) {
138
- project.imageName = preset.getImageName(project.buildArgs);
138
+ project.imageName = this.presetService.getImageName(preset, project.buildArgs);
139
139
  if (!await this.dockerService.imageExists(project.imageName)) {
140
140
  await this.dockerService.buildImage({
141
141
  tag: project.imageName,
@@ -149,6 +149,8 @@ let PresetController = class PresetController {
149
149
  }
150
150
  }
151
151
  }
152
+ async add(preset) {
153
+ }
152
154
  async eject(name) {
153
155
  if (name) {
154
156
  await this.projectService.cdProject(name);
@@ -204,7 +206,7 @@ let PresetController = class PresetController {
204
206
  if (preset.buildArgsOptions) {
205
207
  buildArgs = await (0, utils_1.promptGroup)(preset.buildArgsOptions);
206
208
  }
207
- const imageName = preset.getImageName(buildArgs);
209
+ const imageName = this.presetService.getImageName(preset, buildArgs);
208
210
  await this.dockerService.buildImage({
209
211
  tag: imageName,
210
212
  labels: {
@@ -217,6 +219,12 @@ let PresetController = class PresetController {
217
219
  }
218
220
  };
219
221
  exports.PresetController = PresetController;
222
+ __decorate([
223
+ (0, core_1.Command)("preset:add <preset>"),
224
+ __metadata("design:type", Function),
225
+ __metadata("design:paramtypes", [String]),
226
+ __metadata("design:returntype", Promise)
227
+ ], PresetController.prototype, "add", null);
220
228
  __decorate([
221
229
  (0, core_1.Command)("preset:eject"),
222
230
  __param(0, (0, core_1.Option)("name", {
@@ -7,6 +7,7 @@ export declare class ProjectController {
7
7
  protected readonly logService: LogService;
8
8
  constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService, logService: LogService);
9
9
  protected getProjectNames(): Promise<string[]>;
10
+ getScriptNames(): Promise<string[]>;
10
11
  init(name: string, type: string, preset: string): Promise<void>;
11
12
  projectList(all: boolean): Promise<string>;
12
13
  start(name?: string, detach?: boolean, rebuild?: boolean, restart?: boolean): Promise<void>;
@@ -62,6 +62,15 @@ let ProjectController = class ProjectController {
62
62
  return project.name;
63
63
  });
64
64
  }
65
+ async getScriptNames() {
66
+ try {
67
+ const project = await this.projectService.get();
68
+ return Object.keys(project.scripts);
69
+ }
70
+ catch (err) {
71
+ return [];
72
+ }
73
+ }
65
74
  async init(name, type, preset) {
66
75
  let project = await this.projectService.searchOne({
67
76
  path: this.appConfigService.getPWD()
@@ -404,6 +413,10 @@ let ProjectController = class ProjectController {
404
413
  const prepareLog = (str) => {
405
414
  return str.replace(/^\[.*]\s([^:]+):\s.*$/gm, (substring, type) => {
406
415
  switch (type) {
416
+ case "debug":
417
+ return chalk_1.default.grey(substring);
418
+ case "log":
419
+ return chalk_1.default.white(substring);
407
420
  case "info":
408
421
  return chalk_1.default.green(substring);
409
422
  case "warn":
@@ -485,6 +498,12 @@ __decorate([
485
498
  __metadata("design:paramtypes", []),
486
499
  __metadata("design:returntype", Promise)
487
500
  ], ProjectController.prototype, "getProjectNames", null);
501
+ __decorate([
502
+ (0, core_1.Completion)("script"),
503
+ __metadata("design:type", Function),
504
+ __metadata("design:paramtypes", []),
505
+ __metadata("design:returntype", Promise)
506
+ ], ProjectController.prototype, "getScriptNames", null);
488
507
  __decorate([
489
508
  (0, core_1.Command)("init"),
490
509
  __param(0, (0, core_1.Option)("name", {
@@ -519,22 +538,27 @@ __decorate([
519
538
  ], ProjectController.prototype, "projectList", null);
520
539
  __decorate([
521
540
  (0, core_1.Command)("start"),
541
+ (0, core_1.Description)("Starting project"),
522
542
  __param(0, (0, core_1.Option)("name", {
523
543
  type: "string",
524
544
  alias: "n",
525
- description: "Project name"
545
+ description: "Project name",
546
+ help: true
526
547
  })),
527
548
  __param(1, (0, core_1.Option)("detach", {
528
549
  type: "boolean",
550
+ description: "Detach",
529
551
  alias: "d"
530
552
  })),
531
553
  __param(2, (0, core_1.Option)("build", {
532
554
  type: "boolean",
555
+ description: "Build",
533
556
  alias: "b"
534
557
  })),
535
558
  __param(3, (0, core_1.Option)("restart", {
536
559
  type: "boolean",
537
- alias: "r"
560
+ alias: "r",
561
+ description: "Restart"
538
562
  })),
539
563
  __metadata("design:type", Function),
540
564
  __metadata("design:paramtypes", [String, Boolean, Boolean, Boolean]),
@@ -597,6 +621,7 @@ __decorate([
597
621
  type: "boolean",
598
622
  alias: "g"
599
623
  })),
624
+ __param(2, (0, core_1.Param)("key")),
600
625
  __metadata("design:type", Function),
601
626
  __metadata("design:paramtypes", [String, Boolean, Array]),
602
627
  __metadata("design:returntype", Promise)
@@ -1,5 +1,4 @@
1
1
  import { FSManager } from "@wocker/core";
2
- import { Cli } from "@kearisp/cli";
3
2
  import { AppConfigService, DockerService } from "../services";
4
3
  type StartOptions = {
5
4
  restart?: boolean;
@@ -10,7 +9,6 @@ export declare class ElasticSearchPlugin {
10
9
  protected containerName: string;
11
10
  protected fs: FSManager;
12
11
  constructor(appConfigService: AppConfigService, dockerService: DockerService);
13
- install(cli: Cli): void;
14
12
  start(options: StartOptions): Promise<void>;
15
13
  stop(): Promise<void>;
16
14
  }
@@ -19,17 +19,6 @@ let ElasticSearchPlugin = class ElasticSearchPlugin {
19
19
  this.containerName = "elastic-search.workspace";
20
20
  this.fs = new core_1.FSManager(this.appConfigService.pluginsPath("elastic-search"), this.appConfigService.dataPath("plugins/elastic-search"));
21
21
  }
22
- install(cli) {
23
- cli.command("elastica:start")
24
- .option("restart", {
25
- type: "boolean",
26
- alias: "r",
27
- description: "Restart service"
28
- })
29
- .action((options) => this.start(options));
30
- cli.command("elastica:stop")
31
- .action(() => this.stop());
32
- }
33
22
  async start(options) {
34
23
  const { restart } = options;
35
24
  await this.dockerService.pullImage("docker.elastic.co/elasticsearch/elasticsearch:7.5.2");
@@ -1,5 +1,4 @@
1
1
  import { Project } from "@wocker/core";
2
- import { Cli } from "@kearisp/cli";
3
2
  import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
4
3
  type InitOptions = {
5
4
  name?: string;
@@ -21,7 +20,6 @@ export declare class LocaltunnelPlugin {
21
20
  protected readonly projectService: ProjectService;
22
21
  protected readonly dockerService: DockerService;
23
22
  constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService);
24
- install(cli: Cli): void;
25
23
  getIp(): Promise<string>;
26
24
  onProjectStart(project: Project): Promise<void>;
27
25
  onProjectStop(project: Project): Promise<void>;
@@ -25,64 +25,6 @@ let LocaltunnelPlugin = class LocaltunnelPlugin {
25
25
  this.projectService = projectService;
26
26
  this.dockerService = dockerService;
27
27
  }
28
- install(cli) {
29
- this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
30
- this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
31
- cli.command("localtunnel:init")
32
- .option("name", {
33
- alias: "n",
34
- type: "string",
35
- description: "Project name"
36
- })
37
- .action((options) => this.init(options));
38
- cli.command("localtunnel:start")
39
- .option("name", {
40
- alias: "n",
41
- type: "string",
42
- description: "Project name"
43
- })
44
- .option("detach", {
45
- type: "boolean",
46
- alias: "d",
47
- description: "Detach"
48
- })
49
- .action((options) => this.start(options));
50
- cli.command("localtunnel:restart")
51
- .option("name", {
52
- alias: "n",
53
- type: "string",
54
- description: "Project name"
55
- })
56
- .option("detach", {
57
- type: "boolean",
58
- alias: "d",
59
- description: "Detach"
60
- })
61
- .action((options) => this.restart(options));
62
- cli.command("localtunnel:stop")
63
- .option("name", {
64
- alias: "n",
65
- type: "string",
66
- description: "Project name"
67
- })
68
- .action((options) => this.stop(options));
69
- cli.command("localtunnel:build")
70
- .action(() => this.build());
71
- cli.command("localtunnel:rebuild")
72
- .action(() => this.rebuild());
73
- cli.command("localtunnel:logs")
74
- .option("name", {
75
- alias: "n",
76
- type: "string",
77
- description: "Project name"
78
- })
79
- .option("detach", {
80
- type: "boolean",
81
- alias: "d",
82
- description: "Detach"
83
- })
84
- .action((options) => this.logs(options));
85
- }
86
28
  async getIp() {
87
29
  const res = await axios_1.default.get("https://ipv4.icanhazip.com");
88
30
  return res.data.replace("\n", "");
@@ -1,11 +1,9 @@
1
- import { Cli } from "@kearisp/cli";
2
1
  import { DockerService, AppConfigService } from "../services";
3
2
  export declare class MaildevPlugin {
4
3
  protected readonly appConfigService: AppConfigService;
5
4
  protected readonly dockerService: DockerService;
6
5
  protected containerName: string;
7
6
  constructor(appConfigService: AppConfigService, dockerService: DockerService);
8
- install(cli: Cli): void;
9
7
  start(): Promise<void>;
10
8
  stop(): Promise<void>;
11
9
  }
@@ -18,12 +18,6 @@ let MaildevPlugin = class MaildevPlugin {
18
18
  this.dockerService = dockerService;
19
19
  this.containerName = "maildev.workspace";
20
20
  }
21
- install(cli) {
22
- cli.command("maildev:start")
23
- .action(() => this.start());
24
- cli.command("maildev:stop")
25
- .action(() => this.stop());
26
- }
27
21
  async start() {
28
22
  console.log("Maildev starting...");
29
23
  const imageName = "ws-maildev";
@@ -1,4 +1,3 @@
1
- import { Cli } from "@kearisp/cli";
2
1
  import { DockerService } from "../services";
3
2
  export declare class MongodbPlugin {
4
3
  protected readonly dockerService: DockerService;
@@ -7,7 +6,6 @@ export declare class MongodbPlugin {
7
6
  protected dataDir: string;
8
7
  constructor(dockerService: DockerService);
9
8
  protected dataPath(...parts: string[]): string;
10
- install(cli: Cli): void;
11
9
  getDatabases(): Promise<string[]>;
12
10
  getDatabasesDumps(): Promise<string[]>;
13
11
  start(): Promise<void>;
@@ -50,63 +50,6 @@ let MongodbPlugin = class MongodbPlugin {
50
50
  dataPath(...parts) {
51
51
  return Path.join(this.dataDir, ...parts);
52
52
  }
53
- install(cli) {
54
- cli.command("mongodb:start").action(() => {
55
- return this.start();
56
- });
57
- cli.command("mongodb:stop").action(() => {
58
- return this.stop();
59
- });
60
- cli.command("mongodb:restart").action(() => {
61
- return this.restart();
62
- });
63
- cli.command("mongodb:backup [database]")
64
- .completion("database", () => {
65
- return this.getDatabases();
66
- })
67
- .action((options, database) => {
68
- return this.backup(database);
69
- });
70
- cli.command("mongodb:restore [database] [filename]")
71
- .completion("database", () => {
72
- const dumpPath = this.dataPath("dump");
73
- return makes_1.FS.readdir(dumpPath);
74
- })
75
- .completion("filename", (options, database) => {
76
- if (!database) {
77
- return [];
78
- }
79
- const dirPath = this.dataPath("dump", database);
80
- if (!makes_1.FS.existsSync(dirPath)) {
81
- return [];
82
- }
83
- return makes_1.FS.readdir(dirPath);
84
- })
85
- .action((options, database, filename) => {
86
- return this.restore(database, filename);
87
- });
88
- cli.command("mongodb:delete-backup [database] [filename]")
89
- .option("yes", {
90
- type: "boolean",
91
- alias: "y"
92
- })
93
- .completion("database", () => {
94
- return this.getDatabasesDumps();
95
- })
96
- .completion("filename", (options, database) => {
97
- if (!database) {
98
- return [];
99
- }
100
- const dumpPath = this.dataPath("dump", database);
101
- if (!makes_1.FS.existsSync(dumpPath)) {
102
- return [];
103
- }
104
- return makes_1.FS.readdirFiles(dumpPath);
105
- })
106
- .action((options, database, filename) => {
107
- return this.deleteBackup(database, filename, options.yes);
108
- });
109
- }
110
53
  async getDatabases() {
111
54
  const stream = await this.dockerService.exec(this.container, [
112
55
  "mongosh",
@@ -1,5 +1,4 @@
1
1
  import { Project } from "@wocker/core";
2
- import { Cli } from "@kearisp/cli";
3
2
  import { AppConfigService, AppEventsService, ProjectService, DockerService } from "../services";
4
3
  type InitOptions = {};
5
4
  type StartOptions = {
@@ -21,7 +20,6 @@ export declare class PageKitePlugin {
21
20
  protected readonly dockerService: DockerService;
22
21
  constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService, dockerService: DockerService);
23
22
  pluginPath(...parts: string[]): string;
24
- install(cli: Cli): void;
25
23
  onProjectStart(project: Project): Promise<void>;
26
24
  onProjectStop(project: Project): Promise<void>;
27
25
  init(options: InitOptions): Promise<void>;
@@ -23,38 +23,6 @@ let PageKitePlugin = class PageKitePlugin {
23
23
  pluginPath(...parts) {
24
24
  return this.appConfigService.pluginsPath("pagekite", ...parts);
25
25
  }
26
- install(cli) {
27
- this.appEventsService.on("project:start", (project) => this.onProjectStart(project));
28
- this.appEventsService.on("project:stop", (project) => this.onProjectStop(project));
29
- cli.command("pagekite:init")
30
- .action((options) => this.init(options));
31
- cli.command("pagekite:start")
32
- .option("name", {
33
- type: "string",
34
- alias: "n",
35
- description: "Project name"
36
- })
37
- .option("restart", {
38
- type: "boolean",
39
- alias: "r",
40
- description: "Restart"
41
- })
42
- .action((options) => this.start(options));
43
- cli.command("pagekite:stop")
44
- .option("name", {
45
- type: "string",
46
- alias: "n",
47
- description: "Project name"
48
- })
49
- .action((options) => this.stop(options));
50
- cli.command("pagekite:build")
51
- .option("rebuild", {
52
- type: "boolean",
53
- alias: "r",
54
- description: "Rebuild"
55
- })
56
- .action((options) => this.build(options));
57
- }
58
26
  async onProjectStart(project) {
59
27
  if (!project || project.getEnv("PAGEKITE_ENABLE", "false") !== "true") {
60
28
  return;
@@ -44,14 +44,14 @@ let PresetService = class PresetService {
44
44
  }
45
45
  async get(name) {
46
46
  const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, name, "config.json");
47
+ const _this = this;
47
48
  return new class extends core_1.Preset {
48
- constructor(presetService, data) {
49
+ constructor(data) {
49
50
  super(data);
50
- this.presetService = presetService;
51
51
  }
52
52
  async save() {
53
53
  }
54
- }(this, {
54
+ }({
55
55
  name,
56
56
  ...config
57
57
  });
@@ -64,11 +64,7 @@ let PresetService = class PresetService {
64
64
  if (name && name !== dir) {
65
65
  continue;
66
66
  }
67
- const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, dir, "config.json");
68
- const preset = new core_1.Preset({
69
- name: dir,
70
- ...config
71
- });
67
+ const preset = await this.get(dir);
72
68
  presets.push(preset);
73
69
  }
74
70
  return presets;
@@ -96,6 +96,7 @@ let ProjectService = class ProjectService {
96
96
  });
97
97
  }
98
98
  }
99
+ await this.appEventsService.emit("project:beforeStart", project);
99
100
  let container = await this.dockerService.getContainer(project.containerName);
100
101
  if (container && restart) {
101
102
  container = null;
@@ -120,7 +121,6 @@ let ProjectService = class ProjectService {
120
121
  });
121
122
  }
122
123
  const { State: { Status } } = await container.inspect();
123
- await this.appEventsService.emit("project:beforeStart", project);
124
124
  if (Status === "created" || Status === "exited") {
125
125
  await container.start();
126
126
  }
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@wocker/ws",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
5
  "description": "Docker workspace for web projects",
6
6
  "license": "MIT",
7
+ "main": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "bin": {
10
+ "ws": "./bin/ws.js"
11
+ },
7
12
  "homepage": "https://kearisp.github.io/wocker",
8
13
  "repository": {
9
14
  "type": "git",
@@ -12,11 +17,6 @@
12
17
  "bugs": {
13
18
  "url": "https://github.com/kearisp/wocker-ws/issues"
14
19
  },
15
- "main": "lib/index.js",
16
- "types": "lib/index.d.ts",
17
- "bin": {
18
- "ws": "./bin/ws.js"
19
- },
20
20
  "scripts": {
21
21
  "prepare": "npm run build",
22
22
  "start": "npm run watch",
@@ -25,8 +25,7 @@
25
25
  "lint": "eslint \"**/*.{js,jsx,ts,tsx}\""
26
26
  },
27
27
  "dependencies": {
28
- "@kearisp/cli": "^1.0.7",
29
- "@wocker/core": "^1.0.10",
28
+ "@wocker/core": "^1.0.11",
30
29
  "@wocker/utils": "^1.0.4",
31
30
  "async-mutex": "^0.4.0",
32
31
  "axios": "^1.6.7",