@wocker/ws 1.0.25 → 1.0.27

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 (130) hide show
  1. package/README.md +1 -1
  2. package/lib/AppModule.d.ts +0 -4
  3. package/lib/AppModule.js +44 -48
  4. package/lib/env.d.ts +2 -3
  5. package/lib/env.js +12 -42
  6. package/lib/main.d.ts +2 -3
  7. package/lib/main.js +23 -25
  8. package/lib/makes/GithubClient.d.ts +24 -3
  9. package/lib/makes/GithubClient.js +20 -6
  10. package/lib/makes/Version.d.ts +22 -0
  11. package/lib/makes/Version.js +59 -0
  12. package/lib/makes/VersionRange.d.ts +6 -0
  13. package/lib/makes/VersionRange.js +18 -0
  14. package/lib/makes/VersionRule.d.ts +24 -0
  15. package/lib/makes/VersionRule.js +68 -0
  16. package/lib/makes/index.d.ts +2 -0
  17. package/lib/makes/index.js +2 -0
  18. package/lib/modules/core/index.js +7 -26
  19. package/lib/modules/dns/controllers/DnsController.d.ts +7 -0
  20. package/lib/modules/dns/controllers/DnsController.js +47 -0
  21. package/lib/modules/dns/index.d.ts +4 -0
  22. package/lib/modules/dns/index.js +44 -0
  23. package/lib/modules/dns/services/DnsService.d.ts +10 -0
  24. package/lib/modules/dns/services/DnsService.js +77 -0
  25. package/lib/modules/index.d.ts +3 -1
  26. package/lib/modules/index.js +3 -1
  27. package/lib/modules/keystore/controllers/KeystoreController.d.ts +0 -3
  28. package/lib/modules/keystore/controllers/KeystoreController.js +3 -54
  29. package/lib/modules/keystore/services/KeystoreService.d.ts +1 -0
  30. package/lib/modules/keystore/services/KeystoreService.js +4 -0
  31. package/lib/modules/keystore/utils/createEncryptionKey.d.ts +1 -1
  32. package/lib/modules/package-manager/index.d.ts +5 -0
  33. package/lib/modules/package-manager/index.js +33 -0
  34. package/lib/modules/package-manager/providers/NpmProvider.d.ts +7 -0
  35. package/lib/modules/package-manager/providers/NpmProvider.js +39 -0
  36. package/lib/modules/package-manager/providers/PnpmProvider.d.ts +7 -0
  37. package/lib/modules/package-manager/providers/PnpmProvider.js +30 -0
  38. package/lib/modules/package-manager/providers/YarnProvider.d.ts +7 -0
  39. package/lib/modules/package-manager/providers/YarnProvider.js +29 -0
  40. package/lib/modules/package-manager/service/PackageManager.d.ts +10 -0
  41. package/lib/modules/package-manager/service/PackageManager.js +70 -0
  42. package/lib/modules/package-manager/service/RegistryService.d.ts +4 -0
  43. package/lib/{services/NpmService.js → modules/package-manager/service/RegistryService.js} +6 -11
  44. package/lib/modules/package-manager/types/Package.d.ts +4 -0
  45. package/lib/modules/package-manager/types/PackageManagerProvider.d.ts +6 -0
  46. package/lib/modules/package-manager/types/PackageManagerProvider.js +6 -0
  47. package/lib/{controllers → modules/plugin/controllers}/PluginController.d.ts +2 -2
  48. package/lib/{controllers → modules/plugin/controllers}/PluginController.js +21 -20
  49. package/lib/modules/plugin/index.d.ts +4 -0
  50. package/lib/modules/plugin/index.js +67 -0
  51. package/lib/{services → modules/plugin/services}/PluginService.d.ts +7 -5
  52. package/lib/{services → modules/plugin/services}/PluginService.js +38 -40
  53. package/lib/modules/preset/controllers/PresetController.d.ts +2 -2
  54. package/lib/modules/preset/controllers/PresetController.js +14 -8
  55. package/lib/modules/preset/controllers/PresetListener.d.ts +1 -1
  56. package/lib/modules/preset/controllers/PresetListener.js +2 -2
  57. package/lib/modules/preset/index.js +5 -2
  58. package/lib/modules/preset/repositories/PresetRepository.d.ts +3 -2
  59. package/lib/modules/preset/repositories/PresetRepository.js +9 -4
  60. package/lib/modules/preset/services/PresetService.d.ts +2 -1
  61. package/lib/modules/preset/services/PresetService.js +74 -14
  62. package/lib/modules/project/controllers/ProjectController.d.ts +37 -2
  63. package/lib/modules/project/controllers/ProjectController.js +837 -7
  64. package/lib/modules/project/controllers/SecretsController.d.ts +8 -0
  65. package/lib/modules/project/controllers/SecretsController.js +72 -0
  66. package/lib/modules/project/index.js +11 -4
  67. package/lib/modules/project/repositories/ProjectRepository.d.ts +3 -6
  68. package/lib/modules/project/repositories/ProjectRepository.js +9 -28
  69. package/lib/modules/project/services/ProjectService.d.ts +5 -3
  70. package/lib/modules/project/services/ProjectService.js +59 -4
  71. package/lib/modules/proxy/controllers/ProxyController.d.ts +1 -2
  72. package/lib/modules/proxy/controllers/ProxyController.js +1 -2
  73. package/lib/modules/proxy/index.js +5 -2
  74. package/lib/modules/proxy/services/CertService.d.ts +1 -1
  75. package/lib/modules/proxy/services/CertService.js +3 -3
  76. package/lib/modules/proxy/services/ProxyService.d.ts +2 -1
  77. package/lib/modules/proxy/services/ProxyService.js +7 -3
  78. package/lib/utils/exec.js +4 -1
  79. package/lib/utils/get-cursor-position.js +1 -1
  80. package/package.json +16 -15
  81. package/plugins/dns/Dockerfile +35 -0
  82. package/plugins/dns/app/Procfile +2 -0
  83. package/plugins/dns/app/dnsmasq.conf.tmpl +11 -0
  84. package/plugins/dns/app/dnsmasq.sh +28 -0
  85. package/plugins/proxmox/Dockerfile +35 -0
  86. package/plugins/proxy/Dockerfile +23 -0
  87. package/plugins/proxy/Procfile +2 -0
  88. package/plugins/proxy/bin/wocker-create-ca +19 -0
  89. package/plugins/proxy/bin/wocker-create-cert +38 -0
  90. package/plugins/proxy/bin/wocker-create-domains +21 -0
  91. package/presets/shopify/Dockerfile +160 -0
  92. package/presets/shopify/bin/compare-version +3 -0
  93. package/presets/shopify/config.json +26 -0
  94. package/presets/shopify/etc/apache2/apache2.conf +230 -0
  95. package/presets/shopify/etc/apache2/mods-available/mpm_prefork.conf +16 -0
  96. package/presets/shopify/etc/apache2/sites-available/000-default.conf +21 -0
  97. package/bin/ws.js +0 -6
  98. package/lib/controllers/ProjectController.d.ts +0 -44
  99. package/lib/controllers/ProjectController.js +0 -956
  100. package/lib/controllers/index.d.ts +0 -5
  101. package/lib/controllers/index.js +0 -21
  102. package/lib/modules/docker/index.d.ts +0 -9
  103. package/lib/modules/docker/index.js +0 -45
  104. package/lib/modules/docker/services/ComposeService.d.ts +0 -32
  105. package/lib/modules/docker/services/ComposeService.js +0 -129
  106. package/lib/modules/docker/services/ContainerService.d.ts +0 -14
  107. package/lib/modules/docker/services/ContainerService.js +0 -115
  108. package/lib/modules/docker/services/DockerService.d.ts +0 -31
  109. package/lib/modules/docker/services/DockerService.js +0 -246
  110. package/lib/modules/docker/services/ImageService.d.ts +0 -12
  111. package/lib/modules/docker/services/ImageService.js +0 -80
  112. package/lib/modules/docker/services/ModemService.d.ts +0 -16
  113. package/lib/modules/docker/services/ModemService.js +0 -157
  114. package/lib/modules/docker/services/ProtoService.d.ts +0 -6
  115. package/lib/modules/docker/services/ProtoService.js +0 -20
  116. package/lib/modules/docker/type/ComposeConfig.d.ts +0 -12
  117. package/lib/modules/docker/utils/formatSizeUnits.d.ts +0 -1
  118. package/lib/modules/docker/utils/formatSizeUnits.js +0 -19
  119. package/lib/services/NpmService.d.ts +0 -5
  120. package/lib/types/index.d.ts +0 -1
  121. package/lib/types/index.js +0 -17
  122. /package/lib/{controllers → modules/core/controllers}/CompletionController.d.ts +0 -0
  123. /package/lib/{controllers → modules/core/controllers}/CompletionController.js +0 -0
  124. /package/lib/{controllers → modules/core/controllers}/DebugController.d.ts +0 -0
  125. /package/lib/{controllers → modules/core/controllers}/DebugController.js +0 -0
  126. /package/lib/{controllers → modules/core/controllers}/ExperimentalController.d.ts +0 -0
  127. /package/lib/{controllers → modules/core/controllers}/ExperimentalController.js +0 -0
  128. /package/lib/modules/{docker/type/ComposeConfig.js → package-manager/types/Package.js} +0 -0
  129. /package/lib/{types → modules/package-manager/types}/PackageInfo.d.ts +0 -0
  130. /package/lib/{types → modules/package-manager/types}/PackageInfo.js +0 -0
@@ -23,17 +23,22 @@ let PluginController = class PluginController {
23
23
  async list() {
24
24
  return this.pluginService.getPluginsTable();
25
25
  }
26
- async add(addName, beta) {
27
- await this.pluginService.install(addName, beta);
26
+ async add(names) {
27
+ for (const fullName of names) {
28
+ const [, name, version] = /^(@?[^@/\s]+(?:\/[^@/\s]+)?)(?:@([^@\s]+))?$/.exec(fullName) || [];
29
+ await this.pluginService.install(name, version);
30
+ }
28
31
  }
29
- async remove(removeName) {
30
- await this.pluginService.uninstall(removeName);
32
+ async remove(names) {
33
+ for (const name of names) {
34
+ await this.pluginService.uninstall(name);
35
+ }
31
36
  }
32
37
  async update() {
33
38
  await this.pluginService.update();
34
39
  }
35
40
  getInstalledPlugins() {
36
- return this.appConfigService.config.plugins.map(p => p.name);
41
+ return this.appConfigService.plugins.map(pluginRef => pluginRef.name);
37
42
  }
38
43
  };
39
44
  exports.PluginController = PluginController;
@@ -45,35 +50,31 @@ __decorate([
45
50
  __metadata("design:returntype", Promise)
46
51
  ], PluginController.prototype, "list", null);
47
52
  __decorate([
48
- (0, core_1.Command)("plugin:add <name>"),
49
- (0, core_1.Command)("plugin:install <name>"),
53
+ (0, core_1.Command)("plugin:install <...names>"),
50
54
  (0, core_1.Description)("Install a plugin by specifying its name"),
51
- __param(0, (0, core_1.Param)("name")),
52
- __param(1, (0, core_1.Option)("beta", {
53
- type: "boolean",
54
- alias: "d",
55
- description: "Use the beta version of the plugin (if a beta version exists). Defaults to the latest stable version."
56
- })),
55
+ __param(0, (0, core_1.Param)("names")),
56
+ __param(0, (0, core_1.Description)("Names of plugins to install")),
57
57
  __metadata("design:type", Function),
58
- __metadata("design:paramtypes", [String, Boolean]),
58
+ __metadata("design:paramtypes", [Array]),
59
59
  __metadata("design:returntype", Promise)
60
60
  ], PluginController.prototype, "add", null);
61
61
  __decorate([
62
- (0, core_1.Command)("plugin:remove <name>"),
63
- __param(0, (0, core_1.Param)("name")),
62
+ (0, core_1.Command)("plugin:remove <...names>"),
63
+ (0, core_1.Description)("Remove a plugin"),
64
+ __param(0, (0, core_1.Param)("names")),
65
+ __param(0, (0, core_1.Description)("Names of plugins to remove")),
64
66
  __metadata("design:type", Function),
65
- __metadata("design:paramtypes", [String]),
67
+ __metadata("design:paramtypes", [Array]),
66
68
  __metadata("design:returntype", Promise)
67
69
  ], PluginController.prototype, "remove", null);
68
70
  __decorate([
69
- (0, core_1.Command)("plugin:update [name]"),
71
+ (0, core_1.Command)("plugin:update"),
70
72
  __metadata("design:type", Function),
71
73
  __metadata("design:paramtypes", []),
72
74
  __metadata("design:returntype", Promise)
73
75
  ], PluginController.prototype, "update", null);
74
76
  __decorate([
75
- (0, core_1.Completion)("name", "plugin:update [name]"),
76
- (0, core_1.Completion)("name", "plugin:remove <name>"),
77
+ (0, core_1.Completion)("names", "plugin:remove <...names>"),
77
78
  __metadata("design:type", Function),
78
79
  __metadata("design:paramtypes", []),
79
80
  __metadata("design:returntype", Array)
@@ -0,0 +1,4 @@
1
+ import { DynamicModule } from "@wocker/core";
2
+ export declare class PluginModule {
3
+ static register(): DynamicModule;
4
+ }
@@ -0,0 +1,67 @@
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 PluginModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PluginModule = void 0;
11
+ const core_1 = require("@wocker/core");
12
+ const core_2 = require("../core");
13
+ const package_manager_1 = require("../package-manager");
14
+ const PluginController_1 = require("./controllers/PluginController");
15
+ const PluginService_1 = require("./services/PluginService");
16
+ let PluginModule = PluginModule_1 = class PluginModule {
17
+ static register() {
18
+ return {
19
+ module: PluginModule_1,
20
+ inject: [
21
+ core_1.AppConfigService,
22
+ core_1.AppFileSystemService,
23
+ core_1.LogService,
24
+ PluginService_1.PluginService
25
+ ],
26
+ useFactory: async (appConfigService, fs, logService, pluginService) => {
27
+ const imports = [];
28
+ for (const pluginData of appConfigService.plugins) {
29
+ try {
30
+ const plugin = await pluginService.import(pluginData.name);
31
+ imports.push({
32
+ module: plugin.type,
33
+ providers: [
34
+ {
35
+ provide: core_1.PLUGIN_DIR_KEY,
36
+ useValue: fs.path("plugins", plugin.name)
37
+ }
38
+ ]
39
+ });
40
+ }
41
+ catch (err) {
42
+ logService.error(err.message, {
43
+ pluginName: pluginData.name,
44
+ pluginEnv: pluginData.env
45
+ });
46
+ appConfigService.removePlugin(pluginData.name);
47
+ appConfigService.save();
48
+ }
49
+ }
50
+ return {
51
+ imports
52
+ };
53
+ }
54
+ };
55
+ }
56
+ };
57
+ exports.PluginModule = PluginModule;
58
+ exports.PluginModule = PluginModule = PluginModule_1 = __decorate([
59
+ (0, core_1.Module)({
60
+ imports: [
61
+ core_2.CoreModule,
62
+ package_manager_1.PackageManagerModule
63
+ ],
64
+ controllers: [PluginController_1.PluginController],
65
+ providers: [PluginService_1.PluginService]
66
+ })
67
+ ], PluginModule);
@@ -1,15 +1,17 @@
1
1
  import { Cli, AppConfigService, LogService } from "@wocker/core";
2
- import { NpmService } from "./NpmService";
3
- import { Plugin } from "../makes";
2
+ import { PackageManager, RegistryService } from "../../package-manager";
3
+ import { Plugin } from "../../../makes";
4
4
  export declare class PluginService {
5
5
  protected readonly appConfigService: AppConfigService;
6
- protected readonly npmService: NpmService;
6
+ protected readonly pm: PackageManager;
7
+ protected readonly registryService: RegistryService;
7
8
  protected readonly logService: LogService;
8
9
  protected readonly cli: Cli;
9
- constructor(appConfigService: AppConfigService, npmService: NpmService, logService: LogService, cli: Cli);
10
+ protected rule: string;
11
+ constructor(appConfigService: AppConfigService, pm: PackageManager, registryService: RegistryService, logService: LogService, cli: Cli);
10
12
  getPluginsTable(): string;
11
13
  checkPlugin(pluginName: string): Promise<boolean>;
12
- install(pluginName: string, beta?: boolean): Promise<void>;
14
+ install(pluginName: string, version?: string): Promise<void>;
13
15
  uninstall(pluginName: string): Promise<void>;
14
16
  import(name: string): Promise<Plugin>;
15
17
  update(): Promise<void>;
@@ -49,15 +49,16 @@ exports.PluginService = void 0;
49
49
  const core_1 = require("@wocker/core");
50
50
  const cli_table3_1 = __importDefault(require("cli-table3"));
51
51
  const yoctocolors_cjs_1 = __importDefault(require("yoctocolors-cjs"));
52
- const NpmService_1 = require("./NpmService");
53
- const makes_1 = require("../makes");
54
- const utils_1 = require("../utils");
52
+ const package_manager_1 = require("../../package-manager");
53
+ const makes_1 = require("../../../makes");
55
54
  let PluginService = class PluginService {
56
- constructor(appConfigService, npmService, logService, cli) {
55
+ constructor(appConfigService, pm, registryService, logService, cli) {
57
56
  this.appConfigService = appConfigService;
58
- this.npmService = npmService;
57
+ this.pm = pm;
58
+ this.registryService = registryService;
59
59
  this.logService = logService;
60
60
  this.cli = cli;
61
+ this.rule = "1.x.x";
61
62
  }
62
63
  getPluginsTable() {
63
64
  const table = new cli_table3_1.default({
@@ -84,33 +85,36 @@ let PluginService = class PluginService {
84
85
  }
85
86
  return false;
86
87
  }
87
- async install(pluginName, beta) {
88
+ async install(pluginName, version = "latest") {
88
89
  const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(pluginName) || [];
89
90
  const fullName = `${prefix}${name}${suffix}`;
90
- try {
91
- if (await this.checkPlugin(fullName)) {
92
- this.appConfigService.addPlugin(fullName);
93
- this.appConfigService.save();
94
- console.info(`Plugin ${fullName} activated`);
95
- return;
96
- }
97
- const packageInfo = await this.npmService.getPackageInfo(fullName);
98
- const env = packageInfo["dist-tags"].beta && beta ? "beta" : "latest";
99
- await this.npmService.install(fullName, env);
100
- if (await this.checkPlugin(fullName)) {
101
- this.appConfigService.addPlugin(fullName, env);
102
- this.appConfigService.save();
103
- console.info(`Plugin ${fullName}@${env} activated`);
104
- return;
105
- }
91
+ const currentVersion = await this.getCurrentVersion(fullName), wRule = makes_1.VersionRule.parse(this.rule), rule = makes_1.VersionRule.parse(version === "latest" ? "x" : version || this.rule);
92
+ const packageInfo = await this.registryService.getPackageInfo(fullName);
93
+ const versions = Object.keys(packageInfo.versions)
94
+ .filter((version) => {
95
+ return wRule.match(version, true) && rule.match(version, true);
96
+ })
97
+ .sort((a, b) => {
98
+ return makes_1.Version.parse(b).compare(a);
99
+ });
100
+ const bestSatisfyingVersion = versions.find((version) => rule.match(version)) ??
101
+ versions.find((version) => rule.match(version, true));
102
+ if (!bestSatisfyingVersion) {
103
+ throw new Error(`No matching version found for ${fullName}@${version}.`);
106
104
  }
107
- catch (err) {
108
- this.logService.error(err.message);
105
+ if ((!currentVersion || currentVersion !== bestSatisfyingVersion) || !await this.checkPlugin(fullName)) {
106
+ await this.pm.install(fullName, bestSatisfyingVersion);
109
107
  }
108
+ this.appConfigService.addPlugin(fullName, version);
109
+ this.appConfigService.save();
110
+ console.info(`Plugin ${fullName} activated`);
110
111
  }
111
112
  async uninstall(pluginName) {
112
113
  const [, prefix = "@wocker/", name, suffix = "-plugin"] = /^(@wocker\/)?(\w+)(-plugin)?$/.exec(pluginName) || [];
113
114
  const fullName = `${prefix}${name}${suffix}`;
115
+ if (await this.checkPlugin(fullName)) {
116
+ await this.pm.uninstall(fullName);
117
+ }
114
118
  this.appConfigService.removePlugin(fullName);
115
119
  this.appConfigService.save();
116
120
  console.info(`Plugin ${fullName} deactivated`);
@@ -121,25 +125,16 @@ let PluginService = class PluginService {
121
125
  }
122
126
  async update() {
123
127
  if (this.appConfigService.plugins.length === 0) {
128
+ console.info("No plugins installed");
124
129
  return;
125
130
  }
126
131
  for (const plugin of this.appConfigService.plugins) {
127
132
  console.info(`Checking ${plugin.name}...`);
128
133
  try {
129
- const current = await this.getCurrentVersion(plugin.name);
130
- const res = await makes_1.Http.get("https://registry.npmjs.org")
131
- .send(plugin.name);
132
- if (res.status !== 200) {
133
- continue;
134
- }
135
- const { "dist-tags": { latest } } = res.data;
136
- this.logService.info(plugin.name, current, latest);
137
- if (!current || current < latest) {
138
- console.log(`Updating ${plugin.name}...`);
139
- await (0, utils_1.spawn)("npm", ["i", "-g", plugin.name]);
140
- }
134
+ await this.install(plugin.name, plugin.env);
141
135
  }
142
136
  catch (err) {
137
+ console.info(err.message);
143
138
  this.logService.error(err.message);
144
139
  }
145
140
  }
@@ -147,11 +142,13 @@ let PluginService = class PluginService {
147
142
  }
148
143
  async getCurrentVersion(name) {
149
144
  try {
150
- const { dependencies: { [name]: { version } } } = JSON.parse(await (0, utils_1.exec)(`npm ls --json -g ${name}`));
151
- return version;
145
+ const packages = await this.pm.getPackages(), package1 = packages.find((p) => p.name === name);
146
+ if (package1) {
147
+ return package1.version;
148
+ }
152
149
  }
153
150
  catch (err) {
154
- this.logService.error(`Failed to get current version of ${name}`);
151
+ this.logService.error(`Failed to get current version of "${name}"`);
155
152
  }
156
153
  return null;
157
154
  }
@@ -160,7 +157,8 @@ exports.PluginService = PluginService;
160
157
  exports.PluginService = PluginService = __decorate([
161
158
  (0, core_1.Injectable)(),
162
159
  __metadata("design:paramtypes", [core_1.AppConfigService,
163
- NpmService_1.NpmService,
160
+ package_manager_1.PackageManager,
161
+ package_manager_1.RegistryService,
164
162
  core_1.LogService,
165
163
  core_1.Cli])
166
164
  ], PluginService);
@@ -1,5 +1,5 @@
1
1
  import { AppConfigService } from "@wocker/core";
2
- import { DockerService } from "../../docker";
2
+ import { DockerService } from "@wocker/docker-module";
3
3
  import { PresetRepository } from "../repositories/PresetRepository";
4
4
  import { PresetService } from "../services/PresetService";
5
5
  export declare class PresetController {
@@ -10,7 +10,7 @@ export declare class PresetController {
10
10
  constructor(appConfigService: AppConfigService, dockerService: DockerService, presetRepository: PresetRepository, presetService: PresetService);
11
11
  init(): Promise<void>;
12
12
  list(): Promise<string>;
13
- add(name: string, version?: string): Promise<void>;
13
+ install(repository: string, version?: string): Promise<void>;
14
14
  destroy(): Promise<void>;
15
15
  delete(name: string, confirm?: boolean): Promise<void>;
16
16
  build(presetName: string, rebuild?: boolean): Promise<void>;
@@ -17,9 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PresetController = void 0;
19
19
  const core_1 = require("@wocker/core");
20
+ const docker_module_1 = require("@wocker/docker-module");
20
21
  const cli_table3_1 = __importDefault(require("cli-table3"));
21
22
  const utils_1 = require("@wocker/utils");
22
- const docker_1 = require("../../docker");
23
23
  const PresetRepository_1 = require("../repositories/PresetRepository");
24
24
  const PresetService_1 = require("../services/PresetService");
25
25
  let PresetController = class PresetController {
@@ -50,8 +50,8 @@ let PresetController = class PresetController {
50
50
  }
51
51
  return table.toString();
52
52
  }
53
- async add(name, version) {
54
- await this.presetService.addPreset(name, version);
53
+ async install(repository, version) {
54
+ await this.presetService.install(repository, version);
55
55
  }
56
56
  async destroy() {
57
57
  await this.presetService.deinit();
@@ -114,15 +114,15 @@ __decorate([
114
114
  __metadata("design:returntype", Promise)
115
115
  ], PresetController.prototype, "list", null);
116
116
  __decorate([
117
- (0, core_1.Command)("preset:install <preset>"),
118
- (0, core_1.Command)("preset:install <preset>@<version>"),
117
+ (0, core_1.Command)("preset:install <repository>"),
118
+ (0, core_1.Command)("preset:install <repository>@<version>"),
119
119
  (0, core_1.Description)("Adding preset from github repository"),
120
- __param(0, (0, core_1.Param)("preset")),
120
+ __param(0, (0, core_1.Param)("repository")),
121
121
  __param(1, (0, core_1.Param)("version")),
122
122
  __metadata("design:type", Function),
123
123
  __metadata("design:paramtypes", [String, String]),
124
124
  __metadata("design:returntype", Promise)
125
- ], PresetController.prototype, "add", null);
125
+ ], PresetController.prototype, "install", null);
126
126
  __decorate([
127
127
  (0, core_1.Command)("preset:destroy"),
128
128
  __metadata("design:type", Function),
@@ -148,11 +148,17 @@ __decorate([
148
148
  __metadata("design:paramtypes", [String, Boolean]),
149
149
  __metadata("design:returntype", Promise)
150
150
  ], PresetController.prototype, "build", null);
151
+ __decorate([
152
+ (0, core_1.Completion)("preset"),
153
+ __metadata("design:type", Function),
154
+ __metadata("design:paramtypes", []),
155
+ __metadata("design:returntype", Promise)
156
+ ], PresetController.prototype, "presets", null);
151
157
  exports.PresetController = PresetController = __decorate([
152
158
  (0, core_1.Controller)(),
153
159
  (0, core_1.Description)("Preset commands"),
154
160
  __metadata("design:paramtypes", [core_1.AppConfigService,
155
- docker_1.DockerService,
161
+ docker_module_1.DockerService,
156
162
  PresetRepository_1.PresetRepository,
157
163
  PresetService_1.PresetService])
158
164
  ], PresetController);
@@ -1,5 +1,5 @@
1
1
  import { EventService, Project, AppConfigService } from "@wocker/core";
2
- import { DockerService } from "../../docker";
2
+ import { DockerService } from "@wocker/docker-module";
3
3
  import { PresetRepository } from "../repositories/PresetRepository";
4
4
  import { PresetService } from "../services/PresetService";
5
5
  export declare class PresetListener {
@@ -11,8 +11,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.PresetListener = void 0;
13
13
  const core_1 = require("@wocker/core");
14
+ const docker_module_1 = require("@wocker/docker-module");
14
15
  const utils_1 = require("@wocker/utils");
15
- const docker_1 = require("../../docker");
16
16
  const PresetRepository_1 = require("../repositories/PresetRepository");
17
17
  const PresetService_1 = require("../services/PresetService");
18
18
  const utils_2 = require("../../../utils");
@@ -137,7 +137,7 @@ exports.PresetListener = PresetListener = __decorate([
137
137
  (0, core_1.Controller)(),
138
138
  __metadata("design:paramtypes", [core_1.AppConfigService,
139
139
  core_1.EventService,
140
- docker_1.DockerService,
140
+ docker_module_1.DockerService,
141
141
  PresetRepository_1.PresetRepository,
142
142
  PresetService_1.PresetService])
143
143
  ], PresetListener);
@@ -5,10 +5,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
8
11
  Object.defineProperty(exports, "__esModule", { value: true });
9
12
  exports.PresetService = exports.PresetRepository = exports.PresetModule = void 0;
10
13
  const core_1 = require("@wocker/core");
11
- const docker_1 = require("../docker");
14
+ const docker_module_1 = __importDefault(require("@wocker/docker-module"));
12
15
  const PresetController_1 = require("./controllers/PresetController");
13
16
  const PresetListener_1 = require("./controllers/PresetListener");
14
17
  const PresetRepository_1 = require("./repositories/PresetRepository");
@@ -21,7 +24,7 @@ exports.PresetModule = PresetModule;
21
24
  exports.PresetModule = PresetModule = __decorate([
22
25
  (0, core_1.Module)({
23
26
  imports: [
24
- docker_1.DockerModule
27
+ docker_module_1.default
25
28
  ],
26
29
  controllers: [
27
30
  PresetController_1.PresetController,
@@ -1,4 +1,4 @@
1
- import { AppConfig, PresetServiceSearchOptions as SearchOptions, Preset, PresetSource, AppConfigService, LogService } from "@wocker/core";
1
+ import { AppConfig, PresetServiceSearchOptions as SearchOptions, Preset, PresetSource, AppConfigService, LogService, FileSystemDriver } from "@wocker/core";
2
2
  type PresetData = {
3
3
  name: string;
4
4
  source: PresetSource;
@@ -7,7 +7,8 @@ type PresetData = {
7
7
  export declare class PresetRepository {
8
8
  protected readonly appConfigService: AppConfigService;
9
9
  protected readonly logService: LogService;
10
- constructor(appConfigService: AppConfigService, logService: LogService);
10
+ protected readonly driver: FileSystemDriver;
11
+ constructor(appConfigService: AppConfigService, logService: LogService, driver: FileSystemDriver);
11
12
  protected load(data: PresetData): Preset;
12
13
  protected configs(): AppConfig["presets"];
13
14
  search(options?: SearchOptions): Preset[];
@@ -8,17 +8,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.PresetRepository = void 0;
13
16
  const core_1 = require("@wocker/core");
14
17
  const env_1 = require("../../../env");
15
18
  let PresetRepository = class PresetRepository {
16
- constructor(appConfigService, logService) {
19
+ constructor(appConfigService, logService, driver) {
17
20
  this.appConfigService = appConfigService;
18
21
  this.logService = logService;
22
+ this.driver = driver;
19
23
  }
20
24
  load(data) {
21
- const _this = this, fs = new core_1.FileSystem(data.path);
25
+ const _this = this, fs = new core_1.FileSystem(data.path, this.driver);
22
26
  const config = {
23
27
  ...fs.readJSON("config.json"),
24
28
  name: data.name,
@@ -52,7 +56,7 @@ let PresetRepository = class PresetRepository {
52
56
  }(config);
53
57
  }
54
58
  configs() {
55
- const fs = new core_1.FileSystem(env_1.PRESETS_DIR), dirs = fs.exists("") ? fs.readdir("") : [];
59
+ const fs = new core_1.FileSystem(env_1.PRESETS_DIR, this.driver), dirs = fs.exists("") ? fs.readdir("") : [];
56
60
  const { presets = [] } = this.appConfigService.config;
57
61
  return [
58
62
  ...dirs.map((name) => {
@@ -108,6 +112,7 @@ let PresetRepository = class PresetRepository {
108
112
  exports.PresetRepository = PresetRepository;
109
113
  exports.PresetRepository = PresetRepository = __decorate([
110
114
  (0, core_1.Injectable)(),
115
+ __param(2, (0, core_1.Inject)(core_1.FILE_SYSTEM_DRIVER_KEY)),
111
116
  __metadata("design:paramtypes", [core_1.AppConfigService,
112
- core_1.LogService])
117
+ core_1.LogService, Object])
113
118
  ], PresetRepository);
@@ -4,6 +4,7 @@ export declare class PresetService {
4
4
  protected readonly appConfigService: AppConfigService;
5
5
  protected readonly fs: AppFileSystemService;
6
6
  protected readonly presetRepository: PresetRepository;
7
+ protected range: string;
7
8
  constructor(appConfigService: AppConfigService, fs: AppFileSystemService, presetRepository: PresetRepository);
8
9
  prompt(configMap: {
9
10
  [name: string]: PresetVariableConfig;
@@ -13,5 +14,5 @@ export declare class PresetService {
13
14
  get(name?: string): Preset;
14
15
  init(): Promise<void>;
15
16
  deinit(): Promise<void>;
16
- addPreset(name: string, repository?: string, version?: string): Promise<void>;
17
+ install(repository: string, version?: string): Promise<void>;
17
18
  }
@@ -17,12 +17,14 @@ const core_1 = require("@wocker/core");
17
17
  const utils_1 = require("@wocker/utils");
18
18
  const md5_1 = __importDefault(require("md5"));
19
19
  const PresetRepository_1 = require("../repositories/PresetRepository");
20
+ const makes_1 = require("../../../makes");
20
21
  const GithubClient_1 = require("../../../makes/GithubClient");
21
22
  let PresetService = class PresetService {
22
23
  constructor(appConfigService, fs, presetRepository) {
23
24
  this.appConfigService = appConfigService;
24
25
  this.fs = fs;
25
26
  this.presetRepository = presetRepository;
27
+ this.range = "1.x.x";
26
28
  }
27
29
  async prompt(configMap, values = {}) {
28
30
  for (const name in configMap) {
@@ -134,7 +136,7 @@ let PresetService = class PresetService {
134
136
  return preset;
135
137
  }
136
138
  async init() {
137
- const fs = new core_1.FileSystem(this.appConfigService.pwd());
139
+ const fs = this.fs.cd(this.appConfigService.pwd());
138
140
  let preset = this.presetRepository.searchOne({
139
141
  path: this.appConfigService.pwd()
140
142
  });
@@ -224,20 +226,78 @@ let PresetService = class PresetService {
224
226
  this.appConfigService.config.unregisterPreset(preset.name);
225
227
  this.appConfigService.save();
226
228
  }
227
- async addPreset(name, repository, version) {
228
- if (!repository) {
229
- repository = `kearisp/wocker-${name}-preset`;
229
+ async install(repository, version) {
230
+ if (!/^[\w-]+\/[\w-]+$/.test(repository)) {
231
+ repository = `kearisp/wocker-${repository}-preset`;
230
232
  }
231
- let preset = this.presetRepository.searchOne({
232
- name
233
- });
234
- if (!preset) {
235
- console.info("Loading...");
236
- const [owner, repo] = repository.split("/");
237
- const github = new GithubClient_1.GithubClient(owner, repo);
238
- const info = await github.getInfo();
239
- await github.download(info.default_branch, this.fs.path(`presets/${name}`));
240
- this.appConfigService.registerPreset(name, core_1.PRESET_SOURCE_GITHUB);
233
+ const [owner, name] = repository.split("/");
234
+ let satisfyingTag;
235
+ let satisfyingBranch;
236
+ const github = new GithubClient_1.GithubClient(owner, name), wRule = makes_1.VersionRule.parse(this.range), rule = makes_1.VersionRule.parse(["latest", "beta"].includes(version) ? "x" : version ?? this.range);
237
+ if (version !== "beta") {
238
+ satisfyingTag = (await github.getTags())
239
+ .filter((tag) => {
240
+ if (!makes_1.Version.valid(tag.name)) {
241
+ return false;
242
+ }
243
+ return wRule.match(tag.name) || rule.match(tag.name);
244
+ })
245
+ .reduce((tag, nextTag) => {
246
+ if (!tag) {
247
+ return nextTag;
248
+ }
249
+ return makes_1.Version.parse(tag.name).compare(nextTag.name) < 0 ? nextTag : tag;
250
+ }, null);
251
+ }
252
+ if (!satisfyingTag) {
253
+ satisfyingBranch = (await github.getBranches())
254
+ .filter((branch) => {
255
+ if (!makes_1.Version.valid(branch.name)) {
256
+ return false;
257
+ }
258
+ return wRule.match(branch.name) || rule.match(branch.name);
259
+ })
260
+ .reduce((branch, nextBranch) => {
261
+ if (!branch) {
262
+ return nextBranch;
263
+ }
264
+ return makes_1.Version.parse(branch.name).compare(nextBranch.name) < 0 ? nextBranch : branch;
265
+ }, null);
266
+ }
267
+ if (!satisfyingTag && !satisfyingBranch) {
268
+ throw new Error(`Version "${version}" not found`);
269
+ }
270
+ try {
271
+ const ref = satisfyingTag ? satisfyingTag.name : satisfyingBranch.name, config = await github.getFile(ref, "config.json");
272
+ console.info(`Loading "${ref}"...`);
273
+ let preset = this.presetRepository.searchOne({
274
+ name: config.name
275
+ });
276
+ if (preset && satisfyingTag && preset.source === core_1.PRESET_SOURCE_GITHUB && makes_1.Version.parse(ref).compare(preset.version) === 0) {
277
+ console.info("Preset already installed");
278
+ return;
279
+ }
280
+ if (this.fs.exists(`presets/.tmp/${config.name}`)) {
281
+ this.fs.rm(`presets/.tmp/${config.name}`, {
282
+ recursive: true
283
+ });
284
+ }
285
+ await github.download(ref, this.fs.path(`presets/.tmp/${config.name}`));
286
+ if (this.fs.exists(`presets/${config.name}`)) {
287
+ this.fs.rm(`presets/${config.name}`, {
288
+ recursive: true
289
+ });
290
+ }
291
+ this.fs.mv(`presets/.tmp/${config.name}`, `presets/${config.name}`);
292
+ this.appConfigService.registerPreset(config.name, core_1.PRESET_SOURCE_GITHUB);
293
+ console.info("Preset installed successfully");
294
+ }
295
+ finally {
296
+ if (this.fs.exists("presets/.tmp")) {
297
+ this.fs.rm("presets/.tmp", {
298
+ recursive: true
299
+ });
300
+ }
241
301
  }
242
302
  }
243
303
  };