@eclipse-che/che-devworkspace-generator 0.0.1-7784e80 → 0.0.1-a00c266

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 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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AAC,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,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;wBAG6D,qBAAM,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,EAAA;;wBAA/G,YAAY,GAA+C,SAAoD;wBAG/G,sBAAsB,GAAG,YAAY,CAAC,UAAU,CAAC;wBACrD,IAAI,CAAC,sBAAsB,EAAE;4BAC3B,sBAAsB,GAAG,EAAE,CAAC;4BAC5B,sBAAsB,CAAC,UAAQ,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;4BAC3D,YAAY,CAAC,UAAU,GAAG,sBAAsB,CAAC;yBAClD;6BAAM;4BACL,sBAAsB,CAAC,UAAQ,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;yBAC5D;wBAED,sBAAO,OAAO,EAAC;;;;KAChB;;IA5Fe,2BAAkB,GAAG,0CAA2C,CAAA;IAGhF;QADC,IAAA,kBAAM,EAAC,4DAA2B,CAAC;yDAC6B;IAJtD,QAAQ;QADpB,IAAA,sBAAU,GAAE;OACA,QAAQ,CA8FpB;IAAD,eAAC;CAAA,AA9FD,IA8FC;AA9FY,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
+ }
@@ -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,35 @@
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
+ pluginRegistryUrl?: string;
24
+ editorEntry?: string;
25
+ projects: {
26
+ name: string;
27
+ location: string;
28
+ }[];
29
+ }, axiosInstance: axios.AxiosInstance): Promise<DevfileContext>;
30
+ replaceIfExistingProjects(devfileContent: string, projects: {
31
+ name: string;
32
+ location: string;
33
+ }[]): string;
34
+ start(): Promise<boolean>;
35
+ }
package/lib/main.js CHANGED
@@ -74,56 +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
- Main.prototype.doStart = function () {
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 devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, axiosInstance, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate;
86
+ var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, 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 --editor-path: or --editor-entry: parameter');
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
- if (editorEntry && !pluginRegistryUrl) {
97
+ if (!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
- axiosInstance = axios["default"];
127
101
  inversifyBinbding = new inversify_binding_1.InversifyBinding();
128
102
  return [4 /*yield*/, inversifyBinbding.initBindings({
129
103
  pluginRegistryUrl: pluginRegistryUrl,
@@ -155,25 +129,30 @@ var Main = /** @class */ (function () {
155
129
  }
156
130
  // get back the content
157
131
  devfileContent = jsYaml.dump(devfileParsed);
158
- return [3 /*break*/, 5];
159
- case 3: return [4 /*yield*/, fs.readFile(devfilePath)];
132
+ return [3 /*break*/, 6];
133
+ case 3:
134
+ if (!devfilePath) return [3 /*break*/, 5];
135
+ return [4 /*yield*/, fs.readFile(devfilePath)];
160
136
  case 4:
161
137
  devfileContent = _a.sent();
162
- _a.label = 5;
138
+ return [3 /*break*/, 6];
163
139
  case 5:
140
+ devfileContent = params.devfileContent;
141
+ _a.label = 6;
142
+ case 6:
164
143
  // enhance projects
165
144
  devfileContent = this.replaceIfExistingProjects(devfileContent, projects);
166
- if (!editorEntry) return [3 /*break*/, 7];
145
+ if (!editorEntry) return [3 /*break*/, 8];
167
146
  return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(editorEntry)];
168
- case 6:
147
+ case 7:
169
148
  editorDevfile = _a.sent();
170
149
  editorContent = jsYaml.dump(editorDevfile);
171
- return [3 /*break*/, 9];
172
- case 7: return [4 /*yield*/, fs.readFile(editorPath)];
173
- case 8:
174
- editorContent = _a.sent();
175
- _a.label = 9;
150
+ return [3 /*break*/, 10];
151
+ case 8: return [4 /*yield*/, fs.readFile(editorPath)];
176
152
  case 9:
153
+ editorContent = _a.sent();
154
+ _a.label = 10;
155
+ case 10:
177
156
  generate = container.get(generate_1.Generate);
178
157
  return [2 /*return*/, generate.generate(devfileContent, editorContent, outputFile)];
179
158
  }
@@ -208,21 +187,68 @@ var Main = /** @class */ (function () {
208
187
  };
209
188
  Main.prototype.start = function () {
210
189
  return __awaiter(this, void 0, void 0, function () {
211
- var error_1;
190
+ var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, error_1;
212
191
  return __generator(this, function (_a) {
213
192
  switch (_a.label) {
214
193
  case 0:
215
- _a.trys.push([0, 2, , 3]);
216
- return [4 /*yield*/, this.doStart()];
194
+ projects = [];
195
+ args = process.argv.slice(2);
196
+ args.forEach(function (arg) {
197
+ if (arg.startsWith('--devfile-path:')) {
198
+ devfilePath = arg.substring('--devfile-path:'.length);
199
+ }
200
+ if (arg.startsWith('--devfile-url:')) {
201
+ devfileUrl = arg.substring('--devfile-url:'.length);
202
+ }
203
+ if (arg.startsWith('--plugin-registry-url:')) {
204
+ pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
205
+ }
206
+ if (arg.startsWith('--editor-entry:')) {
207
+ editorEntry = arg.substring('--editor-entry:'.length);
208
+ }
209
+ if (arg.startsWith('--editor-path:')) {
210
+ editorPath = arg.substring('--editor-path:'.length);
211
+ }
212
+ if (arg.startsWith('--output-file:')) {
213
+ outputFile = arg.substring('--output-file:'.length);
214
+ }
215
+ if (arg.startsWith('--project.')) {
216
+ var name = arg.substring('--project.'.length, arg.indexOf('='));
217
+ var location = arg.substring(arg.indexOf('=') + 1);
218
+ location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
219
+ projects.push({ name: name, location: location });
220
+ }
221
+ });
222
+ _a.label = 1;
217
223
  case 1:
224
+ _a.trys.push([1, 3, , 4]);
225
+ if (!editorPath && !editorEntry) {
226
+ throw new Error('missing --editor-path: or --editor-entry: parameter');
227
+ }
228
+ if (!devfilePath && !devfileUrl) {
229
+ throw new Error('missing --devfile-path: or --devfile-url: parameter');
230
+ }
231
+ if (!outputFile) {
232
+ throw new Error('missing --output-file: parameter');
233
+ }
234
+ return [4 /*yield*/, this.generateDevfileContext({
235
+ devfilePath: devfilePath,
236
+ devfileUrl: devfileUrl,
237
+ editorPath: editorPath,
238
+ outputFile: outputFile,
239
+ pluginRegistryUrl: pluginRegistryUrl,
240
+ editorEntry: editorEntry,
241
+ projects: projects
242
+ }, axios["default"])];
243
+ case 2:
218
244
  _a.sent();
219
245
  return [2 /*return*/, true];
220
- case 2:
246
+ case 3:
221
247
  error_1 = _a.sent();
222
248
  console.error('stack=' + error_1.stack);
223
249
  console.error('Unable to start', error_1);
224
250
  return [2 /*return*/, false];
225
- case 3: return [2 /*return*/];
251
+ case 4: return [2 /*return*/];
226
252
  }
227
253
  });
228
254
  });
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;IAAA;IAgJA,CAAC;IA/IiB,sBAAO,GAAvB;;;;;;wBAOQ,QAAQ,GAAyC,EAAE,CAAC;wBAEpD,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;wBACnC,IAAI,CAAC,OAAO,CAAC,UAA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************************************
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-7784e80",
3
+ "version": "0.0.1-a00c266",
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|**)/*.{ts,tsx}\"",
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/**/*.{ts,tsx}"
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: string): Promise<DevfileContext> {
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
- // write templates and then DevWorkspace in a single file
36
- const allContentArray = context.devWorkspaceTemplates.map(template => jsYaml.dump(template));
37
- allContentArray.push(jsYaml.dump(context.devWorkspace));
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
- const generatedContent = allContentArray.join('---\n');
40
+ const generatedContent = allContentArray.join('---\n');
40
41
 
41
- await fs.writeFile(outputFile, generatedContent, 'utf-8');
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,39 @@ import { V1alpha2DevWorkspaceSpecTemplate } from '@devfile/api';
20
20
  import { DevfileContext } from './api/devfile-context';
21
21
 
22
22
  export class Main {
23
- protected async doStart(): Promise<DevfileContext> {
24
- let devfilePath: string | undefined;
25
- let devfileUrl: string | undefined;
26
- let outputFile: string | undefined;
27
- let editorPath: string | undefined;
28
- let pluginRegistryUrl: string | undefined;
29
- let editorEntry: string | undefined;
30
- const projects: { name: string; location: string }[] = [];
31
-
32
- const args = process.argv.slice(2);
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 }}');
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
+ pluginRegistryUrl?: string;
38
+ editorEntry?: string;
39
+ projects: { name: string; location: string }[];
40
+ },
41
+ axiosInstance: axios.AxiosInstance
42
+ ): Promise<DevfileContext> {
43
+ let { devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects } = params;
56
44
 
57
- projects.push({ name, location });
58
- }
59
- });
60
45
  if (!editorPath && !editorEntry) {
61
- throw new Error('missing --editor-path: or --editor-entry: parameter');
46
+ throw new Error('missing editorPath or editorEntry');
62
47
  }
63
- if (editorEntry && !pluginRegistryUrl) {
48
+ if (!devfilePath && !devfileUrl && !params.devfileContent) {
49
+ throw new Error('missing devfilePath or devfileUrl or devfileContent');
50
+ }
51
+ if (!pluginRegistryUrl) {
64
52
  pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
65
53
  console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`);
66
54
  }
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
55
 
74
- const axiosInstance = axios.default;
75
56
  const inversifyBinbding = new InversifyBinding();
76
57
  const container = await inversifyBinbding.initBindings({
77
58
  pluginRegistryUrl,
@@ -107,8 +88,10 @@ export class Main {
107
88
  }
108
89
  // get back the content
109
90
  devfileContent = jsYaml.dump(devfileParsed);
110
- } else {
91
+ } else if (devfilePath) {
111
92
  devfileContent = await fs.readFile(devfilePath);
93
+ } else {
94
+ devfileContent = params.devfileContent;
112
95
  }
113
96
 
114
97
  // enhance projects
@@ -154,8 +137,65 @@ export class Main {
154
137
  }
155
138
 
156
139
  async start(): Promise<boolean> {
140
+ let devfilePath: string | undefined;
141
+ let devfileUrl: string | undefined;
142
+ let outputFile: string | undefined;
143
+ let editorPath: string | undefined;
144
+ let pluginRegistryUrl: string | undefined;
145
+ let editorEntry: string | undefined;
146
+ const projects: { name: string; location: string }[] = [];
147
+
148
+ const args = process.argv.slice(2);
149
+ args.forEach(arg => {
150
+ if (arg.startsWith('--devfile-path:')) {
151
+ devfilePath = arg.substring('--devfile-path:'.length);
152
+ }
153
+ if (arg.startsWith('--devfile-url:')) {
154
+ devfileUrl = arg.substring('--devfile-url:'.length);
155
+ }
156
+ if (arg.startsWith('--plugin-registry-url:')) {
157
+ pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
158
+ }
159
+ if (arg.startsWith('--editor-entry:')) {
160
+ editorEntry = arg.substring('--editor-entry:'.length);
161
+ }
162
+ if (arg.startsWith('--editor-path:')) {
163
+ editorPath = arg.substring('--editor-path:'.length);
164
+ }
165
+ if (arg.startsWith('--output-file:')) {
166
+ outputFile = arg.substring('--output-file:'.length);
167
+ }
168
+ if (arg.startsWith('--project.')) {
169
+ const name = arg.substring('--project.'.length, arg.indexOf('='));
170
+ let location = arg.substring(arg.indexOf('=') + 1);
171
+ location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}');
172
+
173
+ projects.push({ name, location });
174
+ }
175
+ });
176
+
157
177
  try {
158
- await this.doStart();
178
+ if (!editorPath && !editorEntry) {
179
+ throw new Error('missing --editor-path: or --editor-entry: parameter');
180
+ }
181
+ if (!devfilePath && !devfileUrl) {
182
+ throw new Error('missing --devfile-path: or --devfile-url: parameter');
183
+ }
184
+ if (!outputFile) {
185
+ throw new Error('missing --output-file: parameter');
186
+ }
187
+ await this.generateDevfileContext(
188
+ {
189
+ devfilePath,
190
+ devfileUrl,
191
+ editorPath,
192
+ outputFile,
193
+ pluginRegistryUrl,
194
+ editorEntry,
195
+ projects,
196
+ },
197
+ axios.default
198
+ );
159
199
  return true;
160
200
  } catch (error) {
161
201
  console.error('stack=' + error.stack);