@eclipse-che/che-devworkspace-generator 0.0.1-d7aefd7 → 0.0.1-ea73e8b
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.
- package/README.md +56 -0
- package/lib/api/devfile-context.d.ts +19 -0
- package/lib/devfile/dev-container-component-finder.d.ts +18 -0
- package/lib/devfile/dev-container-component-finder.js +20 -7
- package/lib/devfile/dev-container-component-finder.js.map +1 -1
- package/lib/devfile/dev-container-component-inserter.d.ts +18 -0
- package/lib/devfile/dev-container-component-inserter.js +98 -0
- package/lib/devfile/dev-container-component-inserter.js.map +1 -0
- package/lib/devfile/devfile-module.d.ts +12 -0
- package/lib/devfile/devfile-module.js +2 -0
- package/lib/devfile/devfile-module.js.map +1 -1
- package/lib/entrypoint.d.ts +11 -0
- package/lib/fetch/fetch-module.d.ts +12 -0
- package/lib/fetch/url-fetcher.d.ts +9 -0
- package/lib/generate.d.ts +16 -0
- package/lib/generate.js +32 -21
- package/lib/generate.js.map +1 -1
- package/lib/github/github-module.d.ts +12 -0
- package/lib/github/github-resolver.d.ts +18 -0
- package/lib/github/github-resolver.js +4 -2
- package/lib/github/github-resolver.js.map +1 -1
- package/lib/github/github-url.d.ts +29 -0
- package/lib/github/github-url.js +7 -6
- package/lib/github/github-url.js.map +1 -1
- package/lib/inversify/inversify-binding.d.ts +26 -0
- package/lib/main.d.ts +38 -0
- package/lib/main.js +100 -60
- package/lib/main.js.map +1 -1
- package/lib/plugin-registry/plugin-registry-module.d.ts +12 -0
- package/lib/plugin-registry/plugin-registry-resolver.d.ts +17 -0
- package/lib/plugin-registry/plugin-registry-resolver.js +1 -1
- package/lib/plugin-registry/plugin-registry-resolver.js.map +1 -1
- package/package.json +6 -4
- package/src/devfile/dev-container-component-finder.ts +23 -4
- package/src/devfile/dev-container-component-inserter.ts +49 -0
- package/src/devfile/devfile-module.ts +2 -0
- package/src/generate.ts +59 -25
- package/src/github/github-resolver.ts +4 -2
- package/src/github/github-url.ts +6 -6
- package/src/main.ts +119 -55
- package/src/plugin-registry/plugin-registry-resolver.ts +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
## DevWorkspace Generator
|
|
2
|
+
The library is used by Devfile registry component to generate the DevWorkspace components and DevWorkspace templates. It requires editor definitions from the
|
|
3
|
+
[che-plugin-registry](https://github.com/eclipse-che/che-plugin-registry/).
|
|
4
|
+
|
|
5
|
+
## How to use the library
|
|
6
|
+
The library can be used as a standalone library.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
USAGE
|
|
10
|
+
$ node lib/entrypoint.js [OPTIONS]
|
|
11
|
+
|
|
12
|
+
OPTIONS
|
|
13
|
+
--devfile-url: URL to the git repository that contains devfile.yaml
|
|
14
|
+
or
|
|
15
|
+
--devfile-path: path to the devfile.yaml file
|
|
16
|
+
|
|
17
|
+
--plugin-registry-url: URL to the plugin registry that contains editor definitions (devfile.yaml)
|
|
18
|
+
--editor-entry: editor ID, found on the <plugin-registry-url>, to resolve the devfile.yaml
|
|
19
|
+
or
|
|
20
|
+
--editor-path: local file path of the editor devfile.yaml
|
|
21
|
+
|
|
22
|
+
--output-file: local file path for the generated devworkspace yaml
|
|
23
|
+
|
|
24
|
+
--project.<project-name> local file path for the sample project zip (for airgapped/offline registry builds)
|
|
25
|
+
|
|
26
|
+
--injectDefaultComponent: inject a default dev container component if no component is defined in the devfile and it doesn't provide a parent, the value can be true or false, default is false
|
|
27
|
+
|
|
28
|
+
--defaultComponentImage: image to use for the default dev container component that will be injected if no componetn is defined in the devfile and it doesn't provide a parent devfile, default is quay.io/devfile/universal-developer-image:ubi8-latest
|
|
29
|
+
|
|
30
|
+
EXAMPLES
|
|
31
|
+
|
|
32
|
+
# online example, using editor definition from https://che-plugin-registry-main.surge.sh/
|
|
33
|
+
|
|
34
|
+
$ node lib/entrypoint.js \
|
|
35
|
+
--devfile-url:https://github.com/che-samples/java-spring-petclinic/tree/main \
|
|
36
|
+
--plugin-registry-url:https://che-plugin-registry-main.surge.sh/v3/ \
|
|
37
|
+
--editor-entry:che-incubator/che-code/latest \
|
|
38
|
+
--output-file:/tmp/devworkspace-che-code-latest.yaml \
|
|
39
|
+
--injectDefaultComponent:true \
|
|
40
|
+
--defaultComponentImage:registry.access.redhat.com/ubi8/openjdk-11:latest
|
|
41
|
+
|
|
42
|
+
# offline example with devfile.yaml files and zipped project available locally
|
|
43
|
+
|
|
44
|
+
$ node lib/entrypoint.js \
|
|
45
|
+
--devfile-path:/remote-source/python-hello-world/app/devfile.yaml \
|
|
46
|
+
--editor-path:/build/plugins/che-incubator/che-code/latest/devfile.yaml \
|
|
47
|
+
--output-file:./devfiles/python__python-hello-world/devworkspace-che-code-latest.yaml \
|
|
48
|
+
--project.python-hello-world='{{_INTERNAL_URL_}}/resources/v2/python-hello-world.zip'
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The output file `devworkspace-che-code-latest.yaml` contains a DevWorkspace based on the repository devfile and a Che-Code DevWorkspaceTemplate.
|
|
53
|
+
|
|
54
|
+
If the DevWorkspace engine is installed on the cluster, the following command will create a DevWorkspace:
|
|
55
|
+
|
|
56
|
+
`$ kubectl apply -f /tmp/devworkspace-che-code-latest.yaml`
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
* Context used on every call to this service to update DevWorkspace
|
|
13
|
+
*/
|
|
14
|
+
export interface DevfileContext {
|
|
15
|
+
devfile: any;
|
|
16
|
+
devWorkspace: V1alpha2DevWorkspace;
|
|
17
|
+
devWorkspaceTemplates: V1alpha2DevWorkspaceTemplate[];
|
|
18
|
+
suffix: string;
|
|
19
|
+
}
|
|
@@ -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 { DevfileContext } from '../api/devfile-context';
|
|
11
|
+
import { V1alpha2DevWorkspaceSpecTemplateComponents } from '@devfile/api';
|
|
12
|
+
/**
|
|
13
|
+
* Need to find dev container from main dev workspace
|
|
14
|
+
*/
|
|
15
|
+
export declare class DevContainerComponentFinder {
|
|
16
|
+
private devContainerComponentInserter;
|
|
17
|
+
find(devfileContext: DevfileContext, injectDefaultComponent?: string, defaultComponentImage?: string): Promise<V1alpha2DevWorkspaceSpecTemplateComponents | undefined>;
|
|
18
|
+
}
|
|
@@ -53,23 +53,33 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
53
53
|
exports.__esModule = true;
|
|
54
54
|
exports.DevContainerComponentFinder = void 0;
|
|
55
55
|
var inversify_1 = require("inversify");
|
|
56
|
+
var dev_container_component_inserter_1 = require("./dev-container-component-inserter");
|
|
56
57
|
/**
|
|
57
58
|
* Need to find dev container from main dev workspace
|
|
58
59
|
*/
|
|
59
60
|
var DevContainerComponentFinder = /** @class */ (function () {
|
|
60
61
|
function DevContainerComponentFinder() {
|
|
61
62
|
}
|
|
62
|
-
DevContainerComponentFinder.prototype.find = function (devfileContext) {
|
|
63
|
-
var _a, _b, _c;
|
|
63
|
+
DevContainerComponentFinder.prototype.find = function (devfileContext, injectDefaultComponent, defaultComponentImage) {
|
|
64
|
+
var _a, _b, _c, _d;
|
|
64
65
|
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var devComponents;
|
|
66
|
-
return __generator(this, function (
|
|
67
|
-
|
|
66
|
+
var devComponents, devComponents_1;
|
|
67
|
+
return __generator(this, function (_e) {
|
|
68
|
+
// if a devfile contains a parent, we should not add a default dev container
|
|
69
|
+
if ((_a = devfileContext.devfile) === null || _a === void 0 ? void 0 : _a.parent) {
|
|
70
|
+
return [2 /*return*/, undefined];
|
|
71
|
+
}
|
|
72
|
+
devComponents = (_d = (_c = (_b = devfileContext.devWorkspace.spec) === null || _b === void 0 ? void 0 : _b.template) === null || _c === void 0 ? void 0 : _c.components) === null || _d === void 0 ? void 0 : _d.filter(function (component) { return component.container; }).filter(
|
|
68
73
|
// we should ignore component that do not mount the sources
|
|
69
74
|
function (component) { return component.container && component.container.mountSources !== false; });
|
|
70
|
-
// only one, fine, else error
|
|
71
75
|
if (!devComponents || devComponents.length === 0) {
|
|
72
|
-
|
|
76
|
+
// do not inject a default component if injectDefaultComponent parameter is false
|
|
77
|
+
if (!injectDefaultComponent || injectDefaultComponent !== 'true') {
|
|
78
|
+
return [2 /*return*/, undefined];
|
|
79
|
+
}
|
|
80
|
+
this.devContainerComponentInserter.insert(devfileContext, defaultComponentImage);
|
|
81
|
+
devComponents_1 = devfileContext.devWorkspace.spec.template.components.filter(function (component) { return component.container; });
|
|
82
|
+
return [2 /*return*/, devComponents_1[0]];
|
|
73
83
|
}
|
|
74
84
|
else if (devComponents.length === 1) {
|
|
75
85
|
return [2 /*return*/, devComponents[0]];
|
|
@@ -82,6 +92,9 @@ var DevContainerComponentFinder = /** @class */ (function () {
|
|
|
82
92
|
});
|
|
83
93
|
});
|
|
84
94
|
};
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, inversify_1.inject)(dev_container_component_inserter_1.DevContainerComponentInserter)
|
|
97
|
+
], DevContainerComponentFinder.prototype, "devContainerComponentInserter");
|
|
85
98
|
DevContainerComponentFinder = __decorate([
|
|
86
99
|
(0, inversify_1.injectable)()
|
|
87
100
|
], DevContainerComponentFinder);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-container-component-finder.js","sourceRoot":"","sources":["../../src/devfile/dev-container-component-finder.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIzE,
|
|
1
|
+
{"version":3,"file":"dev-container-component-finder.js","sourceRoot":"","sources":["../../src/devfile/dev-container-component-finder.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIzE,uCAA+C;AAC/C,uFAAmF;AAEnF;;GAEG;AAEH;IAAA;IA0CA,CAAC;IAtCO,0CAAI,GAAV,UACE,cAA8B,EAC9B,sBAA+B,EAC/B,qBAA8B;;;;;gBAE9B,4EAA4E;gBAC5E,IAAI,MAAA,cAAc,CAAC,OAAO,0CAAE,MAAM,EAAE;oBAClC,sBAAO,SAAS,EAAC;iBAClB;gBAEK,aAAa,GAAG,MAAA,MAAA,MAAA,cAAc,CAAC,YAAY,CAAC,IAAI,0CAAE,QAAQ,0CAAE,UAAU,0CACxE,MAAM,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,CAAC,SAAS,EAAnB,CAAmB,EACxC,MAAM;gBACL,2DAA2D;gBAC3D,UAAA,SAAS,IAAI,OAAA,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,YAAY,KAAK,KAAK,EAAjE,CAAiE,CAC/E,CAAC;gBAEJ,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE;oBAChD,iFAAiF;oBACjF,IAAI,CAAC,sBAAsB,IAAI,sBAAsB,KAAK,MAAM,EAAE;wBAChE,sBAAO,SAAS,EAAC;qBAClB;oBACD,IAAI,CAAC,6BAA6B,CAAC,MAAM,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;oBAE7E,kBAAgB,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,CAAC,SAAS,EAAnB,CAAmB,CAAC,CAAC;oBAElH,sBAAO,eAAa,CAAC,CAAC,CAAC,EAAC;iBACzB;qBAAM,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE;oBACrC,sBAAO,aAAa,CAAC,CAAC,CAAC,EAAC;iBACzB;qBAAM;oBACL,OAAO,CAAC,IAAI,CACV,+FAA6F,aAAa,CAAC,GAAG,CAC5G,UAAA,SAAS,IAAI,OAAA,SAAS,CAAC,IAAI,EAAd,CAAc,CAC1B,CACJ,CAAC;oBACF,sBAAO,aAAa,CAAC,CAAC,CAAC,EAAC;iBACzB;;;;KACF;IAvCD;QADC,IAAA,kBAAM,EAAC,gEAA6B,CAAC;8EAC+B;IAF1D,2BAA2B;QADvC,IAAA,sBAAU,GAAE;OACA,2BAA2B,CA0CvC;IAAD,kCAAC;CAAA,AA1CD,IA0CC;AA1CY,kEAA2B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**********************************************************************
|
|
2
|
+
* Copyright (c) 2023 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 { DevfileContext } from '../api/devfile-context';
|
|
11
|
+
/**
|
|
12
|
+
* Adds a new component on empty devfile with specific name and image
|
|
13
|
+
*/
|
|
14
|
+
export declare class DevContainerComponentInserter {
|
|
15
|
+
readonly DEFAULT_DEV_CONTAINER_IMAGE = "quay.io/devfile/universal-developer-image:ubi8-latest";
|
|
16
|
+
readonly DEFAULT_DEV_CONTAINER_NAME = "dev";
|
|
17
|
+
insert(devfileContext: DevfileContext, defaultComponentImage?: string): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**********************************************************************
|
|
3
|
+
* Copyright (c) 2023 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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.__esModule = true;
|
|
54
|
+
exports.DevContainerComponentInserter = void 0;
|
|
55
|
+
var inversify_1 = require("inversify");
|
|
56
|
+
/**
|
|
57
|
+
* Adds a new component on empty devfile with specific name and image
|
|
58
|
+
*/
|
|
59
|
+
var DevContainerComponentInserter = /** @class */ (function () {
|
|
60
|
+
function DevContainerComponentInserter() {
|
|
61
|
+
this.DEFAULT_DEV_CONTAINER_IMAGE = 'quay.io/devfile/universal-developer-image:ubi8-latest';
|
|
62
|
+
this.DEFAULT_DEV_CONTAINER_NAME = 'dev';
|
|
63
|
+
}
|
|
64
|
+
DevContainerComponentInserter.prototype.insert = function (devfileContext, defaultComponentImage) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var devContainerImage, devContainerComponent;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
if (!devfileContext.devWorkspace.spec) {
|
|
69
|
+
devfileContext.devWorkspace.spec = {
|
|
70
|
+
started: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (!devfileContext.devWorkspace.spec.template) {
|
|
74
|
+
devfileContext.devWorkspace.spec.template = {};
|
|
75
|
+
}
|
|
76
|
+
if (!devfileContext.devWorkspace.spec.template.components) {
|
|
77
|
+
devfileContext.devWorkspace.spec.template.components = [];
|
|
78
|
+
}
|
|
79
|
+
devContainerImage = defaultComponentImage ? defaultComponentImage : this.DEFAULT_DEV_CONTAINER_IMAGE;
|
|
80
|
+
console.log("No container component has been found. A default container component with image " + devContainerImage + " will be added.");
|
|
81
|
+
devContainerComponent = {
|
|
82
|
+
name: this.DEFAULT_DEV_CONTAINER_NAME,
|
|
83
|
+
container: {
|
|
84
|
+
image: devContainerImage
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
devfileContext.devWorkspace.spec.template.components.push(devContainerComponent);
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
DevContainerComponentInserter = __decorate([
|
|
93
|
+
(0, inversify_1.injectable)()
|
|
94
|
+
], DevContainerComponentInserter);
|
|
95
|
+
return DevContainerComponentInserter;
|
|
96
|
+
}());
|
|
97
|
+
exports.DevContainerComponentInserter = DevContainerComponentInserter;
|
|
98
|
+
//# sourceMappingURL=dev-container-component-inserter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-container-component-inserter.js","sourceRoot":"","sources":["../../src/devfile/dev-container-component-inserter.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIzE,uCAAuC;AAEvC;;GAEG;AAEH;IAAA;QACW,gCAA2B,GAAG,uDAAuD,CAAC;QACtF,+BAA0B,GAAG,KAAK,CAAC;IA4B9C,CAAC;IA1BO,8CAAM,GAAZ,UAAa,cAA8B,EAAE,qBAA8B;;;;gBACzE,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,EAAE;oBACrC,cAAc,CAAC,YAAY,CAAC,IAAI,GAAG;wBACjC,OAAO,EAAE,IAAI;qBACd,CAAC;iBACH;gBACD,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAC9C,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;iBAChD;gBACD,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;oBACzD,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,GAAG,EAAE,CAAC;iBAC3D;gBAEK,iBAAiB,GAAG,qBAAqB,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC;gBAC3G,OAAO,CAAC,GAAG,CACT,qFAAmF,iBAAiB,oBAAiB,CACtH,CAAC;gBACI,qBAAqB,GAA+C;oBACxE,IAAI,EAAE,IAAI,CAAC,0BAA0B;oBACrC,SAAS,EAAE;wBACT,KAAK,EAAE,iBAAiB;qBACzB;iBACF,CAAC;gBAEF,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;;;;KAClF;IA7BU,6BAA6B;QADzC,IAAA,sBAAU,GAAE;OACA,6BAA6B,CA8BzC;IAAD,oCAAC;CAAA,AA9BD,IA8BC;AA9BY,sEAA6B"}
|
|
@@ -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 devfileModule: ContainerModule;
|
|
12
|
+
export { devfileModule };
|
|
@@ -12,8 +12,10 @@ exports.devfileModule = void 0;
|
|
|
12
12
|
***********************************************************************/
|
|
13
13
|
var inversify_1 = require("inversify");
|
|
14
14
|
var dev_container_component_finder_1 = require("./dev-container-component-finder");
|
|
15
|
+
var dev_container_component_inserter_1 = require("./dev-container-component-inserter");
|
|
15
16
|
var devfileModule = new inversify_1.ContainerModule(function (bind) {
|
|
16
17
|
bind(dev_container_component_finder_1.DevContainerComponentFinder).toSelf().inSingletonScope();
|
|
18
|
+
bind(dev_container_component_inserter_1.DevContainerComponentInserter).toSelf().inSingletonScope();
|
|
17
19
|
});
|
|
18
20
|
exports.devfileModule = devfileModule;
|
|
19
21
|
//# sourceMappingURL=devfile-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devfile-module.js","sourceRoot":"","sources":["../../src/devfile/devfile-module.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;yEAQyE;AACzE,uCAAwD;AAExD,mFAA+E;
|
|
1
|
+
{"version":3,"file":"devfile-module.js","sourceRoot":"","sources":["../../src/devfile/devfile-module.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;yEAQyE;AACzE,uCAAwD;AAExD,mFAA+E;AAC/E,uFAAmF;AAEnF,IAAM,aAAa,GAAG,IAAI,2BAAe,CAAC,UAAC,IAAqB;IAC9D,IAAI,CAAC,4DAA2B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC9D,IAAI,CAAC,gEAA6B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;AAClE,CAAC,CAAC,CAAC;AAEM,sCAAa"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
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
|
+
import 'reflect-metadata';
|
|
@@ -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 fetchModule: ContainerModule;
|
|
12
|
+
export { fetchModule };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allow to grab external content
|
|
3
|
+
* if browser support is enabled, it will update URLs to make them work on browser side.
|
|
4
|
+
*/
|
|
5
|
+
export declare class UrlFetcher {
|
|
6
|
+
private axiosInstance;
|
|
7
|
+
fetchTextOptionalContent(url: string): Promise<string | undefined>;
|
|
8
|
+
fetchText(url: string): Promise<string>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { DevfileContext } from './api/devfile-context';
|
|
11
|
+
export declare class Generate {
|
|
12
|
+
private devContainerComponentFinder;
|
|
13
|
+
generate(devfileContent: string, editorContent: string, outputFile?: string, injectDefaultComponent?: string, defaultComponentImage?: string): Promise<DevfileContext>;
|
|
14
|
+
generateContent(devfileContent: string, editorContent: string, injectDefaultComponent?: string, defaultComponentImage?: string): Promise<DevfileContext>;
|
|
15
|
+
private createDevWorkspaceMetadata;
|
|
16
|
+
}
|
package/lib/generate.js
CHANGED
|
@@ -78,37 +78,39 @@ var dev_container_component_finder_1 = require("./devfile/dev-container-componen
|
|
|
78
78
|
var Generate = /** @class */ (function () {
|
|
79
79
|
function Generate() {
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
Generate.prototype.generate = function (devfileContent, editorContent, outputFile) {
|
|
81
|
+
Generate.prototype.generate = function (devfileContent, editorContent, outputFile, injectDefaultComponent, defaultComponentImage) {
|
|
83
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
84
83
|
var context, allContentArray, generatedContent;
|
|
85
84
|
return __generator(this, function (_a) {
|
|
86
85
|
switch (_a.label) {
|
|
87
|
-
case 0: return [4 /*yield*/, this.generateContent(devfileContent, editorContent)];
|
|
86
|
+
case 0: return [4 /*yield*/, this.generateContent(devfileContent, editorContent, injectDefaultComponent, defaultComponentImage)];
|
|
88
87
|
case 1:
|
|
89
88
|
context = _a.sent();
|
|
89
|
+
if (!outputFile) return [3 /*break*/, 3];
|
|
90
90
|
allContentArray = context.devWorkspaceTemplates.map(function (template) { return jsYaml.dump(template); });
|
|
91
91
|
allContentArray.push(jsYaml.dump(context.devWorkspace));
|
|
92
92
|
generatedContent = allContentArray.join('---\n');
|
|
93
93
|
return [4 /*yield*/, fs.writeFile(outputFile, generatedContent, 'utf-8')];
|
|
94
94
|
case 2:
|
|
95
95
|
_a.sent();
|
|
96
|
+
_a.label = 3;
|
|
97
|
+
case 3:
|
|
96
98
|
console.log("DevWorkspace " + context.devWorkspaceTemplates[0].metadata.name + " was generated.");
|
|
97
99
|
return [2 /*return*/, context];
|
|
98
100
|
}
|
|
99
101
|
});
|
|
100
102
|
});
|
|
101
103
|
};
|
|
102
|
-
Generate.prototype.generateContent = function (devfileContent, editorContent) {
|
|
104
|
+
Generate.prototype.generateContent = function (devfileContent, editorContent, injectDefaultComponent, defaultComponentImage) {
|
|
103
105
|
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
-
var devfile, suffix, editorDevfile, metadata, editorDevWorkspaceTemplate, devfileMetadata, devfileCopy, editorSpecContribution, devWorkspace, devWorkspaceTemplates, context
|
|
106
|
+
var devfile, suffix, editorDevfile, metadata, editorDevWorkspaceTemplate, devfileMetadata, devfileCopy, editorSpecContribution, devWorkspace, devWorkspaceTemplates, context;
|
|
105
107
|
return __generator(this, function (_a) {
|
|
106
108
|
switch (_a.label) {
|
|
107
109
|
case 0:
|
|
108
110
|
devfile = jsYaml.load(devfileContent);
|
|
109
111
|
suffix = devfile.metadata.name || '';
|
|
110
112
|
editorDevfile = jsYaml.load(editorContent);
|
|
111
|
-
metadata = editorDevfile
|
|
113
|
+
metadata = this.createDevWorkspaceMetadata(editorDevfile);
|
|
112
114
|
// add sufix
|
|
113
115
|
metadata.name = metadata.name + "-" + suffix;
|
|
114
116
|
delete editorDevfile.metadata;
|
|
@@ -119,7 +121,7 @@ var Generate = /** @class */ (function () {
|
|
|
119
121
|
metadata: metadata,
|
|
120
122
|
spec: editorDevfile
|
|
121
123
|
};
|
|
122
|
-
devfileMetadata = devfile
|
|
124
|
+
devfileMetadata = this.createDevWorkspaceMetadata(devfile, true);
|
|
123
125
|
devfileCopy = Object.assign({}, devfile);
|
|
124
126
|
delete devfileCopy.schemaVersion;
|
|
125
127
|
delete devfileCopy.metadata;
|
|
@@ -135,6 +137,7 @@ var Generate = /** @class */ (function () {
|
|
|
135
137
|
metadata: devfileMetadata,
|
|
136
138
|
spec: {
|
|
137
139
|
started: true,
|
|
140
|
+
routingClass: 'che',
|
|
138
141
|
template: devfileCopy,
|
|
139
142
|
contributions: [editorSpecContribution]
|
|
140
143
|
}
|
|
@@ -146,29 +149,37 @@ var Generate = /** @class */ (function () {
|
|
|
146
149
|
devWorkspaceTemplates: devWorkspaceTemplates,
|
|
147
150
|
suffix: suffix
|
|
148
151
|
};
|
|
149
|
-
|
|
152
|
+
// find devContainer component, add a default one if not found
|
|
153
|
+
return [4 /*yield*/, this.devContainerComponentFinder.find(context, injectDefaultComponent, defaultComponentImage)];
|
|
150
154
|
case 1:
|
|
151
|
-
devContainer
|
|
152
|
-
|
|
153
|
-
if (!devContainerAttributes) {
|
|
154
|
-
devContainerAttributes = {};
|
|
155
|
-
devContainerAttributes[Generate_1.MERGE_CONTRIBUTION] = true;
|
|
156
|
-
devContainer.attributes = devContainerAttributes;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
devContainerAttributes[Generate_1.MERGE_CONTRIBUTION] = true;
|
|
160
|
-
}
|
|
155
|
+
// find devContainer component, add a default one if not found
|
|
156
|
+
_a.sent();
|
|
161
157
|
return [2 /*return*/, context];
|
|
162
158
|
}
|
|
163
159
|
});
|
|
164
160
|
});
|
|
165
161
|
};
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
Generate.prototype.createDevWorkspaceMetadata = function (devfile, addDevfileContent) {
|
|
163
|
+
if (addDevfileContent === void 0) { addDevfileContent = false; }
|
|
164
|
+
var devWorkspaceMetadata = {};
|
|
165
|
+
var devfileMetadata = devfile.metadata;
|
|
166
|
+
if (devfileMetadata.name) {
|
|
167
|
+
devWorkspaceMetadata.name = devfileMetadata.name;
|
|
168
|
+
}
|
|
169
|
+
if (devfileMetadata.generateName) {
|
|
170
|
+
devWorkspaceMetadata.generateName = devfileMetadata.generateName;
|
|
171
|
+
}
|
|
172
|
+
if (addDevfileContent) {
|
|
173
|
+
devWorkspaceMetadata.annotations = {
|
|
174
|
+
'che.eclipse.org/devfile': jsYaml.dump(devfile)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return devWorkspaceMetadata;
|
|
178
|
+
};
|
|
168
179
|
__decorate([
|
|
169
180
|
(0, inversify_1.inject)(dev_container_component_finder_1.DevContainerComponentFinder)
|
|
170
181
|
], Generate.prototype, "devContainerComponentFinder");
|
|
171
|
-
Generate =
|
|
182
|
+
Generate = __decorate([
|
|
172
183
|
(0, inversify_1.injectable)()
|
|
173
184
|
], Generate);
|
|
174
185
|
return Generate;
|
package/lib/generate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWzE,uCAA+C;AAC/C,8CAAkC;AAClC,2CAA+B;AAE/B,2FAAuF;AASvF;IAAA;IAsHA,CAAC;IAlHO,2BAAQ,GAAd,UACE,cAAsB,EACtB,aAAqB,EACrB,UAAmB,EACnB,sBAA+B,EAC/B,qBAA8B;;;;;4BAEd,qBAAM,IAAI,CAAC,eAAe,CACxC,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,qBAAqB,CACtB,EAAA;;wBALK,OAAO,GAAG,SAKf;6BAGG,UAAU,EAAV,wBAAU;wBAEN,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,UAAA,QAAQ,IAAI,OAAA,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAArB,CAAqB,CAAC,CAAC;wBAC7F,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;wBAElD,gBAAgB,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;wBAEvD,qBAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAA;;wBAAzD,SAAyD,CAAC;;;wBAG5D,OAAO,CAAC,GAAG,CAAC,kBAAgB,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,oBAAiB,CAAC,CAAC;wBAC7F,sBAAO,OAAO,EAAC;;;;KAChB;IAEK,kCAAe,GAArB,UACE,cAAsB,EACtB,aAAqB,EACrB,sBAA+B,EAC/B,qBAA8B;;;;;;wBAExB,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;wBAItC,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;wBAGrC,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;wBAG3C,QAAQ,GAAG,IAAI,CAAC,0BAA0B,CAAC,aAAa,CAAC,CAAC;wBAChE,YAAY;wBACZ,QAAQ,CAAC,IAAI,GAAM,QAAQ,CAAC,IAAI,SAAI,MAAQ,CAAC;wBAC7C,OAAO,aAAa,CAAC,QAAQ,CAAC;wBAC9B,OAAO,aAAa,CAAC,aAAa,CAAC;wBAC7B,0BAA0B,GAAiC;4BAC/D,UAAU,EAAE,+BAA+B;4BAC3C,IAAI,EAAE,sBAAsB;4BAC5B,QAAQ,UAAA;4BACR,IAAI,EAAE,aAAiD;yBACxD,CAAC;wBAGI,eAAe,GAAG,IAAI,CAAC,0BAA0B,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;wBACjE,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;wBAC/C,OAAO,WAAW,CAAC,aAAa,CAAC;wBACjC,OAAO,WAAW,CAAC,QAAQ,CAAC;wBACtB,sBAAsB,GAA0C;4BACpE,IAAI,EAAE,QAAQ;4BACd,UAAU,EAAE;gCACV,IAAI,EAAE,0BAA0B,CAAC,QAAQ,CAAC,IAAI;6BAC/C;yBACF,CAAC;wBACI,YAAY,GAAyB;4BACzC,UAAU,EAAE,+BAA+B;4BAC3C,IAAI,EAAE,cAAc;4BACpB,QAAQ,EAAE,eAAe;4BACzB,IAAI,EAAE;gCACJ,OAAO,EAAE,IAAI;gCACb,YAAY,EAAE,KAAK;gCACnB,QAAQ,EAAE,WAAW;gCACrB,aAAa,EAAE,CAAC,sBAAsB,CAAC;6BACxC;yBACF,CAAC;wBAGI,qBAAqB,GAAG,CAAC,0BAA0B,CAAC,CAAC;wBAErD,OAAO,GAAG;4BACd,OAAO,SAAA;4BACP,YAAY,cAAA;4BACZ,qBAAqB,uBAAA;4BACrB,MAAM,QAAA;yBACP,CAAC;wBAEF,8DAA8D;wBAC9D,qBAAM,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,CAAC,EAAA;;wBADnG,8DAA8D;wBAC9D,SAAmG,CAAC;wBAEpG,sBAAO,OAAO,EAAC;;;;KAChB;IAEO,6CAA0B,GAAlC,UAAmC,OAAoB,EAAE,iBAAyB;QAAzB,kCAAA,EAAA,yBAAyB;QAChF,IAAM,oBAAoB,GAAG,EAAkC,CAAC;QAChE,IAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;QAEzC,IAAI,eAAe,CAAC,IAAI,EAAE;YACxB,oBAAoB,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;SAClD;QACD,IAAI,eAAe,CAAC,YAAY,EAAE;YAChC,oBAAoB,CAAC,YAAY,GAAG,eAAe,CAAC,YAAY,CAAC;SAClE;QACD,IAAI,iBAAiB,EAAE;YACrB,oBAAoB,CAAC,WAAW,GAAG;gBACjC,yBAAyB,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;aAChD,CAAC;SACH;QAED,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAnHD;QADC,IAAA,kBAAM,EAAC,4DAA2B,CAAC;yDAC6B;IAFtD,QAAQ;QADpB,IAAA,sBAAU,GAAE;OACA,QAAQ,CAsHpB;IAAD,eAAC;CAAA,AAtHD,IAsHC;AAtHY,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,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
|
+
}
|
|
@@ -30,11 +30,13 @@ var GithubResolver = /** @class */ (function () {
|
|
|
30
30
|
if (!match) {
|
|
31
31
|
throw new Error("Invalid github URL: " + link);
|
|
32
32
|
}
|
|
33
|
+
var scheme = this.getGroup(match, 'scheme');
|
|
34
|
+
var hostName = this.getGroup(match, 'host');
|
|
33
35
|
var repoUser = this.getGroup(match, 'repoUser');
|
|
34
36
|
var repoName = this.getGroup(match, 'repoName');
|
|
35
37
|
var branchName = this.getGroup(match, 'branchName', 'HEAD');
|
|
36
38
|
var subFolder = this.getGroup(match, 'subFolder');
|
|
37
|
-
return new github_url_1.GithubUrl(repoUser, repoName, branchName, subFolder);
|
|
39
|
+
return new github_url_1.GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder);
|
|
38
40
|
};
|
|
39
41
|
GithubResolver.prototype.getGroup = function (match, groupName, defaultValue) {
|
|
40
42
|
if (match.groups && match.groups[groupName]) {
|
|
@@ -44,7 +46,7 @@ var GithubResolver = /** @class */ (function () {
|
|
|
44
46
|
};
|
|
45
47
|
var GithubResolver_1;
|
|
46
48
|
// eslint-disable-next-line max-len
|
|
47
|
-
GithubResolver.GITHUB_URL_PATTERN = /^(
|
|
49
|
+
GithubResolver.GITHUB_URL_PATTERN = /^(?<scheme>https?):\/\/(?<host>github(\..+)?\.[^\/]+)\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?)?$/;
|
|
48
50
|
GithubResolver = GithubResolver_1 = __decorate([
|
|
49
51
|
(0, inversify_1.injectable)()
|
|
50
52
|
], GithubResolver);
|
|
@@ -1 +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;
|
|
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
|
+
}
|