@eclipse-che/che-theia-devworkspace-handler
Advanced tools
Comparing version 0.0.1-1632858145 to 0.0.1-1632923226
@@ -17,11 +17,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -34,16 +25,8 @@ exports.CheTheiaComponentFinder = void 0; | ||
let CheTheiaComponentFinder = class CheTheiaComponentFinder { | ||
find(devfileContext) { | ||
async find(devfileContext) { | ||
// need to find definition | ||
var _a, _b, _c, _d, _e; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// need to find definition | ||
// first, search in all templates | ||
for (const template of devfileContext.devWorkspaceTemplates) { | ||
const theiaComponent = (_b = (_a = template.spec) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.find(component => component.name === 'theia-ide'); | ||
// got one | ||
if (theiaComponent) { | ||
return theiaComponent; | ||
} | ||
} | ||
// then search in main devWorkspace | ||
const theiaComponent = (_e = (_d = (_c = devfileContext.devWorkspace.spec) === null || _c === void 0 ? void 0 : _c.template) === null || _d === void 0 ? void 0 : _d.components) === null || _e === void 0 ? void 0 : _e.find(component => component.name === 'theia-ide'); | ||
// first, search in all templates | ||
for (const template of devfileContext.devWorkspaceTemplates) { | ||
const theiaComponent = (_b = (_a = template.spec) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b.find(component => component.name === 'theia-ide'); | ||
// got one | ||
@@ -53,4 +36,10 @@ if (theiaComponent) { | ||
} | ||
throw new Error('Not able to find theia-ide component in DevWorkspace and its templates'); | ||
}); | ||
} | ||
// then search in main devWorkspace | ||
const theiaComponent = (_e = (_d = (_c = devfileContext.devWorkspace.spec) === null || _c === void 0 ? void 0 : _c.template) === null || _d === void 0 ? void 0 : _d.components) === null || _e === void 0 ? void 0 : _e.find(component => component.name === 'theia-ide'); | ||
// got one | ||
if (theiaComponent) { | ||
return theiaComponent; | ||
} | ||
throw new Error('Not able to find theia-ide component in DevWorkspace and its templates'); | ||
} | ||
@@ -57,0 +46,0 @@ }; |
@@ -20,11 +20,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -35,29 +26,27 @@ exports.CheTheiaComponentUpdater = void 0; | ||
let CheTheiaComponentUpdater = class CheTheiaComponentUpdater { | ||
insert(devfileContext, cheTheiaExtensions) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// skip stuff if no extensions need to be installed in che-theia component | ||
if (cheTheiaExtensions.length === 0) { | ||
return; | ||
} | ||
const theiaComponent = yield this.cheTheiaComponentFinder.find(devfileContext); | ||
// add attributes | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let attributes = theiaComponent.attributes; | ||
if (!attributes) { | ||
attributes = {}; | ||
theiaComponent.attributes = attributes; | ||
} | ||
// grab list of extensions | ||
const cheTheiaVsix = cheTheiaExtensions | ||
.map(extension => extension.extensions) | ||
.reduce((acc, val) => acc.concat(val), []); | ||
// grab list of extensions | ||
const cheTheiaPreferencesArray = cheTheiaExtensions.map(extension => extension.preferences); | ||
const cheTheiaPreferences = Object.assign({}, ...cheTheiaPreferencesArray); | ||
attributes['che-theia.eclipse.org/vscode-extensions'] = cheTheiaVsix; | ||
// add preferences only if there are one | ||
if (cheTheiaPreferences && Object.keys(cheTheiaPreferences).length > 0) { | ||
attributes['che-theia.eclipse.org/vscode-preferences'] = cheTheiaPreferences; | ||
} | ||
}); | ||
async insert(devfileContext, cheTheiaExtensions) { | ||
// skip stuff if no extensions need to be installed in che-theia component | ||
if (cheTheiaExtensions.length === 0) { | ||
return; | ||
} | ||
const theiaComponent = await this.cheTheiaComponentFinder.find(devfileContext); | ||
// add attributes | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let attributes = theiaComponent.attributes; | ||
if (!attributes) { | ||
attributes = {}; | ||
theiaComponent.attributes = attributes; | ||
} | ||
// grab list of extensions | ||
const cheTheiaVsix = cheTheiaExtensions | ||
.map(extension => extension.extensions) | ||
.reduce((acc, val) => acc.concat(val), []); | ||
// grab list of extensions | ||
const cheTheiaPreferencesArray = cheTheiaExtensions.map(extension => extension.preferences); | ||
const cheTheiaPreferences = Object.assign({}, ...cheTheiaPreferencesArray); | ||
attributes['che-theia.eclipse.org/vscode-extensions'] = cheTheiaVsix; | ||
// add preferences only if there are one | ||
if (cheTheiaPreferences && Object.keys(cheTheiaPreferences).length > 0) { | ||
attributes['che-theia.eclipse.org/vscode-preferences'] = cheTheiaPreferences; | ||
} | ||
} | ||
@@ -64,0 +53,0 @@ }; |
@@ -17,11 +17,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -35,19 +26,17 @@ exports.CheTheiaPluginsAnalyzer = void 0; | ||
let CheTheiaPluginsAnalyzer = class CheTheiaPluginsAnalyzer { | ||
extractPlugins(cheTheiaPluginsYamlContent) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// it's a yaml so convert it ! | ||
const cheTheiaPluginsYamlInRepository = jsYaml.load(cheTheiaPluginsYamlContent); | ||
// only format supported right now is list of ids as for example: | ||
// - id: redhat/java8/latest | ||
if (cheTheiaPluginsYamlInRepository && Array.isArray(cheTheiaPluginsYamlInRepository)) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return cheTheiaPluginsYamlInRepository.map(entry => ({ | ||
id: entry.id, | ||
resolved: false, | ||
extensions: [], | ||
})); | ||
} | ||
// not able to really see the content, return something empty | ||
return []; | ||
}); | ||
async extractPlugins(cheTheiaPluginsYamlContent) { | ||
// it's a yaml so convert it ! | ||
const cheTheiaPluginsYamlInRepository = jsYaml.load(cheTheiaPluginsYamlContent); | ||
// only format supported right now is list of ids as for example: | ||
// - id: redhat/java8/latest | ||
if (cheTheiaPluginsYamlInRepository && Array.isArray(cheTheiaPluginsYamlInRepository)) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return cheTheiaPluginsYamlInRepository.map(entry => ({ | ||
id: entry.id, | ||
resolved: false, | ||
extensions: [], | ||
})); | ||
} | ||
// not able to really see the content, return something empty | ||
return []; | ||
} | ||
@@ -54,0 +43,0 @@ }; |
@@ -20,11 +20,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -45,60 +36,58 @@ exports.CheTheiaPluginsDevfileResolver = void 0; | ||
let CheTheiaPluginsDevfileResolver = class CheTheiaPluginsDevfileResolver { | ||
handle(devfileContext) { | ||
async handle(devfileContext) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let cheTheiaPluginsYamlContent = devfileContext.cheTheiaPluginsContent; | ||
let vscodeExtensionJsonContent = devfileContext.vscodeExtensionsJsonContent; | ||
if (!vscodeExtensionJsonContent) { | ||
vscodeExtensionJsonContent = (_a = devfileContext.devfile.attributes) === null || _a === void 0 ? void 0 : _a['.vscode/extensions.json']; | ||
} | ||
if (!cheTheiaPluginsYamlContent) { | ||
cheTheiaPluginsYamlContent = (_b = devfileContext.devfile.attributes) === null || _b === void 0 ? void 0 : _b['.che/che-theia-plugins.yaml']; | ||
} | ||
// no content, skip | ||
if (!cheTheiaPluginsYamlContent && !vscodeExtensionJsonContent) { | ||
return; | ||
} | ||
// we do have '.vscode/extensions.json' file, grab plug-ins from there. | ||
let vscodeExtensions = []; | ||
if (vscodeExtensionJsonContent) { | ||
vscodeExtensions = yield this.vscodeExtensionJsonAnalyzer.extractPlugins(vscodeExtensionJsonContent); | ||
} | ||
let cheTheiaPlugins = []; | ||
if (cheTheiaPluginsYamlContent) { | ||
cheTheiaPlugins = yield this.cheTheiaPluginsAnalyzer.extractPlugins(cheTheiaPluginsYamlContent); | ||
} | ||
// now, need to merge | ||
// if defined in both vscode/extensions.json and che-theia-plugins.yaml file, che-theia-plugins.yaml is winning | ||
// if not defined, add definition from where it is defined | ||
// filter out extensions already defined in che-theia-plugins.yaml files | ||
const allExtensions = cheTheiaPlugins.concat(vscodeExtensions.filter(extension => !cheTheiaPlugins.find(cheTheiaPlugin => cheTheiaPlugin.id === extension.id))); | ||
// unique extensions | ||
const uniqueExtensions = [...new Set(allExtensions)]; | ||
// resolve the given set of extensions (if needed) by grabbing definition using plug-in registry | ||
yield this.pluginRegistryResolver.resolve(uniqueExtensions); | ||
// now we do have definition of all extensions that we want to add into Theia and their optional sidecars for these plug-ins. | ||
// grab a list of VS Code extensions to install on main che-theia instance (no sidecar) | ||
const cheTheiaExtensions = uniqueExtensions | ||
// get only extensions without sidecars | ||
.filter(entry => !entry.sidecar); | ||
// grab a list of extensions with sidecars | ||
const allExtensionsWithSidecars = uniqueExtensions | ||
.filter(entry => entry.sidecar) | ||
.map(entry => entry); | ||
// do we need to change the sidecar and use a dev container instead ? | ||
// if need to use user container, we'll need to update an existing component with the following data | ||
let extensionsWithSidecars = []; | ||
// for dev container merge, we unify all extensions into a single sidecar and then we'll apply all settings except the image | ||
let extensionsForDevContainer; | ||
switch (devfileContext.sidecarPolicy) { | ||
case 'mergeImage': | ||
extensionsWithSidecars = this.cheTheiaPluginSidecarMerger.merge(allExtensionsWithSidecars); | ||
break; | ||
case 'useDevContainer': | ||
extensionsForDevContainer = this.cheTheiaPluginDevContainerMerger.merge(allExtensionsWithSidecars); | ||
break; | ||
} | ||
// ok now we're ready to add the vsix on che-theia component, add component sidecars(if any) and vsix installer component, etc. | ||
yield this.devWorkspaceUpdater.update(devfileContext, cheTheiaExtensions, extensionsWithSidecars, extensionsForDevContainer); | ||
}); | ||
let cheTheiaPluginsYamlContent = devfileContext.cheTheiaPluginsContent; | ||
let vscodeExtensionJsonContent = devfileContext.vscodeExtensionsJsonContent; | ||
if (!vscodeExtensionJsonContent) { | ||
vscodeExtensionJsonContent = (_a = devfileContext.devfile.attributes) === null || _a === void 0 ? void 0 : _a['.vscode/extensions.json']; | ||
} | ||
if (!cheTheiaPluginsYamlContent) { | ||
cheTheiaPluginsYamlContent = (_b = devfileContext.devfile.attributes) === null || _b === void 0 ? void 0 : _b['.che/che-theia-plugins.yaml']; | ||
} | ||
// no content, skip | ||
if (!cheTheiaPluginsYamlContent && !vscodeExtensionJsonContent) { | ||
return; | ||
} | ||
// we do have '.vscode/extensions.json' file, grab plug-ins from there. | ||
let vscodeExtensions = []; | ||
if (vscodeExtensionJsonContent) { | ||
vscodeExtensions = await this.vscodeExtensionJsonAnalyzer.extractPlugins(vscodeExtensionJsonContent); | ||
} | ||
let cheTheiaPlugins = []; | ||
if (cheTheiaPluginsYamlContent) { | ||
cheTheiaPlugins = await this.cheTheiaPluginsAnalyzer.extractPlugins(cheTheiaPluginsYamlContent); | ||
} | ||
// now, need to merge | ||
// if defined in both vscode/extensions.json and che-theia-plugins.yaml file, che-theia-plugins.yaml is winning | ||
// if not defined, add definition from where it is defined | ||
// filter out extensions already defined in che-theia-plugins.yaml files | ||
const allExtensions = cheTheiaPlugins.concat(vscodeExtensions.filter(extension => !cheTheiaPlugins.find(cheTheiaPlugin => cheTheiaPlugin.id === extension.id))); | ||
// unique extensions | ||
const uniqueExtensions = [...new Set(allExtensions)]; | ||
// resolve the given set of extensions (if needed) by grabbing definition using plug-in registry | ||
await this.pluginRegistryResolver.resolve(uniqueExtensions); | ||
// now we do have definition of all extensions that we want to add into Theia and their optional sidecars for these plug-ins. | ||
// grab a list of VS Code extensions to install on main che-theia instance (no sidecar) | ||
const cheTheiaExtensions = uniqueExtensions | ||
// get only extensions without sidecars | ||
.filter(entry => !entry.sidecar); | ||
// grab a list of extensions with sidecars | ||
const allExtensionsWithSidecars = uniqueExtensions | ||
.filter(entry => entry.sidecar) | ||
.map(entry => entry); | ||
// do we need to change the sidecar and use a dev container instead ? | ||
// if need to use user container, we'll need to update an existing component with the following data | ||
let extensionsWithSidecars = []; | ||
// for dev container merge, we unify all extensions into a single sidecar and then we'll apply all settings except the image | ||
let extensionsForDevContainer; | ||
switch (devfileContext.sidecarPolicy) { | ||
case 'mergeImage': | ||
extensionsWithSidecars = this.cheTheiaPluginSidecarMerger.merge(allExtensionsWithSidecars); | ||
break; | ||
case 'useDevContainer': | ||
extensionsForDevContainer = this.cheTheiaPluginDevContainerMerger.merge(allExtensionsWithSidecars); | ||
break; | ||
} | ||
// ok now we're ready to add the vsix on che-theia component, add component sidecars(if any) and vsix installer component, etc. | ||
await this.devWorkspaceUpdater.update(devfileContext, cheTheiaExtensions, extensionsWithSidecars, extensionsForDevContainer); | ||
} | ||
@@ -105,0 +94,0 @@ }; |
@@ -17,11 +17,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -34,19 +25,17 @@ exports.DevContainerComponentFinder = void 0; | ||
let DevContainerComponentFinder = class DevContainerComponentFinder { | ||
find(devfileContext) { | ||
async find(devfileContext) { | ||
// need to find definition | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// need to find definition | ||
// search in main devWorkspace (exclude theia as component name) | ||
const 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(component => component.container && component.name !== 'theia-ide'); | ||
// only one, fine, else error | ||
if (!devComponents || devComponents.length === 0) { | ||
throw new Error('Not able to find any dev container component in DevWorkspace'); | ||
} | ||
else if (devComponents.length === 1) { | ||
return devComponents[0]; | ||
} | ||
else { | ||
throw new Error(`Too many components have been found that could be considered as dev container. There should be only one to merge sidecars. Found component names: ${devComponents.map(component => component.name)}`); | ||
} | ||
}); | ||
// search in main devWorkspace (exclude theia as component name) | ||
const 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(component => component.container && component.name !== 'theia-ide'); | ||
// only one, fine, else error | ||
if (!devComponents || devComponents.length === 0) { | ||
throw new Error('Not able to find any dev container component in DevWorkspace'); | ||
} | ||
else if (devComponents.length === 1) { | ||
return devComponents[0]; | ||
} | ||
else { | ||
throw new Error(`Too many components have been found that could be considered as dev container. There should be only one to merge sidecars. Found component names: ${devComponents.map(component => component.name)}`); | ||
} | ||
} | ||
@@ -53,0 +42,0 @@ }; |
@@ -20,11 +20,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -39,52 +30,50 @@ exports.DevContainerComponentUpdater = void 0; | ||
let DevContainerComponentUpdater = class DevContainerComponentUpdater { | ||
insert(devfileContext, vSCodeExtensionDevContainer) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const devContainerComponent = yield this.devContainerComponentFinder.find(devfileContext); | ||
const devContainer = devContainerComponent.container; | ||
if (!devContainer) { | ||
throw new Error('The dev container should be a component with type "container".'); | ||
} | ||
// add attributes | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let attributes = devContainerComponent.attributes; | ||
if (!attributes) { | ||
attributes = {}; | ||
devContainerComponent.attributes = attributes; | ||
} | ||
// extensions | ||
attributes['che-theia.eclipse.org/vscode-extensions'] = vSCodeExtensionDevContainer.extensions; | ||
// add preferences only if there are one | ||
if (vSCodeExtensionDevContainer.preferences && Object.keys(vSCodeExtensionDevContainer.preferences).length > 0) { | ||
attributes['che-theia.eclipse.org/vscode-preferences'] = vSCodeExtensionDevContainer.preferences; | ||
} | ||
attributes['app.kubernetes.io/name'] = devContainerComponent.name; | ||
// no endpoints ? initialize empty array | ||
if (!devContainer.endpoints) { | ||
devContainer.endpoints = []; | ||
} | ||
const toInsertEndpoints = vSCodeExtensionDevContainer.endpoints || []; | ||
devContainer.endpoints.push(...toInsertEndpoints); | ||
// no env ? initialize empty array | ||
if (!devContainer.env) { | ||
devContainer.env = []; | ||
} | ||
const toInsertEnvs = vSCodeExtensionDevContainer.env || []; | ||
devContainer.env.push(...toInsertEnvs); | ||
// no volumeMounts ? initialize empty array | ||
const devContainerVolumes = devContainer.volumeMounts || []; | ||
devContainer.volumeMounts = devContainerVolumes; | ||
// pick up only volumes that are not already defined | ||
const toInsertVolumeMounts = (vSCodeExtensionDevContainer.volumeMounts || []).filter(volume => !devContainerVolumes.some(containerVolume => containerVolume.name === volume.name)); | ||
devContainer.volumeMounts.push(...toInsertVolumeMounts); | ||
// need to tweak the entrypoint to call the ${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE} | ||
devContainer.args = ['sh', '-c', '${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE}']; | ||
// now, need to add the common stuff | ||
this.containerPluginRemoteUpdater.update(devContainerComponent.name, devContainer); | ||
if (devContainer.endpoints.length === 0) { | ||
delete devContainer.endpoints; | ||
} | ||
if (devContainer.volumeMounts.length === 0) { | ||
delete devContainer.volumeMounts; | ||
} | ||
}); | ||
async insert(devfileContext, vSCodeExtensionDevContainer) { | ||
const devContainerComponent = await this.devContainerComponentFinder.find(devfileContext); | ||
const devContainer = devContainerComponent.container; | ||
if (!devContainer) { | ||
throw new Error('The dev container should be a component with type "container".'); | ||
} | ||
// add attributes | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let attributes = devContainerComponent.attributes; | ||
if (!attributes) { | ||
attributes = {}; | ||
devContainerComponent.attributes = attributes; | ||
} | ||
// extensions | ||
attributes['che-theia.eclipse.org/vscode-extensions'] = vSCodeExtensionDevContainer.extensions; | ||
// add preferences only if there are one | ||
if (vSCodeExtensionDevContainer.preferences && Object.keys(vSCodeExtensionDevContainer.preferences).length > 0) { | ||
attributes['che-theia.eclipse.org/vscode-preferences'] = vSCodeExtensionDevContainer.preferences; | ||
} | ||
attributes['app.kubernetes.io/name'] = devContainerComponent.name; | ||
// no endpoints ? initialize empty array | ||
if (!devContainer.endpoints) { | ||
devContainer.endpoints = []; | ||
} | ||
const toInsertEndpoints = vSCodeExtensionDevContainer.endpoints || []; | ||
devContainer.endpoints.push(...toInsertEndpoints); | ||
// no env ? initialize empty array | ||
if (!devContainer.env) { | ||
devContainer.env = []; | ||
} | ||
const toInsertEnvs = vSCodeExtensionDevContainer.env || []; | ||
devContainer.env.push(...toInsertEnvs); | ||
// no volumeMounts ? initialize empty array | ||
const devContainerVolumes = devContainer.volumeMounts || []; | ||
devContainer.volumeMounts = devContainerVolumes; | ||
// pick up only volumes that are not already defined | ||
const toInsertVolumeMounts = (vSCodeExtensionDevContainer.volumeMounts || []).filter(volume => !devContainerVolumes.some(containerVolume => containerVolume.name === volume.name)); | ||
devContainer.volumeMounts.push(...toInsertVolumeMounts); | ||
// need to tweak the entrypoint to call the ${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE} | ||
devContainer.args = ['sh', '-c', '${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE}']; | ||
// now, need to add the common stuff | ||
this.containerPluginRemoteUpdater.update(devContainerComponent.name, devContainer); | ||
if (devContainer.endpoints.length === 0) { | ||
delete devContainer.endpoints; | ||
} | ||
if (devContainer.volumeMounts.length === 0) { | ||
delete devContainer.volumeMounts; | ||
} | ||
} | ||
@@ -91,0 +80,0 @@ }; |
@@ -20,11 +20,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -43,42 +34,40 @@ exports.DevWorkspaceUpdater = void 0; | ||
let DevWorkspaceUpdater = class DevWorkspaceUpdater { | ||
update(devfileContext, cheTheiaExtensions, extensionsWithSidecars, extensionsForDevContainer) { | ||
async update(devfileContext, cheTheiaExtensions, extensionsWithSidecars, extensionsForDevContainer) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!((_a = devfileContext.devWorkspace.spec) === null || _a === void 0 ? void 0 : _a.template)) { | ||
throw new Error('Can update a dev workspace only if there is a template in spec object'); | ||
} | ||
const components = devfileContext.devWorkspace.spec.template.components || []; | ||
if (!devfileContext.devWorkspace.spec.template.components) { | ||
devfileContext.devWorkspace.spec.template.components = components; | ||
} | ||
// need to add the kubernetes plug-in in the devWorkspace object | ||
if (this.insertTemplates) { | ||
devfileContext.devWorkspaceTemplates.map(template => { | ||
var _a; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const name = (_a = template.metadata) === null || _a === void 0 ? void 0 : _a.name; | ||
if (!name) { | ||
throw new Error(`No name found for the template ${JSON.stringify(template, undefined, 2)}.`); | ||
} | ||
components.push({ | ||
name, | ||
plugin: { | ||
kubernetes: { | ||
name, | ||
}, | ||
if (!((_a = devfileContext.devWorkspace.spec) === null || _a === void 0 ? void 0 : _a.template)) { | ||
throw new Error('Can update a dev workspace only if there is a template in spec object'); | ||
} | ||
const components = devfileContext.devWorkspace.spec.template.components || []; | ||
if (!devfileContext.devWorkspace.spec.template.components) { | ||
devfileContext.devWorkspace.spec.template.components = components; | ||
} | ||
// need to add the kubernetes plug-in in the devWorkspace object | ||
if (this.insertTemplates) { | ||
devfileContext.devWorkspaceTemplates.map(template => { | ||
var _a; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const name = (_a = template.metadata) === null || _a === void 0 ? void 0 : _a.name; | ||
if (!name) { | ||
throw new Error(`No name found for the template ${JSON.stringify(template, undefined, 2)}.`); | ||
} | ||
components.push({ | ||
name, | ||
plugin: { | ||
kubernetes: { | ||
name, | ||
}, | ||
}); | ||
}, | ||
}); | ||
} | ||
// first, update theia component to add the vsix URLS, preferences, etc | ||
this.cheTheiaComponentUpdater.insert(devfileContext, cheTheiaExtensions); | ||
// then, generate sidecar components to add (if any) | ||
const componentsToAdd = yield this.sidecarComponentsCreator.create(extensionsWithSidecars); | ||
// finally, update dev container component with extensions to be deployed there | ||
if (extensionsForDevContainer) { | ||
this.devContainerComponentUpdater.insert(devfileContext, extensionsForDevContainer); | ||
} | ||
// and add them | ||
devfileContext.devWorkspace.spec.template.components.push(...componentsToAdd); | ||
}); | ||
}); | ||
} | ||
// first, update theia component to add the vsix URLS, preferences, etc | ||
this.cheTheiaComponentUpdater.insert(devfileContext, cheTheiaExtensions); | ||
// then, generate sidecar components to add (if any) | ||
const componentsToAdd = await this.sidecarComponentsCreator.create(extensionsWithSidecars); | ||
// finally, update dev container component with extensions to be deployed there | ||
if (extensionsForDevContainer) { | ||
this.devContainerComponentUpdater.insert(devfileContext, extensionsForDevContainer); | ||
} | ||
// and add them | ||
devfileContext.devWorkspace.spec.template.components.push(...componentsToAdd); | ||
} | ||
@@ -85,0 +74,0 @@ }; |
@@ -20,11 +20,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -38,26 +29,24 @@ exports.SidecarComponentsCreator = void 0; | ||
let SidecarComponentsCreator = class SidecarComponentsCreator { | ||
create(extensionsWithSidecars) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// ok now add sidecar components | ||
return extensionsWithSidecars.map(entry => { | ||
const sidecarName = entry.sidecarName || `sidecar-${entry.id.replace(/[^\w\s]/gi, '-')}`; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const attributes = { | ||
'app.kubernetes.io/part-of': 'che-theia.eclipse.org', | ||
'app.kubernetes.io/component': 'vscode-extension', | ||
'che-theia.eclipse.org/vscode-extensions': entry.extensions, | ||
}; | ||
// add preferences only if there are one | ||
if (entry.preferences && Object.keys(entry.preferences).length > 0) { | ||
attributes['che-theia.eclipse.org/vscode-preferences'] = entry.preferences; | ||
} | ||
const component = { | ||
name: sidecarName, | ||
attributes, | ||
container: entry.sidecar, | ||
}; | ||
// add extra stuff | ||
this.containerPluginRemoteUpdater.update(sidecarName, component.container); | ||
return component; | ||
}); | ||
async create(extensionsWithSidecars) { | ||
// ok now add sidecar components | ||
return extensionsWithSidecars.map(entry => { | ||
const sidecarName = entry.sidecarName || `sidecar-${entry.id.replace(/[^\w\s]/gi, '-')}`; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const attributes = { | ||
'app.kubernetes.io/part-of': 'che-theia.eclipse.org', | ||
'app.kubernetes.io/component': 'vscode-extension', | ||
'che-theia.eclipse.org/vscode-extensions': entry.extensions, | ||
}; | ||
// add preferences only if there are one | ||
if (entry.preferences && Object.keys(entry.preferences).length > 0) { | ||
attributes['che-theia.eclipse.org/vscode-preferences'] = entry.preferences; | ||
} | ||
const component = { | ||
name: sidecarName, | ||
attributes, | ||
container: entry.sidecar, | ||
}; | ||
// add extra stuff | ||
this.containerPluginRemoteUpdater.update(sidecarName, component.container); | ||
return component; | ||
}); | ||
@@ -64,0 +53,0 @@ } |
@@ -17,11 +17,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -36,19 +27,17 @@ exports.VscodeExtensionJsonAnalyzer = void 0; | ||
let VscodeExtensionJsonAnalyzer = class VscodeExtensionJsonAnalyzer { | ||
extractPlugins(vscodeExtensionsJsonContent) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// use of JSONC parser as we have comments in the VS code json file | ||
const strippedContent = jsoncparser.stripComments(vscodeExtensionsJsonContent); | ||
const vscodeExtensionsJson = jsoncparser.parse(strippedContent); | ||
// no recommendations or invalid entry | ||
if (!(vscodeExtensionsJson === null || vscodeExtensionsJson === void 0 ? void 0 : vscodeExtensionsJson.recommendations)) { | ||
return []; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return vscodeExtensionsJson.recommendations.map((recommendation) => ({ | ||
id: `${recommendation.replace(/\./g, '/')}/latest`.toLocaleLowerCase(), | ||
resolved: false, | ||
optional: true, | ||
extensions: [], | ||
})); | ||
}); | ||
async extractPlugins(vscodeExtensionsJsonContent) { | ||
// use of JSONC parser as we have comments in the VS code json file | ||
const strippedContent = jsoncparser.stripComments(vscodeExtensionsJsonContent); | ||
const vscodeExtensionsJson = jsoncparser.parse(strippedContent); | ||
// no recommendations or invalid entry | ||
if (!(vscodeExtensionsJson === null || vscodeExtensionsJson === void 0 ? void 0 : vscodeExtensionsJson.recommendations)) { | ||
return []; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return vscodeExtensionsJson.recommendations.map((recommendation) => ({ | ||
id: `${recommendation.replace(/\./g, '/')}/latest`.toLocaleLowerCase(), | ||
resolved: false, | ||
optional: true, | ||
extensions: [], | ||
})); | ||
} | ||
@@ -55,0 +44,0 @@ }; |
@@ -11,21 +11,12 @@ "use strict"; | ||
***********************************************************************/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("reflect-metadata"); | ||
const main_1 = require("./main"); | ||
(() => __awaiter(void 0, void 0, void 0, function* () { | ||
(async () => { | ||
const main = new main_1.Main(); | ||
const success = yield main.start(); | ||
const success = await main.start(); | ||
if (!success) { | ||
process.exit(1); | ||
} | ||
}))(); | ||
})(); | ||
//# sourceMappingURL=entrypoint.js.map |
@@ -11,11 +11,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -39,24 +30,5 @@ exports.UrlFetcher = void 0; | ||
// fetch content optionally, if the URL is not found, we return undefined without throwing errors | ||
fetchTextOptionalContent(url) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield this.axiosInstance.get(url, { | ||
responseType: 'text', | ||
}); | ||
return response.data; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} | ||
catch (error) { | ||
// not found then we return undefined | ||
if (error.response && error.response.status === 404) { | ||
return undefined; | ||
} | ||
throw error; | ||
} | ||
}); | ||
} | ||
// fetch content | ||
fetchText(url) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.axiosInstance.get(url, { | ||
async fetchTextOptionalContent(url) { | ||
try { | ||
const response = await this.axiosInstance.get(url, { | ||
responseType: 'text', | ||
@@ -66,3 +38,18 @@ }); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} | ||
catch (error) { | ||
// not found then we return undefined | ||
if (error.response && error.response.status === 404) { | ||
return undefined; | ||
} | ||
throw error; | ||
} | ||
} | ||
// fetch content | ||
async fetchText(url) { | ||
const response = await this.axiosInstance.get(url, { | ||
responseType: 'text', | ||
}); | ||
return response.data; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} | ||
@@ -69,0 +56,0 @@ }; |
@@ -11,11 +11,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -41,58 +32,56 @@ exports.Generate = void 0; | ||
let Generate = class Generate { | ||
generate(devfileUrl, editorEntry, sidecarPolicy, outputFile) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// gets the github URL | ||
const githubUrl = this.githubResolver.resolve(devfileUrl); | ||
// user devfile | ||
const userDevfileContent = yield this.urlFetcher.fetchText(githubUrl.getContentUrl('devfile.yaml')); | ||
const devfile = jsYaml.load(userDevfileContent); | ||
// sets the suffix to the devfile name | ||
const suffix = devfile.metadata.name || ''; | ||
// devfile of the editor | ||
const editorDevfile = yield this.pluginRegistryResolver.loadDevfilePlugin(editorEntry); | ||
// transform it into a devWorkspace template | ||
const metadata = editorDevfile.metadata; | ||
// add sufix | ||
metadata.name = `${metadata.name}-${suffix}`; | ||
delete editorDevfile.metadata; | ||
delete editorDevfile.schemaVersion; | ||
const editorDevWorkspaceTemplate = { | ||
apiVersion: 'workspace.devfile.io/v1alpha2', | ||
kind: 'DevWorkspaceTemplate', | ||
metadata, | ||
spec: editorDevfile, | ||
}; | ||
// grab the content of the .vscode/extensions.json and .che/che-theia-plugins.yaml files | ||
const vscodeExtensionsJsonContent = yield this.urlFetcher.fetchTextOptionalContent(githubUrl.getContentUrl('.vscode/extensions.json')); | ||
const cheTheiaPluginsContent = yield this.urlFetcher.fetchTextOptionalContent(githubUrl.getContentUrl('.che/che-theia-plugins.yaml')); | ||
// transform it into a devWorkspace | ||
const devfileMetadata = devfile.metadata; | ||
delete devfile.schemaVersion; | ||
delete devfile.metadata; | ||
const devWorkspace = { | ||
apiVersion: 'workspace.devfile.io/v1alpha2', | ||
kind: 'DevWorkspace', | ||
metadata: devfileMetadata, | ||
spec: { | ||
started: true, | ||
template: devfile, | ||
}, | ||
}; | ||
// for now the list of devWorkspace templates is only the editor template | ||
const devWorkspaceTemplates = [editorDevWorkspaceTemplate]; | ||
yield this.cheTheiaPluginsDevfileResolver.handle({ | ||
devfile: userDevfileContent, | ||
vscodeExtensionsJsonContent, | ||
cheTheiaPluginsContent, | ||
devWorkspace, | ||
devWorkspaceTemplates, | ||
sidecarPolicy, | ||
suffix, | ||
}); | ||
// write templates and then DevWorkspace in a single file | ||
const allContentArray = devWorkspaceTemplates.map(template => jsYaml.dump(template)); | ||
allContentArray.push(jsYaml.dump(devWorkspace)); | ||
const generatedContent = allContentArray.join('---\n'); | ||
yield fs.writeFile(outputFile, generatedContent, 'utf-8'); | ||
async generate(devfileUrl, editorEntry, sidecarPolicy, outputFile) { | ||
// gets the github URL | ||
const githubUrl = this.githubResolver.resolve(devfileUrl); | ||
// user devfile | ||
const userDevfileContent = await this.urlFetcher.fetchText(githubUrl.getContentUrl('devfile.yaml')); | ||
const devfile = jsYaml.load(userDevfileContent); | ||
// sets the suffix to the devfile name | ||
const suffix = devfile.metadata.name || ''; | ||
// devfile of the editor | ||
const editorDevfile = await this.pluginRegistryResolver.loadDevfilePlugin(editorEntry); | ||
// transform it into a devWorkspace template | ||
const metadata = editorDevfile.metadata; | ||
// add sufix | ||
metadata.name = `${metadata.name}-${suffix}`; | ||
delete editorDevfile.metadata; | ||
delete editorDevfile.schemaVersion; | ||
const editorDevWorkspaceTemplate = { | ||
apiVersion: 'workspace.devfile.io/v1alpha2', | ||
kind: 'DevWorkspaceTemplate', | ||
metadata, | ||
spec: editorDevfile, | ||
}; | ||
// grab the content of the .vscode/extensions.json and .che/che-theia-plugins.yaml files | ||
const vscodeExtensionsJsonContent = await this.urlFetcher.fetchTextOptionalContent(githubUrl.getContentUrl('.vscode/extensions.json')); | ||
const cheTheiaPluginsContent = await this.urlFetcher.fetchTextOptionalContent(githubUrl.getContentUrl('.che/che-theia-plugins.yaml')); | ||
// transform it into a devWorkspace | ||
const devfileMetadata = devfile.metadata; | ||
delete devfile.schemaVersion; | ||
delete devfile.metadata; | ||
const devWorkspace = { | ||
apiVersion: 'workspace.devfile.io/v1alpha2', | ||
kind: 'DevWorkspace', | ||
metadata: devfileMetadata, | ||
spec: { | ||
started: true, | ||
template: devfile, | ||
}, | ||
}; | ||
// for now the list of devWorkspace templates is only the editor template | ||
const devWorkspaceTemplates = [editorDevWorkspaceTemplate]; | ||
await this.cheTheiaPluginsDevfileResolver.handle({ | ||
devfile: userDevfileContent, | ||
vscodeExtensionsJsonContent, | ||
cheTheiaPluginsContent, | ||
devWorkspace, | ||
devWorkspaceTemplates, | ||
sidecarPolicy, | ||
suffix, | ||
}); | ||
// write templates and then DevWorkspace in a single file | ||
const allContentArray = devWorkspaceTemplates.map(template => jsYaml.dump(template)); | ||
allContentArray.push(jsYaml.dump(devWorkspace)); | ||
const generatedContent = allContentArray.join('---\n'); | ||
await fs.writeFile(outputFile, generatedContent, 'utf-8'); | ||
} | ||
@@ -99,0 +88,0 @@ }; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -32,14 +23,12 @@ exports.InversifyBinding = void 0; | ||
class InversifyBinding { | ||
initBindings(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.container = new inversify_1.Container(); | ||
this.container.load(devfile_module_1.devfileModule); | ||
this.container.load(fetch_module_1.fetchModule); | ||
this.container.load(github_module_1.githubModule); | ||
this.container.load(plugin_registry_module_1.pluginRegistryModule); | ||
this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance); | ||
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL'); | ||
this.container.bind('boolean').toConstantValue(options.insertTemplates).whenTargetNamed('INSERT_TEMPLATES'); | ||
return this.container; | ||
}); | ||
async initBindings(options) { | ||
this.container = new inversify_1.Container(); | ||
this.container.load(devfile_module_1.devfileModule); | ||
this.container.load(fetch_module_1.fetchModule); | ||
this.container.load(github_module_1.githubModule); | ||
this.container.load(plugin_registry_module_1.pluginRegistryModule); | ||
this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance); | ||
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL'); | ||
this.container.bind('boolean').toConstantValue(options.insertTemplates).whenTargetNamed('INSERT_TEMPLATES'); | ||
return this.container; | ||
} | ||
@@ -46,0 +35,0 @@ } |
143
lib/main.js
@@ -11,11 +11,2 @@ "use strict"; | ||
***********************************************************************/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -28,81 +19,77 @@ exports.Main = void 0; | ||
class Main { | ||
doStart() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let devfileUrl; | ||
let outputFile; | ||
let pluginRegistryUrl; | ||
let editor; | ||
let sidecarPolicy; | ||
const args = process.argv.slice(2); | ||
args.forEach(arg => { | ||
if (arg.startsWith('--devfile-url:')) { | ||
devfileUrl = arg.substring('--devfile-url:'.length); | ||
} | ||
if (arg.startsWith('--plugin-registry-url:')) { | ||
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length); | ||
} | ||
if (arg.startsWith('--editor:')) { | ||
editor = arg.substring('--editor:'.length); | ||
} | ||
if (arg.startsWith('--output-file:')) { | ||
outputFile = arg.substring('--output-file:'.length); | ||
} | ||
if (arg.startsWith('--sidecar-policy:')) { | ||
const policy = arg.substring('--sidecar-policy:'.length); | ||
if (policy === devfile_context_1.SidecarPolicy.MERGE_IMAGE.toString()) { | ||
sidecarPolicy = devfile_context_1.SidecarPolicy.MERGE_IMAGE; | ||
} | ||
else if (policy === devfile_context_1.SidecarPolicy.USE_DEV_CONTAINER.toString()) { | ||
sidecarPolicy = devfile_context_1.SidecarPolicy.USE_DEV_CONTAINER; | ||
} | ||
else { | ||
throw new Error(`${policy} is not a valid sidecar policy. Available values are ${Object.values(devfile_context_1.SidecarPolicy)}`); | ||
} | ||
} | ||
}); | ||
if (!pluginRegistryUrl) { | ||
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3'; | ||
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`); | ||
async doStart() { | ||
let devfileUrl; | ||
let outputFile; | ||
let pluginRegistryUrl; | ||
let editor; | ||
let sidecarPolicy; | ||
const args = process.argv.slice(2); | ||
args.forEach(arg => { | ||
if (arg.startsWith('--devfile-url:')) { | ||
devfileUrl = arg.substring('--devfile-url:'.length); | ||
} | ||
if (!editor) { | ||
editor = 'eclipse/che-theia/next'; | ||
console.log(`No editor. Setting to ${editor}`); | ||
if (arg.startsWith('--plugin-registry-url:')) { | ||
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length); | ||
} | ||
if (!sidecarPolicy) { | ||
sidecarPolicy = devfile_context_1.SidecarPolicy.USE_DEV_CONTAINER; | ||
console.log(`No sidecar policy. Setting to ${sidecarPolicy}`); | ||
if (arg.startsWith('--editor:')) { | ||
editor = arg.substring('--editor:'.length); | ||
} | ||
if (!devfileUrl) { | ||
throw new Error('missing --devfile-url: parameter'); | ||
if (arg.startsWith('--output-file:')) { | ||
outputFile = arg.substring('--output-file:'.length); | ||
} | ||
if (!outputFile) { | ||
throw new Error('missing --output-file: parameter'); | ||
if (arg.startsWith('--sidecar-policy:')) { | ||
const policy = arg.substring('--sidecar-policy:'.length); | ||
if (policy === devfile_context_1.SidecarPolicy.MERGE_IMAGE.toString()) { | ||
sidecarPolicy = devfile_context_1.SidecarPolicy.MERGE_IMAGE; | ||
} | ||
else if (policy === devfile_context_1.SidecarPolicy.USE_DEV_CONTAINER.toString()) { | ||
sidecarPolicy = devfile_context_1.SidecarPolicy.USE_DEV_CONTAINER; | ||
} | ||
else { | ||
throw new Error(`${policy} is not a valid sidecar policy. Available values are ${Object.values(devfile_context_1.SidecarPolicy)}`); | ||
} | ||
} | ||
const axiosInstance = axios.default; | ||
const inversifyBinbding = new inversify_binding_1.InversifyBinding(); | ||
const container = yield inversifyBinbding.initBindings({ | ||
pluginRegistryUrl, | ||
insertTemplates: true, | ||
axiosInstance, | ||
}); | ||
container.bind(generate_1.Generate).toSelf().inSingletonScope(); | ||
const generate = container.get(generate_1.Generate); | ||
return generate.generate(devfileUrl, editor, sidecarPolicy, outputFile); | ||
}); | ||
} | ||
start() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this.doStart(); | ||
return true; | ||
} | ||
catch (error) { | ||
console.error('stack=' + error.stack); | ||
console.error('Unable to start', error); | ||
return false; | ||
} | ||
if (!pluginRegistryUrl) { | ||
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3'; | ||
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`); | ||
} | ||
if (!editor) { | ||
editor = 'eclipse/che-theia/next'; | ||
console.log(`No editor. Setting to ${editor}`); | ||
} | ||
if (!sidecarPolicy) { | ||
sidecarPolicy = devfile_context_1.SidecarPolicy.USE_DEV_CONTAINER; | ||
console.log(`No sidecar policy. Setting to ${sidecarPolicy}`); | ||
} | ||
if (!devfileUrl) { | ||
throw new Error('missing --devfile-url: parameter'); | ||
} | ||
if (!outputFile) { | ||
throw new Error('missing --output-file: parameter'); | ||
} | ||
const axiosInstance = axios.default; | ||
const inversifyBinbding = new inversify_binding_1.InversifyBinding(); | ||
const container = await inversifyBinbding.initBindings({ | ||
pluginRegistryUrl, | ||
insertTemplates: true, | ||
axiosInstance, | ||
}); | ||
container.bind(generate_1.Generate).toSelf().inSingletonScope(); | ||
const generate = container.get(generate_1.Generate); | ||
return generate.generate(devfileUrl, editor, sidecarPolicy, outputFile); | ||
} | ||
async start() { | ||
try { | ||
await this.doStart(); | ||
return true; | ||
} | ||
catch (error) { | ||
console.error('stack=' + error.stack); | ||
console.error('Unable to start', error); | ||
return false; | ||
} | ||
} | ||
} | ||
exports.Main = Main; | ||
//# sourceMappingURL=main.js.map |
@@ -20,11 +20,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -39,82 +30,74 @@ exports.PluginRegistryResolver = void 0; | ||
let PluginRegistryResolver = class PluginRegistryResolver { | ||
resolve(vSCodeExtensionEntries) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// resolve extensions references | ||
yield Promise.all(vSCodeExtensionEntries.map(entry => this.resolveEntry(entry))); | ||
// now resolved dependencies | ||
yield this.resolveDependencies(vSCodeExtensionEntries); | ||
}); | ||
async resolve(vSCodeExtensionEntries) { | ||
// resolve extensions references | ||
await Promise.all(vSCodeExtensionEntries.map(entry => this.resolveEntry(entry))); | ||
// now resolved dependencies | ||
await this.resolveDependencies(vSCodeExtensionEntries); | ||
} | ||
// Iterate on dependencies | ||
resolveDependencies(vSCodeExtensionEntries) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// list of all dependencies | ||
const allDependencies = vSCodeExtensionEntries | ||
.map(extension => extension.dependencies || []) | ||
// flatten the array of array | ||
.reduce((acc, val) => acc.concat(val), []); | ||
const uniqueDependencies = [...new Set(allDependencies)]; | ||
// list of all dependencies not yet analyzed (because not yet in the list) | ||
const toAnalyzeDependenciesIds = uniqueDependencies.filter(dependency => !vSCodeExtensionEntries.some(entry => entry.id === `${dependency.replace(/\./g, '/')}/latest`)); | ||
// map new dependencies | ||
const toAnalyzeDependencies = toAnalyzeDependenciesIds.map(name => ({ | ||
id: `${name.replace(/\./g, '/')}/latest`, | ||
resolved: false, | ||
optional: true, | ||
extensions: [], | ||
})); | ||
// resolve these new dependencies | ||
yield Promise.all(toAnalyzeDependencies.map(entry => this.resolveEntry(entry))); | ||
// add new extensions being resolved | ||
vSCodeExtensionEntries.push(...toAnalyzeDependencies); | ||
// new dependencies, check again if new dependencies are there | ||
if (toAnalyzeDependencies.length > 0) { | ||
yield this.resolveDependencies(vSCodeExtensionEntries); | ||
} | ||
}); | ||
async resolveDependencies(vSCodeExtensionEntries) { | ||
// list of all dependencies | ||
const allDependencies = vSCodeExtensionEntries | ||
.map(extension => extension.dependencies || []) | ||
// flatten the array of array | ||
.reduce((acc, val) => acc.concat(val), []); | ||
const uniqueDependencies = [...new Set(allDependencies)]; | ||
// list of all dependencies not yet analyzed (because not yet in the list) | ||
const toAnalyzeDependenciesIds = uniqueDependencies.filter(dependency => !vSCodeExtensionEntries.some(entry => entry.id === `${dependency.replace(/\./g, '/')}/latest`)); | ||
// map new dependencies | ||
const toAnalyzeDependencies = toAnalyzeDependenciesIds.map(name => ({ | ||
id: `${name.replace(/\./g, '/')}/latest`, | ||
resolved: false, | ||
optional: true, | ||
extensions: [], | ||
})); | ||
// resolve these new dependencies | ||
await Promise.all(toAnalyzeDependencies.map(entry => this.resolveEntry(entry))); | ||
// add new extensions being resolved | ||
vSCodeExtensionEntries.push(...toAnalyzeDependencies); | ||
// new dependencies, check again if new dependencies are there | ||
if (toAnalyzeDependencies.length > 0) { | ||
await this.resolveDependencies(vSCodeExtensionEntries); | ||
} | ||
} | ||
// FQN id (like eclipse/che-theia/next) | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
loadDevfilePlugin(devfileId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const devfileUrl = `${this.pluginRegistryUrl}/plugins/${devfileId}/devfile.yaml`; | ||
const devfileContent = yield this.urlFetcher.fetchText(devfileUrl); | ||
return jsYaml.load(devfileContent); | ||
}); | ||
async loadDevfilePlugin(devfileId) { | ||
const devfileUrl = `${this.pluginRegistryUrl}/plugins/${devfileId}/devfile.yaml`; | ||
const devfileContent = await this.urlFetcher.fetchText(devfileUrl); | ||
return jsYaml.load(devfileContent); | ||
} | ||
// check if extension is not resolved | ||
// if not, reach plugin-registry | ||
resolveEntry(vSCodeExtensionEntry) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// skip already resolved | ||
if (vSCodeExtensionEntry.resolved === true) { | ||
async resolveEntry(vSCodeExtensionEntry) { | ||
// skip already resolved | ||
if (vSCodeExtensionEntry.resolved === true) { | ||
return; | ||
} | ||
// grab the content from the plugin registry | ||
// plugin registry url is with the format "https://plugin-registry.com/v3" | ||
const url = `${this.pluginRegistryUrl}/plugins/${vSCodeExtensionEntry.id}/che-theia-plugin.yaml`; | ||
// let's propagate the error if the plugin definition does not exist | ||
const cheTheiaPluginYamlContent = await this.urlFetcher.fetchTextOptionalContent(url); | ||
if (!cheTheiaPluginYamlContent) { | ||
if (vSCodeExtensionEntry.optional === true) { | ||
console.error(`${vSCodeExtensionEntry.id} is missing on the plug-in registry but it is flagged as optional, skipping it`); | ||
return; | ||
} | ||
// grab the content from the plugin registry | ||
// plugin registry url is with the format "https://plugin-registry.com/v3" | ||
const url = `${this.pluginRegistryUrl}/plugins/${vSCodeExtensionEntry.id}/che-theia-plugin.yaml`; | ||
// let's propagate the error if the plugin definition does not exist | ||
const cheTheiaPluginYamlContent = yield this.urlFetcher.fetchTextOptionalContent(url); | ||
if (!cheTheiaPluginYamlContent) { | ||
if (vSCodeExtensionEntry.optional === true) { | ||
console.error(`${vSCodeExtensionEntry.id} is missing on the plug-in registry but it is flagged as optional, skipping it`); | ||
return; | ||
} | ||
else { | ||
throw new Error(`${vSCodeExtensionEntry.id} is a mandatory plug-in but definition is not found on the plug-in registry. Aborting !`); | ||
} | ||
else { | ||
throw new Error(`${vSCodeExtensionEntry.id} is a mandatory plug-in but definition is not found on the plug-in registry. Aborting !`); | ||
} | ||
const cheTheiaPluginYaml = jsYaml.load(cheTheiaPluginYamlContent); | ||
// resolve now the extension | ||
vSCodeExtensionEntry.resolved = true; | ||
vSCodeExtensionEntry.extensions = cheTheiaPluginYaml.extensions; | ||
const sidecar = cheTheiaPluginYaml.sidecar; | ||
if (sidecar) { | ||
vSCodeExtensionEntry.sidecarName = sidecar.name; | ||
delete sidecar.name; | ||
} | ||
vSCodeExtensionEntry.sidecar = sidecar; | ||
vSCodeExtensionEntry.preferences = cheTheiaPluginYaml.preferences; | ||
vSCodeExtensionEntry.dependencies = cheTheiaPluginYaml.dependencies; | ||
}); | ||
} | ||
const cheTheiaPluginYaml = jsYaml.load(cheTheiaPluginYamlContent); | ||
// resolve now the extension | ||
vSCodeExtensionEntry.resolved = true; | ||
vSCodeExtensionEntry.extensions = cheTheiaPluginYaml.extensions; | ||
const sidecar = cheTheiaPluginYaml.sidecar; | ||
if (sidecar) { | ||
vSCodeExtensionEntry.sidecarName = sidecar.name; | ||
delete sidecar.name; | ||
} | ||
vSCodeExtensionEntry.sidecar = sidecar; | ||
vSCodeExtensionEntry.preferences = cheTheiaPluginYaml.preferences; | ||
vSCodeExtensionEntry.dependencies = cheTheiaPluginYaml.dependencies; | ||
} | ||
@@ -121,0 +104,0 @@ }; |
{ | ||
"name": "@eclipse-che/che-theia-devworkspace-handler", | ||
"version": "0.0.1-1632858145", | ||
"version": "0.0.1-1632923226", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Handle management of che-theia-plugins and devWorkspace templates", |
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
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
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 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 2 instances in 1 package
7
199107
3221