@eclipse-che/che-devworkspace-generator 0.0.1-7784e80 → 0.0.1-bd2d989
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 +28 -0
- package/lib/api/devfile-context.d.ts +19 -0
- package/lib/devfile/dev-container-component-finder.d.ts +17 -0
- package/lib/devfile/devfile-module.d.ts +12 -0
- 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 +3 -0
- 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-url.d.ts +28 -0
- package/lib/inversify/inversify-binding.d.ts +26 -0
- package/lib/main.d.ts +34 -0
- package/lib/main.js +79 -52
- 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/package.json +6 -4
- package/src/generate.ts +8 -6
- package/src/main.ts +80 -45
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
## DevWorkspace Generator
|
|
2
|
+
The library is used by Devfile registry component to generate the DevWorkspace components and DevWorkspace templates.
|
|
3
|
+
|
|
4
|
+
## How to use the library
|
|
5
|
+
The library could be used as a standalone library.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
USAGE
|
|
9
|
+
$ node lib/entrypoint.js [OPTIONS]
|
|
10
|
+
|
|
11
|
+
OPTIONS
|
|
12
|
+
--devfile-path path to the devfile.yaml file
|
|
13
|
+
--devfile-url URL to the git repository that contains devfile.yaml
|
|
14
|
+
--plugin-registry-url URL to the plugin registry that contains an editor's definition
|
|
15
|
+
--editor-entry editor's ID
|
|
16
|
+
--editor-path: path to the editor's devfile.yaml file
|
|
17
|
+
--output-file path to the file where the generated content will be stored
|
|
18
|
+
--project. describes project entry
|
|
19
|
+
|
|
20
|
+
EXAMPLE
|
|
21
|
+
|
|
22
|
+
$ node lib/entrypoint.js --devfile-url:https://github.com/che-samples/java-spring-petclinic/tree/main --editor-entry:che-incubator/che-code/insiders --plugin-registry-url:https://che-plugin-registry-main.surge.sh/v3/ --output-file:/tmp/all-in-one.yaml`
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The file `/tmp/all-in-one.yaml` contains a DevWorkspace based on the repository devfile and a Che-Code DevWorkspaceTemplate.
|
|
26
|
+
If DevWorkspace engine is available on the cluster, the following command will create a DevWorkspace:
|
|
27
|
+
|
|
28
|
+
`$ kubectl apply -f /tmp/all-in-one.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,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
|
+
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
|
+
find(devfileContext: DevfileContext): Promise<V1alpha2DevWorkspaceSpecTemplateComponents | undefined>;
|
|
17
|
+
}
|
|
@@ -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 };
|
|
@@ -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
|
+
static readonly MERGE_CONTRIBUTION = "controller.devfile.io/merge-contribution";
|
|
13
|
+
private devContainerComponentFinder;
|
|
14
|
+
generate(devfileContent: string, editorContent: string, outputFile?: string): Promise<DevfileContext>;
|
|
15
|
+
generateContent(devfileContent: string, editorContent: string): Promise<DevfileContext>;
|
|
16
|
+
}
|
package/lib/generate.js
CHANGED
|
@@ -87,12 +87,15 @@ var Generate = /** @class */ (function () {
|
|
|
87
87
|
case 0: return [4 /*yield*/, this.generateContent(devfileContent, editorContent)];
|
|
88
88
|
case 1:
|
|
89
89
|
context = _a.sent();
|
|
90
|
+
if (!outputFile) return [3 /*break*/, 3];
|
|
90
91
|
allContentArray = context.devWorkspaceTemplates.map(function (template) { return jsYaml.dump(template); });
|
|
91
92
|
allContentArray.push(jsYaml.dump(context.devWorkspace));
|
|
92
93
|
generatedContent = allContentArray.join('---\n');
|
|
93
94
|
return [4 /*yield*/, fs.writeFile(outputFile, generatedContent, 'utf-8')];
|
|
94
95
|
case 2:
|
|
95
96
|
_a.sent();
|
|
97
|
+
_a.label = 3;
|
|
98
|
+
case 3:
|
|
96
99
|
console.log("DevWorkspace " + context.devWorkspaceTemplates[0].metadata.name + " was generated.");
|
|
97
100
|
return [2 /*return*/, context];
|
|
98
101
|
}
|
package/lib/generate.js.map
CHANGED
|
@@ -1 +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;
|
|
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;IA8FA,CAAC;iBA9FY,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,QAAQ,IAAI,OAAA,MAAM,CA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|
@@ -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
|
+
}
|
|
@@ -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
|
+
/**
|
|
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 repoUser;
|
|
15
|
+
private readonly repoName;
|
|
16
|
+
private readonly branchName;
|
|
17
|
+
private readonly subFolder;
|
|
18
|
+
static readonly RAW_LINK = "https://raw.githubusercontent.com";
|
|
19
|
+
constructor(repoUser: string, repoName: string, branchName: string, subFolder: string);
|
|
20
|
+
/**
|
|
21
|
+
* Provides the raw link to the given path based on the current repository information
|
|
22
|
+
*/
|
|
23
|
+
getContentUrl(path: string): string;
|
|
24
|
+
getUrl(): string;
|
|
25
|
+
getCloneUrl(): string;
|
|
26
|
+
getRepoName(): string;
|
|
27
|
+
getBranchName(): string;
|
|
28
|
+
}
|
|
@@ -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
|
+
}
|
package/lib/main.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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 Main {
|
|
12
|
+
/**
|
|
13
|
+
* Default constructor.
|
|
14
|
+
*/
|
|
15
|
+
constructor();
|
|
16
|
+
generateDevfileContext(params: {
|
|
17
|
+
devfilePath?: string;
|
|
18
|
+
devfileUrl?: string;
|
|
19
|
+
devfileContent?: string;
|
|
20
|
+
outputFile?: string;
|
|
21
|
+
editorPath?: string;
|
|
22
|
+
pluginRegistryUrl?: string;
|
|
23
|
+
editorEntry?: string;
|
|
24
|
+
projects: {
|
|
25
|
+
name: string;
|
|
26
|
+
location: string;
|
|
27
|
+
}[];
|
|
28
|
+
}): Promise<DevfileContext>;
|
|
29
|
+
replaceIfExistingProjects(devfileContent: string, projects: {
|
|
30
|
+
name: string;
|
|
31
|
+
location: string;
|
|
32
|
+
}[]): string;
|
|
33
|
+
start(): Promise<boolean>;
|
|
34
|
+
}
|
package/lib/main.js
CHANGED
|
@@ -74,55 +74,30 @@ var inversify_binding_1 = require("./inversify/inversify-binding");
|
|
|
74
74
|
var url_fetcher_1 = require("./fetch/url-fetcher");
|
|
75
75
|
var plugin_registry_resolver_1 = require("./plugin-registry/plugin-registry-resolver");
|
|
76
76
|
var Main = /** @class */ (function () {
|
|
77
|
+
/**
|
|
78
|
+
* Default constructor.
|
|
79
|
+
*/
|
|
77
80
|
function Main() {
|
|
81
|
+
// no-op
|
|
78
82
|
}
|
|
79
|
-
|
|
83
|
+
// Generates a devfile context object based on params
|
|
84
|
+
Main.prototype.generateDevfileContext = function (params) {
|
|
80
85
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects,
|
|
86
|
+
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, axiosInstance, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate;
|
|
82
87
|
return __generator(this, function (_a) {
|
|
83
88
|
switch (_a.label) {
|
|
84
89
|
case 0:
|
|
85
|
-
projects =
|
|
86
|
-
args = process.argv.slice(2);
|
|
87
|
-
args.forEach(function (arg) {
|
|
88
|
-
if (arg.startsWith('--devfile-path:')) {
|
|
89
|
-
devfilePath = arg.substring('--devfile-path:'.length);
|
|
90
|
-
}
|
|
91
|
-
if (arg.startsWith('--devfile-url:')) {
|
|
92
|
-
devfileUrl = arg.substring('--devfile-url:'.length);
|
|
93
|
-
}
|
|
94
|
-
if (arg.startsWith('--plugin-registry-url:')) {
|
|
95
|
-
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
|
|
96
|
-
}
|
|
97
|
-
if (arg.startsWith('--editor-entry:')) {
|
|
98
|
-
editorEntry = arg.substring('--editor-entry:'.length);
|
|
99
|
-
}
|
|
100
|
-
if (arg.startsWith('--editor-path:')) {
|
|
101
|
-
editorPath = arg.substring('--editor-path:'.length);
|
|
102
|
-
}
|
|
103
|
-
if (arg.startsWith('--output-file:')) {
|
|
104
|
-
outputFile = arg.substring('--output-file:'.length);
|
|
105
|
-
}
|
|
106
|
-
if (arg.startsWith('--project.')) {
|
|
107
|
-
var name = arg.substring('--project.'.length, arg.indexOf('='));
|
|
108
|
-
var location = arg.substring(arg.indexOf('=') + 1);
|
|
109
|
-
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
|
|
110
|
-
projects.push({ name: name, location: location });
|
|
111
|
-
}
|
|
112
|
-
});
|
|
90
|
+
devfilePath = params.devfilePath, devfileUrl = params.devfileUrl, outputFile = params.outputFile, editorPath = params.editorPath, pluginRegistryUrl = params.pluginRegistryUrl, editorEntry = params.editorEntry, projects = params.projects;
|
|
113
91
|
if (!editorPath && !editorEntry) {
|
|
114
|
-
throw new Error('missing
|
|
92
|
+
throw new Error('missing editorPath or editorEntry');
|
|
93
|
+
}
|
|
94
|
+
if (!devfilePath && !devfileUrl && !params.devfileContent) {
|
|
95
|
+
throw new Error('missing devfilePath or devfileUrl or devfileContent');
|
|
115
96
|
}
|
|
116
97
|
if (editorEntry && !pluginRegistryUrl) {
|
|
117
98
|
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
|
|
118
99
|
console.log("No plug-in registry url. Setting to " + pluginRegistryUrl);
|
|
119
100
|
}
|
|
120
|
-
if (!devfilePath && !devfileUrl) {
|
|
121
|
-
throw new Error('missing --devfile-path: or --devfile-url: parameter');
|
|
122
|
-
}
|
|
123
|
-
if (!outputFile) {
|
|
124
|
-
throw new Error('missing --output-file: parameter');
|
|
125
|
-
}
|
|
126
101
|
axiosInstance = axios["default"];
|
|
127
102
|
inversifyBinbding = new inversify_binding_1.InversifyBinding();
|
|
128
103
|
return [4 /*yield*/, inversifyBinbding.initBindings({
|
|
@@ -155,25 +130,30 @@ var Main = /** @class */ (function () {
|
|
|
155
130
|
}
|
|
156
131
|
// get back the content
|
|
157
132
|
devfileContent = jsYaml.dump(devfileParsed);
|
|
158
|
-
return [3 /*break*/,
|
|
159
|
-
case 3:
|
|
133
|
+
return [3 /*break*/, 6];
|
|
134
|
+
case 3:
|
|
135
|
+
if (!devfilePath) return [3 /*break*/, 5];
|
|
136
|
+
return [4 /*yield*/, fs.readFile(devfilePath)];
|
|
160
137
|
case 4:
|
|
161
138
|
devfileContent = _a.sent();
|
|
162
|
-
|
|
139
|
+
return [3 /*break*/, 6];
|
|
163
140
|
case 5:
|
|
141
|
+
devfileContent = params.devfileContent;
|
|
142
|
+
_a.label = 6;
|
|
143
|
+
case 6:
|
|
164
144
|
// enhance projects
|
|
165
145
|
devfileContent = this.replaceIfExistingProjects(devfileContent, projects);
|
|
166
|
-
if (!editorEntry) return [3 /*break*/,
|
|
146
|
+
if (!editorEntry) return [3 /*break*/, 8];
|
|
167
147
|
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(editorEntry)];
|
|
168
|
-
case
|
|
148
|
+
case 7:
|
|
169
149
|
editorDevfile = _a.sent();
|
|
170
150
|
editorContent = jsYaml.dump(editorDevfile);
|
|
171
|
-
return [3 /*break*/,
|
|
172
|
-
case
|
|
173
|
-
case 8:
|
|
174
|
-
editorContent = _a.sent();
|
|
175
|
-
_a.label = 9;
|
|
151
|
+
return [3 /*break*/, 10];
|
|
152
|
+
case 8: return [4 /*yield*/, fs.readFile(editorPath)];
|
|
176
153
|
case 9:
|
|
154
|
+
editorContent = _a.sent();
|
|
155
|
+
_a.label = 10;
|
|
156
|
+
case 10:
|
|
177
157
|
generate = container.get(generate_1.Generate);
|
|
178
158
|
return [2 /*return*/, generate.generate(devfileContent, editorContent, outputFile)];
|
|
179
159
|
}
|
|
@@ -208,21 +188,68 @@ var Main = /** @class */ (function () {
|
|
|
208
188
|
};
|
|
209
189
|
Main.prototype.start = function () {
|
|
210
190
|
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
-
var error_1;
|
|
191
|
+
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, error_1;
|
|
212
192
|
return __generator(this, function (_a) {
|
|
213
193
|
switch (_a.label) {
|
|
214
194
|
case 0:
|
|
215
|
-
|
|
216
|
-
|
|
195
|
+
projects = [];
|
|
196
|
+
args = process.argv.slice(2);
|
|
197
|
+
args.forEach(function (arg) {
|
|
198
|
+
if (arg.startsWith('--devfile-path:')) {
|
|
199
|
+
devfilePath = arg.substring('--devfile-path:'.length);
|
|
200
|
+
}
|
|
201
|
+
if (arg.startsWith('--devfile-url:')) {
|
|
202
|
+
devfileUrl = arg.substring('--devfile-url:'.length);
|
|
203
|
+
}
|
|
204
|
+
if (arg.startsWith('--plugin-registry-url:')) {
|
|
205
|
+
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
|
|
206
|
+
}
|
|
207
|
+
if (arg.startsWith('--editor-entry:')) {
|
|
208
|
+
editorEntry = arg.substring('--editor-entry:'.length);
|
|
209
|
+
}
|
|
210
|
+
if (arg.startsWith('--editor-path:')) {
|
|
211
|
+
editorPath = arg.substring('--editor-path:'.length);
|
|
212
|
+
}
|
|
213
|
+
if (arg.startsWith('--output-file:')) {
|
|
214
|
+
outputFile = arg.substring('--output-file:'.length);
|
|
215
|
+
}
|
|
216
|
+
if (arg.startsWith('--project.')) {
|
|
217
|
+
var name = arg.substring('--project.'.length, arg.indexOf('='));
|
|
218
|
+
var location = arg.substring(arg.indexOf('=') + 1);
|
|
219
|
+
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
|
|
220
|
+
projects.push({ name: name, location: location });
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
_a.label = 1;
|
|
217
224
|
case 1:
|
|
225
|
+
_a.trys.push([1, 3, , 4]);
|
|
226
|
+
if (!editorPath && !editorEntry) {
|
|
227
|
+
throw new Error('missing --editor-path: or --editor-entry: parameter');
|
|
228
|
+
}
|
|
229
|
+
if (!devfilePath && !devfileUrl) {
|
|
230
|
+
throw new Error('missing --devfile-path: or --devfile-url: parameter');
|
|
231
|
+
}
|
|
232
|
+
if (!outputFile) {
|
|
233
|
+
throw new Error('missing --output-file: parameter');
|
|
234
|
+
}
|
|
235
|
+
return [4 /*yield*/, this.generateDevfileContext({
|
|
236
|
+
devfilePath: devfilePath,
|
|
237
|
+
devfileUrl: devfileUrl,
|
|
238
|
+
editorPath: editorPath,
|
|
239
|
+
outputFile: outputFile,
|
|
240
|
+
pluginRegistryUrl: pluginRegistryUrl,
|
|
241
|
+
editorEntry: editorEntry,
|
|
242
|
+
projects: projects
|
|
243
|
+
})];
|
|
244
|
+
case 2:
|
|
218
245
|
_a.sent();
|
|
219
246
|
return [2 /*return*/, true];
|
|
220
|
-
case
|
|
247
|
+
case 3:
|
|
221
248
|
error_1 = _a.sent();
|
|
222
249
|
console.error('stack=' + error_1.stack);
|
|
223
250
|
console.error('Unable to start', error_1);
|
|
224
251
|
return [2 /*return*/, false];
|
|
225
|
-
case
|
|
252
|
+
case 4: return [2 /*return*/];
|
|
226
253
|
}
|
|
227
254
|
});
|
|
228
255
|
});
|
package/lib/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzE,2CAA+B;AAC/B,2CAA+B;AAC/B,uCAAsC;AACtC,4DAA0D;AAC1D,8CAAkC;AAClC,mEAAiE;AACjE,mDAAiD;AACjD,uFAAoF;AAIpF;
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAAA;;;;;;;;yEAQyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEzE,2CAA+B;AAC/B,2CAA+B;AAC/B,uCAAsC;AACtC,4DAA0D;AAC1D,8CAAkC;AAClC,mEAAiE;AACjE,mDAAiD;AACjD,uFAAoF;AAIpF;IACE;;OAEG;IACH;QACE,QAAQ;IACV,CAAC;IACD,qDAAqD;IACxC,qCAAsB,GAAnC,UAAoC,MASnC;;;;;;wBACO,WAAW,GAAmF,MAAM,YAAzF,EAAE,UAAU,GAAuE,MAAM,WAA7E,EAAE,UAAU,GAA2D,MAAM,WAAjE,EAAE,UAAU,GAA+C,MAAM,WAArD,EAAE,iBAAiB,GAA4B,MAAM,kBAAlC,EAAE,WAAW,GAAe,MAAM,YAArB,EAAE,QAAQ,GAAK,MAAM,SAAX,CAAY;wBAE3G,IAAI,CAAC,UAAU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AC,qDAAqD,CAAC,CAAC;yBACxE;wBACD,IAAI,CAAC,UAAU,EAAE;4BACf,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;yBACrD;wBACD,qBAAM,IAAI,CAAC,sBAAsB,CAAC;gCAChC,WAAW,aAAA;gCACX,UAAU,YAAA;gCACV,UAAU,YAAA;gCACV,UAAU,YAAA;gCACV,iBAAiB,mBAAA;gCACjB,WAAW,aAAA;gCACX,QAAQ,UAAA;6BACT,CAAC,EAAA;;wBARF,SAQE,CAAC;wBACH,sBAAO,IAAI,EAAC;;;wBAEZ,OAAO,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAK,CAAC,KAAK,CAAC,CAAC;wBACtC,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,OAAK,CAAC,CAAC;wBACxC,sBAAO,KAAK,EAAC;;;;;KAEhB;IACH,WAAC;AAAD,CAAC,AAnLD,IAmLC;AAnLY,oBAAI"}
|
|
@@ -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,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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eclipse-che/che-devworkspace-generator",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-bd2d989",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Generates DevWorkspaces by transforming existing devfiles",
|
|
6
6
|
"main": "lib/entrypoint.js",
|
|
@@ -18,13 +18,15 @@
|
|
|
18
18
|
"prepare": "yarn run clean && yarn run build",
|
|
19
19
|
"clean": "rimraf lib",
|
|
20
20
|
"build": "yarn run format && yarn run compile && yarn run lint && yarn run test",
|
|
21
|
-
"compile": "tsc --project .",
|
|
21
|
+
"compile": "tsc --declaration --project .",
|
|
22
22
|
"format": "if-env SKIP_FORMAT=true && echo 'skip format check' || prettier --check '{src,tests}/**/*.ts' package.json",
|
|
23
23
|
"format:fix": "prettier --write '{src,tests}/**/*.ts' package.json",
|
|
24
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|**)/*.
|
|
25
|
+
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/(!model|**)/*.ts\"",
|
|
26
26
|
"test": "if-env SKIP_TEST=true && echo 'skip test' || jest --forceExit",
|
|
27
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",
|
|
28
30
|
"publish:next": "yarn publish --registry=https://registry.npmjs.org/ --no-git-tag-version --new-version 0.0.1-\"$(date +%s)\""
|
|
29
31
|
},
|
|
30
32
|
"repository": {
|
|
@@ -72,7 +74,7 @@
|
|
|
72
74
|
"clearMocks": true,
|
|
73
75
|
"collectCoverage": true,
|
|
74
76
|
"collectCoverageFrom": [
|
|
75
|
-
"src/**/*.
|
|
77
|
+
"src/**/*.ts"
|
|
76
78
|
],
|
|
77
79
|
"coverageThreshold": {
|
|
78
80
|
"global": {
|
package/src/generate.ts
CHANGED
|
@@ -28,17 +28,19 @@ export class Generate {
|
|
|
28
28
|
@inject(DevContainerComponentFinder)
|
|
29
29
|
private devContainerComponentFinder: DevContainerComponentFinder;
|
|
30
30
|
|
|
31
|
-
async generate(devfileContent: string, editorContent: string, outputFile
|
|
31
|
+
async generate(devfileContent: string, editorContent: string, outputFile?: string): Promise<DevfileContext> {
|
|
32
32
|
const context = await this.generateContent(devfileContent, editorContent);
|
|
33
33
|
|
|
34
34
|
// write the result
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (outputFile) {
|
|
36
|
+
// write templates and then DevWorkspace in a single file
|
|
37
|
+
const allContentArray = context.devWorkspaceTemplates.map(template => jsYaml.dump(template));
|
|
38
|
+
allContentArray.push(jsYaml.dump(context.devWorkspace));
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
const generatedContent = allContentArray.join('---\n');
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
await fs.writeFile(outputFile, generatedContent, 'utf-8');
|
|
43
|
+
}
|
|
42
44
|
|
|
43
45
|
console.log(`DevWorkspace ${context.devWorkspaceTemplates[0].metadata.name} was generated.`);
|
|
44
46
|
return context;
|
package/src/main.ts
CHANGED
|
@@ -20,56 +20,35 @@ import { V1alpha2DevWorkspaceSpecTemplate } from '@devfile/api';
|
|
|
20
20
|
import { DevfileContext } from './api/devfile-context';
|
|
21
21
|
|
|
22
22
|
export class Main {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
|
|
42
|
-
}
|
|
43
|
-
if (arg.startsWith('--editor-entry:')) {
|
|
44
|
-
editorEntry = arg.substring('--editor-entry:'.length);
|
|
45
|
-
}
|
|
46
|
-
if (arg.startsWith('--editor-path:')) {
|
|
47
|
-
editorPath = arg.substring('--editor-path:'.length);
|
|
48
|
-
}
|
|
49
|
-
if (arg.startsWith('--output-file:')) {
|
|
50
|
-
outputFile = arg.substring('--output-file:'.length);
|
|
51
|
-
}
|
|
52
|
-
if (arg.startsWith('--project.')) {
|
|
53
|
-
const name = arg.substring('--project.'.length, arg.indexOf('='));
|
|
54
|
-
let location = arg.substring(arg.indexOf('=') + 1);
|
|
55
|
-
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
|
|
23
|
+
/**
|
|
24
|
+
* Default constructor.
|
|
25
|
+
*/
|
|
26
|
+
constructor() {
|
|
27
|
+
// no-op
|
|
28
|
+
}
|
|
29
|
+
// Generates a devfile context object based on params
|
|
30
|
+
public async generateDevfileContext(params: {
|
|
31
|
+
devfilePath?: string;
|
|
32
|
+
devfileUrl?: string;
|
|
33
|
+
devfileContent?: string;
|
|
34
|
+
outputFile?: string;
|
|
35
|
+
editorPath?: string;
|
|
36
|
+
pluginRegistryUrl?: string;
|
|
37
|
+
editorEntry?: string;
|
|
38
|
+
projects: { name: string; location: string }[];
|
|
39
|
+
}): Promise<DevfileContext> {
|
|
40
|
+
let { devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects } = params;
|
|
56
41
|
|
|
57
|
-
projects.push({ name, location });
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
42
|
if (!editorPath && !editorEntry) {
|
|
61
|
-
throw new Error('missing
|
|
43
|
+
throw new Error('missing editorPath or editorEntry');
|
|
44
|
+
}
|
|
45
|
+
if (!devfilePath && !devfileUrl && !params.devfileContent) {
|
|
46
|
+
throw new Error('missing devfilePath or devfileUrl or devfileContent');
|
|
62
47
|
}
|
|
63
48
|
if (editorEntry && !pluginRegistryUrl) {
|
|
64
49
|
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
|
|
65
50
|
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`);
|
|
66
51
|
}
|
|
67
|
-
if (!devfilePath && !devfileUrl) {
|
|
68
|
-
throw new Error('missing --devfile-path: or --devfile-url: parameter');
|
|
69
|
-
}
|
|
70
|
-
if (!outputFile) {
|
|
71
|
-
throw new Error('missing --output-file: parameter');
|
|
72
|
-
}
|
|
73
52
|
|
|
74
53
|
const axiosInstance = axios.default;
|
|
75
54
|
const inversifyBinbding = new InversifyBinding();
|
|
@@ -107,8 +86,10 @@ export class Main {
|
|
|
107
86
|
}
|
|
108
87
|
// get back the content
|
|
109
88
|
devfileContent = jsYaml.dump(devfileParsed);
|
|
110
|
-
} else {
|
|
89
|
+
} else if (devfilePath) {
|
|
111
90
|
devfileContent = await fs.readFile(devfilePath);
|
|
91
|
+
} else {
|
|
92
|
+
devfileContent = params.devfileContent;
|
|
112
93
|
}
|
|
113
94
|
|
|
114
95
|
// enhance projects
|
|
@@ -154,8 +135,62 @@ export class Main {
|
|
|
154
135
|
}
|
|
155
136
|
|
|
156
137
|
async start(): Promise<boolean> {
|
|
138
|
+
let devfilePath: string | undefined;
|
|
139
|
+
let devfileUrl: string | undefined;
|
|
140
|
+
let outputFile: string | undefined;
|
|
141
|
+
let editorPath: string | undefined;
|
|
142
|
+
let pluginRegistryUrl: string | undefined;
|
|
143
|
+
let editorEntry: string | undefined;
|
|
144
|
+
const projects: { name: string; location: string }[] = [];
|
|
145
|
+
|
|
146
|
+
const args = process.argv.slice(2);
|
|
147
|
+
args.forEach(arg => {
|
|
148
|
+
if (arg.startsWith('--devfile-path:')) {
|
|
149
|
+
devfilePath = arg.substring('--devfile-path:'.length);
|
|
150
|
+
}
|
|
151
|
+
if (arg.startsWith('--devfile-url:')) {
|
|
152
|
+
devfileUrl = arg.substring('--devfile-url:'.length);
|
|
153
|
+
}
|
|
154
|
+
if (arg.startsWith('--plugin-registry-url:')) {
|
|
155
|
+
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
|
|
156
|
+
}
|
|
157
|
+
if (arg.startsWith('--editor-entry:')) {
|
|
158
|
+
editorEntry = arg.substring('--editor-entry:'.length);
|
|
159
|
+
}
|
|
160
|
+
if (arg.startsWith('--editor-path:')) {
|
|
161
|
+
editorPath = arg.substring('--editor-path:'.length);
|
|
162
|
+
}
|
|
163
|
+
if (arg.startsWith('--output-file:')) {
|
|
164
|
+
outputFile = arg.substring('--output-file:'.length);
|
|
165
|
+
}
|
|
166
|
+
if (arg.startsWith('--project.')) {
|
|
167
|
+
const name = arg.substring('--project.'.length, arg.indexOf('='));
|
|
168
|
+
let location = arg.substring(arg.indexOf('=') + 1);
|
|
169
|
+
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
|
|
170
|
+
|
|
171
|
+
projects.push({ name, location });
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
157
175
|
try {
|
|
158
|
-
|
|
176
|
+
if (!editorPath && !editorEntry) {
|
|
177
|
+
throw new Error('missing --editor-path: or --editor-entry: parameter');
|
|
178
|
+
}
|
|
179
|
+
if (!devfilePath && !devfileUrl) {
|
|
180
|
+
throw new Error('missing --devfile-path: or --devfile-url: parameter');
|
|
181
|
+
}
|
|
182
|
+
if (!outputFile) {
|
|
183
|
+
throw new Error('missing --output-file: parameter');
|
|
184
|
+
}
|
|
185
|
+
await this.generateDevfileContext({
|
|
186
|
+
devfilePath,
|
|
187
|
+
devfileUrl,
|
|
188
|
+
editorPath,
|
|
189
|
+
outputFile,
|
|
190
|
+
pluginRegistryUrl,
|
|
191
|
+
editorEntry,
|
|
192
|
+
projects,
|
|
193
|
+
});
|
|
159
194
|
return true;
|
|
160
195
|
} catch (error) {
|
|
161
196
|
console.error('stack=' + error.stack);
|