@eclipse-che/che-devworkspace-generator
Advanced tools
Comparing version 0.0.1-25f630b to 0.0.1-4e80d1b
@@ -10,2 +10,3 @@ /********************************************************************** | ||
***********************************************************************/ | ||
import * as axios from 'axios'; | ||
import { DevfileContext } from './api/devfile-context'; | ||
@@ -23,4 +24,5 @@ export declare class Main { | ||
editorPath?: string; | ||
editorContent?: string; | ||
editorEntry?: string; | ||
pluginRegistryUrl?: string; | ||
editorEntry?: string; | ||
projects: { | ||
@@ -30,3 +32,3 @@ name: string; | ||
}[]; | ||
}): Promise<DevfileContext>; | ||
}, axiosInstance: axios.AxiosInstance): Promise<DevfileContext>; | ||
replaceIfExistingProjects(devfileContent: string, projects: { | ||
@@ -33,0 +35,0 @@ name: string; |
@@ -84,20 +84,21 @@ "use strict"; | ||
// Generates a devfile context object based on params | ||
Main.prototype.generateDevfileContext = function (params) { | ||
Main.prototype.generateDevfileContext = function (params, axiosInstance) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, axiosInstance, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate; | ||
var pluginRegistryUrl, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
devfilePath = params.devfilePath, devfileUrl = params.devfileUrl, outputFile = params.outputFile, editorPath = params.editorPath, pluginRegistryUrl = params.pluginRegistryUrl, editorEntry = params.editorEntry, projects = params.projects; | ||
if (!editorPath && !editorEntry) { | ||
throw new Error('missing editorPath or editorEntry'); | ||
if (!params.editorPath && !params.editorEntry && !params.editorContent) { | ||
throw new Error('missing editorPath or editorEntry or editorContent'); | ||
} | ||
if (!devfilePath && !devfileUrl && !params.devfileContent) { | ||
if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { | ||
throw new Error('missing devfilePath or devfileUrl or devfileContent'); | ||
} | ||
if (editorEntry && !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); | ||
} | ||
axiosInstance = axios["default"]; | ||
inversifyBinbding = new inversify_binding_1.InversifyBinding(); | ||
@@ -111,5 +112,5 @@ return [4 /*yield*/, inversifyBinbding.initBindings({ | ||
container.bind(generate_1.Generate).toSelf().inSingletonScope(); | ||
if (!devfileUrl) return [3 /*break*/, 3]; | ||
if (!params.devfileUrl) return [3 /*break*/, 3]; | ||
githubResolver = container.get(github_resolver_1.GithubResolver); | ||
githubUrl = githubResolver.resolve(devfileUrl); | ||
githubUrl = githubResolver.resolve(params.devfileUrl); | ||
return [4 /*yield*/, container.get(url_fetcher_1.UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml'))]; | ||
@@ -137,4 +138,4 @@ case 2: | ||
case 3: | ||
if (!devfilePath) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, fs.readFile(devfilePath)]; | ||
if (!params.devfilePath) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, fs.readFile(params.devfilePath)]; | ||
case 4: | ||
@@ -148,16 +149,20 @@ devfileContent = _a.sent(); | ||
// enhance projects | ||
devfileContent = this.replaceIfExistingProjects(devfileContent, projects); | ||
if (!editorEntry) return [3 /*break*/, 8]; | ||
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(editorEntry)]; | ||
devfileContent = this.replaceIfExistingProjects(devfileContent, params.projects); | ||
if (!params.editorContent) return [3 /*break*/, 7]; | ||
editorContent = params.editorContent; | ||
return [3 /*break*/, 11]; | ||
case 7: | ||
if (!params.editorEntry) return [3 /*break*/, 9]; | ||
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(params.editorEntry)]; | ||
case 8: | ||
editorDevfile = _a.sent(); | ||
editorContent = jsYaml.dump(editorDevfile); | ||
return [3 /*break*/, 10]; | ||
case 8: return [4 /*yield*/, fs.readFile(editorPath)]; | ||
case 9: | ||
return [3 /*break*/, 11]; | ||
case 9: return [4 /*yield*/, fs.readFile(params.editorPath)]; | ||
case 10: | ||
editorContent = _a.sent(); | ||
_a.label = 10; | ||
case 10: | ||
_a.label = 11; | ||
case 11: | ||
generate = container.get(generate_1.Generate); | ||
return [2 /*return*/, generate.generate(devfileContent, editorContent, outputFile)]; | ||
return [2 /*return*/, generate.generate(devfileContent, editorContent, params.outputFile)]; | ||
} | ||
@@ -247,3 +252,3 @@ }); | ||
projects: projects | ||
})]; | ||
}, axios["default"])]; | ||
case 2: | ||
@@ -250,0 +255,0 @@ _a.sent(); |
{ | ||
"name": "@eclipse-che/che-devworkspace-generator", | ||
"version": "0.0.1-25f630b", | ||
"version": "0.0.1-4e80d1b", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Generates DevWorkspaces by transforming existing devfiles", |
@@ -30,21 +30,28 @@ /********************************************************************** | ||
// Generates a devfile context object based on params | ||
public async generateDevfileContext(params: { | ||
devfilePath?: string; | ||
devfileUrl?: string; | ||
devfileContent?: string; | ||
outputFile?: string; | ||
editorPath?: string; | ||
pluginRegistryUrl?: string; | ||
editorEntry?: string; | ||
projects: { name: string; location: string }[]; | ||
}): Promise<DevfileContext> { | ||
let { devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects } = params; | ||
if (!editorPath && !editorEntry) { | ||
throw new Error('missing editorPath or editorEntry'); | ||
public async generateDevfileContext( | ||
params: { | ||
devfilePath?: string; | ||
devfileUrl?: string; | ||
devfileContent?: string; | ||
outputFile?: string; | ||
editorPath?: string; | ||
editorContent?: string; | ||
editorEntry?: string; | ||
pluginRegistryUrl?: string; | ||
projects: { name: string; location: string }[]; | ||
}, | ||
axiosInstance: axios.AxiosInstance | ||
): Promise<DevfileContext> { | ||
if (!params.editorPath && !params.editorEntry && !params.editorContent) { | ||
throw new Error('missing editorPath or editorEntry or editorContent'); | ||
} | ||
if (!devfilePath && !devfileUrl && !params.devfileContent) { | ||
if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { | ||
throw new Error('missing devfilePath or devfileUrl or devfileContent'); | ||
} | ||
if (editorEntry && !pluginRegistryUrl) { | ||
let pluginRegistryUrl: string; | ||
if (params.pluginRegistryUrl) { | ||
pluginRegistryUrl = params.pluginRegistryUrl; | ||
} else { | ||
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3'; | ||
@@ -54,3 +61,2 @@ console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`); | ||
const axiosInstance = axios.default; | ||
const inversifyBinbding = new InversifyBinding(); | ||
@@ -67,5 +73,5 @@ const container = await inversifyBinbding.initBindings({ | ||
// gets the github URL | ||
if (devfileUrl) { | ||
if (params.devfileUrl) { | ||
const githubResolver = container.get(GithubResolver); | ||
const githubUrl = githubResolver.resolve(devfileUrl); | ||
const githubUrl = githubResolver.resolve(params.devfileUrl); | ||
// user devfile | ||
@@ -92,4 +98,4 @@ devfileContent = await container.get(UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml')); | ||
devfileContent = jsYaml.dump(devfileParsed); | ||
} else if (devfilePath) { | ||
devfileContent = await fs.readFile(devfilePath); | ||
} else if (params.devfilePath) { | ||
devfileContent = await fs.readFile(params.devfilePath); | ||
} else { | ||
@@ -100,14 +106,16 @@ devfileContent = params.devfileContent; | ||
// enhance projects | ||
devfileContent = this.replaceIfExistingProjects(devfileContent, projects); | ||
devfileContent = this.replaceIfExistingProjects(devfileContent, params.projects); | ||
if (editorEntry) { | ||
if (params.editorContent) { | ||
editorContent = params.editorContent; | ||
} else if (params.editorEntry) { | ||
// devfile of the editor | ||
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(editorEntry); | ||
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(params.editorEntry); | ||
editorContent = jsYaml.dump(editorDevfile); | ||
} else { | ||
editorContent = await fs.readFile(editorPath); | ||
editorContent = await fs.readFile(params.editorPath); | ||
} | ||
const generate = container.get(Generate); | ||
return generate.generate(devfileContent, editorContent, outputFile); | ||
return generate.generate(devfileContent, editorContent, params.outputFile); | ||
} | ||
@@ -190,11 +198,14 @@ | ||
} | ||
await this.generateDevfileContext({ | ||
devfilePath, | ||
devfileUrl, | ||
editorPath, | ||
outputFile, | ||
pluginRegistryUrl, | ||
editorEntry, | ||
projects, | ||
}); | ||
await this.generateDevfileContext( | ||
{ | ||
devfilePath, | ||
devfileUrl, | ||
editorPath, | ||
outputFile, | ||
pluginRegistryUrl, | ||
editorEntry, | ||
projects, | ||
}, | ||
axios.default | ||
); | ||
return true; | ||
@@ -201,0 +212,0 @@ } catch (error) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
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 1 instance in 1 package
111725
58
1947
1
29