@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
@@ -0,0 +1,183 @@
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.Generate = void 0;
74
+ var inversify_1 = require("inversify");
75
+ var jsYaml = __importStar(require("js-yaml"));
76
+ var fs = __importStar(require("fs-extra"));
77
+ var dev_container_component_finder_1 = require("./devfile/dev-container-component-finder");
78
+ var Generate = /** @class */ (function () {
79
+ function Generate() {
80
+ }
81
+ Generate_1 = Generate;
82
+ Generate.prototype.generate = function (devfileContent, editorContent, outputFile) {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var context, allContentArray, generatedContent;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0: return [4 /*yield*/, this.generateContent(devfileContent, editorContent)];
88
+ case 1:
89
+ context = _a.sent();
90
+ if (!outputFile) return [3 /*break*/, 3];
91
+ allContentArray = context.devWorkspaceTemplates.map(function (template) { return jsYaml.dump(template); });
92
+ allContentArray.push(jsYaml.dump(context.devWorkspace));
93
+ generatedContent = allContentArray.join('---\n');
94
+ return [4 /*yield*/, fs.writeFile(outputFile, generatedContent, 'utf-8')];
95
+ case 2:
96
+ _a.sent();
97
+ _a.label = 3;
98
+ case 3:
99
+ console.log("DevWorkspace " + context.devWorkspaceTemplates[0].metadata.name + " was generated.");
100
+ return [2 /*return*/, context];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ Generate.prototype.generateContent = function (devfileContent, editorContent) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ var devfile, suffix, editorDevfile, metadata, editorDevWorkspaceTemplate, devfileMetadata, devfileCopy, editorSpecContribution, devWorkspace, devWorkspaceTemplates, context, devContainer, devContainerAttributes;
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0:
111
+ devfile = jsYaml.load(devfileContent);
112
+ suffix = devfile.metadata.name || '';
113
+ editorDevfile = jsYaml.load(editorContent);
114
+ metadata = editorDevfile.metadata;
115
+ // add sufix
116
+ metadata.name = metadata.name + "-" + suffix;
117
+ delete editorDevfile.metadata;
118
+ delete editorDevfile.schemaVersion;
119
+ editorDevWorkspaceTemplate = {
120
+ apiVersion: 'workspace.devfile.io/v1alpha2',
121
+ kind: 'DevWorkspaceTemplate',
122
+ metadata: metadata,
123
+ spec: editorDevfile
124
+ };
125
+ devfileMetadata = devfile.metadata;
126
+ devfileCopy = Object.assign({}, devfile);
127
+ delete devfileCopy.schemaVersion;
128
+ delete devfileCopy.metadata;
129
+ editorSpecContribution = {
130
+ name: 'editor',
131
+ kubernetes: {
132
+ name: editorDevWorkspaceTemplate.metadata.name
133
+ }
134
+ };
135
+ devWorkspace = {
136
+ apiVersion: 'workspace.devfile.io/v1alpha2',
137
+ kind: 'DevWorkspace',
138
+ metadata: devfileMetadata,
139
+ spec: {
140
+ started: true,
141
+ template: devfileCopy,
142
+ contributions: [editorSpecContribution]
143
+ }
144
+ };
145
+ devWorkspaceTemplates = [editorDevWorkspaceTemplate];
146
+ context = {
147
+ devfile: devfile,
148
+ devWorkspace: devWorkspace,
149
+ devWorkspaceTemplates: devWorkspaceTemplates,
150
+ suffix: suffix
151
+ };
152
+ return [4 /*yield*/, this.devContainerComponentFinder.find(context)];
153
+ case 1:
154
+ devContainer = _a.sent();
155
+ if (!devContainer) {
156
+ return [2 /*return*/, context];
157
+ }
158
+ devContainerAttributes = devContainer.attributes;
159
+ if (!devContainerAttributes) {
160
+ devContainerAttributes = {};
161
+ devContainerAttributes[Generate_1.MERGE_CONTRIBUTION] = true;
162
+ devContainer.attributes = devContainerAttributes;
163
+ }
164
+ else {
165
+ devContainerAttributes[Generate_1.MERGE_CONTRIBUTION] = true;
166
+ }
167
+ return [2 /*return*/, context];
168
+ }
169
+ });
170
+ });
171
+ };
172
+ var Generate_1;
173
+ Generate.MERGE_CONTRIBUTION = 'controller.devfile.io/merge-contribution';
174
+ __decorate([
175
+ (0, inversify_1.inject)(dev_container_component_finder_1.DevContainerComponentFinder)
176
+ ], Generate.prototype, "devContainerComponentFinder");
177
+ Generate = Generate_1 = __decorate([
178
+ (0, inversify_1.injectable)()
179
+ ], Generate);
180
+ return Generate;
181
+ }());
182
+ exports.Generate = Generate;
183
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASzE,uCAA+C;AAC/C,8CAAkC;AAClC,2CAA+B;AAE/B,2FAAuF;AAGvF;IAAA;IAiGA,CAAC;iBAjGY,QAAQ;IAMb,2BAAQ,GAAd,UAAe,cAAsB,EAAE,aAAqB,EAAE,UAAmB;;;;;4BAC/D,qBAAM,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE,aAAa,CAAC,EAAA;;wBAAnE,OAAO,GAAG,SAAyD;6BAGrE,UAAU,EAAV,wBAAU;wBAEN,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,UAAA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IAAA,sBAAU,GAAE;OACA,QAAQ,CAiGpB;IAAD,eAAC;CAAA,AAjGD,IAiGC;AAjGY,4BAAQ"}
@@ -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 githubModule: ContainerModule;
12
+ export { githubModule };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.githubModule = 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 github_resolver_1 = require("./github-resolver");
15
+ var githubModule = new inversify_1.ContainerModule(function (bind) {
16
+ bind(github_resolver_1.GithubResolver).toSelf().inSingletonScope();
17
+ });
18
+ exports.githubModule = githubModule;
19
+ //# sourceMappingURL=github-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-module.js","sourceRoot":"","sources":["../../src/github/github-module.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;yEAQyE;AACzE,uCAAwD;AAExD,qDAAmD;AAEnD,IAAM,YAAY,GAAG,IAAI,2BAAe,CAAC,UAAC,IAAqB;IAC7D,IAAI,CAAC,gCAAc,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;AACnD,CAAC,CAAC,CAAC;AAEM,oCAAY"}
@@ -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 { GithubUrl } from './github-url';
11
+ /**
12
+ * Provides a github URL object allowing to interact
13
+ */
14
+ export declare class GithubResolver {
15
+ static readonly GITHUB_URL_PATTERN: RegExp;
16
+ resolve(link: string): GithubUrl;
17
+ getGroup(match: RegExpExecArray, groupName: string, defaultValue?: string): string;
18
+ }
@@ -0,0 +1,56 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
12
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
13
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
14
+ 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;
15
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
16
+ };
17
+ exports.__esModule = true;
18
+ exports.GithubResolver = void 0;
19
+ var github_url_1 = require("./github-url");
20
+ var inversify_1 = require("inversify");
21
+ /**
22
+ * Provides a github URL object allowing to interact
23
+ */
24
+ var GithubResolver = /** @class */ (function () {
25
+ function GithubResolver() {
26
+ }
27
+ GithubResolver_1 = GithubResolver;
28
+ GithubResolver.prototype.resolve = function (link) {
29
+ var match = GithubResolver_1.GITHUB_URL_PATTERN.exec(link);
30
+ if (!match) {
31
+ throw new Error("Invalid github URL: " + link);
32
+ }
33
+ var scheme = this.getGroup(match, 'scheme');
34
+ var hostName = this.getGroup(match, 'host');
35
+ var repoUser = this.getGroup(match, 'repoUser');
36
+ var repoName = this.getGroup(match, 'repoName');
37
+ var branchName = this.getGroup(match, 'branchName', 'HEAD');
38
+ var subFolder = this.getGroup(match, 'subFolder');
39
+ return new github_url_1.GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder);
40
+ };
41
+ GithubResolver.prototype.getGroup = function (match, groupName, defaultValue) {
42
+ if (match.groups && match.groups[groupName]) {
43
+ return match.groups[groupName];
44
+ }
45
+ return defaultValue || '';
46
+ };
47
+ var GithubResolver_1;
48
+ // eslint-disable-next-line max-len
49
+ GithubResolver.GITHUB_URL_PATTERN = /^(?<scheme>https?):\/\/(?<host>github(\..+)?\.[^\/]+)\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?)?$/;
50
+ GithubResolver = GithubResolver_1 = __decorate([
51
+ (0, inversify_1.injectable)()
52
+ ], GithubResolver);
53
+ return GithubResolver;
54
+ }());
55
+ exports.GithubResolver = GithubResolver;
56
+ //# sourceMappingURL=github-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-resolver.js","sourceRoot":"","sources":["../../src/github/github-resolver.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;AAEzE,2CAAyC;AACzC,uCAAuC;AAEvC;;GAEG;AAEH;IAAA;IAyBA,CAAC;uBAzBY,cAAc;IAKzB,gCAAO,GAAP,UAAQ,IAAY;QAClB,IAAM,KAAK,GAAG,gBAAc,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,yBAAuB,IAAM,CAAC,CAAC;SAChD;QACD,IAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC9C,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC9C,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QAC9D,IAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACpD,OAAO,IAAI,sBAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;IAED,iCAAQ,GAAR,UAAS,KAAsB,EAAE,SAAiB,EAAE,YAAqB;QACvE,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;YAC3C,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;SAChC;QACD,OAAO,YAAY,IAAI,EAAE,CAAC;IAC5B,CAAC;;IAvBD,mCAAmC;IACnB,iCAAkB,GAChC,qKAAsK,CAAA;IAH7J,cAAc;QAD1B,IAAA,sBAAU,GAAE;OACA,cAAc,CAyB1B;IAAD,qBAAC;CAAA,AAzBD,IAyBC;AAzBY,wCAAc"}
@@ -0,0 +1,29 @@
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
+ * Provides helper methods on top of github URL to get for example raw content of get relative links
12
+ */
13
+ export declare class GithubUrl {
14
+ private readonly scheme;
15
+ private readonly hostName;
16
+ private readonly repoUser;
17
+ private readonly repoName;
18
+ private readonly branchName;
19
+ private readonly subFolder;
20
+ constructor(scheme: string, hostName: string, repoUser: string, repoName: string, branchName: string, subFolder: string);
21
+ /**
22
+ * Provides the raw link to the given path based on the current repository information
23
+ */
24
+ getContentUrl(path: string): string;
25
+ getUrl(): string;
26
+ getCloneUrl(): string;
27
+ getRepoName(): string;
28
+ getBranchName(): string;
29
+ }
@@ -0,0 +1,47 @@
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
+ exports.__esModule = true;
12
+ exports.GithubUrl = void 0;
13
+ /**
14
+ * Provides helper methods on top of github URL to get for example raw content of get relative links
15
+ */
16
+ var GithubUrl = /** @class */ (function () {
17
+ function GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder) {
18
+ this.scheme = scheme;
19
+ this.hostName = hostName;
20
+ this.repoUser = repoUser;
21
+ this.repoName = repoName;
22
+ this.branchName = branchName;
23
+ this.subFolder = subFolder;
24
+ }
25
+ /**
26
+ * Provides the raw link to the given path based on the current repository information
27
+ */
28
+ GithubUrl.prototype.getContentUrl = function (path) {
29
+ var hostName = this.hostName === 'github.com' ? 'githubusercontent.com' : this.hostName;
30
+ return this.scheme + "://raw." + hostName + "/" + this.repoUser + "/" + this.repoName + "/" + this.branchName + "/" + path;
31
+ };
32
+ GithubUrl.prototype.getUrl = function () {
33
+ return this.scheme + "://" + this.hostName + "/" + this.repoUser + "/" + this.repoName + "/tree/" + this.branchName + "/" + this.subFolder;
34
+ };
35
+ GithubUrl.prototype.getCloneUrl = function () {
36
+ return this.scheme + "://" + this.hostName + "/" + this.repoUser + "/" + this.repoName + ".git";
37
+ };
38
+ GithubUrl.prototype.getRepoName = function () {
39
+ return this.repoName;
40
+ };
41
+ GithubUrl.prototype.getBranchName = function () {
42
+ return this.branchName;
43
+ };
44
+ return GithubUrl;
45
+ }());
46
+ exports.GithubUrl = GithubUrl;
47
+ //# sourceMappingURL=github-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-url.js","sourceRoot":"","sources":["../../src/github/github-url.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;AAEzE;;GAEG;AACH;IACE,mBACmB,MAAc,EACd,QAAgB,EAChB,QAAgB,EAChB,QAAgB,EAChB,UAAkB,EAClB,SAAiB;QALjB,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,eAAU,GAAV,UAAU,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAQ;IACjC,CAAC;IAEJ;;OAEG;IACH,iCAAa,GAAb,UAAc,IAAY;QACxB,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC1F,OAAU,IAAI,CAAC,MAAM,eAAU,QAAQ,SAAI,IAAI,CAAC,QAAQ,SAAI,IAAI,CAAC,QAAQ,SAAI,IAAI,CAAC,UAAU,SAAI,IAAM,CAAC;IACzG,CAAC;IAED,0BAAM,GAAN;QACE,OAAU,IAAI,CAAC,MAAM,WAAM,IAAI,CAAC,QAAQ,SAAI,IAAI,CAAC,QAAQ,SAAI,IAAI,CAAC,QAAQ,cAAS,IAAI,CAAC,UAAU,SAAI,IAAI,CAAC,SAAW,CAAC;IACzH,CAAC;IAED,+BAAW,GAAX;QACE,OAAU,IAAI,CAAC,MAAM,WAAM,IAAI,CAAC,QAAQ,SAAI,IAAI,CAAC,QAAQ,SAAI,IAAI,CAAC,QAAQ,SAAM,CAAC;IACnF,CAAC;IAED,+BAAW,GAAX;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,iCAAa,GAAb;QACE,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IACH,gBAAC;AAAD,CAAC,AAjCD,IAiCC;AAjCY,8BAAS"}
@@ -0,0 +1,26 @@
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 'reflect-metadata';
11
+ import { AxiosInstance } from 'axios';
12
+ import { Container } from 'inversify';
13
+ /**
14
+ * Manage all bindings for inversify
15
+ */
16
+ export declare class InversifyBinding {
17
+ private container;
18
+ initBindings(options: InversifyBindingOptions): Promise<Container>;
19
+ }
20
+ /**
21
+ * Options for inversify bindings
22
+ */
23
+ export interface InversifyBindingOptions {
24
+ pluginRegistryUrl: string;
25
+ axiosInstance: AxiosInstance;
26
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ exports.__esModule = true;
39
+ exports.InversifyBinding = void 0;
40
+ /**********************************************************************
41
+ * Copyright (c) 2022 Red Hat, Inc.
42
+ *
43
+ * This program and the accompanying materials are made
44
+ * available under the terms of the Eclipse Public License 2.0
45
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
46
+ *
47
+ * SPDX-License-Identifier: EPL-2.0
48
+ ***********************************************************************/
49
+ require("reflect-metadata");
50
+ var inversify_1 = require("inversify");
51
+ var devfile_module_1 = require("../devfile/devfile-module");
52
+ var fetch_module_1 = require("../fetch/fetch-module");
53
+ var github_module_1 = require("../github/github-module");
54
+ var plugin_registry_module_1 = require("../plugin-registry/plugin-registry-module");
55
+ /**
56
+ * Manage all bindings for inversify
57
+ */
58
+ var InversifyBinding = /** @class */ (function () {
59
+ function InversifyBinding() {
60
+ }
61
+ InversifyBinding.prototype.initBindings = function (options) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ return __generator(this, function (_a) {
64
+ this.container = new inversify_1.Container();
65
+ this.container.load(devfile_module_1.devfileModule);
66
+ this.container.load(fetch_module_1.fetchModule);
67
+ this.container.load(github_module_1.githubModule);
68
+ this.container.load(plugin_registry_module_1.pluginRegistryModule);
69
+ this.container.bind(Symbol["for"]('AxiosInstance')).toConstantValue(options.axiosInstance);
70
+ this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL');
71
+ return [2 /*return*/, this.container];
72
+ });
73
+ });
74
+ };
75
+ return InversifyBinding;
76
+ }());
77
+ exports.InversifyBinding = InversifyBinding;
78
+ //# sourceMappingURL=inversify-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inversify-binding.js","sourceRoot":"","sources":["../../src/inversify/inversify-binding.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;yEAQyE;AACzE,4BAA0B;AAG1B,uCAAsC;AACtC,4DAA0D;AAC1D,sDAAoD;AACpD,yDAAuD;AACvD,oFAAiF;AAEjF;;GAEG;AACH;IAAA;IAgBA,CAAC;IAbc,uCAAY,GAAzB,UAA0B,OAAgC;;;gBACxD,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;gBAEjC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,8BAAa,CAAC,CAAC;gBACnC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,0BAAW,CAAC,CAAC;gBACjC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAAY,CAAC,CAAC;gBAClC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,6CAAoB,CAAC,CAAC;gBAE1C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,KAAG,CAAA,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;gBACxF,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC;gBAEhH,sBAAO,IAAI,CAAC,SAAS,EAAC;;;KACvB;IACH,uBAAC;AAAD,CAAC,AAhBD,IAgBC;AAhBY,4CAAgB"}
package/lib/main.d.ts ADDED
@@ -0,0 +1,36 @@
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 * as axios from 'axios';
11
+ import { DevfileContext } from './api/devfile-context';
12
+ export declare class Main {
13
+ /**
14
+ * Default constructor.
15
+ */
16
+ constructor();
17
+ generateDevfileContext(params: {
18
+ devfilePath?: string;
19
+ devfileUrl?: string;
20
+ devfileContent?: string;
21
+ outputFile?: string;
22
+ editorPath?: string;
23
+ editorContent?: string;
24
+ editorEntry?: string;
25
+ pluginRegistryUrl?: string;
26
+ projects: {
27
+ name: string;
28
+ location: string;
29
+ }[];
30
+ }, axiosInstance: axios.AxiosInstance): Promise<DevfileContext>;
31
+ replaceIfExistingProjects(devfileContent: string, projects: {
32
+ name: string;
33
+ location: string;
34
+ }[]): string;
35
+ start(): Promise<boolean>;
36
+ }