@eclipse-che/che-devworkspace-generator 0.0.1-09a1f81

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 (58) hide show
  1. package/README.md +50 -0
  2. package/lib/api/devfile-context.d.ts +19 -0
  3. package/lib/api/devfile-context.js +3 -0
  4. package/lib/api/devfile-context.js.map +1 -0
  5. package/lib/devfile/dev-container-component-finder.d.ts +17 -0
  6. package/lib/devfile/dev-container-component-finder.js +93 -0
  7. package/lib/devfile/dev-container-component-finder.js.map +1 -0
  8. package/lib/devfile/devfile-module.d.ts +12 -0
  9. package/lib/devfile/devfile-module.js +19 -0
  10. package/lib/devfile/devfile-module.js.map +1 -0
  11. package/lib/entrypoint.d.ts +11 -0
  12. package/lib/entrypoint.js +67 -0
  13. package/lib/entrypoint.js.map +1 -0
  14. package/lib/fetch/fetch-module.d.ts +12 -0
  15. package/lib/fetch/fetch-module.js +19 -0
  16. package/lib/fetch/fetch-module.js.map +1 -0
  17. package/lib/fetch/url-fetcher.d.ts +9 -0
  18. package/lib/fetch/url-fetcher.js +114 -0
  19. package/lib/fetch/url-fetcher.js.map +1 -0
  20. package/lib/generate.d.ts +16 -0
  21. package/lib/generate.js +183 -0
  22. package/lib/generate.js.map +1 -0
  23. package/lib/github/github-module.d.ts +12 -0
  24. package/lib/github/github-module.js +19 -0
  25. package/lib/github/github-module.js.map +1 -0
  26. package/lib/github/github-resolver.d.ts +18 -0
  27. package/lib/github/github-resolver.js +56 -0
  28. package/lib/github/github-resolver.js.map +1 -0
  29. package/lib/github/github-url.d.ts +29 -0
  30. package/lib/github/github-url.js +47 -0
  31. package/lib/github/github-url.js.map +1 -0
  32. package/lib/inversify/inversify-binding.d.ts +26 -0
  33. package/lib/inversify/inversify-binding.js +78 -0
  34. package/lib/inversify/inversify-binding.js.map +1 -0
  35. package/lib/main.d.ts +36 -0
  36. package/lib/main.js +265 -0
  37. package/lib/main.js.map +1 -0
  38. package/lib/plugin-registry/plugin-registry-module.d.ts +12 -0
  39. package/lib/plugin-registry/plugin-registry-module.js +19 -0
  40. package/lib/plugin-registry/plugin-registry-module.js.map +1 -0
  41. package/lib/plugin-registry/plugin-registry-resolver.d.ts +17 -0
  42. package/lib/plugin-registry/plugin-registry-resolver.js +113 -0
  43. package/lib/plugin-registry/plugin-registry-resolver.js.map +1 -0
  44. package/package.json +93 -0
  45. package/src/api/devfile-context.ts +28 -0
  46. package/src/devfile/dev-container-component-finder.ts +45 -0
  47. package/src/devfile/devfile-module.ts +18 -0
  48. package/src/entrypoint.ts +22 -0
  49. package/src/fetch/fetch-module.ts +18 -0
  50. package/src/fetch/url-fetcher.ts +49 -0
  51. package/src/generate.ts +122 -0
  52. package/src/github/github-module.ts +18 -0
  53. package/src/github/github-resolver.ts +43 -0
  54. package/src/github/github-url.ts +47 -0
  55. package/src/inversify/inversify-binding.ts +46 -0
  56. package/src/main.ts +212 -0
  57. package/src/plugin-registry/plugin-registry-module.ts +18 -0
  58. package/src/plugin-registry/plugin-registry-resolver.ts +36 -0
package/lib/main.js ADDED
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ /**********************************************************************
3
+ * Copyright (c) 2022 Red Hat, Inc.
4
+ *
5
+ * This program and the accompanying materials are made
6
+ * available under the terms of the Eclipse Public License 2.0
7
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
8
+ *
9
+ * SPDX-License-Identifier: EPL-2.0
10
+ ***********************************************************************/
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || function (mod) {
24
+ if (mod && mod.__esModule) return mod;
25
+ var result = {};
26
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ __setModuleDefault(result, mod);
28
+ return result;
29
+ };
30
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
+ return new (P || (P = Promise))(function (resolve, reject) {
33
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
37
+ });
38
+ };
39
+ var __generator = (this && this.__generator) || function (thisArg, body) {
40
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
41
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
42
+ function verb(n) { return function (v) { return step([n, v]); }; }
43
+ function step(op) {
44
+ if (f) throw new TypeError("Generator is already executing.");
45
+ while (_) try {
46
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
47
+ if (y = 0, t) op = [op[0] & 2, t.value];
48
+ switch (op[0]) {
49
+ case 0: case 1: t = op; break;
50
+ case 4: _.label++; return { value: op[1], done: false };
51
+ case 5: _.label++; y = op[1]; op = [0]; continue;
52
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
53
+ default:
54
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
55
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
56
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
57
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
58
+ if (t[2]) _.ops.pop();
59
+ _.trys.pop(); continue;
60
+ }
61
+ op = body.call(thisArg, _);
62
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
63
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
64
+ }
65
+ };
66
+ exports.__esModule = true;
67
+ exports.Main = void 0;
68
+ var axios = __importStar(require("axios"));
69
+ var fs = __importStar(require("fs-extra"));
70
+ var generate_1 = require("./generate");
71
+ var github_resolver_1 = require("./github/github-resolver");
72
+ var jsYaml = __importStar(require("js-yaml"));
73
+ var inversify_binding_1 = require("./inversify/inversify-binding");
74
+ var url_fetcher_1 = require("./fetch/url-fetcher");
75
+ var plugin_registry_resolver_1 = require("./plugin-registry/plugin-registry-resolver");
76
+ var Main = /** @class */ (function () {
77
+ /**
78
+ * Default constructor.
79
+ */
80
+ function Main() {
81
+ // no-op
82
+ }
83
+ // Generates a devfile context object based on params
84
+ Main.prototype.generateDevfileContext = function (params, axiosInstance) {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var pluginRegistryUrl, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate;
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0:
90
+ if (!params.editorPath && !params.editorEntry && !params.editorContent) {
91
+ throw new Error('missing editorPath or editorEntry or editorContent');
92
+ }
93
+ if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) {
94
+ throw new Error('missing devfilePath or devfileUrl or devfileContent');
95
+ }
96
+ if (params.pluginRegistryUrl) {
97
+ pluginRegistryUrl = params.pluginRegistryUrl;
98
+ }
99
+ else {
100
+ pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
101
+ console.log("No plug-in registry url. Setting to " + pluginRegistryUrl);
102
+ }
103
+ inversifyBinbding = new inversify_binding_1.InversifyBinding();
104
+ return [4 /*yield*/, inversifyBinbding.initBindings({
105
+ pluginRegistryUrl: pluginRegistryUrl,
106
+ axiosInstance: axiosInstance
107
+ })];
108
+ case 1:
109
+ container = _a.sent();
110
+ container.bind(generate_1.Generate).toSelf().inSingletonScope();
111
+ if (!params.devfileUrl) return [3 /*break*/, 3];
112
+ githubResolver = container.get(github_resolver_1.GithubResolver);
113
+ githubUrl = githubResolver.resolve(params.devfileUrl);
114
+ return [4 /*yield*/, container.get(url_fetcher_1.UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml'))];
115
+ case 2:
116
+ // user devfile
117
+ devfileContent = _a.sent();
118
+ devfileParsed = jsYaml.load(devfileContent);
119
+ // is there projects in the devfile ?
120
+ if (devfileParsed && !devfileParsed.projects) {
121
+ // no, so add the current project being cloned
122
+ devfileParsed.projects = [
123
+ {
124
+ name: githubUrl.getRepoName(),
125
+ git: {
126
+ remotes: { origin: githubUrl.getCloneUrl() },
127
+ checkoutFrom: { revision: githubUrl.getBranchName() }
128
+ }
129
+ },
130
+ ];
131
+ }
132
+ // get back the content
133
+ devfileContent = jsYaml.dump(devfileParsed);
134
+ return [3 /*break*/, 6];
135
+ case 3:
136
+ if (!params.devfilePath) return [3 /*break*/, 5];
137
+ return [4 /*yield*/, fs.readFile(params.devfilePath)];
138
+ case 4:
139
+ devfileContent = _a.sent();
140
+ return [3 /*break*/, 6];
141
+ case 5:
142
+ devfileContent = params.devfileContent;
143
+ _a.label = 6;
144
+ case 6:
145
+ // enhance projects
146
+ devfileContent = this.replaceIfExistingProjects(devfileContent, params.projects);
147
+ if (!params.editorContent) return [3 /*break*/, 7];
148
+ editorContent = params.editorContent;
149
+ return [3 /*break*/, 11];
150
+ case 7:
151
+ if (!params.editorEntry) return [3 /*break*/, 9];
152
+ return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(params.editorEntry)];
153
+ case 8:
154
+ editorDevfile = _a.sent();
155
+ editorContent = jsYaml.dump(editorDevfile);
156
+ return [3 /*break*/, 11];
157
+ case 9: return [4 /*yield*/, fs.readFile(params.editorPath)];
158
+ case 10:
159
+ editorContent = _a.sent();
160
+ _a.label = 11;
161
+ case 11:
162
+ generate = container.get(generate_1.Generate);
163
+ return [2 /*return*/, generate.generate(devfileContent, editorContent, params.outputFile)];
164
+ }
165
+ });
166
+ });
167
+ };
168
+ // Update project entry based on the projects passed as parameter
169
+ Main.prototype.replaceIfExistingProjects = function (devfileContent, projects) {
170
+ // do nothing if no override
171
+ if (projects.length === 0) {
172
+ return devfileContent;
173
+ }
174
+ var devfileParsed = jsYaml.load(devfileContent);
175
+ if (!devfileParsed || !devfileParsed.projects) {
176
+ return devfileContent;
177
+ }
178
+ devfileParsed.projects = devfileParsed.projects.map(function (project) {
179
+ var userProjectConfiguration = projects.find(function (p) { return p.name === project.name; });
180
+ if (userProjectConfiguration) {
181
+ if (userProjectConfiguration.location.endsWith('.zip')) {
182
+ // delete git section and use instead zip
183
+ delete project.git;
184
+ project.zip = { location: userProjectConfiguration.location };
185
+ }
186
+ else {
187
+ project.git.remotes.origin = userProjectConfiguration.location;
188
+ }
189
+ }
190
+ return project;
191
+ });
192
+ return jsYaml.dump(devfileParsed);
193
+ };
194
+ Main.prototype.start = function () {
195
+ return __awaiter(this, void 0, void 0, function () {
196
+ var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, error_1;
197
+ return __generator(this, function (_a) {
198
+ switch (_a.label) {
199
+ case 0:
200
+ projects = [];
201
+ args = process.argv.slice(2);
202
+ args.forEach(function (arg) {
203
+ if (arg.startsWith('--devfile-path:')) {
204
+ devfilePath = arg.substring('--devfile-path:'.length);
205
+ }
206
+ if (arg.startsWith('--devfile-url:')) {
207
+ devfileUrl = arg.substring('--devfile-url:'.length);
208
+ }
209
+ if (arg.startsWith('--plugin-registry-url:')) {
210
+ pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
211
+ }
212
+ if (arg.startsWith('--editor-entry:')) {
213
+ editorEntry = arg.substring('--editor-entry:'.length);
214
+ }
215
+ if (arg.startsWith('--editor-path:')) {
216
+ editorPath = arg.substring('--editor-path:'.length);
217
+ }
218
+ if (arg.startsWith('--output-file:')) {
219
+ outputFile = arg.substring('--output-file:'.length);
220
+ }
221
+ if (arg.startsWith('--project.')) {
222
+ var name = arg.substring('--project.'.length, arg.indexOf('='));
223
+ var location = arg.substring(arg.indexOf('=') + 1);
224
+ location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
225
+ projects.push({ name: name, location: location });
226
+ }
227
+ });
228
+ _a.label = 1;
229
+ case 1:
230
+ _a.trys.push([1, 3, , 4]);
231
+ if (!editorPath && !editorEntry) {
232
+ throw new Error('missing --editor-path: or --editor-entry: parameter');
233
+ }
234
+ if (!devfilePath && !devfileUrl) {
235
+ throw new Error('missing --devfile-path: or --devfile-url: parameter');
236
+ }
237
+ if (!outputFile) {
238
+ throw new Error('missing --output-file: parameter');
239
+ }
240
+ return [4 /*yield*/, this.generateDevfileContext({
241
+ devfilePath: devfilePath,
242
+ devfileUrl: devfileUrl,
243
+ editorPath: editorPath,
244
+ outputFile: outputFile,
245
+ pluginRegistryUrl: pluginRegistryUrl,
246
+ editorEntry: editorEntry,
247
+ projects: projects
248
+ }, axios["default"])];
249
+ case 2:
250
+ _a.sent();
251
+ return [2 /*return*/, true];
252
+ case 3:
253
+ error_1 = _a.sent();
254
+ console.error('stack=' + error_1.stack);
255
+ console.error('Unable to start', error_1);
256
+ return [2 /*return*/, false];
257
+ case 4: return [2 /*return*/];
258
+ }
259
+ });
260
+ });
261
+ };
262
+ return Main;
263
+ }());
264
+ exports.Main = Main;
265
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAAA;;;;;;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BAAI"}
@@ -0,0 +1,12 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2022 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+ import { ContainerModule } from 'inversify';
11
+ declare const pluginRegistryModule: ContainerModule;
12
+ export { pluginRegistryModule };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.pluginRegistryModule = void 0;
4
+ /**********************************************************************
5
+ * Copyright (c) 2022 Red Hat, Inc.
6
+ *
7
+ * This program and the accompanying materials are made
8
+ * available under the terms of the Eclipse Public License 2.0
9
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
10
+ *
11
+ * SPDX-License-Identifier: EPL-2.0
12
+ ***********************************************************************/
13
+ var inversify_1 = require("inversify");
14
+ var plugin_registry_resolver_1 = require("./plugin-registry-resolver");
15
+ var pluginRegistryModule = new inversify_1.ContainerModule(function (bind) {
16
+ bind(plugin_registry_resolver_1.PluginRegistryResolver).toSelf().inSingletonScope();
17
+ });
18
+ exports.pluginRegistryModule = pluginRegistryModule;
19
+ //# sourceMappingURL=plugin-registry-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-registry-module.js","sourceRoot":"","sources":["../../src/plugin-registry/plugin-registry-module.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;yEAQyE;AACzE,uCAAwD;AAExD,uEAAoE;AAEpE,IAAM,oBAAoB,GAAG,IAAI,2BAAe,CAAC,UAAC,IAAqB;IACrE,IAAI,CAAC,iDAAsB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;AAC3D,CAAC,CAAC,CAAC;AAEM,oDAAoB"}
@@ -0,0 +1,17 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2022 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+ /**
11
+ * Resolve plug-ins by grabbing the definition from the plug-in registry.
12
+ */
13
+ export declare class PluginRegistryResolver {
14
+ private pluginRegistryUrl;
15
+ private urlFetcher;
16
+ loadDevfilePlugin(devfileId: string): Promise<any>;
17
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ /**********************************************************************
3
+ * Copyright (c) 2022 Red Hat, Inc.
4
+ *
5
+ * This program and the accompanying materials are made
6
+ * available under the terms of the Eclipse Public License 2.0
7
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
8
+ *
9
+ * SPDX-License-Identifier: EPL-2.0
10
+ ***********************************************************************/
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
24
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
25
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
26
+ 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;
27
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
28
+ };
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (_) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
72
+ exports.__esModule = true;
73
+ exports.PluginRegistryResolver = void 0;
74
+ var jsYaml = __importStar(require("js-yaml"));
75
+ var inversify_1 = require("inversify");
76
+ var url_fetcher_1 = require("../fetch/url-fetcher");
77
+ /**
78
+ * Resolve plug-ins by grabbing the definition from the plug-in registry.
79
+ */
80
+ var PluginRegistryResolver = /** @class */ (function () {
81
+ function PluginRegistryResolver() {
82
+ }
83
+ // FQN id (like che-incubator/che-code/next)
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ PluginRegistryResolver.prototype.loadDevfilePlugin = function (devfileId) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ var devfileUrl, devfileContent;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ devfileUrl = this.pluginRegistryUrl + "/plugins/" + devfileId + "/devfile.yaml";
92
+ return [4 /*yield*/, this.urlFetcher.fetchText(devfileUrl)];
93
+ case 1:
94
+ devfileContent = _a.sent();
95
+ return [2 /*return*/, jsYaml.load(devfileContent)];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ __decorate([
101
+ (0, inversify_1.inject)('string'),
102
+ (0, inversify_1.named)('PLUGIN_REGISTRY_URL')
103
+ ], PluginRegistryResolver.prototype, "pluginRegistryUrl");
104
+ __decorate([
105
+ (0, inversify_1.inject)(url_fetcher_1.UrlFetcher)
106
+ ], PluginRegistryResolver.prototype, "urlFetcher");
107
+ PluginRegistryResolver = __decorate([
108
+ (0, inversify_1.injectable)()
109
+ ], PluginRegistryResolver);
110
+ return PluginRegistryResolver;
111
+ }());
112
+ exports.PluginRegistryResolver = PluginRegistryResolver;
113
+ //# sourceMappingURL=plugin-registry-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-registry-resolver.js","sourceRoot":"","sources":["../../src/plugin-registry/plugin-registry-resolver.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzE,8CAAkC;AAElC,uCAAsD;AAEtD,oDAAkD;AAElD;;GAEG;AAEH;IAAA;IAeA,CAAC;IAPC,4CAA4C;IAC5C,8DAA8D;IACxD,kDAAiB,GAAvB,UAAwB,SAAiB;;;;;;wBACjC,UAAU,GAAM,IAAI,CAAC,iBAAiB,iBAAY,SAAS,kBAAe,CAAC;wBAC1D,qBAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,EAAA;;wBAA5D,cAAc,GAAG,SAA2C;wBAClE,sBAAO,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAAC;;;;KACpC;IAXD;QAFC,IAAA,kBAAM,EAAC,QAAQ,CAAC;QAChB,IAAA,iBAAK,EAAC,qBAAqB,CAAC;6DACK;IAGlC;QADC,IAAA,kBAAM,EAAC,wBAAU,CAAC;sDACY;IANpB,sBAAsB;QADlC,IAAA,sBAAU,GAAE;OACA,sBAAsB,CAelC;IAAD,6BAAC;CAAA,AAfD,IAeC;AAfY,wDAAsB"}
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@eclipse-che/che-devworkspace-generator",
3
+ "version": "0.0.1-09a1f81",
4
+ "private": false,
5
+ "description": "Generates DevWorkspaces by transforming existing devfiles",
6
+ "main": "lib/entrypoint.js",
7
+ "bin": {
8
+ "che-devworkspace-generator": "lib/entrypoint.js"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "lib",
15
+ "src"
16
+ ],
17
+ "scripts": {
18
+ "prepare": "yarn run clean && yarn run build",
19
+ "clean": "rimraf lib",
20
+ "build": "yarn run format && yarn run compile && yarn run lint && yarn run test",
21
+ "compile": "tsc --declaration --project .",
22
+ "format": "if-env SKIP_FORMAT=true && echo 'skip format check' || prettier --check '{src,tests}/**/*.ts' package.json",
23
+ "format:fix": "prettier --write '{src,tests}/**/*.ts' package.json",
24
+ "lint": "if-env SKIP_LINT=true && echo 'skip lint check' || eslint --cache=true --no-error-on-unmatched-pattern=true '{src,tests}/(!model|**)/*.ts'",
25
+ "lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/(!model|**)/*.ts\"",
26
+ "test": "if-env SKIP_TEST=true && echo 'skip test' || jest --forceExit",
27
+ "watch": "tsc -w",
28
+ "license:check": "docker run --rm -t -v ${PWD}/:/workspace/project quay.io/che-incubator/dash-licenses:next --check",
29
+ "license:generate": "docker run --rm -t -v ${PWD}/:/workspace/project quay.io/che-incubator/dash-licenses:next",
30
+ "publish:next": "yarn publish --registry=https://registry.npmjs.org/ --no-git-tag-version --new-version 0.0.1-\"$(date +%s)\""
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/eclipse-che/che-devfile-registry.git"
35
+ },
36
+ "author": "",
37
+ "license": "EPL-2.0",
38
+ "bugs": {
39
+ "url": "https://github.com/eclipse/che/issues"
40
+ },
41
+ "homepage": "https://github.com/eclipse-che/che-devfile-registry#readme",
42
+ "dependencies": {
43
+ "@devfile/api": "latest",
44
+ "axios": "0.21.2",
45
+ "fs-extra": "^10.0.0",
46
+ "inversify": "^5.0.1",
47
+ "js-yaml": "^4.0.0",
48
+ "jsonc-parser": "^3.0.0",
49
+ "reflect-metadata": "^0.1.13"
50
+ },
51
+ "devDependencies": {
52
+ "@types/jest": "^27.0.2",
53
+ "eslint": "^8.1.0",
54
+ "if-env": "^1.0.4",
55
+ "jest": "^27.3.1",
56
+ "prettier": "^2.4.1",
57
+ "rimraf": "^3.0.2",
58
+ "rollup": "^2.44.0",
59
+ "ts-jest": "^27.0.7",
60
+ "typescript": "^4.4.4"
61
+ },
62
+ "prettier": {
63
+ "printWidth": 120,
64
+ "singleQuote": true,
65
+ "arrowParens": "avoid"
66
+ },
67
+ "importSort": {
68
+ ".ts": {
69
+ "style": "eslint",
70
+ "parser": "typescript"
71
+ }
72
+ },
73
+ "jest": {
74
+ "clearMocks": true,
75
+ "collectCoverage": true,
76
+ "collectCoverageFrom": [
77
+ "src/**/*.ts"
78
+ ],
79
+ "coverageThreshold": {
80
+ "global": {
81
+ "branches": 100,
82
+ "functions": 100,
83
+ "lines": 100,
84
+ "statements": 100
85
+ }
86
+ },
87
+ "coverageDirectory": "coverage",
88
+ "modulePathIgnorePatterns": [
89
+ "<rootDir>/lib"
90
+ ],
91
+ "preset": "ts-jest"
92
+ }
93
+ }
@@ -0,0 +1,28 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2022 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+ import { V1alpha2DevWorkspace, V1alpha2DevWorkspaceTemplate } from '@devfile/api';
11
+
12
+ /**
13
+ * Context used on every call to this service to update DevWorkspace
14
+ */
15
+ export interface DevfileContext {
16
+ // devfile Content
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ devfile: any;
19
+
20
+ // devWorkspace
21
+ devWorkspace: V1alpha2DevWorkspace;
22
+
23
+ // devWorkspace templates
24
+ devWorkspaceTemplates: V1alpha2DevWorkspaceTemplate[];
25
+
26
+ // suffix to append on generated names
27
+ suffix: string;
28
+ }
@@ -0,0 +1,45 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2022 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+
11
+ import { DevfileContext } from '../api/devfile-context';
12
+ import { V1alpha2DevWorkspaceSpecTemplateComponents } from '@devfile/api';
13
+ import { injectable } from 'inversify';
14
+
15
+ /**
16
+ * Need to find dev container from main dev workspace
17
+ */
18
+ @injectable()
19
+ export class DevContainerComponentFinder {
20
+ async find(devfileContext: DevfileContext): Promise<V1alpha2DevWorkspaceSpecTemplateComponents | undefined> {
21
+ // search in main devWorkspace
22
+ const devComponents = devfileContext.devWorkspace.spec?.template?.components
23
+ ?.filter(component => component.container)
24
+ .filter(
25
+ // we should ignore component that do not mount the sources
26
+ component => component.container && component.container.mountSources !== false
27
+ );
28
+
29
+ if (!devComponents || devComponents.length === 0) {
30
+ if (devfileContext.devfile.parent) {
31
+ return undefined;
32
+ }
33
+ throw new Error('Not able to find any dev container component in DevWorkspace');
34
+ } else if (devComponents.length === 1) {
35
+ return devComponents[0];
36
+ } else {
37
+ console.warn(
38
+ `More than one dev container component has been potentially found, taking the first one of ${devComponents.map(
39
+ component => component.name
40
+ )}`
41
+ );
42
+ return devComponents[0];
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,18 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2022 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+ import { ContainerModule, interfaces } from 'inversify';
11
+
12
+ import { DevContainerComponentFinder } from './dev-container-component-finder';
13
+
14
+ const devfileModule = new ContainerModule((bind: interfaces.Bind) => {
15
+ bind(DevContainerComponentFinder).toSelf().inSingletonScope();
16
+ });
17
+
18
+ export { devfileModule };