@wocker/ws 1.0.8 → 1.0.9

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 (55) hide show
  1. package/bin/ws.js +1 -12
  2. package/lib/AppModule.js +6 -3
  3. package/lib/controllers/DebugController.d.ts +7 -0
  4. package/lib/controllers/DebugController.js +44 -0
  5. package/lib/controllers/PluginController.d.ts +2 -0
  6. package/lib/controllers/PluginController.js +42 -41
  7. package/lib/controllers/PresetController.d.ts +1 -0
  8. package/lib/controllers/PresetController.js +71 -6
  9. package/lib/controllers/ProjectController.d.ts +2 -3
  10. package/lib/controllers/ProjectController.js +36 -60
  11. package/lib/controllers/ProxyController.js +15 -6
  12. package/lib/controllers/index.d.ts +1 -0
  13. package/lib/controllers/index.js +1 -0
  14. package/lib/main.d.ts +1 -1
  15. package/lib/main.js +21 -2
  16. package/lib/makes/FS.d.ts +15 -5
  17. package/lib/makes/FS.js +42 -9
  18. package/lib/makes/Http.d.ts +18 -0
  19. package/lib/makes/Http.js +72 -0
  20. package/lib/makes/Preset.d.ts +2 -2
  21. package/lib/makes/index.d.ts +1 -0
  22. package/lib/makes/index.js +1 -0
  23. package/lib/services/AppConfigService.d.ts +6 -16
  24. package/lib/services/AppConfigService.js +29 -113
  25. package/lib/services/PluginService.d.ts +9 -2
  26. package/lib/services/PluginService.js +85 -3
  27. package/lib/services/PresetService.d.ts +1 -2
  28. package/lib/services/PresetService.js +19 -7
  29. package/lib/services/ProjectService.js +15 -11
  30. package/lib/utils/exec.d.ts +4 -1
  31. package/lib/utils/exec.js +16 -31
  32. package/lib/utils/followProgress.js +49 -45
  33. package/lib/utils/index.d.ts +0 -6
  34. package/lib/utils/index.js +0 -6
  35. package/lib/utils/spawn.d.ts +1 -1
  36. package/lib/utils/spawn.js +20 -12
  37. package/package.json +3 -5
  38. package/presets/php-apache/Dockerfile +1 -1
  39. package/presets/php-apache/config.json +2 -1
  40. package/lib/App.d.ts +0 -11
  41. package/lib/App.js +0 -81
  42. package/lib/index.d.ts +0 -5
  43. package/lib/index.js +0 -22
  44. package/lib/utils/buildOptions.d.ts +0 -1
  45. package/lib/utils/buildOptions.js +0 -9
  46. package/lib/utils/fetch.d.ts +0 -5
  47. package/lib/utils/fetch.js +0 -52
  48. package/lib/utils/get-config.d.ts +0 -2
  49. package/lib/utils/get-config.js +0 -17
  50. package/lib/utils/image-build.d.ts +0 -13
  51. package/lib/utils/image-build.js +0 -46
  52. package/lib/utils/set-config.d.ts +0 -2
  53. package/lib/utils/set-config.js +0 -15
  54. package/lib/utils/tty.d.ts +0 -2
  55. package/lib/utils/tty.js +0 -6
package/lib/main.js CHANGED
@@ -1,11 +1,30 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.app = void 0;
4
7
  const core_1 = require("@wocker/core");
8
+ const chalk_1 = __importDefault(require("chalk"));
5
9
  const AppModule_1 = require("./AppModule");
10
+ const services_1 = require("./services");
6
11
  exports.app = {
7
12
  async run(args) {
8
- const factory = await core_1.Factory.create(AppModule_1.AppModule);
9
- return factory.run(args);
13
+ const app = await core_1.Factory.create(AppModule_1.AppModule);
14
+ const config = app.get(services_1.AppConfigService);
15
+ const logger = app.get(services_1.LogService);
16
+ try {
17
+ const res = await app.run(args);
18
+ if (res) {
19
+ process.stdout.write(res);
20
+ }
21
+ }
22
+ catch (err) {
23
+ console.error(chalk_1.default.red(err.message));
24
+ const { debug } = await config.getConfig();
25
+ if (debug) {
26
+ logger.error(err.stack || err.message);
27
+ }
28
+ }
10
29
  }
11
30
  };
package/lib/makes/FS.d.ts CHANGED
@@ -2,17 +2,27 @@
2
2
  /// <reference types="node" />
3
3
  import { FS as CoreFS } from "@wocker/core";
4
4
  import * as fs from "fs";
5
- import { Stats, BigIntStats, PathLike, PathOrFileDescriptor, WriteFileOptions, MakeDirectoryOptions } from "fs";
5
+ import { Stats, BigIntStats, PathLike, PathOrFileDescriptor, WriteFileOptions, ObjectEncodingOptions, MakeDirectoryOptions } from "fs";
6
6
  import { PassThrough } from "readable-stream";
7
+ type ReaddirOptions = ObjectEncodingOptions & {
8
+ recursive?: boolean;
9
+ };
7
10
  type ReaddirFilesOptions = {
8
11
  recursive?: boolean;
9
12
  };
10
- declare class FS extends CoreFS {
13
+ export declare class FS extends CoreFS {
14
+ protected source: string;
15
+ constructor(source: string);
16
+ path(...parts: string[]): string;
17
+ exists(...parts: string[]): boolean;
18
+ stat(...parts: string[]): fs.Stats;
19
+ mkdir(path: string, options?: MakeDirectoryOptions): void;
20
+ readdir(...parts: string[]): Promise<string[]>;
21
+ readdirFiles(path?: string, options?: ReaddirOptions): Promise<string[]>;
11
22
  static access(path: PathLike): Promise<any>;
12
- static exists(path: PathLike): Promise<boolean>;
13
23
  static existsSync(path: PathLike): boolean;
14
24
  static mkdir(dirPath: string, options?: MakeDirectoryOptions): Promise<void>;
15
- static mkdirSync(path: any, options?: MakeDirectoryOptions): string;
25
+ static mkdirSync(path: string, options?: MakeDirectoryOptions): string;
16
26
  static readdir(path: PathLike): Promise<string[]>;
17
27
  static readdirFiles(path: string, options?: ReaddirFilesOptions): Promise<string[]>;
18
28
  static appendFile(path: PathOrFileDescriptor, data: any, options?: WriteFileOptions): Promise<unknown>;
@@ -28,4 +38,4 @@ declare class FS extends CoreFS {
28
38
  static createReadLinesStream(path: PathLike, count?: number): PassThrough;
29
39
  static copyFile(src: PathLike, dest: PathLike): Promise<void>;
30
40
  }
31
- export { FS };
41
+ export {};
package/lib/makes/FS.js CHANGED
@@ -29,6 +29,45 @@ const fs = __importStar(require("fs"));
29
29
  const Path = __importStar(require("path"));
30
30
  const readable_stream_1 = require("readable-stream");
31
31
  class FS extends core_1.FS {
32
+ constructor(source) {
33
+ super();
34
+ this.source = source;
35
+ }
36
+ path(...parts) {
37
+ return Path.join(this.source, ...parts);
38
+ }
39
+ exists(...parts) {
40
+ const fullPath = this.path(...parts);
41
+ return FS.existsSync(fullPath);
42
+ }
43
+ stat(...parts) {
44
+ const fullPath = this.path(...parts);
45
+ return fs.statSync(fullPath);
46
+ }
47
+ mkdir(path, options) {
48
+ const fullPath = this.path(path);
49
+ fs.mkdirSync(fullPath, options);
50
+ }
51
+ async readdir(...parts) {
52
+ const fullPath = this.path(...parts);
53
+ return FS.readdir(fullPath);
54
+ }
55
+ async readdirFiles(path, options) {
56
+ const fullPath = this.path(path);
57
+ return new Promise((resolve, reject) => {
58
+ fs.readdir(fullPath, options, (err, files) => {
59
+ if (err) {
60
+ reject(err);
61
+ return;
62
+ }
63
+ files = files.filter((path) => {
64
+ const stat = this.stat(path);
65
+ return stat.isFile();
66
+ });
67
+ resolve(files);
68
+ });
69
+ });
70
+ }
32
71
  static async access(path) {
33
72
  return new Promise((resolve, reject) => {
34
73
  fs.access(path, (err) => {
@@ -41,13 +80,6 @@ class FS extends core_1.FS {
41
80
  });
42
81
  });
43
82
  }
44
- static async exists(path) {
45
- return new Promise((resolve) => {
46
- fs.exists(path, (exists) => {
47
- resolve(exists);
48
- });
49
- });
50
- }
51
83
  static existsSync(path) {
52
84
  return fs.existsSync(path);
53
85
  }
@@ -106,7 +138,8 @@ class FS extends core_1.FS {
106
138
  withFileTypes: true
107
139
  }, (err, files) => {
108
140
  if (err) {
109
- return reject(err);
141
+ reject(err);
142
+ return;
110
143
  }
111
144
  const names = files.filter((dirent) => {
112
145
  return dirent.isFile();
@@ -160,7 +193,7 @@ class FS extends core_1.FS {
160
193
  reject(err);
161
194
  return;
162
195
  }
163
- fs.read(file, buffer, 0, buffer.length, position, (err, bytesRead, buffer) => {
196
+ fs.read(file, buffer, 0, buffer.length, position, (err, _, buffer) => {
164
197
  if (err) {
165
198
  reject(err);
166
199
  return;
@@ -0,0 +1,18 @@
1
+ import { AxiosHeaders, AxiosResponse } from "axios";
2
+ type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
3
+ export declare class Http {
4
+ readonly method: HttpMethod;
5
+ readonly url: string;
6
+ body?: any;
7
+ protected headers: AxiosHeaders;
8
+ private constructor();
9
+ withHeader(name: string, value: string): Http;
10
+ withBody(body: any): Http;
11
+ send(path: string): Promise<AxiosResponse>;
12
+ static get(url: string): Http;
13
+ static post(url: string): Http;
14
+ static put(url: string): Http;
15
+ static patch(url: string): Http;
16
+ static delete(url: string): Http;
17
+ }
18
+ export {};
@@ -0,0 +1,72 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Http = void 0;
27
+ const axios_1 = __importStar(require("axios"));
28
+ class Http {
29
+ constructor(method = "GET", url, body) {
30
+ this.method = method;
31
+ this.url = url;
32
+ this.body = body;
33
+ this.headers = new axios_1.AxiosHeaders();
34
+ }
35
+ withHeader(name, value) {
36
+ this.headers.set(name, value);
37
+ return this;
38
+ }
39
+ withBody(body) {
40
+ this.body = body;
41
+ return this;
42
+ }
43
+ async send(path) {
44
+ return axios_1.default.create({
45
+ method: this.method,
46
+ baseURL: this.url,
47
+ headers: this.headers.toJSON(),
48
+ validateStatus() {
49
+ return true;
50
+ }
51
+ }).request({
52
+ url: path,
53
+ data: this.body
54
+ });
55
+ }
56
+ static get(url) {
57
+ return new Http("GET", url);
58
+ }
59
+ static post(url) {
60
+ return new Http("POST", url);
61
+ }
62
+ static put(url) {
63
+ return new Http("PUT", url);
64
+ }
65
+ static patch(url) {
66
+ return new Http("PATCH", url);
67
+ }
68
+ static delete(url) {
69
+ return new Http("DELETE", url);
70
+ }
71
+ }
72
+ exports.Http = Http;
@@ -39,7 +39,7 @@ declare class Preset {
39
39
  save(): Promise<void>;
40
40
  getImageName(buildArgs?: EnvConfig): string;
41
41
  static install(ps: PresetService): void;
42
- static search(options: SearchOptions): Promise<Preset[]>;
43
- static searchOne(options: SearchOptions): Promise<Preset>;
42
+ static search(options: SearchOptions): Promise<import("@wocker/core").Preset[]>;
43
+ static searchOne(options: SearchOptions): Promise<import("@wocker/core").Preset>;
44
44
  }
45
45
  export { Preset };
@@ -1,3 +1,4 @@
1
1
  export * from "./FS";
2
+ export * from "./Http";
2
3
  export * from "./Logger";
3
4
  export * from "./Preset";
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./FS"), exports);
18
+ __exportStar(require("./Http"), exports);
18
19
  __exportStar(require("./Logger"), exports);
19
20
  __exportStar(require("./Preset"), exports);
@@ -1,28 +1,18 @@
1
- import { AppConfig as Config, EnvConfig } from "@wocker/core";
1
+ import { Config, AppConfigService as CoreAppConfigService } from "@wocker/core";
2
2
  type TypeMap = {
3
3
  [type: string]: string;
4
4
  };
5
- export declare class AppConfigService {
5
+ export declare class AppConfigService extends CoreAppConfigService {
6
6
  protected pwd: string;
7
7
  protected mapTypes: TypeMap;
8
8
  constructor();
9
- dataPath(...args: string[]): string;
10
- pluginsPath(...args: string[]): string;
9
+ dataPath(...parts: string[]): string;
10
+ pluginsPath(...parts: string[]): string;
11
+ presetPath(...parts: string[]): string;
11
12
  getPWD(): string;
12
13
  setPWD(pwd: string): void;
13
- getAppConfig(): Promise<Config>;
14
- private saveAppConfig;
15
- getMeta(name: string, defaultValue?: string): Promise<string>;
16
- setMeta(name: string, value?: string | number): Promise<void>;
17
- getAllEnvVariables(): Promise<EnvConfig>;
18
- getEnvVariable(name: string, defaultValue?: string): Promise<string>;
19
- setEnv(env: any): Promise<void>;
20
- setEnvVariable(name: string, value: string | number): Promise<void>;
21
- unsetEnv(...keys: string[]): Promise<void>;
22
14
  getProjectTypes(): TypeMap;
23
15
  registerProjectType(name: string, title?: string): void;
24
- setProjectConfig(id: string, path: string): Promise<void>;
25
- activatePlugin(name: string): Promise<void>;
26
- deactivatePlugin(name: string): Promise<void>;
16
+ protected loadConfig(): Promise<Config>;
27
17
  }
28
18
  export {};
@@ -37,19 +37,23 @@ const core_1 = require("@wocker/core");
37
37
  const Path = __importStar(require("path"));
38
38
  const env_1 = require("../env");
39
39
  const makes_1 = require("../makes");
40
- let AppConfigService = class AppConfigService {
40
+ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
41
41
  constructor() {
42
+ super();
42
43
  this.mapTypes = {
43
44
  image: "Image",
44
45
  dockerfile: "Dockerfile"
45
46
  };
46
47
  this.pwd = (process.cwd() || process.env.PWD);
47
48
  }
48
- dataPath(...args) {
49
- return Path.join(env_1.DATA_DIR, ...args);
49
+ dataPath(...parts) {
50
+ return Path.join(env_1.DATA_DIR, ...parts);
50
51
  }
51
- pluginsPath(...args) {
52
- return Path.join(env_1.PLUGINS_DIR, ...args);
52
+ pluginsPath(...parts) {
53
+ return Path.join(env_1.PLUGINS_DIR, ...parts);
54
+ }
55
+ presetPath(...parts) {
56
+ return Path.join(env_1.PRESETS_DIR, ...parts);
53
57
  }
54
58
  getPWD() {
55
59
  return this.pwd;
@@ -57,121 +61,33 @@ let AppConfigService = class AppConfigService {
57
61
  setPWD(pwd) {
58
62
  this.pwd = pwd;
59
63
  }
60
- async getAppConfig() {
61
- return makes_1.FS.readJSON(env_1.MAP_PATH);
62
- }
63
- async saveAppConfig(config) {
64
- await makes_1.FS.writeJSON(env_1.MAP_PATH, config);
65
- }
66
- async getMeta(name, defaultValue) {
67
- const config = await this.getAppConfig();
68
- const value = (config.meta || {})[name];
69
- if (!value) {
70
- return defaultValue;
71
- }
72
- return value;
73
- }
74
- async setMeta(name, value) {
75
- const config = await this.getAppConfig();
76
- if (!config.meta) {
77
- config.meta = {};
78
- }
79
- config.meta[name] = value ? value.toString() : undefined;
80
- await this.saveAppConfig(config);
81
- }
82
- async getAllEnvVariables() {
83
- const { env = {} } = await makes_1.FS.readJSON(env_1.MAP_PATH);
84
- return env;
85
- }
86
- async getEnvVariable(name, defaultValue) {
87
- const { [name]: value = defaultValue } = await this.getAllEnvVariables();
88
- if (value === null) {
89
- return defaultValue;
90
- }
91
- return value;
92
- }
93
- async setEnv(env) {
94
- const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
95
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
96
- ...config,
97
- env: {
98
- ...config.env || {},
99
- ...env
100
- }
101
- });
102
- }
103
- async setEnvVariable(name, value) {
104
- const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
105
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
106
- ...config,
107
- env: {
108
- ...config.env || {},
109
- [name]: value
110
- }
111
- });
112
- }
113
- async unsetEnv(...keys) {
114
- const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
115
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
116
- ...config,
117
- env: Object.keys(config.env || {}).reduce((res, key) => {
118
- if (!keys.includes(key)) {
119
- res[key] = config.env[key];
120
- }
121
- return res;
122
- }, {})
123
- });
124
- }
125
64
  getProjectTypes() {
126
65
  return this.mapTypes;
127
66
  }
128
67
  registerProjectType(name, title) {
129
68
  this.mapTypes[name] = title || name;
130
69
  }
131
- async setProjectConfig(id, path) {
132
- const { projects, ...rest } = await this.getAppConfig();
133
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
134
- ...rest,
135
- projects: [
136
- ...(projects || []).filter((project) => {
137
- return project.id !== id;
138
- }).filter((project) => {
139
- return project.src !== path;
140
- }),
141
- {
142
- id: id,
143
- src: path
70
+ async loadConfig() {
71
+ const data = makes_1.FS.existsSync(env_1.MAP_PATH)
72
+ ? await makes_1.FS.readJSON(env_1.MAP_PATH)
73
+ : {};
74
+ return new class extends core_1.Config {
75
+ constructor(data) {
76
+ super(data);
77
+ }
78
+ addPlugin(plugin) {
79
+ if (!this.plugins) {
80
+ this.plugins = [];
144
81
  }
145
- ]
146
- });
147
- }
148
- async activatePlugin(name) {
149
- const { default: Plugin } = await Promise.resolve(`${name}`).then(s => __importStar(require(s)));
150
- if (!Plugin) {
151
- throw new Error("No plugin");
152
- }
153
- const { plugins = [], ...rest } = await this.getAppConfig();
154
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
155
- plugins: [
156
- ...plugins.filter((plugin) => {
157
- return plugin !== name;
158
- }),
159
- name
160
- ],
161
- ...rest
162
- });
163
- }
164
- async deactivatePlugin(name) {
165
- const { plugins = [], ...rest } = await this.getAppConfig();
166
- if (!plugins.includes(name)) {
167
- return;
168
- }
169
- await makes_1.FS.writeJSON(env_1.MAP_PATH, {
170
- plugins: plugins.filter((plugin) => {
171
- return plugin !== name;
172
- }),
173
- ...rest
174
- });
82
+ if (this.plugins.includes(plugin)) {
83
+ return;
84
+ }
85
+ this.plugins.push(plugin);
86
+ }
87
+ async save() {
88
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, this.toJson());
89
+ }
90
+ }(data);
175
91
  }
176
92
  };
177
93
  exports.AppConfigService = AppConfigService;
@@ -1,6 +1,13 @@
1
1
  import { Cli } from "@wocker/core";
2
+ import { AppConfigService } from "./AppConfigService";
3
+ import { LogService } from "./LogService";
2
4
  export declare class PluginService {
5
+ protected readonly appConfigService: AppConfigService;
6
+ protected readonly logService: LogService;
3
7
  protected readonly cli: Cli;
4
- constructor(cli: Cli);
5
- use(): void;
8
+ constructor(appConfigService: AppConfigService, logService: LogService, cli: Cli);
9
+ checkPlugin(pluginName: string): Promise<boolean>;
10
+ import(): Promise<void>;
11
+ update(): Promise<void>;
12
+ protected getCurrentVersion(name: string): Promise<string | null>;
6
13
  }
@@ -1,25 +1,107 @@
1
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
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
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;
6
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  var __metadata = (this && this.__metadata) || function (k, v) {
9
32
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
33
  };
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  exports.PluginService = void 0;
13
36
  const core_1 = require("@wocker/core");
37
+ const AppConfigService_1 = require("./AppConfigService");
38
+ const LogService_1 = require("./LogService");
39
+ const makes_1 = require("../makes");
40
+ const utils_1 = require("../utils");
14
41
  let PluginService = class PluginService {
15
- constructor(cli) {
42
+ constructor(appConfigService, logService, cli) {
43
+ this.appConfigService = appConfigService;
44
+ this.logService = logService;
16
45
  this.cli = cli;
17
46
  }
18
- use() {
47
+ async checkPlugin(pluginName) {
48
+ try {
49
+ const { default: Plugin } = await Promise.resolve(`${pluginName}`).then(s => __importStar(require(s)));
50
+ const name = Reflect.getMetadata(core_1.MODULE_METADATA.NAME, Plugin);
51
+ if (!name) {
52
+ console.log("No name");
53
+ }
54
+ return !!name;
55
+ }
56
+ catch (err) {
57
+ this.logService.error(err.message);
58
+ }
59
+ return false;
60
+ }
61
+ async import() {
62
+ }
63
+ async update() {
64
+ const config = await this.appConfigService.getConfig();
65
+ if (!config.plugins) {
66
+ return;
67
+ }
68
+ for (const name of new Set(config.plugins).values()) {
69
+ console.info(`Checking ${name}...`);
70
+ try {
71
+ const current = await this.getCurrentVersion(name);
72
+ const res = await makes_1.Http.get("https://registry.npmjs.org")
73
+ .send(name);
74
+ if (res.status !== 200) {
75
+ continue;
76
+ }
77
+ const { "dist-tags": { latest } } = res.data;
78
+ this.logService.info(name, current, latest);
79
+ if (!current || current < latest) {
80
+ console.log(`Updating ${name}...`);
81
+ await (0, utils_1.spawn)("npm", ["i", "-g", name]);
82
+ }
83
+ }
84
+ catch (err) {
85
+ this.logService.error(err.message);
86
+ }
87
+ }
88
+ console.info("Done");
89
+ }
90
+ async getCurrentVersion(name) {
91
+ try {
92
+ const { dependencies: { [name]: { version } } } = JSON.parse(await (0, utils_1.exec)(`npm ls --json -g ${name}`));
93
+ return version;
94
+ }
95
+ catch (err) {
96
+ this.logService.error(`Failed to get current version of ${name}`);
97
+ }
98
+ return null;
19
99
  }
20
100
  };
21
101
  exports.PluginService = PluginService;
22
102
  exports.PluginService = PluginService = __decorate([
23
103
  (0, core_1.Injectable)(),
24
- __metadata("design:paramtypes", [core_1.Cli])
104
+ __metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
105
+ LogService_1.LogService,
106
+ core_1.Cli])
25
107
  ], PluginService);
@@ -1,5 +1,4 @@
1
- import { EnvConfig } from "@wocker/core";
2
- import { Preset } from "../makes";
1
+ import { EnvConfig, Preset } from "@wocker/core";
3
2
  type SearchOptions = Partial<{
4
3
  name: string;
5
4
  }>;
@@ -1,16 +1,24 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  exports.PresetService = void 0;
16
+ const core_1 = require("@wocker/core");
7
17
  const md5_1 = __importDefault(require("md5"));
8
18
  const env_1 = require("../env");
9
19
  const makes_1 = require("../makes");
10
- class PresetService {
11
- constructor() {
12
- makes_1.Preset.install(this);
13
- }
20
+ let PresetService = class PresetService {
21
+ constructor() { }
14
22
  getImageName(preset, buildArgs = {}) {
15
23
  const rawValues = [];
16
24
  const hashValues = [];
@@ -36,7 +44,7 @@ class PresetService {
36
44
  }
37
45
  async get(name) {
38
46
  const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, name, "config.json");
39
- return new class extends makes_1.Preset {
47
+ return new class extends core_1.Preset {
40
48
  constructor(presetService, data) {
41
49
  super(data);
42
50
  this.presetService = presetService;
@@ -57,7 +65,7 @@ class PresetService {
57
65
  continue;
58
66
  }
59
67
  const config = await makes_1.FS.readJSON(env_1.PRESETS_DIR, dir, "config.json");
60
- const preset = new makes_1.Preset({
68
+ const preset = new core_1.Preset({
61
69
  name: dir,
62
70
  ...config
63
71
  });
@@ -69,5 +77,9 @@ class PresetService {
69
77
  const [preset] = await this.search(options);
70
78
  return preset || null;
71
79
  }
72
- }
80
+ };
73
81
  exports.PresetService = PresetService;
82
+ exports.PresetService = PresetService = __decorate([
83
+ (0, core_1.Injectable)(),
84
+ __metadata("design:paramtypes", [])
85
+ ], PresetService);