@eclipse-che/che-devworkspace-generator
Advanced tools
Comparing version 7.93.0-next-e0a0622 to 7.93.0-next-e5ac546
@@ -24,4 +24,3 @@ /********************************************************************** | ||
export interface InversifyBindingOptions { | ||
pluginRegistryUrl: string; | ||
axiosInstance: AxiosInstance; | ||
} |
@@ -19,3 +19,3 @@ "use strict"; | ||
const resolve_module_1 = require("../resolve/resolve-module"); | ||
const plugin_registry_module_1 = require("../plugin-registry/plugin-registry-module"); | ||
const editor_module_1 = require("../editor/editor-module"); | ||
const devfile_schema_module_1 = require("../devfile-schema/devfile-schema-module"); | ||
@@ -37,6 +37,5 @@ const bitbucket_module_1 = require("../bitbucket/bitbucket-module"); | ||
this.container.load(resolve_module_1.resolveModule); | ||
this.container.load(plugin_registry_module_1.pluginRegistryModule); | ||
this.container.load(editor_module_1.editorModule); | ||
this.container.load(devfile_schema_module_1.devfileSchemaModule); | ||
this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance); | ||
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL'); | ||
return this.container; | ||
@@ -43,0 +42,0 @@ } |
@@ -24,4 +24,3 @@ /********************************************************************** | ||
editorContent?: string; | ||
editorEntry?: string; | ||
pluginRegistryUrl?: string; | ||
editorUrl?: string; | ||
projects: { | ||
@@ -28,0 +27,0 @@ name: string; |
@@ -43,3 +43,3 @@ "use strict"; | ||
const url_fetcher_1 = require("./fetch/url-fetcher"); | ||
const plugin_registry_resolver_1 = require("./plugin-registry/plugin-registry-resolver"); | ||
const editor_resolver_1 = require("./editor/editor-resolver"); | ||
const git_url_resolver_1 = require("./resolve/git-url-resolver"); | ||
@@ -55,4 +55,4 @@ class Main { | ||
async generateDevfileContext(params, axiosInstance) { | ||
if (!params.editorPath && !params.editorEntry && !params.editorContent) { | ||
throw new Error('missing editorPath or editorEntry or editorContent'); | ||
if (!params.editorPath && !params.editorUrl && !params.editorContent) { | ||
throw new Error('missing editorPath or editorUrl or editorContent'); | ||
} | ||
@@ -62,13 +62,4 @@ if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { | ||
} | ||
let pluginRegistryUrl; | ||
if (params.pluginRegistryUrl) { | ||
pluginRegistryUrl = params.pluginRegistryUrl; | ||
} | ||
else { | ||
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3'; | ||
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`); | ||
} | ||
const inversifyBinbding = new inversify_binding_1.InversifyBinding(); | ||
const container = await inversifyBinbding.initBindings({ | ||
pluginRegistryUrl, | ||
axiosInstance, | ||
@@ -127,5 +118,5 @@ }); | ||
} | ||
else if (params.editorEntry) { | ||
else if (params.editorUrl) { | ||
// devfile of the editor | ||
const editorDevfile = await container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(params.editorEntry); | ||
const editorDevfile = await container.get(editor_resolver_1.EditorResolver).loadEditor(params.editorUrl); | ||
editorContent = jsYaml.dump(editorDevfile); | ||
@@ -170,4 +161,3 @@ } | ||
let editorPath; | ||
let pluginRegistryUrl; | ||
let editorEntry; | ||
let editorUrl; | ||
let injectDefaultComponent; | ||
@@ -184,8 +174,5 @@ let defaultComponentImage; | ||
} | ||
if (arg.startsWith('--plugin-registry-url:')) { | ||
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length); | ||
if (arg.startsWith('--editor-url:')) { | ||
editorUrl = arg.substring('--editor-url:'.length); | ||
} | ||
if (arg.startsWith('--editor-entry:')) { | ||
editorEntry = arg.substring('--editor-entry:'.length); | ||
} | ||
if (arg.startsWith('--editor-path:')) { | ||
@@ -211,4 +198,4 @@ editorPath = arg.substring('--editor-path:'.length); | ||
try { | ||
if (!editorPath && !editorEntry) { | ||
throw new Error('missing --editor-path: or --editor-entry: parameter'); | ||
if (!editorPath && !editorUrl) { | ||
throw new Error('missing --editor-path: or --editor-url: parameter'); | ||
} | ||
@@ -226,4 +213,3 @@ if (!devfilePath && !devfileUrl) { | ||
outputFile, | ||
pluginRegistryUrl, | ||
editorEntry, | ||
editorUrl, | ||
projects, | ||
@@ -230,0 +216,0 @@ injectDefaultComponent, |
{ | ||
"name": "@eclipse-che/che-devworkspace-generator", | ||
"version": "7.93.0-next-e0a0622", | ||
"version": "7.93.0-next-e5ac546", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Generates DevWorkspaces by transforming existing devfiles", |
## DevWorkspace Generator | ||
The library is used by Devfile registry component to generate the DevWorkspace components and DevWorkspace templates. It requires editor definitions from the | ||
[che-plugin-registry](https://github.com/eclipse-che/che-plugin-registry/). | ||
[![Contribute](https://www.eclipse.org/che/contribute.svg)](https://workspaces.openshift.com#https://github.com/devfile/devworkspace-generator) | ||
[![Contribute (nightly)](https://img.shields.io/static/v1?label=nightly%20Che&message=for%20maintainers&logo=eclipseche&color=FDB940&labelColor=525C86)](https://che-dogfooding.apps.che-dev.x6e0.p1.openshiftapps.com#https://github.com/devfile/devworkspace-generator) | ||
## How to use the library | ||
The library can be used as a standalone library. | ||
The library is used by Eclipse Che to generate DevWorkspace components and templates. It requires both the original devfile.yaml and the editor definitions. | ||
## Where is it Published? | ||
This library is available on npm. | ||
You can find the published package here: \ | ||
__npm:__ [@eclipse-che/che-devworkspace-generator](https://www.npmjs.com/package/@eclipse-che/che-devworkspace-generator) | ||
## Usage | ||
### Here’s an example of how to use the @eclipse-che/che-devworkspace-generator library to generate a DevWorkspace and DevWorkspaceTemplate: | ||
```typescript | ||
import { Main as DevworkspaceGenerator } from '@eclipse-che/che-devworkspace-generator/lib/main'; | ||
import { V1alpha2DevWorkspaceTemplate } from '@devfile/api'; | ||
import { dump } from 'js-yaml'; | ||
// Initialize the DevWorkspace generator | ||
const generator = new DevworkspaceGenerator(); | ||
// Example function to generate DevWorkspace resources | ||
async function generateDevWorkspace(devfileContent: string, editorContent: string, axiosInstance: any) { | ||
// Generate the Devfile context | ||
const context = await generator.generateDevfileContext( | ||
{ | ||
devfileContent, | ||
editorContent, | ||
projects: [], | ||
}, | ||
axiosInstance, | ||
); | ||
// Convert templates and DevWorkspace to YAML | ||
const allContentArray = context.devWorkspaceTemplates.map( | ||
(template: V1alpha2DevWorkspaceTemplate) => dump(template), | ||
); | ||
allContentArray.push(dump(context.devWorkspace)); | ||
// Return the YAML content joined by "---" | ||
return allContentArray.join('---\n'); | ||
} | ||
``` | ||
### The library can be used as a standalone library: | ||
``` | ||
USAGE | ||
@@ -17,6 +59,7 @@ $ node lib/entrypoint.js [OPTIONS] | ||
--plugin-registry-url: URL to the plugin registry that contains editor definitions (devfile.yaml) | ||
--editor-entry: editor ID, found on the <plugin-registry-url>, to resolve the devfile.yaml | ||
--editor-url: URL for the editor's definition, should be publicly accessible for download. | ||
or | ||
--editor-path: local file path of the editor devfile.yaml | ||
or | ||
--editor-content: content of the editor devfile.yaml | ||
@@ -33,8 +76,7 @@ --output-file: local file path for the generated devworkspace yaml | ||
# online example, using editor definition from https://che-plugin-registry-main.surge.sh/ | ||
# online example, using editor definition from https://raw.githubusercontent.com/eclipse-che/che-operator/refs/heads/main/editors-definitions/che-code-insiders.yaml | ||
$ node lib/entrypoint.js \ | ||
--devfile-url:https://github.com/che-samples/java-spring-petclinic/tree/main \ | ||
--plugin-registry-url:https://che-plugin-registry-main.surge.sh/v3/ \ | ||
--editor-entry:che-incubator/che-code/latest \ | ||
--editor-url:https://raw.githubusercontent.com/eclipse-che/che-operator/refs/heads/main/editors-definitions/che-code-insiders.yaml \ | ||
--output-file:/tmp/devworkspace-che-code-latest.yaml \ | ||
@@ -41,0 +83,0 @@ --injectDefaultComponent:true \ |
@@ -18,3 +18,3 @@ /********************************************************************** | ||
import { resolveModule } from '../resolve/resolve-module'; | ||
import { pluginRegistryModule } from '../plugin-registry/plugin-registry-module'; | ||
import { editorModule } from '../editor/editor-module'; | ||
import { devfileSchemaModule } from '../devfile-schema/devfile-schema-module'; | ||
@@ -39,7 +39,6 @@ import { bitbucketModule } from '../bitbucket/bitbucket-module'; | ||
this.container.load(resolveModule); | ||
this.container.load(pluginRegistryModule); | ||
this.container.load(editorModule); | ||
this.container.load(devfileSchemaModule); | ||
this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance); | ||
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL'); | ||
@@ -54,4 +53,3 @@ return this.container; | ||
export interface InversifyBindingOptions { | ||
pluginRegistryUrl: string; | ||
axiosInstance: AxiosInstance; | ||
} |
@@ -18,3 +18,3 @@ /********************************************************************** | ||
import { UrlFetcher } from './fetch/url-fetcher'; | ||
import { PluginRegistryResolver } from './plugin-registry/plugin-registry-resolver'; | ||
import { EditorResolver } from './editor/editor-resolver'; | ||
import { V1alpha2DevWorkspaceSpecTemplate } from '@devfile/api'; | ||
@@ -41,4 +41,3 @@ import { DevfileContext } from './api/devfile-context'; | ||
editorContent?: string; | ||
editorEntry?: string; | ||
pluginRegistryUrl?: string; | ||
editorUrl?: string; | ||
projects: { name: string; location: string }[]; | ||
@@ -50,4 +49,4 @@ injectDefaultComponent?: string; | ||
): Promise<DevfileContext> { | ||
if (!params.editorPath && !params.editorEntry && !params.editorContent) { | ||
throw new Error('missing editorPath or editorEntry or editorContent'); | ||
if (!params.editorPath && !params.editorUrl && !params.editorContent) { | ||
throw new Error('missing editorPath or editorUrl or editorContent'); | ||
} | ||
@@ -58,14 +57,4 @@ if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { | ||
let pluginRegistryUrl: string; | ||
if (params.pluginRegistryUrl) { | ||
pluginRegistryUrl = params.pluginRegistryUrl; | ||
} else { | ||
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3'; | ||
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`); | ||
} | ||
const inversifyBinbding = new InversifyBinding(); | ||
const container = await inversifyBinbding.initBindings({ | ||
pluginRegistryUrl, | ||
axiosInstance, | ||
@@ -132,5 +121,5 @@ }); | ||
editorContent = params.editorContent; | ||
} else if (params.editorEntry) { | ||
} else if (params.editorUrl) { | ||
// devfile of the editor | ||
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(params.editorEntry); | ||
const editorDevfile = await container.get(EditorResolver).loadEditor(params.editorUrl); | ||
editorContent = jsYaml.dump(editorDevfile); | ||
@@ -183,4 +172,3 @@ } else { | ||
let editorPath: string | undefined; | ||
let pluginRegistryUrl: string | undefined; | ||
let editorEntry: string | undefined; | ||
let editorUrl: string | undefined; | ||
let injectDefaultComponent: string | undefined; | ||
@@ -198,8 +186,5 @@ let defaultComponentImage: string | undefined; | ||
} | ||
if (arg.startsWith('--plugin-registry-url:')) { | ||
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length); | ||
if (arg.startsWith('--editor-url:')) { | ||
editorUrl = arg.substring('--editor-url:'.length); | ||
} | ||
if (arg.startsWith('--editor-entry:')) { | ||
editorEntry = arg.substring('--editor-entry:'.length); | ||
} | ||
if (arg.startsWith('--editor-path:')) { | ||
@@ -227,4 +212,4 @@ editorPath = arg.substring('--editor-path:'.length); | ||
try { | ||
if (!editorPath && !editorEntry) { | ||
throw new Error('missing --editor-path: or --editor-entry: parameter'); | ||
if (!editorPath && !editorUrl) { | ||
throw new Error('missing --editor-path: or --editor-url: parameter'); | ||
} | ||
@@ -243,4 +228,3 @@ if (!devfilePath && !devfileUrl) { | ||
outputFile, | ||
pluginRegistryUrl, | ||
editorEntry, | ||
editorUrl, | ||
projects, | ||
@@ -247,0 +231,0 @@ injectDefaultComponent, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
2031693
127
99
7
34828