From 5d674f237652bd72b8caa98edc62de560aedd2e6 Mon Sep 17 00:00:00 2001 From: Roman Nikitenko Date: Wed, 1 Mar 2023 15:56:55 +0200 Subject: [PATCH 1/3] feat: Add an ability to pass editor description as URL to the generator Signed-off-by: Roman Nikitenko --- tools/devworkspace-generator/src/main.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/devworkspace-generator/src/main.ts b/tools/devworkspace-generator/src/main.ts index 7bef59a40..875b33815 100644 --- a/tools/devworkspace-generator/src/main.ts +++ b/tools/devworkspace-generator/src/main.ts @@ -36,13 +36,14 @@ export class Main { editorPath?: string; editorContent?: string; editorEntry?: string; + editorUrl?: string; pluginRegistryUrl?: string; projects: { name: string; location: string }[]; }, axiosInstance: axios.AxiosInstance ): Promise { - if (!params.editorPath && !params.editorEntry && !params.editorContent) { - throw new Error('missing editorPath or editorEntry or editorContent'); + if (!params.editorPath && !params.editorEntry && !params.editorContent && !params.editorUrl) { + throw new Error('missing editorPath or editorEntry or editorContent or editorUrl'); } if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { throw new Error('missing devfilePath or devfileUrl or devfileContent'); @@ -107,6 +108,8 @@ export class Main { // devfile of the editor const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(params.editorEntry); editorContent = jsYaml.dump(editorDevfile); + } else if (params.editorUrl) { + editorContent = await container.get(UrlFetcher).fetchText(params.editorUrl); } else { editorContent = await fs.readFile(params.editorPath); } @@ -147,6 +150,7 @@ export class Main { let devfileUrl: string | undefined; let outputFile: string | undefined; let editorPath: string | undefined; + let editorUrl: string | undefined; let pluginRegistryUrl: string | undefined; let editorEntry: string | undefined; const projects: { name: string; location: string }[] = []; @@ -168,6 +172,9 @@ export class Main { if (arg.startsWith('--editor-path:')) { editorPath = arg.substring('--editor-path:'.length); } + if (arg.startsWith('--editor-url:')) { + editorUrl = arg.substring('--editor-url:'.length); + } if (arg.startsWith('--output-file:')) { outputFile = arg.substring('--output-file:'.length); } @@ -181,8 +188,8 @@ export class Main { }); try { - if (!editorPath && !editorEntry) { - throw new Error('missing --editor-path: or --editor-entry: parameter'); + if (!editorPath && !editorEntry && !editorUrl) { + throw new Error('missing --editor-path: or --editor-entry: or --editor-url: parameter'); } if (!devfilePath && !devfileUrl) { throw new Error('missing --devfile-path: or --devfile-url: parameter'); @@ -198,6 +205,7 @@ export class Main { outputFile, pluginRegistryUrl, editorEntry, + editorUrl, projects, }, axios.default From 67a9d439e683d62c88ee55e17763fae90139ecd3 Mon Sep 17 00:00:00 2001 From: Roman Nikitenko Date: Wed, 1 Mar 2023 15:57:59 +0200 Subject: [PATCH 2/3] feat: Respect inline format of the editor devfile Signed-off-by: Roman Nikitenko --- tools/devworkspace-generator/src/generate.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/devworkspace-generator/src/generate.ts b/tools/devworkspace-generator/src/generate.ts index b8960ac59..8f53e07bf 100644 --- a/tools/devworkspace-generator/src/generate.ts +++ b/tools/devworkspace-generator/src/generate.ts @@ -54,7 +54,12 @@ export class Generate { const suffix = devfile.metadata.name || ''; // devfile of the editor - const editorDevfile = jsYaml.load(editorContent); + let editorDevfile = jsYaml.load(editorContent); + + // support for the inline format of the devfile + if (editorDevfile.inline) { + editorDevfile = editorDevfile.inline; + } // transform it into a devWorkspace template const metadata = editorDevfile.metadata; From a26a45c7e321af3da3ae53e5a923f0ae18e1f8ad Mon Sep 17 00:00:00 2001 From: Roman Nikitenko Date: Wed, 1 Mar 2023 16:05:54 +0200 Subject: [PATCH 3/3] Adopt tests related to generator Signed-off-by: Roman Nikitenko --- tools/devworkspace-generator/tests/main.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/devworkspace-generator/tests/main.spec.ts b/tools/devworkspace-generator/tests/main.spec.ts index 3f7daee29..c103ff39f 100644 --- a/tools/devworkspace-generator/tests/main.spec.ts +++ b/tools/devworkspace-generator/tests/main.spec.ts @@ -275,7 +275,7 @@ describe('Test Main with stubs', () => { } catch (e) { message = e.message; } - expect(message).toEqual('missing editorPath or editorEntry or editorContent'); + expect(message).toEqual('missing editorPath or editorEntry or editorContent or editorUrl'); }); test('missing devfile', async () => {