@eclipse-che/devfile-converter
Advanced tools
Comparing version 0.0.1-14c62ee to 0.0.1-3d5ba2a
@@ -28,2 +28,5 @@ import { V220DevfileCommands, V220DevfileComponents, V220DevfileComponentsItemsContainerEndpoints, V220DevfileComponentsItemsContainerEnv, V220DevfileComponentsItemsContainerVolumeMounts, V220DevfileProjects, V220DevfileProjectsItemsGit } from '@devfile/api'; | ||
devfileV1toDevfileV2(devfileV1: che.workspace.devfile.Devfile): Promise<Devfile>; | ||
fixProjectsZipLocations(devfileV2: Devfile): Promise<void>; | ||
fixDuplicatedEndpoints(devfileV2: Devfile): Promise<void>; | ||
fixInvalidVolumeName(devfileV2: Devfile): Promise<void>; | ||
processVolumesFromDevfileV2(devfileV2: Devfile): Promise<void>; | ||
@@ -30,0 +33,0 @@ processPluginsAndEditorsFromDevfileV2(devfileV2: Devfile, devfileV1: che.workspace.devfile.Devfile, externalContentAccess?: (filename: string) => Promise<string>): Promise<void>; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -116,3 +120,12 @@ if (k2 === undefined) k2 = k; | ||
if (endpointV1.name) { | ||
endpoint.name = endpointV1.name; | ||
// the name can't have spaces | ||
// replace space by dash and then remove all special characters | ||
var endpointName = endpointV1.name | ||
.replace(/\s+/g, '-') | ||
// names should not use _ | ||
.replace(/_/g, '-') | ||
// trim '-' character from start or end | ||
.replace(/^\-+|\-+$/g, '') | ||
.toLowerCase(); | ||
endpoint.name = endpointName; | ||
} | ||
@@ -372,5 +385,16 @@ if (endpointV1.port) { | ||
DevfileConverter.prototype.projectV1toProjectV2 = function (projectV1) { | ||
// the name can't have spaces | ||
// replace space by dash and then remove all special characters | ||
var projectName = projectV1.name | ||
.replace(/\s+/g, '-') | ||
// names should not use _ | ||
.replace(/_/g, '-') | ||
// names should not use . | ||
.replace(/\./g, '-') | ||
// trim '-' character from start or end | ||
.replace(/^\-+|\-+$/g, '') | ||
.toLowerCase(); | ||
var devfileV2Project = { | ||
attributes: {}, | ||
name: projectV1.name | ||
name: projectName | ||
}; | ||
@@ -522,3 +546,5 @@ if (projectV1.clonePath) { | ||
} | ||
var cheTheiaPluginsContent = chePluginComponents.map(function (chePluginComponent) { | ||
var cheTheiaPluginsContent = chePluginComponents | ||
.filter(function (component) { return component.id; }) | ||
.map(function (chePluginComponent) { | ||
var cheTheiaPlugin = {}; | ||
@@ -528,5 +554,2 @@ if (chePluginComponent.id) { | ||
} | ||
if (chePluginComponent.reference) { | ||
cheTheiaPlugin.reference = chePluginComponent.reference; | ||
} | ||
cheTheiaPlugin.override = { | ||
@@ -580,5 +603,2 @@ sidecar: {} | ||
} | ||
if (cheEditorComponentV1.reference) { | ||
cheEditorYaml.reference = cheEditorComponentV1.reference; | ||
} | ||
if (cheEditorComponentV1.registryUrl) { | ||
@@ -635,2 +655,8 @@ cheEditorYaml.registryUrl = cheEditorComponentV1.registryUrl; | ||
devfileV2.attributes = {}; | ||
// handle the ephemeral attribute | ||
if (devfileV1.attributes && | ||
devfileV1.attributes.persistVolumes && | ||
devfileV1.attributes.persistVolumes === 'false') { | ||
devfileV2.attributes['controller.devfile.io/storage-type'] = 'ephemeral'; | ||
} | ||
inlineCheTheiaPluginsYaml = this.inlineCheTheiaPluginsYamlFromComponentsV1(devfileV1.components); | ||
@@ -658,7 +684,20 @@ if (inlineCheTheiaPluginsYaml) { | ||
} | ||
// process plugins and editors | ||
return [4 /*yield*/, this.processVolumesFromDevfileV2(devfileV2)]; | ||
// fix duplicated endpoints (same properties (name, port, etc..) | ||
return [4 /*yield*/, this.fixDuplicatedEndpoints(devfileV2)]; | ||
case 1: | ||
// process plugins and editors | ||
// fix duplicated endpoints (same properties (name, port, etc..) | ||
_b.sent(); | ||
// process volumes | ||
return [4 /*yield*/, this.fixInvalidVolumeName(devfileV2)]; | ||
case 2: | ||
// process volumes | ||
_b.sent(); | ||
return [4 /*yield*/, this.processVolumesFromDevfileV2(devfileV2)]; | ||
case 3: | ||
_b.sent(); | ||
// fix zip project location (multi-host --> single-host) | ||
return [4 /*yield*/, this.fixProjectsZipLocations(devfileV2)]; | ||
case 4: | ||
// fix zip project location (multi-host --> single-host) | ||
_b.sent(); | ||
content = JSON.stringify(devfileV2); | ||
@@ -673,2 +712,96 @@ // update devfile v1 constants | ||
}; | ||
// if some endpoints have excactly the same value, remove duplicates | ||
DevfileConverter.prototype.fixProjectsZipLocations = function (devfileV2) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
// get projects | ||
devfileV2.projects.forEach(function (project) { | ||
if (project.zip && project.zip.location) { | ||
var location = project.zip.location; | ||
// if matching a pattern, then update the location | ||
var regex = /https:\/\/(?<name>.*?)-(?<namespace>.*?)\.(?<subdomain>.*)\/devfile-registry\/resources\/(?<resourcelink>.*)/gm; | ||
var m = regex.exec(location); | ||
if (m !== null) { | ||
var namespace = m.groups.namespace; | ||
var resourcelink = m.groups.resourcelink; | ||
var newLocation = "http://devfile-registry.".concat(namespace, ".svc:8080/resources/").concat(resourcelink); | ||
project.zip.location = newLocation; | ||
} | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
// if some endpoints have excactly the same value, remove duplicates | ||
DevfileConverter.prototype.fixDuplicatedEndpoints = function (devfileV2) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var endpoints, uniqueEndpoints, uniqueEndpointsJson, alreadyProcessedEndpoints; | ||
return __generator(this, function (_a) { | ||
endpoints = devfileV2.components | ||
.filter(function (component) { return component.container; }) | ||
.map(function (component) { return component.container.endpoints; }) | ||
.flat(); | ||
uniqueEndpoints = endpoints.filter(function (value, index) { | ||
var _value = JSON.stringify(value); | ||
return (index === | ||
endpoints.findIndex(function (obj) { | ||
return JSON.stringify(obj) === _value; | ||
})); | ||
}); | ||
uniqueEndpointsJson = uniqueEndpoints.map(function (endpoint) { return JSON.stringify(endpoint); }); | ||
alreadyProcessedEndpoints = []; | ||
// ok now we'll iterate on endpoints and check if we need to replace endpoint if it's already been added | ||
devfileV2.components | ||
.filter(function (component) { return component.container; }) | ||
.forEach(function (component) { | ||
var endpoints = component.container.endpoints || []; | ||
var i = endpoints.length; | ||
while (i--) { | ||
var jsonEndpoint = JSON.stringify(endpoints[i]); | ||
if (uniqueEndpointsJson.includes(jsonEndpoint)) { | ||
// first time we see, we keep | ||
if (!alreadyProcessedEndpoints.includes(jsonEndpoint)) { | ||
alreadyProcessedEndpoints.push(jsonEndpoint); | ||
} | ||
else { | ||
// need to remove this endpoint | ||
endpoints.splice(i, 1); | ||
} | ||
} | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
// if some volume component are also components, update the name of the volume component | ||
// to be componentName-volume | ||
DevfileConverter.prototype.fixInvalidVolumeName = function (devfileV2) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var mountedVolumes, mountedVolumeNames, allComponentExceptVolumeNames, invalidVolumeNames; | ||
return __generator(this, function (_a) { | ||
mountedVolumes = devfileV2.components | ||
.map(function (component) { return component.container; }) | ||
.filter(function (container) { return container; }) | ||
.map(function (container) { return container.volumeMounts; }) | ||
.reduce(function (acc, volumeMounts) { return acc.concat(volumeMounts); }, []) | ||
.filter(function (volume) { return volume; }); | ||
mountedVolumeNames = mountedVolumes.map(function (volume) { return volume.name; }); | ||
allComponentExceptVolumeNames = devfileV2.components | ||
.filter(function (component) { return !component.volume; }) | ||
.map(function (component) { return component.name; }); | ||
invalidVolumeNames = mountedVolumeNames.filter(function (componentName) { | ||
return allComponentExceptVolumeNames.includes(componentName); | ||
}); | ||
// we have duplicates, need to update the volume name | ||
mountedVolumes.forEach(function (volume) { | ||
if (invalidVolumeNames.includes(volume.name)) { | ||
volume.name = "".concat(volume.name, "-volume"); | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
// add missing volumes components when a volumeMount is defined in the devfile | ||
@@ -689,3 +822,3 @@ DevfileConverter.prototype.processVolumesFromDevfileV2 = function (devfileV2) { | ||
.map(function (component) { return component.name; }); | ||
missingVolumes = mountedVolumeNames.filter(function (volumeName) { return !allComponentVolumeNames.includes(volumeName); }); | ||
missingVolumes = Array.from(new Set(mountedVolumeNames.filter(function (volumeName) { return !allComponentVolumeNames.includes(volumeName); }))); | ||
// add missing volumes | ||
@@ -793,5 +926,2 @@ missingVolumes.forEach(function (volumeName) { | ||
} | ||
if (component.reference) { | ||
v1component.reference = component.reference; | ||
} | ||
if (component.registryUrl) { | ||
@@ -848,5 +978,2 @@ v1component.registryUrl = component.registryUrl; | ||
} | ||
if (cheEditorYaml.reference) { | ||
v1component.reference = cheEditorYaml.reference; | ||
} | ||
if (cheEditorYaml.registryUrl) { | ||
@@ -853,0 +980,0 @@ v1component.registryUrl = cheEditorYaml.registryUrl; |
{ | ||
"name": "@eclipse-che/devfile-converter", | ||
"version": "0.0.1-14c62ee", | ||
"version": "0.0.1-3d5ba2a", | ||
"description": "Convert devfile v1 to v2 or v2 to v1", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
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
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
129714
1486