@eclipse-che/che-devworkspace-generator
Advanced tools
Comparing version 0.0.1-4f0e375 to 0.0.1-58f79fb
@@ -16,3 +16,4 @@ /********************************************************************** | ||
export declare class DevContainerComponentFinder { | ||
find(devfileContext: DevfileContext): Promise<V1alpha2DevWorkspaceSpecTemplateComponents | undefined>; | ||
private devContainerComponentInserter; | ||
find(devfileContext: DevfileContext, injectDefaultComponent?: string, defaultComponentImage?: string): Promise<V1alpha2DevWorkspaceSpecTemplateComponents | undefined>; | ||
} |
@@ -56,2 +56,3 @@ "use strict"; | ||
var inversify_1 = require("inversify"); | ||
var dev_container_component_inserter_1 = require("./dev-container-component-inserter"); | ||
/** | ||
@@ -63,13 +64,22 @@ * Need to find dev container from main dev workspace | ||
} | ||
DevContainerComponentFinder.prototype.find = function (devfileContext) { | ||
var _a, _b, _c; | ||
DevContainerComponentFinder.prototype.find = function (devfileContext, injectDefaultComponent, defaultComponentImage) { | ||
var _a, _b, _c, _d; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var devComponents; | ||
return __generator(this, function (_d) { | ||
devComponents = (_c = (_b = (_a = devfileContext.devWorkspace.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.components) === null || _c === void 0 ? void 0 : _c.filter(function (component) { return component.container; }).filter( | ||
var devComponents, devComponents_1; | ||
return __generator(this, function (_e) { | ||
// if a devfile contains a parent, we should not add a default dev container | ||
if ((_a = devfileContext.devfile) === null || _a === void 0 ? void 0 : _a.parent) { | ||
return [2 /*return*/, undefined]; | ||
} | ||
devComponents = (_d = (_c = (_b = devfileContext.devWorkspace.spec) === null || _b === void 0 ? void 0 : _b.template) === null || _c === void 0 ? void 0 : _c.components) === null || _d === void 0 ? void 0 : _d.filter(function (component) { return component.container; }).filter( | ||
// we should ignore component that do not mount the sources | ||
function (component) { return component.container && component.container.mountSources !== false; }); | ||
// only one, fine, else error | ||
if (!devComponents || devComponents.length === 0) { | ||
throw new Error('Not able to find any dev container component in DevWorkspace'); | ||
// do not inject a default component if injectDefaultComponent parameter is false | ||
if (!injectDefaultComponent || injectDefaultComponent !== 'true') { | ||
return [2 /*return*/, undefined]; | ||
} | ||
this.devContainerComponentInserter.insert(devfileContext, defaultComponentImage); | ||
devComponents_1 = devfileContext.devWorkspace.spec.template.components.filter(function (component) { return component.container; }); | ||
return [2 /*return*/, devComponents_1[0]]; | ||
} | ||
@@ -87,2 +97,5 @@ else if (devComponents.length === 1) { | ||
}; | ||
__decorate([ | ||
(0, inversify_1.inject)(dev_container_component_inserter_1.DevContainerComponentInserter) | ||
], DevContainerComponentFinder.prototype, "devContainerComponentInserter"); | ||
DevContainerComponentFinder = __decorate([ | ||
@@ -89,0 +102,0 @@ (0, inversify_1.injectable)() |
@@ -15,6 +15,8 @@ "use strict"; | ||
var dev_container_component_finder_1 = require("./dev-container-component-finder"); | ||
var dev_container_component_inserter_1 = require("./dev-container-component-inserter"); | ||
var devfileModule = new inversify_1.ContainerModule(function (bind) { | ||
bind(dev_container_component_finder_1.DevContainerComponentFinder).toSelf().inSingletonScope(); | ||
bind(dev_container_component_inserter_1.DevContainerComponentInserter).toSelf().inSingletonScope(); | ||
}); | ||
exports.devfileModule = devfileModule; | ||
//# sourceMappingURL=devfile-module.js.map |
@@ -14,4 +14,4 @@ /********************************************************************** | ||
private devContainerComponentFinder; | ||
generate(devfileContent: string, editorContent: string, outputFile?: string): Promise<DevfileContext>; | ||
generateContent(devfileContent: string, editorContent: string): Promise<DevfileContext>; | ||
generate(devfileContent: string, editorContent: string, outputFile?: string, injectDefaultComponent?: string, defaultComponentImage?: string): Promise<DevfileContext>; | ||
generateContent(devfileContent: string, editorContent: string, injectDefaultComponent?: string, defaultComponentImage?: string): Promise<DevfileContext>; | ||
} |
@@ -82,3 +82,3 @@ "use strict"; | ||
Generate_1 = Generate; | ||
Generate.prototype.generate = function (devfileContent, editorContent, outputFile) { | ||
Generate.prototype.generate = function (devfileContent, editorContent, outputFile, injectDefaultComponent, defaultComponentImage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -88,3 +88,3 @@ var context, allContentArray, generatedContent; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.generateContent(devfileContent, editorContent)]; | ||
case 0: return [4 /*yield*/, this.generateContent(devfileContent, editorContent, injectDefaultComponent, defaultComponentImage)]; | ||
case 1: | ||
@@ -107,3 +107,3 @@ context = _a.sent(); | ||
}; | ||
Generate.prototype.generateContent = function (devfileContent, editorContent) { | ||
Generate.prototype.generateContent = function (devfileContent, editorContent, injectDefaultComponent, defaultComponentImage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -155,5 +155,8 @@ var devfile, suffix, editorDevfile, metadata, editorDevWorkspaceTemplate, devfileMetadata, devfileCopy, editorSpecContribution, devWorkspace, devWorkspaceTemplates, context, devContainer, devContainerAttributes; | ||
}; | ||
return [4 /*yield*/, this.devContainerComponentFinder.find(context)]; | ||
return [4 /*yield*/, this.devContainerComponentFinder.find(context, injectDefaultComponent, defaultComponentImage)]; | ||
case 1: | ||
devContainer = _a.sent(); | ||
if (!devContainer) { | ||
return [2 /*return*/, context]; | ||
} | ||
devContainerAttributes = devContainer.attributes; | ||
@@ -160,0 +163,0 @@ if (!devContainerAttributes) { |
@@ -33,2 +33,4 @@ "use strict"; | ||
} | ||
var scheme = this.getGroup(match, 'scheme'); | ||
var hostName = this.getGroup(match, 'host'); | ||
var repoUser = this.getGroup(match, 'repoUser'); | ||
@@ -38,3 +40,3 @@ var repoName = this.getGroup(match, 'repoName'); | ||
var subFolder = this.getGroup(match, 'subFolder'); | ||
return new github_url_1.GithubUrl(repoUser, repoName, branchName, subFolder); | ||
return new github_url_1.GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder); | ||
}; | ||
@@ -49,3 +51,3 @@ GithubResolver.prototype.getGroup = function (match, groupName, defaultValue) { | ||
// eslint-disable-next-line max-len | ||
GithubResolver.GITHUB_URL_PATTERN = /^(?:http)(?:s)?(?:\:\/\/)github\.com\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|(?:\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?))?$/; | ||
GithubResolver.GITHUB_URL_PATTERN = /^(?<scheme>https?):\/\/(?<host>github(\..+)?\.[^\/]+)\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?)?$/; | ||
GithubResolver = GithubResolver_1 = __decorate([ | ||
@@ -52,0 +54,0 @@ (0, inversify_1.injectable)() |
@@ -14,2 +14,4 @@ /********************************************************************** | ||
export declare class GithubUrl { | ||
private readonly scheme; | ||
private readonly hostName; | ||
private readonly repoUser; | ||
@@ -19,4 +21,3 @@ private readonly repoName; | ||
private readonly subFolder; | ||
static readonly RAW_LINK = "https://raw.githubusercontent.com"; | ||
constructor(repoUser: string, repoName: string, branchName: string, subFolder: string); | ||
constructor(scheme: string, hostName: string, repoUser: string, repoName: string, branchName: string, subFolder: string); | ||
/** | ||
@@ -23,0 +24,0 @@ * Provides the raw link to the given path based on the current repository information |
@@ -17,3 +17,5 @@ "use strict"; | ||
var GithubUrl = /** @class */ (function () { | ||
function GithubUrl(repoUser, repoName, branchName, subFolder) { | ||
function GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder) { | ||
this.scheme = scheme; | ||
this.hostName = hostName; | ||
this.repoUser = repoUser; | ||
@@ -28,9 +30,10 @@ this.repoName = repoName; | ||
GithubUrl.prototype.getContentUrl = function (path) { | ||
return GithubUrl.RAW_LINK + "/" + this.repoUser + "/" + this.repoName + "/" + this.branchName + "/" + path; | ||
var hostName = this.hostName === 'github.com' ? 'githubusercontent.com' : this.hostName; | ||
return this.scheme + "://raw." + hostName + "/" + this.repoUser + "/" + this.repoName + "/" + this.branchName + "/" + path; | ||
}; | ||
GithubUrl.prototype.getUrl = function () { | ||
return "https://github.com/" + this.repoUser + "/" + this.repoName + "/tree/" + this.branchName + "/" + this.subFolder; | ||
return this.scheme + "://" + this.hostName + "/" + this.repoUser + "/" + this.repoName + "/tree/" + this.branchName + "/" + this.subFolder; | ||
}; | ||
GithubUrl.prototype.getCloneUrl = function () { | ||
return "https://github.com/" + this.repoUser + "/" + this.repoName + ".git"; | ||
return this.scheme + "://" + this.hostName + "/" + this.repoUser + "/" + this.repoName + ".git"; | ||
}; | ||
@@ -43,4 +46,2 @@ GithubUrl.prototype.getRepoName = function () { | ||
}; | ||
// raw link | ||
GithubUrl.RAW_LINK = 'https://raw.githubusercontent.com'; | ||
return GithubUrl; | ||
@@ -47,0 +48,0 @@ }()); |
@@ -30,2 +30,4 @@ /********************************************************************** | ||
}[]; | ||
injectDefaultComponent?: string; | ||
defaultComponentImage?: string; | ||
}, axiosInstance: axios.AxiosInstance): Promise<DevfileContext>; | ||
@@ -32,0 +34,0 @@ replaceIfExistingProjects(devfileContent: string, projects: { |
@@ -163,3 +163,3 @@ "use strict"; | ||
generate = container.get(generate_1.Generate); | ||
return [2 /*return*/, generate.generate(devfileContent, editorContent, params.outputFile)]; | ||
return [2 /*return*/, generate.generate(devfileContent, editorContent, params.outputFile, params.injectDefaultComponent, params.defaultComponentImage)]; | ||
} | ||
@@ -197,3 +197,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, error_1; | ||
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, injectDefaultComponent, defaultComponentImage, projects, args, error_1; | ||
return __generator(this, function (_a) { | ||
@@ -229,2 +229,8 @@ switch (_a.label) { | ||
} | ||
if (arg.startsWith('--injectDefaultComponent:')) { | ||
injectDefaultComponent = arg.substring('--injectDefaultComponent:'.length); | ||
} | ||
if (arg.startsWith('--defaultComponentImage:')) { | ||
defaultComponentImage = arg.substring('--defaultComponentImage:'.length); | ||
} | ||
}); | ||
@@ -250,3 +256,5 @@ _a.label = 1; | ||
editorEntry: editorEntry, | ||
projects: projects | ||
projects: projects, | ||
injectDefaultComponent: injectDefaultComponent, | ||
defaultComponentImage: defaultComponentImage | ||
}, axios["default"])]; | ||
@@ -253,0 +261,0 @@ case 2: |
{ | ||
"name": "@eclipse-che/che-devworkspace-generator", | ||
"version": "0.0.1-4f0e375", | ||
"version": "0.0.1-58f79fb", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Generates DevWorkspaces by transforming existing devfiles", |
@@ -26,2 +26,6 @@ ## DevWorkspace Generator | ||
--injectDefaultComponent: inject a default dev container component if no component is defined in the devfile and it doesn't provide a parent, the value can be true or false, default is false | ||
--defaultComponentImage: image to use for the default dev container component that will be injected if no componetn is defined in the devfile and it doesn't provide a parent devfile, default is quay.io/devfile/universal-developer-image:ubi8-latest | ||
EXAMPLES | ||
@@ -35,3 +39,5 @@ | ||
--editor-entry:che-incubator/che-code/latest \ | ||
--output-file:/tmp/devworkspace-che-code-latest.yaml` | ||
--output-file:/tmp/devworkspace-che-code-latest.yaml \ | ||
--injectDefaultComponent:true \ | ||
--defaultComponentImage:registry.access.redhat.com/ubi8/openjdk-11:latest | ||
@@ -38,0 +44,0 @@ # offline example with devfile.yaml files and zipped project available locally |
@@ -13,3 +13,4 @@ /********************************************************************** | ||
import { V1alpha2DevWorkspaceSpecTemplateComponents } from '@devfile/api'; | ||
import { injectable } from 'inversify'; | ||
import { inject, injectable } from 'inversify'; | ||
import { DevContainerComponentInserter } from './dev-container-component-inserter'; | ||
@@ -21,3 +22,14 @@ /** | ||
export class DevContainerComponentFinder { | ||
async find(devfileContext: DevfileContext): Promise<V1alpha2DevWorkspaceSpecTemplateComponents | undefined> { | ||
@inject(DevContainerComponentInserter) | ||
private devContainerComponentInserter: DevContainerComponentInserter; | ||
async find( | ||
devfileContext: DevfileContext, | ||
injectDefaultComponent?: string, | ||
defaultComponentImage?: string | ||
): Promise<V1alpha2DevWorkspaceSpecTemplateComponents | undefined> { | ||
// if a devfile contains a parent, we should not add a default dev container | ||
if (devfileContext.devfile?.parent) { | ||
return undefined; | ||
} | ||
// search in main devWorkspace | ||
@@ -31,5 +43,12 @@ const devComponents = devfileContext.devWorkspace.spec?.template?.components | ||
// only one, fine, else error | ||
if (!devComponents || devComponents.length === 0) { | ||
throw new Error('Not able to find any dev container component in DevWorkspace'); | ||
// do not inject a default component if injectDefaultComponent parameter is false | ||
if (!injectDefaultComponent || injectDefaultComponent !== 'true') { | ||
return undefined; | ||
} | ||
this.devContainerComponentInserter.insert(devfileContext, defaultComponentImage); | ||
let devComponents = devfileContext.devWorkspace.spec.template.components.filter(component => component.container); | ||
return devComponents[0]; | ||
} else if (devComponents.length === 1) { | ||
@@ -36,0 +55,0 @@ return devComponents[0]; |
@@ -13,7 +13,9 @@ /********************************************************************** | ||
import { DevContainerComponentFinder } from './dev-container-component-finder'; | ||
import { DevContainerComponentInserter } from './dev-container-component-inserter'; | ||
const devfileModule = new ContainerModule((bind: interfaces.Bind) => { | ||
bind(DevContainerComponentFinder).toSelf().inSingletonScope(); | ||
bind(DevContainerComponentInserter).toSelf().inSingletonScope(); | ||
}); | ||
export { devfileModule }; |
@@ -31,4 +31,15 @@ /********************************************************************** | ||
async generate(devfileContent: string, editorContent: string, outputFile?: string): Promise<DevfileContext> { | ||
const context = await this.generateContent(devfileContent, editorContent); | ||
async generate( | ||
devfileContent: string, | ||
editorContent: string, | ||
outputFile?: string, | ||
injectDefaultComponent?: string, | ||
defaultComponentImage?: string | ||
): Promise<DevfileContext> { | ||
const context = await this.generateContent( | ||
devfileContent, | ||
editorContent, | ||
injectDefaultComponent, | ||
defaultComponentImage | ||
); | ||
@@ -50,3 +61,8 @@ // write the result | ||
async generateContent(devfileContent: string, editorContent: string): Promise<DevfileContext> { | ||
async generateContent( | ||
devfileContent: string, | ||
editorContent: string, | ||
injectDefaultComponent?: string, | ||
defaultComponentImage?: string | ||
): Promise<DevfileContext> { | ||
const devfile = jsYaml.load(devfileContent); | ||
@@ -107,4 +123,9 @@ | ||
// grab container where to inject controller.devfile.io/merge-contribution attribute | ||
let devContainer: V1alpha2DevWorkspaceSpecTemplateComponents = await this.devContainerComponentFinder.find(context); | ||
let devContainer: V1alpha2DevWorkspaceSpecTemplateComponents | undefined = | ||
await this.devContainerComponentFinder.find(context, injectDefaultComponent, defaultComponentImage); | ||
if (!devContainer) { | ||
return context; | ||
} | ||
// add attributes | ||
@@ -111,0 +132,0 @@ let devContainerAttributes = devContainer.attributes; |
@@ -21,3 +21,3 @@ /********************************************************************** | ||
static readonly GITHUB_URL_PATTERN = | ||
/^(?:http)(?:s)?(?:\:\/\/)github\.com\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|(?:\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?))?$/; | ||
/^(?<scheme>https?):\/\/(?<host>github(\..+)?\.[^\/]+)\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?)?$/; | ||
@@ -29,2 +29,4 @@ resolve(link: string): GithubUrl { | ||
} | ||
const scheme = this.getGroup(match, 'scheme'); | ||
const hostName = this.getGroup(match, 'host'); | ||
const repoUser = this.getGroup(match, 'repoUser'); | ||
@@ -34,3 +36,3 @@ const repoName = this.getGroup(match, 'repoName'); | ||
const subFolder = this.getGroup(match, 'subFolder'); | ||
return new GithubUrl(repoUser, repoName, branchName, subFolder); | ||
return new GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder); | ||
} | ||
@@ -37,0 +39,0 @@ |
@@ -15,6 +15,5 @@ /********************************************************************** | ||
export class GithubUrl { | ||
// raw link | ||
static readonly RAW_LINK = 'https://raw.githubusercontent.com'; | ||
constructor( | ||
private readonly scheme: string, | ||
private readonly hostName: string, | ||
private readonly repoUser: string, | ||
@@ -30,11 +29,12 @@ private readonly repoName: string, | ||
getContentUrl(path: string): string { | ||
return `${GithubUrl.RAW_LINK}/${this.repoUser}/${this.repoName}/${this.branchName}/${path}`; | ||
const hostName = this.hostName === 'github.com' ? 'githubusercontent.com' : this.hostName; | ||
return `${this.scheme}://raw.${hostName}/${this.repoUser}/${this.repoName}/${this.branchName}/${path}`; | ||
} | ||
getUrl(): string { | ||
return `https://github.com/${this.repoUser}/${this.repoName}/tree/${this.branchName}/${this.subFolder}`; | ||
return `${this.scheme}://${this.hostName}/${this.repoUser}/${this.repoName}/tree/${this.branchName}/${this.subFolder}`; | ||
} | ||
getCloneUrl(): string { | ||
return `https://github.com/${this.repoUser}/${this.repoName}.git`; | ||
return `${this.scheme}://${this.hostName}/${this.repoUser}/${this.repoName}.git`; | ||
} | ||
@@ -41,0 +41,0 @@ |
@@ -41,2 +41,4 @@ /********************************************************************** | ||
projects: { name: string; location: string }[]; | ||
injectDefaultComponent?: string; | ||
defaultComponentImage?: string; | ||
}, | ||
@@ -116,3 +118,9 @@ axiosInstance: axios.AxiosInstance | ||
const generate = container.get(Generate); | ||
return generate.generate(devfileContent, editorContent, params.outputFile); | ||
return generate.generate( | ||
devfileContent, | ||
editorContent, | ||
params.outputFile, | ||
params.injectDefaultComponent, | ||
params.defaultComponentImage | ||
); | ||
} | ||
@@ -154,2 +162,4 @@ | ||
let editorEntry: string | undefined; | ||
let injectDefaultComponent: string | undefined; | ||
let defaultComponentImage: string | undefined; | ||
const projects: { name: string; location: string }[] = []; | ||
@@ -184,2 +194,8 @@ | ||
} | ||
if (arg.startsWith('--injectDefaultComponent:')) { | ||
injectDefaultComponent = arg.substring('--injectDefaultComponent:'.length); | ||
} | ||
if (arg.startsWith('--defaultComponentImage:')) { | ||
defaultComponentImage = arg.substring('--defaultComponentImage:'.length); | ||
} | ||
}); | ||
@@ -206,2 +222,4 @@ | ||
projects, | ||
injectDefaultComponent, | ||
defaultComponentImage, | ||
}, | ||
@@ -208,0 +226,0 @@ axios.default |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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 2 instances 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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 4 instances in 1 package
129376
62
4
2198
57