@wocker/ws 1.0.21 → 1.0.23

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 (127) hide show
  1. package/README.md +8 -0
  2. package/lib/AppModule.js +46 -75
  3. package/lib/controllers/DebugController.d.ts +4 -2
  4. package/lib/controllers/DebugController.js +19 -11
  5. package/lib/controllers/ExperimentalController.d.ts +8 -0
  6. package/lib/controllers/ExperimentalController.js +77 -0
  7. package/lib/controllers/PluginController.d.ts +4 -5
  8. package/lib/controllers/PluginController.js +14 -59
  9. package/lib/controllers/PresetController.d.ts +9 -3
  10. package/lib/controllers/PresetController.js +61 -52
  11. package/lib/controllers/ProjectController.d.ts +7 -2
  12. package/lib/controllers/ProjectController.js +124 -94
  13. package/lib/controllers/index.d.ts +1 -3
  14. package/lib/controllers/index.js +1 -3
  15. package/lib/env.d.ts +2 -2
  16. package/lib/env.js +3 -3
  17. package/lib/main.js +16 -7
  18. package/lib/makes/GithubClient.d.ts +14 -0
  19. package/lib/makes/GithubClient.js +65 -0
  20. package/lib/makes/Logger.d.ts +1 -1
  21. package/lib/makes/Plugin.d.ts +5 -0
  22. package/lib/makes/Plugin.js +15 -0
  23. package/lib/makes/index.d.ts +1 -1
  24. package/lib/makes/index.js +1 -1
  25. package/lib/modules/app/index.d.ts +2 -0
  26. package/lib/{plugins/proxmox → modules/app}/index.js +6 -13
  27. package/lib/modules/docker/index.d.ts +8 -0
  28. package/lib/modules/docker/index.js +41 -0
  29. package/lib/modules/docker/services/ContainerService.d.ts +14 -0
  30. package/lib/modules/docker/services/ContainerService.js +115 -0
  31. package/lib/{services → modules/docker/services}/DockerService.d.ts +12 -5
  32. package/lib/{services → modules/docker/services}/DockerService.js +33 -117
  33. package/lib/modules/docker/services/ImageService.d.ts +18 -0
  34. package/lib/modules/docker/services/ImageService.js +68 -0
  35. package/lib/modules/docker/services/ModemService.d.ts +14 -0
  36. package/lib/modules/docker/services/ModemService.js +137 -0
  37. package/lib/modules/docker/services/ProtoService.d.ts +6 -0
  38. package/lib/modules/docker/services/ProtoService.js +20 -0
  39. package/lib/modules/index.d.ts +3 -0
  40. package/lib/{plugins → modules}/index.js +3 -3
  41. package/lib/modules/keystore/controllers/KeystoreController.d.ts +11 -0
  42. package/lib/modules/keystore/controllers/KeystoreController.js +106 -0
  43. package/lib/modules/keystore/index.d.ts +4 -0
  44. package/lib/{plugins/elastic-search → modules/keystore}/index.js +16 -9
  45. package/lib/modules/keystore/providers/FileKeystoreProvider.d.ts +16 -0
  46. package/lib/modules/keystore/providers/FileKeystoreProvider.js +97 -0
  47. package/lib/modules/keystore/providers/KeytarKeystoreProvider.d.ts +9 -0
  48. package/lib/modules/keystore/providers/KeytarKeystoreProvider.js +74 -0
  49. package/lib/modules/keystore/services/KeystoreService.d.ts +12 -0
  50. package/lib/modules/keystore/services/KeystoreService.js +70 -0
  51. package/lib/modules/keystore/types/FileKeystore.d.ts +17 -0
  52. package/lib/modules/keystore/types/FileKeystore.js +33 -0
  53. package/lib/modules/keystore/types/Keytar.d.ts +8 -0
  54. package/lib/modules/keystore/types/Keytar.js +2 -0
  55. package/lib/modules/keystore/utils/createEncryptionKey.d.ts +1 -0
  56. package/lib/modules/keystore/utils/createEncryptionKey.js +46 -0
  57. package/lib/modules/keystore/utils/createPasswordHash.d.ts +1 -0
  58. package/lib/modules/keystore/utils/createPasswordHash.js +20 -0
  59. package/lib/modules/keystore/utils/decrypt.d.ts +1 -0
  60. package/lib/modules/keystore/utils/decrypt.js +15 -0
  61. package/lib/modules/keystore/utils/encrypt.d.ts +1 -0
  62. package/lib/modules/keystore/utils/encrypt.js +19 -0
  63. package/lib/modules/keystore/utils/index.d.ts +5 -0
  64. package/lib/{services → modules/keystore/utils}/index.js +5 -10
  65. package/lib/modules/keystore/utils/verifyPasswordHash.d.ts +1 -0
  66. package/lib/modules/keystore/utils/verifyPasswordHash.js +9 -0
  67. package/lib/{controllers → modules/proxy/controllers}/CertController.d.ts +2 -1
  68. package/lib/{controllers → modules/proxy/controllers}/CertController.js +4 -3
  69. package/lib/{controllers → modules/proxy/controllers}/ProxyController.d.ts +4 -1
  70. package/lib/{controllers → modules/proxy/controllers}/ProxyController.js +46 -37
  71. package/lib/modules/proxy/index.d.ts +5 -0
  72. package/lib/modules/proxy/index.js +39 -0
  73. package/lib/{services → modules/proxy/services}/CertService.d.ts +3 -3
  74. package/lib/{services → modules/proxy/services}/CertService.js +11 -11
  75. package/lib/{services → modules/proxy/services}/ProxyService.d.ts +2 -2
  76. package/lib/{services → modules/proxy/services}/ProxyService.js +21 -13
  77. package/lib/repositories/PresetRepository.d.ts +23 -0
  78. package/lib/repositories/PresetRepository.js +115 -0
  79. package/lib/repositories/index.d.ts +1 -0
  80. package/lib/repositories/index.js +17 -0
  81. package/lib/services/AppConfigService.d.ts +6 -2
  82. package/lib/services/AppConfigService.js +60 -53
  83. package/lib/services/AppEventsService.d.ts +4 -4
  84. package/lib/services/AppEventsService.js +14 -10
  85. package/lib/services/LogService.d.ts +3 -1
  86. package/lib/services/LogService.js +12 -10
  87. package/lib/services/PluginService.d.ts +8 -2
  88. package/lib/services/PluginService.js +69 -16
  89. package/lib/services/PresetService.d.ts +9 -8
  90. package/lib/services/PresetService.js +145 -260
  91. package/lib/services/ProjectService.d.ts +8 -5
  92. package/lib/services/ProjectService.js +44 -18
  93. package/lib/utils/followProgress2.d.ts +1 -0
  94. package/lib/utils/followProgress2.js +63 -0
  95. package/lib/utils/index.d.ts +1 -4
  96. package/lib/utils/index.js +1 -4
  97. package/package.json +24 -15
  98. package/proto/buildkit.proto +55 -0
  99. package/proto/solver/pb/ops.proto +443 -0
  100. package/lib/controllers/ImageController.d.ts +0 -7
  101. package/lib/controllers/ImageController.js +0 -46
  102. package/lib/makes/FS.d.ts +0 -27
  103. package/lib/makes/FS.js +0 -284
  104. package/lib/makes/LineConvertStream.d.ts +0 -11
  105. package/lib/makes/LineConvertStream.js +0 -42
  106. package/lib/makes/Model.d.ts +0 -5
  107. package/lib/makes/Model.js +0 -12
  108. package/lib/plugins/MongodbPlugin.d.ts +0 -20
  109. package/lib/plugins/MongodbPlugin.js +0 -288
  110. package/lib/plugins/elastic-search/controllers/ElasticSearchController.d.ts +0 -10
  111. package/lib/plugins/elastic-search/controllers/ElasticSearchController.js +0 -91
  112. package/lib/plugins/elastic-search/index.d.ts +0 -2
  113. package/lib/plugins/index.d.ts +0 -3
  114. package/lib/plugins/proxmox/controllers/ProxmoxController.d.ts +0 -14
  115. package/lib/plugins/proxmox/controllers/ProxmoxController.js +0 -127
  116. package/lib/plugins/proxmox/index.d.ts +0 -2
  117. package/lib/services/index.d.ts +0 -10
  118. package/lib/utils/followProgress.d.ts +0 -1
  119. package/lib/utils/followProgress.js +0 -73
  120. package/lib/utils/volumeFormat.d.ts +0 -6
  121. package/lib/utils/volumeFormat.js +0 -8
  122. package/lib/utils/volumeParse.d.ts +0 -2
  123. package/lib/utils/volumeParse.js +0 -13
  124. package/presets/bun/Dockerfile +0 -11
  125. package/presets/bun/config.json +0 -4
  126. /package/lib/{utils/format-size-units.d.ts → modules/docker/utils/formatSizeUnits.d.ts} +0 -0
  127. /package/lib/{utils/format-size-units.js → modules/docker/utils/formatSizeUnits.js} +0 -0
@@ -0,0 +1,23 @@
1
+ import { AppConfig, Preset, PresetSource } from "@wocker/core";
2
+ import { AppConfigService } from "../services/AppConfigService";
3
+ import { LogService } from "../services/LogService";
4
+ type PresetData = {
5
+ name: string;
6
+ source: PresetSource;
7
+ path?: string;
8
+ };
9
+ type SearchOptions = Partial<{
10
+ name: string;
11
+ source: string;
12
+ path: string;
13
+ }>;
14
+ export declare class PresetRepository {
15
+ protected readonly appConfig: AppConfigService;
16
+ protected readonly logService: LogService;
17
+ constructor(appConfig: AppConfigService, logService: LogService);
18
+ protected load(data: PresetData): Preset;
19
+ protected configs(): AppConfig["presets"];
20
+ search(options?: SearchOptions): Preset[];
21
+ searchOne(options?: SearchOptions): Preset | null;
22
+ }
23
+ export {};
@@ -0,0 +1,115 @@
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.PresetRepository = void 0;
13
+ const core_1 = require("@wocker/core");
14
+ const AppConfigService_1 = require("../services/AppConfigService");
15
+ const LogService_1 = require("../services/LogService");
16
+ const env_1 = require("../env");
17
+ let PresetRepository = class PresetRepository {
18
+ constructor(appConfig, logService) {
19
+ this.appConfig = appConfig;
20
+ this.logService = logService;
21
+ }
22
+ load(data) {
23
+ const _this = this, fs = new core_1.FileSystem(data.path);
24
+ const config = {
25
+ ...fs.readJSON("config.json"),
26
+ name: data.name,
27
+ source: data.source,
28
+ path: data.path
29
+ };
30
+ return new class extends core_1.Preset {
31
+ constructor(data) {
32
+ super(data);
33
+ }
34
+ save() {
35
+ switch (this.source) {
36
+ case core_1.PRESET_SOURCE_EXTERNAL:
37
+ fs.writeJSON("config.json", this.toObject());
38
+ break;
39
+ }
40
+ _this.appConfig.registerPreset(this.name, this.source, data.path);
41
+ }
42
+ delete() {
43
+ switch (this.source) {
44
+ case core_1.PRESET_SOURCE_GITHUB:
45
+ if (fs.exists()) {
46
+ fs.rm("", {
47
+ recursive: true
48
+ });
49
+ }
50
+ break;
51
+ }
52
+ _this.appConfig.unregisterPreset(this.name);
53
+ }
54
+ }(config);
55
+ }
56
+ configs() {
57
+ const fs = new core_1.FileSystem(env_1.PRESETS_DIR), dirs = fs.exists("") ? fs.readdir("") : [];
58
+ const { presets = [] } = this.appConfig.config;
59
+ return [
60
+ ...dirs.map((name) => {
61
+ return {
62
+ name,
63
+ source: core_1.PRESET_SOURCE_INTERNAL,
64
+ path: fs.path(name)
65
+ };
66
+ }),
67
+ ...presets.map((item) => {
68
+ if (item.source === core_1.PRESET_SOURCE_GITHUB) {
69
+ return {
70
+ ...item,
71
+ path: this.appConfig.fs.path("presets", item.name)
72
+ };
73
+ }
74
+ return item;
75
+ })
76
+ ];
77
+ }
78
+ search(options = {}) {
79
+ const { name, source, path } = options;
80
+ const presets = [], configs = this.configs();
81
+ for (const config of configs) {
82
+ if (name && name !== config.name) {
83
+ continue;
84
+ }
85
+ if (source && source !== config.source) {
86
+ continue;
87
+ }
88
+ if (path && path !== config.path) {
89
+ continue;
90
+ }
91
+ try {
92
+ const preset = this.load(config);
93
+ presets.push(preset);
94
+ }
95
+ catch (err) {
96
+ this.logService.error(err.message, {
97
+ name: config.name,
98
+ source: config.source,
99
+ path: config.path
100
+ });
101
+ }
102
+ }
103
+ return presets;
104
+ }
105
+ searchOne(options = {}) {
106
+ const [preset] = this.search(options);
107
+ return preset || null;
108
+ }
109
+ };
110
+ exports.PresetRepository = PresetRepository;
111
+ exports.PresetRepository = PresetRepository = __decorate([
112
+ (0, core_1.Injectable)(),
113
+ __metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
114
+ LogService_1.LogService])
115
+ ], PresetRepository);
@@ -0,0 +1 @@
1
+ export * from "./PresetRepository";
@@ -0,0 +1,17 @@
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("./PresetRepository"), exports);
@@ -5,16 +5,20 @@ type TypeMap = {
5
5
  export declare class AppConfigService extends CoreAppConfigService {
6
6
  protected _pwd: string;
7
7
  protected _fs?: FileSystem;
8
+ protected _config?: AppConfig;
8
9
  protected readonly mapTypes: TypeMap;
9
10
  constructor();
10
11
  get version(): string;
12
+ get config(): AppConfig;
13
+ get projects(): import("@wocker/core/lib/types/ProjectRef").ProjectRef[];
11
14
  get fs(): FileSystem;
12
15
  pwd(...parts: string[]): string;
13
16
  setPWD(pwd: string): void;
14
17
  dataPath(...parts: string[]): string;
15
- pluginsPath(...parts: string[]): string;
16
18
  presetPath(...parts: string[]): string;
17
19
  getProjectTypes(): TypeMap;
18
- protected loadConfig(): AppConfig;
20
+ addProject(id: string, name: string, path: string): void;
21
+ removeProject(name: string): void;
22
+ save(): void;
19
23
  }
20
24
  export {};
@@ -59,6 +59,50 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
59
59
  get version() {
60
60
  return env_1.WOCKER_VERSION;
61
61
  }
62
+ get config() {
63
+ if (!this._config) {
64
+ const fs = this.fs;
65
+ let data = {};
66
+ if (fs.exists("wocker.config.js")) {
67
+ try {
68
+ const { config } = require(fs.path("wocker.config.js"));
69
+ data = config;
70
+ }
71
+ catch (err) {
72
+ if (fs.exists("wocker.config.json")) {
73
+ let json = fs.readJSON("wocker.config.json");
74
+ if (typeof json === "string") {
75
+ json = JSON.parse(json);
76
+ }
77
+ data = json;
78
+ }
79
+ }
80
+ }
81
+ else if (fs.exists("wocker.config.json")) {
82
+ data = fs.readJSON("wocker.config.json");
83
+ }
84
+ else if (fs.exists("wocker.json")) {
85
+ let json = fs.readJSON("wocker.json");
86
+ if (typeof json === "string") {
87
+ json = JSON.parse(json);
88
+ }
89
+ data = json;
90
+ }
91
+ else if (fs.exists("data.json")) {
92
+ data = fs.readJSON("data.json");
93
+ }
94
+ else if (!fs.exists()) {
95
+ fs.mkdir("", {
96
+ recursive: true
97
+ });
98
+ }
99
+ this._config = new core_1.AppConfig(data);
100
+ }
101
+ return this._config;
102
+ }
103
+ get projects() {
104
+ return this.config.projects;
105
+ }
62
106
  get fs() {
63
107
  if (!this._fs) {
64
108
  this._fs = new core_1.FileSystem(env_1.DATA_DIR);
@@ -74,70 +118,33 @@ let AppConfigService = class AppConfigService extends core_1.AppConfigService {
74
118
  dataPath(...parts) {
75
119
  return Path.join(env_1.DATA_DIR, ...parts);
76
120
  }
77
- pluginsPath(...parts) {
78
- return Path.join(env_1.PLUGINS_DIR, ...parts);
79
- }
80
121
  presetPath(...parts) {
81
122
  return Path.join(env_1.PRESETS_DIR, ...parts);
82
123
  }
83
124
  getProjectTypes() {
84
125
  return this.mapTypes;
85
126
  }
86
- loadConfig() {
127
+ addProject(id, name, path) {
128
+ this.config.addProject(id, name, path);
129
+ }
130
+ removeProject(name) {
131
+ return this.config.removeProject(name);
132
+ }
133
+ save() {
87
134
  const fs = this.fs;
88
- let data = {};
89
- if (fs.exists("wocker.config.js")) {
90
- try {
91
- const { config } = require(fs.path("wocker.config.js"));
92
- data = config;
93
- }
94
- catch (err) {
95
- if (fs.exists("wocker.config.json")) {
96
- let json = fs.readJSON("wocker.config.json");
97
- if (typeof json === "string") {
98
- json = JSON.parse(json);
99
- }
100
- data = json;
101
- }
102
- }
103
- }
104
- else if (fs.exists("wocker.config.json")) {
105
- data = fs.readJSON("wocker.config.json");
106
- }
107
- else if (fs.exists("wocker.json")) {
108
- let json = fs.readJSON("wocker.json");
109
- if (typeof json === "string") {
110
- json = JSON.parse(json);
111
- }
112
- data = json;
113
- }
114
- else if (fs.exists("data.json")) {
115
- data = fs.readJSON("data.json");
116
- }
117
- else if (!fs.exists()) {
135
+ if (!fs.exists()) {
118
136
  fs.mkdir("", {
119
137
  recursive: true
120
138
  });
121
139
  }
122
- return new class extends core_1.AppConfig {
123
- constructor(data) {
124
- super(data);
125
- }
126
- async save() {
127
- if (!fs.exists()) {
128
- fs.mkdir("");
129
- }
130
- const json = JSON.stringify(this.toJson(), null, 4);
131
- await fs.writeFile("wocker.config.js", `// Wocker config\nexports.config = ${json};`);
132
- await fs.writeFile("wocker.config.json", json);
133
- if (fs.exists("data.json")) {
134
- await fs.rm("data.json");
135
- }
136
- if (fs.exists("wocker.json")) {
137
- await fs.rm("wocker.json");
138
- }
139
- }
140
- }(data);
140
+ fs.writeFile("wocker.config.js", this.config.toJsString());
141
+ fs.writeFile("wocker.config.json", this.config.toString());
142
+ if (fs.exists("data.json")) {
143
+ fs.rm("data.json");
144
+ }
145
+ if (fs.exists("wocker.json")) {
146
+ fs.rm("wocker.json");
147
+ }
141
148
  }
142
149
  };
143
150
  exports.AppConfigService = AppConfigService;
@@ -1,9 +1,9 @@
1
1
  import { AppEventsService as CoreAppEventsService, AppEventHandle } from "@wocker/core";
2
2
  export declare class AppEventsService extends CoreAppEventsService {
3
- protected handles: ({
4
- [event: string]: AppEventHandle[];
5
- });
6
- on(event: string, handle: AppEventHandle): () => void;
3
+ protected handles: {
4
+ [event: string]: Set<AppEventHandle>;
5
+ };
6
+ on(event: string, handle: AppEventHandle): (() => void);
7
7
  off(event: string, handle: AppEventHandle): void;
8
8
  emit(event: string, ...args: any[]): Promise<void>;
9
9
  }
@@ -14,22 +14,26 @@ let AppEventsService = class AppEventsService extends core_1.AppEventsService {
14
14
  this.handles = {};
15
15
  }
16
16
  on(event, handle) {
17
- this.handles[event] = [
18
- ...this.handles[event] || [],
19
- handle
20
- ];
17
+ if (!this.handles[event]) {
18
+ this.handles[event] = new Set();
19
+ }
20
+ this.handles[event].add(handle);
21
21
  return () => {
22
- this.handles[event] = this.handles[event].filter((filterHandle) => {
23
- return filterHandle !== handle;
24
- });
22
+ this.off(event, handle);
25
23
  };
26
24
  }
27
25
  off(event, handle) {
26
+ if (!this.handles[event]) {
27
+ return;
28
+ }
29
+ this.handles[event].delete(handle);
28
30
  }
29
31
  async emit(event, ...args) {
30
- const handles = this.handles[event] || [];
31
- for (const i in handles) {
32
- await handles[i](...args);
32
+ if (!this.handles[event]) {
33
+ return;
34
+ }
35
+ for (const handle of this.handles[event].values()) {
36
+ await handle(...args);
33
37
  }
34
38
  }
35
39
  };
@@ -1,8 +1,10 @@
1
- import { LogService as CoreLogService } from "@wocker/core";
1
+ import { FileSystem, LogService as CoreLogService } from "@wocker/core";
2
2
  import { AppConfigService } from "./AppConfigService";
3
3
  export declare class LogService extends CoreLogService {
4
4
  protected readonly appConfigService: AppConfigService;
5
5
  constructor(appConfigService: AppConfigService);
6
+ protected get fs(): FileSystem;
7
+ protected get logName(): string;
6
8
  debug(...data: any[]): void;
7
9
  log(...data: any[]): void;
8
10
  info(...data: any[]): void;
@@ -23,6 +23,12 @@ let LogService = class LogService extends core_1.LogService {
23
23
  this.appConfigService = appConfigService;
24
24
  makes_1.Logger.install(this);
25
25
  }
26
+ get fs() {
27
+ return this.appConfigService.fs;
28
+ }
29
+ get logName() {
30
+ return "ws.log";
31
+ }
26
32
  debug(...data) {
27
33
  this._log("debug", ...data);
28
34
  }
@@ -39,23 +45,19 @@ let LogService = class LogService extends core_1.LogService {
39
45
  this._log("error", ...data);
40
46
  }
41
47
  clear() {
42
- const logPath = this.appConfigService.dataPath("ws.log");
43
- makes_1.FS.writeFileSync(logPath, "");
48
+ this.fs.writeFile(this.logName, "");
44
49
  }
45
50
  _log(type, ...data) {
46
- const config = this.appConfigService.getConfig();
47
- if (type === "debug" && !config.debug) {
51
+ if (type === "debug" && !this.appConfigService.config.debug) {
48
52
  return;
49
53
  }
50
- const time = (0, format_1.default)(new Date(), "yyyy-MM-dd hh:mm:ss");
51
- const logPath = this.appConfigService.dataPath("ws.log");
52
- const logData = data.map((item) => {
54
+ const time = (0, format_1.default)(new Date(), "yyyy-MM-dd HH:mm:ss"), logData = data.map((item) => {
53
55
  return typeof item !== "string" ? JSON.stringify(item) : item;
54
56
  }).join(" ");
55
- if (!makes_1.FS.existsSync(logPath)) {
56
- makes_1.FS.writeFileSync(logPath, "");
57
+ if (!this.fs.exists(this.logName)) {
58
+ this.fs.writeFile(this.logName, "");
57
59
  }
58
- makes_1.FS.appendFileSync(logPath, `[${time}] ${type}: ${logData}\n`);
60
+ this.fs.appendFile(this.logName, `[${time}] ${type}: ${logData}\n`);
59
61
  }
60
62
  };
61
63
  exports.LogService = LogService;
@@ -1,13 +1,19 @@
1
1
  import { Cli } from "@wocker/core";
2
2
  import { AppConfigService } from "./AppConfigService";
3
3
  import { LogService } from "./LogService";
4
+ import { NpmService } from "./NpmService";
5
+ import { Plugin } from "../makes";
4
6
  export declare class PluginService {
5
7
  protected readonly appConfigService: AppConfigService;
8
+ protected readonly npmService: NpmService;
6
9
  protected readonly logService: LogService;
7
10
  protected readonly cli: Cli;
8
- constructor(appConfigService: AppConfigService, logService: LogService, cli: Cli);
11
+ constructor(appConfigService: AppConfigService, npmService: NpmService, logService: LogService, cli: Cli);
12
+ getPluginsTable(): string;
9
13
  checkPlugin(pluginName: string): Promise<boolean>;
10
- import(): Promise<void>;
14
+ install(pluginName: string, beta?: boolean): Promise<void>;
15
+ uninstall(pluginName: string): Promise<void>;
16
+ import(name: string): Promise<Plugin>;
11
17
  update(): Promise<void>;
12
18
  protected getCurrentVersion(name: string): Promise<string | null>;
13
19
  }
@@ -41,54 +41,106 @@ var __importStar = (this && this.__importStar) || (function () {
41
41
  var __metadata = (this && this.__metadata) || function (k, v) {
42
42
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
43
  };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
44
47
  Object.defineProperty(exports, "__esModule", { value: true });
45
48
  exports.PluginService = void 0;
46
49
  const core_1 = require("@wocker/core");
50
+ const cli_table3_1 = __importDefault(require("cli-table3"));
51
+ const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
47
52
  const AppConfigService_1 = require("./AppConfigService");
48
53
  const LogService_1 = require("./LogService");
54
+ const NpmService_1 = require("./NpmService");
49
55
  const makes_1 = require("../makes");
50
56
  const utils_1 = require("../utils");
51
57
  let PluginService = class PluginService {
52
- constructor(appConfigService, logService, cli) {
58
+ constructor(appConfigService, npmService, logService, cli) {
53
59
  this.appConfigService = appConfigService;
60
+ this.npmService = npmService;
54
61
  this.logService = logService;
55
62
  this.cli = cli;
56
63
  }
64
+ getPluginsTable() {
65
+ const config = this.appConfigService.config;
66
+ const table = new cli_table3_1.default({
67
+ head: ["Name", "Env"],
68
+ colWidths: [30]
69
+ });
70
+ if (config.plugins.length === 0) {
71
+ return yoctocolors_cjs_1.default.gray("No plugins installed");
72
+ }
73
+ for (const plugin of config.plugins) {
74
+ table.push([plugin.name, plugin.env]);
75
+ }
76
+ return table.toString();
77
+ }
57
78
  async checkPlugin(pluginName) {
58
79
  try {
59
- const { default: Plugin } = await Promise.resolve(`${pluginName}`).then(s => __importStar(require(s)));
60
- const name = Reflect.getMetadata(core_1.PLUGIN_NAME_METADATA, Plugin);
61
- if (!name) {
62
- console.error("No name");
80
+ await this.import(pluginName);
81
+ return true;
82
+ }
83
+ catch (err) {
84
+ this.logService.error(err.message, {
85
+ pluginName
86
+ });
87
+ }
88
+ return false;
89
+ }
90
+ async install(pluginName, beta) {
91
+ const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(pluginName) || [];
92
+ const fullName = `${prefix}${name}${suffix}`;
93
+ try {
94
+ if (await this.checkPlugin(fullName)) {
95
+ this.appConfigService.config.addPlugin(fullName);
96
+ this.appConfigService.save();
97
+ console.info(`Plugin ${fullName} activated`);
98
+ return;
99
+ }
100
+ const packageInfo = await this.npmService.getPackageInfo(fullName);
101
+ const env = packageInfo["dist-tags"].beta && beta ? "beta" : "latest";
102
+ await this.npmService.install(fullName, env);
103
+ if (await this.checkPlugin(fullName)) {
104
+ this.appConfigService.config.addPlugin(fullName, env);
105
+ this.appConfigService.save();
106
+ console.info(`Plugin ${fullName}@${env} activated`);
107
+ return;
63
108
  }
64
- return !!name;
65
109
  }
66
110
  catch (err) {
67
111
  this.logService.error(err.message);
68
112
  }
69
- return false;
70
113
  }
71
- async import() {
114
+ async uninstall(pluginName) {
115
+ const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(pluginName) || [];
116
+ const fullName = `${prefix}${name}${suffix}`;
117
+ this.appConfigService.config.removePlugin(fullName);
118
+ this.appConfigService.save();
119
+ console.info(`Plugin ${fullName} deactivated`);
120
+ }
121
+ async import(name) {
122
+ const { default: type } = await Promise.resolve(`${name}`).then(s => __importStar(require(s)));
123
+ return new makes_1.Plugin(type);
72
124
  }
73
125
  async update() {
74
- const config = this.appConfigService.getConfig();
126
+ const config = this.appConfigService.config;
75
127
  if (!config.plugins) {
76
128
  return;
77
129
  }
78
- for (const name of new Set(config.plugins).values()) {
79
- console.info(`Checking ${name}...`);
130
+ for (const plugin of config.plugins) {
131
+ console.info(`Checking ${plugin.name}...`);
80
132
  try {
81
- const current = await this.getCurrentVersion(name);
133
+ const current = await this.getCurrentVersion(plugin.name);
82
134
  const res = await makes_1.Http.get("https://registry.npmjs.org")
83
- .send(name);
135
+ .send(plugin.name);
84
136
  if (res.status !== 200) {
85
137
  continue;
86
138
  }
87
139
  const { "dist-tags": { latest } } = res.data;
88
- this.logService.info(name, current, latest);
140
+ this.logService.info(plugin.name, current, latest);
89
141
  if (!current || current < latest) {
90
- console.log(`Updating ${name}...`);
91
- await (0, utils_1.spawn)("npm", ["i", "-g", name]);
142
+ console.log(`Updating ${plugin.name}...`);
143
+ await (0, utils_1.spawn)("npm", ["i", "-g", plugin.name]);
92
144
  }
93
145
  }
94
146
  catch (err) {
@@ -112,6 +164,7 @@ exports.PluginService = PluginService;
112
164
  exports.PluginService = PluginService = __decorate([
113
165
  (0, core_1.Injectable)(),
114
166
  __metadata("design:paramtypes", [AppConfigService_1.AppConfigService,
167
+ NpmService_1.NpmService,
115
168
  LogService_1.LogService,
116
169
  core_1.Cli])
117
170
  ], PluginService);
@@ -1,6 +1,7 @@
1
- import { EnvConfig, Project, Preset, AppConfig, PresetProperties } from "@wocker/core";
1
+ import { EnvConfig, Project, Preset, PresetVariableConfig } from "@wocker/core";
2
2
  import { AppConfigService } from "./AppConfigService";
3
3
  import { LogService } from "./LogService";
4
+ import { PresetRepository } from "../repositories/PresetRepository";
4
5
  type SearchOptions = Partial<{
5
6
  name: string;
6
7
  source: string;
@@ -8,17 +9,17 @@ type SearchOptions = Partial<{
8
9
  }>;
9
10
  export declare class PresetService {
10
11
  protected readonly appConfigService: AppConfigService;
12
+ protected readonly presetRepository: PresetRepository;
11
13
  protected readonly logService: LogService;
12
- constructor(appConfigService: AppConfigService, logService: LogService);
13
- protected toObject(config: PresetProperties): Preset;
14
- protected getList(): Promise<AppConfig["presets"]>;
14
+ constructor(appConfigService: AppConfigService, presetRepository: PresetRepository, logService: LogService);
15
+ prompt(configMap: {
16
+ [name: string]: PresetVariableConfig;
17
+ }, values?: EnvConfig): Promise<EnvConfig>;
15
18
  getImageNameForProject(project: Project, preset: Preset): string;
16
19
  getImageName(preset: Preset, buildArgs: EnvConfig): string;
17
20
  init(): Promise<void>;
18
21
  deinit(): Promise<void>;
19
- get(name: string): Promise<Preset>;
20
- addPreset(name: string, version?: string): Promise<void>;
21
- search(options?: SearchOptions): Promise<Preset[]>;
22
- searchOne(options?: SearchOptions): Promise<Preset | null>;
22
+ get(name?: string): Preset;
23
+ addPreset(name: string, repository?: string, version?: string): Promise<void>;
23
24
  }
24
25
  export { SearchOptions as PresetServiceSearchOptions };