@eclipse-che/che-devworkspace-generator 0.0.1-7784e80 → 0.0.1-96cdbb4
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 +36 -0
- package/lib/main.js +92 -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/package.json +6 -4
- package/src/generate.ts +8 -6
- package/src/main.ts +101 -55
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,C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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,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
|
+
}
|
package/lib/main.js
CHANGED
|
@@ -74,56 +74,32 @@ 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, axiosInstance) {
|
|
80
85
|
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
-
var
|
|
86
|
+
var pluginRegistryUrl, 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
|
-
|
|
86
|
-
|
|
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
|
-
});
|
|
113
|
-
if (!editorPath && !editorEntry) {
|
|
114
|
-
throw new Error('missing --editor-path: or --editor-entry: parameter');
|
|
90
|
+
if (!params.editorPath && !params.editorEntry && !params.editorContent) {
|
|
91
|
+
throw new Error('missing editorPath or editorEntry or editorContent');
|
|
115
92
|
}
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
console.log("No plug-in registry url. Setting to " + pluginRegistryUrl);
|
|
93
|
+
if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) {
|
|
94
|
+
throw new Error('missing devfilePath or devfileUrl or devfileContent');
|
|
119
95
|
}
|
|
120
|
-
if (
|
|
121
|
-
|
|
96
|
+
if (params.pluginRegistryUrl) {
|
|
97
|
+
pluginRegistryUrl = params.pluginRegistryUrl;
|
|
122
98
|
}
|
|
123
|
-
|
|
124
|
-
|
|
99
|
+
else {
|
|
100
|
+
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
|
|
101
|
+
console.log("No plug-in registry url. Setting to " + pluginRegistryUrl);
|
|
125
102
|
}
|
|
126
|
-
axiosInstance = axios["default"];
|
|
127
103
|
inversifyBinbding = new inversify_binding_1.InversifyBinding();
|
|
128
104
|
return [4 /*yield*/, inversifyBinbding.initBindings({
|
|
129
105
|
pluginRegistryUrl: pluginRegistryUrl,
|
|
@@ -132,9 +108,9 @@ var Main = /** @class */ (function () {
|
|
|
132
108
|
case 1:
|
|
133
109
|
container = _a.sent();
|
|
134
110
|
container.bind(generate_1.Generate).toSelf().inSingletonScope();
|
|
135
|
-
if (!devfileUrl) return [3 /*break*/, 3];
|
|
111
|
+
if (!params.devfileUrl) return [3 /*break*/, 3];
|
|
136
112
|
githubResolver = container.get(github_resolver_1.GithubResolver);
|
|
137
|
-
githubUrl = githubResolver.resolve(devfileUrl);
|
|
113
|
+
githubUrl = githubResolver.resolve(params.devfileUrl);
|
|
138
114
|
return [4 /*yield*/, container.get(url_fetcher_1.UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml'))];
|
|
139
115
|
case 2:
|
|
140
116
|
// user devfile
|
|
@@ -155,27 +131,36 @@ var Main = /** @class */ (function () {
|
|
|
155
131
|
}
|
|
156
132
|
// get back the content
|
|
157
133
|
devfileContent = jsYaml.dump(devfileParsed);
|
|
158
|
-
return [3 /*break*/,
|
|
159
|
-
case 3:
|
|
134
|
+
return [3 /*break*/, 6];
|
|
135
|
+
case 3:
|
|
136
|
+
if (!params.devfilePath) return [3 /*break*/, 5];
|
|
137
|
+
return [4 /*yield*/, fs.readFile(params.devfilePath)];
|
|
160
138
|
case 4:
|
|
161
139
|
devfileContent = _a.sent();
|
|
162
|
-
|
|
140
|
+
return [3 /*break*/, 6];
|
|
163
141
|
case 5:
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (!editorEntry) return [3 /*break*/, 7];
|
|
167
|
-
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(editorEntry)];
|
|
142
|
+
devfileContent = params.devfileContent;
|
|
143
|
+
_a.label = 6;
|
|
168
144
|
case 6:
|
|
145
|
+
// enhance projects
|
|
146
|
+
devfileContent = this.replaceIfExistingProjects(devfileContent, params.projects);
|
|
147
|
+
if (!params.editorContent) return [3 /*break*/, 7];
|
|
148
|
+
editorContent = params.editorContent;
|
|
149
|
+
return [3 /*break*/, 11];
|
|
150
|
+
case 7:
|
|
151
|
+
if (!params.editorEntry) return [3 /*break*/, 9];
|
|
152
|
+
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(params.editorEntry)];
|
|
153
|
+
case 8:
|
|
169
154
|
editorDevfile = _a.sent();
|
|
170
155
|
editorContent = jsYaml.dump(editorDevfile);
|
|
171
|
-
return [3 /*break*/,
|
|
172
|
-
case
|
|
173
|
-
case
|
|
156
|
+
return [3 /*break*/, 11];
|
|
157
|
+
case 9: return [4 /*yield*/, fs.readFile(params.editorPath)];
|
|
158
|
+
case 10:
|
|
174
159
|
editorContent = _a.sent();
|
|
175
|
-
_a.label =
|
|
176
|
-
case
|
|
160
|
+
_a.label = 11;
|
|
161
|
+
case 11:
|
|
177
162
|
generate = container.get(generate_1.Generate);
|
|
178
|
-
return [2 /*return*/, generate.generate(devfileContent, editorContent, outputFile)];
|
|
163
|
+
return [2 /*return*/, generate.generate(devfileContent, editorContent, params.outputFile)];
|
|
179
164
|
}
|
|
180
165
|
});
|
|
181
166
|
});
|
|
@@ -208,21 +193,68 @@ var Main = /** @class */ (function () {
|
|
|
208
193
|
};
|
|
209
194
|
Main.prototype.start = function () {
|
|
210
195
|
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
-
var error_1;
|
|
196
|
+
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, error_1;
|
|
212
197
|
return __generator(this, function (_a) {
|
|
213
198
|
switch (_a.label) {
|
|
214
199
|
case 0:
|
|
215
|
-
|
|
216
|
-
|
|
200
|
+
projects = [];
|
|
201
|
+
args = process.argv.slice(2);
|
|
202
|
+
args.forEach(function (arg) {
|
|
203
|
+
if (arg.startsWith('--devfile-path:')) {
|
|
204
|
+
devfilePath = arg.substring('--devfile-path:'.length);
|
|
205
|
+
}
|
|
206
|
+
if (arg.startsWith('--devfile-url:')) {
|
|
207
|
+
devfileUrl = arg.substring('--devfile-url:'.length);
|
|
208
|
+
}
|
|
209
|
+
if (arg.startsWith('--plugin-registry-url:')) {
|
|
210
|
+
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
|
|
211
|
+
}
|
|
212
|
+
if (arg.startsWith('--editor-entry:')) {
|
|
213
|
+
editorEntry = arg.substring('--editor-entry:'.length);
|
|
214
|
+
}
|
|
215
|
+
if (arg.startsWith('--editor-path:')) {
|
|
216
|
+
editorPath = arg.substring('--editor-path:'.length);
|
|
217
|
+
}
|
|
218
|
+
if (arg.startsWith('--output-file:')) {
|
|
219
|
+
outputFile = arg.substring('--output-file:'.length);
|
|
220
|
+
}
|
|
221
|
+
if (arg.startsWith('--project.')) {
|
|
222
|
+
var name = arg.substring('--project.'.length, arg.indexOf('='));
|
|
223
|
+
var location = arg.substring(arg.indexOf('=') + 1);
|
|
224
|
+
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
|
|
225
|
+
projects.push({ name: name, location: location });
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
_a.label = 1;
|
|
217
229
|
case 1:
|
|
230
|
+
_a.trys.push([1, 3, , 4]);
|
|
231
|
+
if (!editorPath && !editorEntry) {
|
|
232
|
+
throw new Error('missing --editor-path: or --editor-entry: parameter');
|
|
233
|
+
}
|
|
234
|
+
if (!devfilePath && !devfileUrl) {
|
|
235
|
+
throw new Error('missing --devfile-path: or --devfile-url: parameter');
|
|
236
|
+
}
|
|
237
|
+
if (!outputFile) {
|
|
238
|
+
throw new Error('missing --output-file: parameter');
|
|
239
|
+
}
|
|
240
|
+
return [4 /*yield*/, this.generateDevfileContext({
|
|
241
|
+
devfilePath: devfilePath,
|
|
242
|
+
devfileUrl: devfileUrl,
|
|
243
|
+
editorPath: editorPath,
|
|
244
|
+
outputFile: outputFile,
|
|
245
|
+
pluginRegistryUrl: pluginRegistryUrl,
|
|
246
|
+
editorEntry: editorEntry,
|
|
247
|
+
projects: projects
|
|
248
|
+
}, axios["default"])];
|
|
249
|
+
case 2:
|
|
218
250
|
_a.sent();
|
|
219
251
|
return [2 /*return*/, true];
|
|
220
|
-
case
|
|
252
|
+
case 3:
|
|
221
253
|
error_1 = _a.sent();
|
|
222
254
|
console.error('stack=' + error_1.stack);
|
|
223
255
|
console.error('Unable to start', error_1);
|
|
224
256
|
return [2 /*return*/, false];
|
|
225
|
-
case
|
|
257
|
+
case 4: return [2 /*return*/];
|
|
226
258
|
}
|
|
227
259
|
});
|
|
228
260
|
});
|
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+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G,OAAK,CAAC,KAAK,CAAC,CAAC;wBACtC,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,OAAK,CAAC,CAAC;wBACxC,sBAAO,KAAK,EAAC;;;;;KAEhB;IACH,WAAC;AAAD,CAAC,AA9LD,IA8LC;AA9LY,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-96cdbb4",
|
|
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,58 +20,43 @@ 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
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Default constructor.
|
|
25
|
+
*/
|
|
26
|
+
constructor() {
|
|
27
|
+
// no-op
|
|
28
|
+
}
|
|
29
|
+
// Generates a devfile context object based on params
|
|
30
|
+
public async generateDevfileContext(
|
|
31
|
+
params: {
|
|
32
|
+
devfilePath?: string;
|
|
33
|
+
devfileUrl?: string;
|
|
34
|
+
devfileContent?: string;
|
|
35
|
+
outputFile?: string;
|
|
36
|
+
editorPath?: string;
|
|
37
|
+
editorContent?: string;
|
|
38
|
+
editorEntry?: string;
|
|
39
|
+
pluginRegistryUrl?: string;
|
|
40
|
+
projects: { name: string; location: string }[];
|
|
41
|
+
},
|
|
42
|
+
axiosInstance: axios.AxiosInstance
|
|
43
|
+
): Promise<DevfileContext> {
|
|
44
|
+
if (!params.editorPath && !params.editorEntry && !params.editorContent) {
|
|
45
|
+
throw new Error('missing editorPath or editorEntry or editorContent');
|
|
46
|
+
}
|
|
47
|
+
if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) {
|
|
48
|
+
throw new Error('missing devfilePath or devfileUrl or devfileContent');
|
|
49
|
+
}
|
|
31
50
|
|
|
32
|
-
|
|
33
|
-
args.forEach(arg => {
|
|
34
|
-
if (arg.startsWith('--devfile-path:')) {
|
|
35
|
-
devfilePath = arg.substring('--devfile-path:'.length);
|
|
36
|
-
}
|
|
37
|
-
if (arg.startsWith('--devfile-url:')) {
|
|
38
|
-
devfileUrl = arg.substring('--devfile-url:'.length);
|
|
39
|
-
}
|
|
40
|
-
if (arg.startsWith('--plugin-registry-url:')) {
|
|
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 }}');
|
|
51
|
+
let pluginRegistryUrl: string;
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
if (!editorPath && !editorEntry) {
|
|
61
|
-
throw new Error('missing --editor-path: or --editor-entry: parameter');
|
|
62
|
-
}
|
|
63
|
-
if (editorEntry && !pluginRegistryUrl) {
|
|
53
|
+
if (params.pluginRegistryUrl) {
|
|
54
|
+
pluginRegistryUrl = params.pluginRegistryUrl;
|
|
55
|
+
} else {
|
|
64
56
|
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
|
|
65
57
|
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`);
|
|
66
58
|
}
|
|
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
59
|
|
|
74
|
-
const axiosInstance = axios.default;
|
|
75
60
|
const inversifyBinbding = new InversifyBinding();
|
|
76
61
|
const container = await inversifyBinbding.initBindings({
|
|
77
62
|
pluginRegistryUrl,
|
|
@@ -83,9 +68,9 @@ export class Main {
|
|
|
83
68
|
let editorContent;
|
|
84
69
|
|
|
85
70
|
// gets the github URL
|
|
86
|
-
if (devfileUrl) {
|
|
71
|
+
if (params.devfileUrl) {
|
|
87
72
|
const githubResolver = container.get(GithubResolver);
|
|
88
|
-
const githubUrl = githubResolver.resolve(devfileUrl);
|
|
73
|
+
const githubUrl = githubResolver.resolve(params.devfileUrl);
|
|
89
74
|
// user devfile
|
|
90
75
|
devfileContent = await container.get(UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml'));
|
|
91
76
|
|
|
@@ -107,23 +92,27 @@ export class Main {
|
|
|
107
92
|
}
|
|
108
93
|
// get back the content
|
|
109
94
|
devfileContent = jsYaml.dump(devfileParsed);
|
|
95
|
+
} else if (params.devfilePath) {
|
|
96
|
+
devfileContent = await fs.readFile(params.devfilePath);
|
|
110
97
|
} else {
|
|
111
|
-
devfileContent =
|
|
98
|
+
devfileContent = params.devfileContent;
|
|
112
99
|
}
|
|
113
100
|
|
|
114
101
|
// enhance projects
|
|
115
|
-
devfileContent = this.replaceIfExistingProjects(devfileContent, projects);
|
|
102
|
+
devfileContent = this.replaceIfExistingProjects(devfileContent, params.projects);
|
|
116
103
|
|
|
117
|
-
if (
|
|
104
|
+
if (params.editorContent) {
|
|
105
|
+
editorContent = params.editorContent;
|
|
106
|
+
} else if (params.editorEntry) {
|
|
118
107
|
// devfile of the editor
|
|
119
|
-
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(editorEntry);
|
|
108
|
+
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(params.editorEntry);
|
|
120
109
|
editorContent = jsYaml.dump(editorDevfile);
|
|
121
110
|
} else {
|
|
122
|
-
editorContent = await fs.readFile(editorPath);
|
|
111
|
+
editorContent = await fs.readFile(params.editorPath);
|
|
123
112
|
}
|
|
124
113
|
|
|
125
114
|
const generate = container.get(Generate);
|
|
126
|
-
return generate.generate(devfileContent, editorContent, outputFile);
|
|
115
|
+
return generate.generate(devfileContent, editorContent, params.outputFile);
|
|
127
116
|
}
|
|
128
117
|
|
|
129
118
|
// Update project entry based on the projects passed as parameter
|
|
@@ -154,8 +143,65 @@ export class Main {
|
|
|
154
143
|
}
|
|
155
144
|
|
|
156
145
|
async start(): Promise<boolean> {
|
|
146
|
+
let devfilePath: string | undefined;
|
|
147
|
+
let devfileUrl: string | undefined;
|
|
148
|
+
let outputFile: string | undefined;
|
|
149
|
+
let editorPath: string | undefined;
|
|
150
|
+
let pluginRegistryUrl: string | undefined;
|
|
151
|
+
let editorEntry: string | undefined;
|
|
152
|
+
const projects: { name: string; location: string }[] = [];
|
|
153
|
+
|
|
154
|
+
const args = process.argv.slice(2);
|
|
155
|
+
args.forEach(arg => {
|
|
156
|
+
if (arg.startsWith('--devfile-path:')) {
|
|
157
|
+
devfilePath = arg.substring('--devfile-path:'.length);
|
|
158
|
+
}
|
|
159
|
+
if (arg.startsWith('--devfile-url:')) {
|
|
160
|
+
devfileUrl = arg.substring('--devfile-url:'.length);
|
|
161
|
+
}
|
|
162
|
+
if (arg.startsWith('--plugin-registry-url:')) {
|
|
163
|
+
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
|
|
164
|
+
}
|
|
165
|
+
if (arg.startsWith('--editor-entry:')) {
|
|
166
|
+
editorEntry = arg.substring('--editor-entry:'.length);
|
|
167
|
+
}
|
|
168
|
+
if (arg.startsWith('--editor-path:')) {
|
|
169
|
+
editorPath = arg.substring('--editor-path:'.length);
|
|
170
|
+
}
|
|
171
|
+
if (arg.startsWith('--output-file:')) {
|
|
172
|
+
outputFile = arg.substring('--output-file:'.length);
|
|
173
|
+
}
|
|
174
|
+
if (arg.startsWith('--project.')) {
|
|
175
|
+
const name = arg.substring('--project.'.length, arg.indexOf('='));
|
|
176
|
+
let location = arg.substring(arg.indexOf('=') + 1);
|
|
177
|
+
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
|
|
178
|
+
|
|
179
|
+
projects.push({ name, location });
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
157
183
|
try {
|
|
158
|
-
|
|
184
|
+
if (!editorPath && !editorEntry) {
|
|
185
|
+
throw new Error('missing --editor-path: or --editor-entry: parameter');
|
|
186
|
+
}
|
|
187
|
+
if (!devfilePath && !devfileUrl) {
|
|
188
|
+
throw new Error('missing --devfile-path: or --devfile-url: parameter');
|
|
189
|
+
}
|
|
190
|
+
if (!outputFile) {
|
|
191
|
+
throw new Error('missing --output-file: parameter');
|
|
192
|
+
}
|
|
193
|
+
await this.generateDevfileContext(
|
|
194
|
+
{
|
|
195
|
+
devfilePath,
|
|
196
|
+
devfileUrl,
|
|
197
|
+
editorPath,
|
|
198
|
+
outputFile,
|
|
199
|
+
pluginRegistryUrl,
|
|
200
|
+
editorEntry,
|
|
201
|
+
projects,
|
|
202
|
+
},
|
|
203
|
+
axios.default
|
|
204
|
+
);
|
|
159
205
|
return true;
|
|
160
206
|
} catch (error) {
|
|
161
207
|
console.error('stack=' + error.stack);
|