@eclipse-che/che-devworkspace-generator
Advanced tools
Comparing version 7.92.0 to 7.93.0-next-8e99f85
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DevfileSchemaVersion = void 0; | ||
@@ -15,3 +15,3 @@ /** | ||
DevfileSchemaVersion["V230"] = "2.3.0"; | ||
})(DevfileSchemaVersion = exports.DevfileSchemaVersion || (exports.DevfileSchemaVersion = {})); | ||
})(DevfileSchemaVersion || (exports.DevfileSchemaVersion = DevfileSchemaVersion = {})); | ||
//# sourceMappingURL=devfile-context.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bitbucketServerModule = void 0; | ||
@@ -13,7 +13,7 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var bitbucket_server_resolver_1 = require("./bitbucket-server-resolver"); | ||
var types_1 = require("../types"); | ||
var Resolver = types_1.TYPES.Resolver; | ||
var bitbucketServerModule = new inversify_1.ContainerModule(function (bind) { | ||
const inversify_1 = require("inversify"); | ||
const bitbucket_server_resolver_1 = require("./bitbucket-server-resolver"); | ||
const types_1 = require("../types"); | ||
const { Resolver } = types_1.TYPES; | ||
const bitbucketServerModule = new inversify_1.ContainerModule((bind) => { | ||
bind(Resolver).to(bitbucket_server_resolver_1.BitbucketServerResolver).inSingletonScope(); | ||
@@ -20,0 +20,0 @@ }); |
@@ -17,25 +17,31 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
var BitbucketServerResolver_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BitbucketServerResolver = void 0; | ||
var bitbucket_server_url_1 = require("./bitbucket-server-url"); | ||
var inversify_1 = require("inversify"); | ||
var BitbucketServerResolver = /** @class */ (function () { | ||
function BitbucketServerResolver() { | ||
const bitbucket_server_url_1 = require("./bitbucket-server-url"); | ||
const inversify_1 = require("inversify"); | ||
let BitbucketServerResolver = class BitbucketServerResolver { | ||
static { BitbucketServerResolver_1 = this; } | ||
// eslint-disable-next-line max-len | ||
static BITBUCKET_URL_PATTERNS = [ | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/scm\/~(?<user>[^\/]+)\/(?<repo>.*).git$/, | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/users\/(?<user>[^\/]+)\/repos\/(?<repo>[^\/]+)\/browse(\?at=(?<branch>.*))?$/, | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/scm\/(?<project>[^\/~]+)\/(?<repo>[^\/]+).git$/, | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/projects\/(?<project>[^\/]+)\/repos\/(?<repo>[^\/]+)\/browse(\?at=(?<branch>.*))?$/, | ||
]; | ||
isValid(url) { | ||
return BitbucketServerResolver_1.BITBUCKET_URL_PATTERNS.some(p => p.test(url)); | ||
} | ||
BitbucketServerResolver_1 = BitbucketServerResolver; | ||
BitbucketServerResolver.prototype.isValid = function (url) { | ||
return BitbucketServerResolver_1.BITBUCKET_URL_PATTERNS.some(function (p) { return p.test(url); }); | ||
}; | ||
BitbucketServerResolver.prototype.resolve = function (url) { | ||
var regExp = BitbucketServerResolver_1.BITBUCKET_URL_PATTERNS.find(function (p) { return p.test(url); }); | ||
resolve(url) { | ||
const regExp = BitbucketServerResolver_1.BITBUCKET_URL_PATTERNS.find(p => p.test(url)); | ||
if (!regExp) { | ||
throw new Error("Invalid bitbucket-server URL: ".concat(url)); | ||
throw new Error(`Invalid bitbucket-server URL: ${url}`); | ||
} | ||
var match = regExp.exec(url); | ||
var scheme = this.getGroup(match, 'scheme'); | ||
var hostName = this.getGroup(match, 'host'); | ||
var user = this.getGroup(match, 'user'); | ||
var project = this.getGroup(match, 'project'); | ||
var repo = this.getGroup(match, 'repo'); | ||
var branch = this.getGroup(match, 'branch'); | ||
const match = regExp.exec(url); | ||
const scheme = this.getGroup(match, 'scheme'); | ||
const hostName = this.getGroup(match, 'host'); | ||
const user = this.getGroup(match, 'user'); | ||
const project = this.getGroup(match, 'project'); | ||
const repo = this.getGroup(match, 'repo'); | ||
let branch = this.getGroup(match, 'branch'); | ||
if (branch !== undefined && branch.startsWith('refs%2Fheads%2F')) { | ||
@@ -45,22 +51,13 @@ branch = branch.substring(15); | ||
return new bitbucket_server_url_1.BitbucketServerUrl(scheme, hostName, user, project, repo, branch); | ||
}; | ||
BitbucketServerResolver.prototype.getGroup = function (match, groupName) { | ||
} | ||
getGroup(match, groupName) { | ||
if (match.groups && match.groups[groupName]) { | ||
return match.groups[groupName]; | ||
} | ||
}; | ||
var BitbucketServerResolver_1; | ||
// eslint-disable-next-line max-len | ||
BitbucketServerResolver.BITBUCKET_URL_PATTERNS = [ | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/scm\/~(?<user>[^\/]+)\/(?<repo>.*).git$/, | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/users\/(?<user>[^\/]+)\/repos\/(?<repo>[^\/]+)\/browse(\?at=(?<branch>.*))?$/, | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/scm\/(?<project>[^\/~]+)\/(?<repo>[^\/]+).git$/, | ||
/^(?<scheme>https?):\/\/(?<host>.*)\/projects\/(?<project>[^\/]+)\/repos\/(?<repo>[^\/]+)\/browse(\?at=(?<branch>.*))?$/, | ||
]; | ||
BitbucketServerResolver = BitbucketServerResolver_1 = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], BitbucketServerResolver); | ||
return BitbucketServerResolver; | ||
}()); | ||
} | ||
}; | ||
exports.BitbucketServerResolver = BitbucketServerResolver; | ||
exports.BitbucketServerResolver = BitbucketServerResolver = BitbucketServerResolver_1 = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], BitbucketServerResolver); | ||
//# sourceMappingURL=bitbucket-server-resolver.js.map |
@@ -11,6 +11,12 @@ "use strict"; | ||
***********************************************************************/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BitbucketServerUrl = void 0; | ||
var BitbucketServerUrl = /** @class */ (function () { | ||
function BitbucketServerUrl(scheme, hostName, user, project, repo, branch) { | ||
class BitbucketServerUrl { | ||
scheme; | ||
hostName; | ||
user; | ||
project; | ||
repo; | ||
branch; | ||
constructor(scheme, hostName, user, project, repo, branch) { | ||
this.scheme = scheme; | ||
@@ -23,23 +29,22 @@ this.hostName = hostName; | ||
} | ||
BitbucketServerUrl.prototype.getContentUrl = function (path) { | ||
var isUser = this.user !== undefined; | ||
return "".concat(this.scheme, "://").concat(this.hostName, "/").concat(isUser ? 'users' : 'projects', "/").concat(isUser ? this.user : this.project, "/repos/").concat(this.repo, "/raw/").concat(path).concat(this.branch !== undefined ? '?/at=' + this.branch : ''); | ||
}; | ||
BitbucketServerUrl.prototype.getUrl = function () { | ||
var isUser = this.user !== undefined; | ||
return "".concat(this.scheme, "://").concat(this.hostName, "/").concat(isUser ? 'users' : 'projects', "/").concat(isUser ? this.user : this.project, "/repos/").concat(this.repo).concat(this.branch !== undefined ? '/browse?at=' + this.branch : ''); | ||
}; | ||
BitbucketServerUrl.prototype.getCloneUrl = function () { | ||
var isUser = this.user !== undefined; | ||
return "".concat(this.scheme, "://").concat(this.hostName, "/scm/").concat(isUser ? '~' + this.user : this.project.toLowerCase(), "/").concat(this.repo, ".git"); | ||
}; | ||
BitbucketServerUrl.prototype.getRepoName = function () { | ||
getContentUrl(path) { | ||
const isUser = this.user !== undefined; | ||
return `${this.scheme}://${this.hostName}/${isUser ? 'users' : 'projects'}/${isUser ? this.user : this.project}/repos/${this.repo}/raw/${path}${this.branch !== undefined ? '?/at=' + this.branch : ''}`; | ||
} | ||
getUrl() { | ||
const isUser = this.user !== undefined; | ||
return `${this.scheme}://${this.hostName}/${isUser ? 'users' : 'projects'}/${isUser ? this.user : this.project}/repos/${this.repo}${this.branch !== undefined ? '/browse?at=' + this.branch : ''}`; | ||
} | ||
getCloneUrl() { | ||
const isUser = this.user !== undefined; | ||
return `${this.scheme}://${this.hostName}/scm/${isUser ? '~' + this.user : this.project.toLowerCase()}/${this.repo}.git`; | ||
} | ||
getRepoName() { | ||
return this.repo; | ||
}; | ||
BitbucketServerUrl.prototype.getBranchName = function () { | ||
} | ||
getBranchName() { | ||
return this.branch; | ||
}; | ||
return BitbucketServerUrl; | ||
}()); | ||
} | ||
} | ||
exports.BitbucketServerUrl = BitbucketServerUrl; | ||
//# sourceMappingURL=bitbucket-server-url.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bitbucketModule = void 0; | ||
@@ -13,7 +13,7 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var bitbucket_resolver_1 = require("./bitbucket-resolver"); | ||
var types_1 = require("../types"); | ||
var Resolver = types_1.TYPES.Resolver; | ||
var bitbucketModule = new inversify_1.ContainerModule(function (bind) { | ||
const inversify_1 = require("inversify"); | ||
const bitbucket_resolver_1 = require("./bitbucket-resolver"); | ||
const types_1 = require("../types"); | ||
const { Resolver } = types_1.TYPES; | ||
const bitbucketModule = new inversify_1.ContainerModule((bind) => { | ||
bind(Resolver).to(bitbucket_resolver_1.BitbucketResolver).inSingletonScope(); | ||
@@ -20,0 +20,0 @@ }); |
@@ -17,27 +17,28 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
var BitbucketResolver_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BitbucketResolver = void 0; | ||
var bitbucket_url_1 = require("./bitbucket-url"); | ||
var inversify_1 = require("inversify"); | ||
var BitbucketResolver = /** @class */ (function () { | ||
function BitbucketResolver() { | ||
const bitbucket_url_1 = require("./bitbucket-url"); | ||
const inversify_1 = require("inversify"); | ||
let BitbucketResolver = class BitbucketResolver { | ||
static { BitbucketResolver_1 = this; } | ||
// eslint-disable-next-line max-len | ||
static BITBUCKET_URL_PATTERN = /^https:\/\/.*@?bitbucket\.org\/(?<workspaceId>[^\/]+)\/(?<repoName>[^\/]+)(\/(src|branch)\/(?<branchName>[^\/]+))?\/?$/; | ||
isValid(url) { | ||
return BitbucketResolver_1.BITBUCKET_URL_PATTERN.test(url); | ||
} | ||
BitbucketResolver_1 = BitbucketResolver; | ||
BitbucketResolver.prototype.isValid = function (url) { | ||
return BitbucketResolver_1.BITBUCKET_URL_PATTERN.test(url); | ||
}; | ||
BitbucketResolver.prototype.resolve = function (url) { | ||
var match = BitbucketResolver_1.BITBUCKET_URL_PATTERN.exec(url); | ||
resolve(url) { | ||
const match = BitbucketResolver_1.BITBUCKET_URL_PATTERN.exec(url); | ||
if (!match) { | ||
throw new Error("Invalid bitbucket URL: ".concat(url)); | ||
throw new Error(`Invalid bitbucket URL: ${url}`); | ||
} | ||
var workspaceId = this.getGroup(match, 'workspaceId'); | ||
var repoName = this.getGroup(match, 'repoName'); | ||
const workspaceId = this.getGroup(match, 'workspaceId'); | ||
let repoName = this.getGroup(match, 'repoName'); | ||
if (/^[\w-][\w.-]*?\.git$/.test(repoName)) { | ||
repoName = repoName.substring(0, repoName.length - 4); | ||
} | ||
var branchName = this.getGroup(match, 'branchName', 'HEAD'); | ||
const branchName = this.getGroup(match, 'branchName', 'HEAD'); | ||
return new bitbucket_url_1.BitbucketUrl(workspaceId, repoName, branchName); | ||
}; | ||
BitbucketResolver.prototype.getGroup = function (match, groupName, defaultValue) { | ||
} | ||
getGroup(match, groupName, defaultValue) { | ||
if (match.groups && match.groups[groupName]) { | ||
@@ -47,12 +48,8 @@ return match.groups[groupName]; | ||
return defaultValue; | ||
}; | ||
var BitbucketResolver_1; | ||
// eslint-disable-next-line max-len | ||
BitbucketResolver.BITBUCKET_URL_PATTERN = /^https:\/\/.*@?bitbucket\.org\/(?<workspaceId>[^\/]+)\/(?<repoName>[^\/]+)(\/(src|branch)\/(?<branchName>[^\/]+))?\/?$/; | ||
BitbucketResolver = BitbucketResolver_1 = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], BitbucketResolver); | ||
return BitbucketResolver; | ||
}()); | ||
} | ||
}; | ||
exports.BitbucketResolver = BitbucketResolver; | ||
exports.BitbucketResolver = BitbucketResolver = BitbucketResolver_1 = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], BitbucketResolver); | ||
//# sourceMappingURL=bitbucket-resolver.js.map |
@@ -11,6 +11,10 @@ "use strict"; | ||
***********************************************************************/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BitbucketUrl = void 0; | ||
var BitbucketUrl = /** @class */ (function () { | ||
function BitbucketUrl(workspaceId, repoName, branchName) { | ||
class BitbucketUrl { | ||
workspaceId; | ||
repoName; | ||
branchName; | ||
static BITBUCKET_URL = 'https://bitbucket.org'; | ||
constructor(workspaceId, repoName, branchName) { | ||
this.workspaceId = workspaceId; | ||
@@ -20,21 +24,19 @@ this.repoName = repoName; | ||
} | ||
BitbucketUrl.prototype.getContentUrl = function (path) { | ||
return "".concat(BitbucketUrl.BITBUCKET_URL, "/").concat(this.workspaceId, "/").concat(this.repoName, "/raw/").concat(this.branchName, "/").concat(path); | ||
}; | ||
BitbucketUrl.prototype.getUrl = function () { | ||
return "".concat(BitbucketUrl.BITBUCKET_URL, "/").concat(this.workspaceId, "/").concat(this.repoName, "/src/").concat(this.branchName); | ||
}; | ||
BitbucketUrl.prototype.getCloneUrl = function () { | ||
return "".concat(BitbucketUrl.BITBUCKET_URL, "/").concat(this.workspaceId, "/").concat(this.repoName, ".git"); | ||
}; | ||
BitbucketUrl.prototype.getRepoName = function () { | ||
getContentUrl(path) { | ||
return `${BitbucketUrl.BITBUCKET_URL}/${this.workspaceId}/${this.repoName}/raw/${this.branchName}/${path}`; | ||
} | ||
getUrl() { | ||
return `${BitbucketUrl.BITBUCKET_URL}/${this.workspaceId}/${this.repoName}/src/${this.branchName}`; | ||
} | ||
getCloneUrl() { | ||
return `${BitbucketUrl.BITBUCKET_URL}/${this.workspaceId}/${this.repoName}.git`; | ||
} | ||
getRepoName() { | ||
return this.repoName; | ||
}; | ||
BitbucketUrl.prototype.getBranchName = function () { | ||
} | ||
getBranchName() { | ||
return this.branchName; | ||
}; | ||
BitbucketUrl.BITBUCKET_URL = 'https://bitbucket.org'; | ||
return BitbucketUrl; | ||
}()); | ||
} | ||
} | ||
exports.BitbucketUrl = BitbucketUrl; | ||
//# sourceMappingURL=bitbucket-url.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.devfileSchemaModule = void 0; | ||
@@ -13,5 +13,5 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var devfile_schema_validator_1 = require("./devfile-schema-validator"); | ||
var devfileSchemaModule = new inversify_1.ContainerModule(function (bind) { | ||
const inversify_1 = require("inversify"); | ||
const devfile_schema_validator_1 = require("./devfile-schema-validator"); | ||
const devfileSchemaModule = new inversify_1.ContainerModule((bind) => { | ||
bind(devfile_schema_validator_1.DevfileSchemaValidator).toSelf().inSingletonScope(); | ||
@@ -18,0 +18,0 @@ }); |
@@ -31,3 +31,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DevfileSchemaValidator = void 0; | ||
@@ -43,15 +43,13 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var devfileSchemaV200 = __importStar(require("./2.0.0/devfile.json")); | ||
var devfileSchemaV210 = __importStar(require("./2.1.0/devfile.json")); | ||
var devfileSchemaV220 = __importStar(require("./2.2.0/devfile.json")); | ||
var devfileSchemaV221 = __importStar(require("./2.2.1/devfile.json")); | ||
var devfileSchemaV222 = __importStar(require("./2.2.2/devfile.json")); | ||
var devfileSchemaV230 = __importStar(require("./2.3.0/devfile.json")); | ||
var Validator = __importStar(require("jsonschema")); | ||
var devfile_context_1 = require("../api/devfile-context"); | ||
var DevfileSchemaValidator = /** @class */ (function () { | ||
function DevfileSchemaValidator() { | ||
} | ||
DevfileSchemaValidator.prototype.getDevfileSchema = function (version) { | ||
const inversify_1 = require("inversify"); | ||
const devfileSchemaV200 = __importStar(require("./2.0.0/devfile.json")); | ||
const devfileSchemaV210 = __importStar(require("./2.1.0/devfile.json")); | ||
const devfileSchemaV220 = __importStar(require("./2.2.0/devfile.json")); | ||
const devfileSchemaV221 = __importStar(require("./2.2.1/devfile.json")); | ||
const devfileSchemaV222 = __importStar(require("./2.2.2/devfile.json")); | ||
const devfileSchemaV230 = __importStar(require("./2.3.0/devfile.json")); | ||
const Validator = __importStar(require("jsonschema")); | ||
const devfile_context_1 = require("../api/devfile-context"); | ||
let DevfileSchemaValidator = class DevfileSchemaValidator { | ||
getDevfileSchema(version) { | ||
switch (version) { | ||
@@ -71,17 +69,16 @@ case devfile_context_1.DevfileSchemaVersion.V200: | ||
default: | ||
throw new Error("Dev Workspace generator tool doesn't support devfile version: ".concat(version)); | ||
throw new Error(`Dev Workspace generator tool doesn't support devfile version: ${version}`); | ||
} | ||
}; | ||
} | ||
// Validates devfile against schema | ||
DevfileSchemaValidator.prototype.validateDevfile = function (devfile, version) { | ||
var schema = this.getDevfileSchema(version); | ||
var validatorResult = Validator.validate(devfile, schema, { nestedErrors: true }); | ||
validateDevfile(devfile, version) { | ||
const schema = this.getDevfileSchema(version); | ||
const validatorResult = Validator.validate(devfile, schema, { nestedErrors: true }); | ||
return validatorResult; | ||
}; | ||
DevfileSchemaValidator = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], DevfileSchemaValidator); | ||
return DevfileSchemaValidator; | ||
}()); | ||
} | ||
}; | ||
exports.DevfileSchemaValidator = DevfileSchemaValidator; | ||
exports.DevfileSchemaValidator = DevfileSchemaValidator = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], DevfileSchemaValidator); | ||
//# sourceMappingURL=devfile-schema-validator.js.map |
@@ -17,89 +17,47 @@ "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()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DevContainerComponentFinder = void 0; | ||
var inversify_1 = require("inversify"); | ||
var dev_container_component_inserter_1 = require("./dev-container-component-inserter"); | ||
const inversify_1 = require("inversify"); | ||
const dev_container_component_inserter_1 = require("./dev-container-component-inserter"); | ||
/** | ||
* Need to find dev container from main dev workspace | ||
*/ | ||
var DevContainerComponentFinder = /** @class */ (function () { | ||
function DevContainerComponentFinder() { | ||
let DevContainerComponentFinder = class DevContainerComponentFinder { | ||
devContainerComponentInserter; | ||
async find(devfileContext, injectDefaultComponent, defaultComponentImage) { | ||
// if a devfile contains a parent, we should not add a default dev container | ||
if (devfileContext.devfile?.parent) { | ||
return undefined; | ||
} | ||
// search in main devWorkspace | ||
const devComponents = devfileContext.devWorkspace.spec?.template?.components | ||
?.filter(component => component.container) | ||
.filter( | ||
// we should ignore component that do not mount the sources | ||
component => component.container && component.container.mountSources !== false); | ||
if (!devComponents || devComponents.length === 0) { | ||
// 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) { | ||
return devComponents[0]; | ||
} | ||
else { | ||
console.warn(`More than one dev container component has been potentially found, taking the first one of ${devComponents.map(component => component.name)}`); | ||
return devComponents[0]; | ||
} | ||
} | ||
DevContainerComponentFinder.prototype.find = function (devfileContext, injectDefaultComponent, defaultComponentImage) { | ||
var _a, _b, _c, _d; | ||
return __awaiter(this, void 0, void 0, function () { | ||
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; }); | ||
if (!devComponents || devComponents.length === 0) { | ||
// 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]]; | ||
} | ||
else if (devComponents.length === 1) { | ||
return [2 /*return*/, devComponents[0]]; | ||
} | ||
else { | ||
console.warn("More than one dev container component has been potentially found, taking the first one of ".concat(devComponents.map(function (component) { return component.name; }))); | ||
return [2 /*return*/, devComponents[0]]; | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
__decorate([ | ||
(0, inversify_1.inject)(dev_container_component_inserter_1.DevContainerComponentInserter) | ||
], DevContainerComponentFinder.prototype, "devContainerComponentInserter"); | ||
DevContainerComponentFinder = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], DevContainerComponentFinder); | ||
return DevContainerComponentFinder; | ||
}()); | ||
}; | ||
exports.DevContainerComponentFinder = DevContainerComponentFinder; | ||
__decorate([ | ||
(0, inversify_1.inject)(dev_container_component_inserter_1.DevContainerComponentInserter) | ||
], DevContainerComponentFinder.prototype, "devContainerComponentInserter", void 0); | ||
exports.DevContainerComponentFinder = DevContainerComponentFinder = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], DevContainerComponentFinder); | ||
//# sourceMappingURL=dev-container-component-finder.js.map |
@@ -17,83 +17,38 @@ "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()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DevContainerComponentInserter = void 0; | ||
var inversify_1 = require("inversify"); | ||
const inversify_1 = require("inversify"); | ||
/** | ||
* Adds a new component on empty devfile with specific name and image | ||
*/ | ||
var DevContainerComponentInserter = /** @class */ (function () { | ||
function DevContainerComponentInserter() { | ||
this.DEFAULT_DEV_CONTAINER_IMAGE = 'quay.io/devfile/universal-developer-image:ubi8-latest'; | ||
this.DEFAULT_DEV_CONTAINER_NAME = 'dev'; | ||
let DevContainerComponentInserter = class DevContainerComponentInserter { | ||
DEFAULT_DEV_CONTAINER_IMAGE = 'quay.io/devfile/universal-developer-image:ubi8-latest'; | ||
DEFAULT_DEV_CONTAINER_NAME = 'dev'; | ||
async insert(devfileContext, defaultComponentImage) { | ||
if (!devfileContext.devWorkspace.spec) { | ||
devfileContext.devWorkspace.spec = { | ||
started: true, | ||
}; | ||
} | ||
if (!devfileContext.devWorkspace.spec.template) { | ||
devfileContext.devWorkspace.spec.template = {}; | ||
} | ||
if (!devfileContext.devWorkspace.spec.template.components) { | ||
devfileContext.devWorkspace.spec.template.components = []; | ||
} | ||
const devContainerImage = defaultComponentImage ? defaultComponentImage : this.DEFAULT_DEV_CONTAINER_IMAGE; | ||
console.log(`No container component has been found. A default container component with image ${devContainerImage} will be added.`); | ||
const devContainerComponent = { | ||
name: this.DEFAULT_DEV_CONTAINER_NAME, | ||
container: { | ||
image: devContainerImage, | ||
}, | ||
}; | ||
devfileContext.devWorkspace.spec.template.components.push(devContainerComponent); | ||
} | ||
DevContainerComponentInserter.prototype.insert = function (devfileContext, defaultComponentImage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var devContainerImage, devContainerComponent; | ||
return __generator(this, function (_a) { | ||
if (!devfileContext.devWorkspace.spec) { | ||
devfileContext.devWorkspace.spec = { | ||
started: true | ||
}; | ||
} | ||
if (!devfileContext.devWorkspace.spec.template) { | ||
devfileContext.devWorkspace.spec.template = {}; | ||
} | ||
if (!devfileContext.devWorkspace.spec.template.components) { | ||
devfileContext.devWorkspace.spec.template.components = []; | ||
} | ||
devContainerImage = defaultComponentImage ? defaultComponentImage : this.DEFAULT_DEV_CONTAINER_IMAGE; | ||
console.log("No container component has been found. A default container component with image ".concat(devContainerImage, " will be added.")); | ||
devContainerComponent = { | ||
name: this.DEFAULT_DEV_CONTAINER_NAME, | ||
container: { | ||
image: devContainerImage | ||
} | ||
}; | ||
devfileContext.devWorkspace.spec.template.components.push(devContainerComponent); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
DevContainerComponentInserter = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], DevContainerComponentInserter); | ||
return DevContainerComponentInserter; | ||
}()); | ||
}; | ||
exports.DevContainerComponentInserter = DevContainerComponentInserter; | ||
exports.DevContainerComponentInserter = DevContainerComponentInserter = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], DevContainerComponentInserter); | ||
//# sourceMappingURL=dev-container-component-inserter.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.devfileModule = void 0; | ||
@@ -13,6 +13,6 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
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) { | ||
const inversify_1 = require("inversify"); | ||
const dev_container_component_finder_1 = require("./dev-container-component-finder"); | ||
const dev_container_component_inserter_1 = require("./dev-container-component-inserter"); | ||
const devfileModule = new inversify_1.ContainerModule((bind) => { | ||
bind(dev_container_component_finder_1.DevContainerComponentFinder).toSelf().inSingletonScope(); | ||
@@ -19,0 +19,0 @@ bind(dev_container_component_inserter_1.DevContainerComponentInserter).toSelf().inSingletonScope(); |
@@ -12,57 +12,12 @@ #!/usr/bin/env node | ||
***********************************************************************/ | ||
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()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("reflect-metadata"); | ||
const main_1 = require("./main"); | ||
(async () => { | ||
const main = new main_1.Main(); | ||
const success = await main.start(); | ||
if (!success) { | ||
process.exit(1); | ||
} | ||
}; | ||
exports.__esModule = true; | ||
require("reflect-metadata"); | ||
var main_1 = require("./main"); | ||
(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var main, success; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
main = new main_1.Main(); | ||
return [4 /*yield*/, main.start()]; | ||
case 1: | ||
success = _a.sent(); | ||
if (!success) { | ||
process.exit(1); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); })(); | ||
})(); | ||
//# sourceMappingURL=entrypoint.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchModule = void 0; | ||
@@ -13,5 +13,5 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var url_fetcher_1 = require("./url-fetcher"); | ||
var fetchModule = new inversify_1.ContainerModule(function (bind) { | ||
const inversify_1 = require("inversify"); | ||
const url_fetcher_1 = require("./url-fetcher"); | ||
const fetchModule = new inversify_1.ContainerModule((bind) => { | ||
bind(url_fetcher_1.UrlFetcher).toSelf().inSingletonScope(); | ||
@@ -18,0 +18,0 @@ }); |
@@ -8,39 +8,3 @@ "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()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UrlFetcher = void 0; | ||
@@ -56,3 +20,3 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
const inversify_1 = require("inversify"); | ||
/** | ||
@@ -62,56 +26,38 @@ * Allow to grab external content | ||
*/ | ||
var UrlFetcher = /** @class */ (function () { | ||
function UrlFetcher() { | ||
} | ||
let UrlFetcher = class UrlFetcher { | ||
// Can't use AxiosInstance interface there | ||
axiosInstance; | ||
// fetch content optionally, if the URL is not found, we return undefined without throwing errors | ||
UrlFetcher.prototype.fetchTextOptionalContent = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, this.axiosInstance.get(url, { | ||
responseType: 'text' | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response.data]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
// not found then we return undefined | ||
if (error_1.response && error_1.response.status === 404) { | ||
return [2 /*return*/, undefined]; | ||
} | ||
throw error_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
async fetchTextOptionalContent(url) { | ||
try { | ||
const response = await 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 | ||
UrlFetcher.prototype.fetchText = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.axiosInstance.get(url, { | ||
responseType: 'text' | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response.data]; | ||
} | ||
}); | ||
async fetchText(url) { | ||
const response = await this.axiosInstance.get(url, { | ||
responseType: 'text', | ||
}); | ||
}; | ||
__decorate([ | ||
(0, inversify_1.inject)(Symbol["for"]('AxiosInstance')) | ||
], UrlFetcher.prototype, "axiosInstance"); | ||
UrlFetcher = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], UrlFetcher); | ||
return UrlFetcher; | ||
}()); | ||
return response.data; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} | ||
}; | ||
exports.UrlFetcher = UrlFetcher; | ||
__decorate([ | ||
(0, inversify_1.inject)(Symbol.for('AxiosInstance')) | ||
], UrlFetcher.prototype, "axiosInstance", void 0); | ||
exports.UrlFetcher = UrlFetcher = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], UrlFetcher); | ||
//# sourceMappingURL=url-fetcher.js.map |
@@ -40,138 +40,84 @@ "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()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Generate = void 0; | ||
var inversify_1 = require("inversify"); | ||
var jsYaml = __importStar(require("js-yaml")); | ||
var fs = __importStar(require("fs-extra")); | ||
var dev_container_component_finder_1 = require("./devfile/dev-container-component-finder"); | ||
var Generate = /** @class */ (function () { | ||
function Generate() { | ||
const inversify_1 = require("inversify"); | ||
const jsYaml = __importStar(require("js-yaml")); | ||
const fs = __importStar(require("fs-extra")); | ||
const dev_container_component_finder_1 = require("./devfile/dev-container-component-finder"); | ||
let Generate = class Generate { | ||
devContainerComponentFinder; | ||
async generate(devfileContent, editorContent, outputFile, injectDefaultComponent, defaultComponentImage) { | ||
const context = await this.generateContent(devfileContent, editorContent, injectDefaultComponent, defaultComponentImage); | ||
// write the result | ||
if (outputFile) { | ||
// write templates and then DevWorkspace in a single file | ||
const allContentArray = context.devWorkspaceTemplates.map(template => jsYaml.dump(template)); | ||
allContentArray.push(jsYaml.dump(context.devWorkspace)); | ||
const generatedContent = allContentArray.join('---\n'); | ||
await fs.writeFile(outputFile, generatedContent, 'utf-8'); | ||
} | ||
console.log(`DevWorkspace ${context.devWorkspaceTemplates[0].metadata.name} was generated`); | ||
return context; | ||
} | ||
Generate.prototype.generate = function (devfileContent, editorContent, outputFile, injectDefaultComponent, defaultComponentImage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var context, allContentArray, generatedContent; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.generateContent(devfileContent, editorContent, injectDefaultComponent, defaultComponentImage)]; | ||
case 1: | ||
context = _a.sent(); | ||
if (!outputFile) return [3 /*break*/, 3]; | ||
allContentArray = context.devWorkspaceTemplates.map(function (template) { return jsYaml.dump(template); }); | ||
allContentArray.push(jsYaml.dump(context.devWorkspace)); | ||
generatedContent = allContentArray.join('---\n'); | ||
return [4 /*yield*/, fs.writeFile(outputFile, generatedContent, 'utf-8')]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: | ||
console.log("DevWorkspace ".concat(context.devWorkspaceTemplates[0].metadata.name, " was generated")); | ||
return [2 /*return*/, context]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Generate.prototype.generateContent = function (devfileContent, editorContent, injectDefaultComponent, defaultComponentImage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var devfile, suffix, editorDevfile, metadata, editorDevWorkspaceTemplate, devfileMetadata, devfileCopy, editorSpecContribution, devWorkspace, devWorkspaceTemplates, context; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
devfile = jsYaml.load(devfileContent); | ||
suffix = devfile.metadata.name || ''; | ||
editorDevfile = jsYaml.load(editorContent); | ||
metadata = this.createDevWorkspaceMetadata(editorDevfile); | ||
// add sufix | ||
metadata.name = "".concat(metadata.name, "-").concat(suffix); | ||
delete editorDevfile.metadata; | ||
delete editorDevfile.schemaVersion; | ||
editorDevWorkspaceTemplate = { | ||
apiVersion: 'workspace.devfile.io/v1alpha2', | ||
kind: 'DevWorkspaceTemplate', | ||
metadata: metadata, | ||
spec: editorDevfile | ||
}; | ||
devfileMetadata = this.createDevWorkspaceMetadata(devfile, true); | ||
devfileCopy = Object.assign({}, devfile); | ||
delete devfileCopy.schemaVersion; | ||
delete devfileCopy.metadata; | ||
editorSpecContribution = { | ||
name: 'editor', | ||
kubernetes: { | ||
name: editorDevWorkspaceTemplate.metadata.name | ||
} | ||
}; | ||
devWorkspace = { | ||
apiVersion: 'workspace.devfile.io/v1alpha2', | ||
kind: 'DevWorkspace', | ||
metadata: devfileMetadata, | ||
spec: { | ||
started: true, | ||
routingClass: 'che', | ||
template: devfileCopy, | ||
contributions: [editorSpecContribution] | ||
} | ||
}; | ||
// if the devfile has a starter project, we use it for the devWorkspace | ||
if (devfileCopy.starterProjects && devfileCopy.starterProjects.length > 0) { | ||
devWorkspace.spec.template.attributes = { | ||
'controller.devfile.io/use-starter-project': devfileCopy.starterProjects[0].name | ||
}; | ||
} | ||
devWorkspaceTemplates = [editorDevWorkspaceTemplate]; | ||
context = { | ||
devfile: devfile, | ||
devWorkspace: devWorkspace, | ||
devWorkspaceTemplates: devWorkspaceTemplates, | ||
suffix: suffix | ||
}; | ||
// find devContainer component, add a default one if not found | ||
return [4 /*yield*/, this.devContainerComponentFinder.find(context, injectDefaultComponent, defaultComponentImage)]; | ||
case 1: | ||
// find devContainer component, add a default one if not found | ||
_a.sent(); | ||
return [2 /*return*/, context]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Generate.prototype.createDevWorkspaceMetadata = function (devfile, addDevfileContent) { | ||
if (addDevfileContent === void 0) { addDevfileContent = false; } | ||
var devWorkspaceMetadata = {}; | ||
var devfileMetadata = devfile.metadata; | ||
async generateContent(devfileContent, editorContent, injectDefaultComponent, defaultComponentImage) { | ||
const devfile = jsYaml.load(devfileContent); | ||
// sets the suffix to the devfile name | ||
const suffix = devfile.metadata.name || ''; | ||
// devfile of the editor | ||
const editorDevfile = jsYaml.load(editorContent); | ||
// transform it into a devWorkspace template | ||
const metadata = this.createDevWorkspaceMetadata(editorDevfile); | ||
// 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, | ||
}; | ||
// transform it into a devWorkspace | ||
const devfileMetadata = this.createDevWorkspaceMetadata(devfile, true); | ||
const devfileCopy = Object.assign({}, devfile); | ||
delete devfileCopy.schemaVersion; | ||
delete devfileCopy.metadata; | ||
const editorSpecContribution = { | ||
name: 'editor', | ||
kubernetes: { | ||
name: editorDevWorkspaceTemplate.metadata.name, | ||
}, | ||
}; | ||
const devWorkspace = { | ||
apiVersion: 'workspace.devfile.io/v1alpha2', | ||
kind: 'DevWorkspace', | ||
metadata: devfileMetadata, | ||
spec: { | ||
started: true, | ||
routingClass: 'che', | ||
template: devfileCopy, | ||
contributions: [editorSpecContribution], | ||
}, | ||
}; | ||
// if the devfile has a starter project, we use it for the devWorkspace | ||
if (devfileCopy.starterProjects && devfileCopy.starterProjects.length > 0) { | ||
devWorkspace.spec.template.attributes = { | ||
'controller.devfile.io/use-starter-project': devfileCopy.starterProjects[0].name, | ||
}; | ||
} | ||
// for now the list of devWorkspace templates is only the editor template | ||
const devWorkspaceTemplates = [editorDevWorkspaceTemplate]; | ||
const context = { | ||
devfile, | ||
devWorkspace, | ||
devWorkspaceTemplates, | ||
suffix, | ||
}; | ||
// find devContainer component, add a default one if not found | ||
await this.devContainerComponentFinder.find(context, injectDefaultComponent, defaultComponentImage); | ||
return context; | ||
} | ||
createDevWorkspaceMetadata(devfile, addDevfileContent = false) { | ||
const devWorkspaceMetadata = {}; | ||
const devfileMetadata = devfile.metadata; | ||
if (devfileMetadata.name) { | ||
@@ -185,16 +131,15 @@ devWorkspaceMetadata.name = devfileMetadata.name; | ||
devWorkspaceMetadata.annotations = { | ||
'che.eclipse.org/devfile': jsYaml.dump(devfile) | ||
'che.eclipse.org/devfile': jsYaml.dump(devfile), | ||
}; | ||
} | ||
return devWorkspaceMetadata; | ||
}; | ||
__decorate([ | ||
(0, inversify_1.inject)(dev_container_component_finder_1.DevContainerComponentFinder) | ||
], Generate.prototype, "devContainerComponentFinder"); | ||
Generate = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], Generate); | ||
return Generate; | ||
}()); | ||
} | ||
}; | ||
exports.Generate = Generate; | ||
__decorate([ | ||
(0, inversify_1.inject)(dev_container_component_finder_1.DevContainerComponentFinder) | ||
], Generate.prototype, "devContainerComponentFinder", void 0); | ||
exports.Generate = Generate = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], Generate); | ||
//# sourceMappingURL=generate.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.githubModule = void 0; | ||
@@ -13,7 +13,7 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var github_resolver_1 = require("./github-resolver"); | ||
var types_1 = require("../types"); | ||
var Resolver = types_1.TYPES.Resolver; | ||
var githubModule = new inversify_1.ContainerModule(function (bind) { | ||
const inversify_1 = require("inversify"); | ||
const github_resolver_1 = require("./github-resolver"); | ||
const types_1 = require("../types"); | ||
const { Resolver } = types_1.TYPES; | ||
const githubModule = new inversify_1.ContainerModule((bind) => { | ||
bind(Resolver).to(github_resolver_1.GithubResolver).inSingletonScope(); | ||
@@ -20,0 +20,0 @@ }); |
@@ -17,30 +17,31 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
var GithubResolver_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GithubResolver = void 0; | ||
var github_url_1 = require("./github-url"); | ||
var inversify_1 = require("inversify"); | ||
var GithubResolver = /** @class */ (function () { | ||
function GithubResolver() { | ||
const github_url_1 = require("./github-url"); | ||
const inversify_1 = require("inversify"); | ||
let GithubResolver = class GithubResolver { | ||
static { GithubResolver_1 = this; } | ||
// eslint-disable-next-line max-len | ||
static GITHUB_URL_PATTERN = /^(?<scheme>https?):\/\/(?<host>github(\..+)?\.[^\/]+)\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?)?$/; | ||
isValid(url) { | ||
return GithubResolver_1.GITHUB_URL_PATTERN.test(url); | ||
} | ||
GithubResolver_1 = GithubResolver; | ||
GithubResolver.prototype.isValid = function (url) { | ||
return GithubResolver_1.GITHUB_URL_PATTERN.test(url); | ||
}; | ||
GithubResolver.prototype.resolve = function (link) { | ||
var match = GithubResolver_1.GITHUB_URL_PATTERN.exec(link); | ||
resolve(link) { | ||
const match = GithubResolver_1.GITHUB_URL_PATTERN.exec(link); | ||
if (!match) { | ||
throw new Error("Invalid github URL: ".concat(link)); | ||
throw new Error(`Invalid github URL: ${link}`); | ||
} | ||
var scheme = this.getGroup(match, 'scheme'); | ||
var hostName = this.getGroup(match, 'host'); | ||
var repoUser = this.getGroup(match, 'repoUser'); | ||
var repoName = this.getGroup(match, 'repoName'); | ||
const scheme = this.getGroup(match, 'scheme'); | ||
const hostName = this.getGroup(match, 'host'); | ||
const repoUser = this.getGroup(match, 'repoUser'); | ||
let repoName = this.getGroup(match, 'repoName'); | ||
if (/^[\w-][\w.-]*?\.git$/.test(repoName)) { | ||
repoName = repoName.substring(0, repoName.length - 4); | ||
} | ||
var branchName = this.getGroup(match, 'branchName', 'HEAD'); | ||
var subFolder = this.getGroup(match, 'subFolder'); | ||
const branchName = this.getGroup(match, 'branchName', 'HEAD'); | ||
const subFolder = this.getGroup(match, 'subFolder'); | ||
return new github_url_1.GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder); | ||
}; | ||
GithubResolver.prototype.getGroup = function (match, groupName, defaultValue) { | ||
} | ||
getGroup(match, groupName, defaultValue) { | ||
if (match.groups && match.groups[groupName]) { | ||
@@ -50,12 +51,8 @@ return match.groups[groupName]; | ||
return defaultValue || ''; | ||
}; | ||
var GithubResolver_1; | ||
// eslint-disable-next-line max-len | ||
GithubResolver.GITHUB_URL_PATTERN = /^(?<scheme>https?):\/\/(?<host>github(\..+)?\.[^\/]+)\/(?<repoUser>[^\/]+)\/(?<repoName>[^\/]+)((\/)|\/(blob|tree)\/(?<branchName>[^\/]+)(?:\/(?<subFolder>.*))?)?$/; | ||
GithubResolver = GithubResolver_1 = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], GithubResolver); | ||
return GithubResolver; | ||
}()); | ||
} | ||
}; | ||
exports.GithubResolver = GithubResolver; | ||
exports.GithubResolver = GithubResolver = GithubResolver_1 = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], GithubResolver); | ||
//# sourceMappingURL=github-resolver.js.map |
@@ -11,6 +11,12 @@ "use strict"; | ||
***********************************************************************/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GithubUrl = void 0; | ||
var GithubUrl = /** @class */ (function () { | ||
function GithubUrl(scheme, hostName, repoUser, repoName, branchName, subFolder) { | ||
class GithubUrl { | ||
scheme; | ||
hostName; | ||
repoUser; | ||
repoName; | ||
branchName; | ||
subFolder; | ||
constructor(scheme, hostName, repoUser, repoName, branchName, subFolder) { | ||
this.scheme = scheme; | ||
@@ -26,21 +32,20 @@ this.hostName = hostName; | ||
*/ | ||
GithubUrl.prototype.getContentUrl = function (path) { | ||
var hostName = this.hostName === 'github.com' ? 'githubusercontent.com' : this.hostName; | ||
return "".concat(this.scheme, "://raw.").concat(hostName, "/").concat(this.repoUser, "/").concat(this.repoName, "/").concat(this.branchName, "/").concat(path); | ||
}; | ||
GithubUrl.prototype.getUrl = function () { | ||
return "".concat(this.scheme, "://").concat(this.hostName, "/").concat(this.repoUser, "/").concat(this.repoName, "/tree/").concat(this.branchName, "/").concat(this.subFolder); | ||
}; | ||
GithubUrl.prototype.getCloneUrl = function () { | ||
return "".concat(this.scheme, "://").concat(this.hostName, "/").concat(this.repoUser, "/").concat(this.repoName, ".git"); | ||
}; | ||
GithubUrl.prototype.getRepoName = function () { | ||
getContentUrl(path) { | ||
const hostName = this.hostName === 'github.com' ? 'githubusercontent.com' : this.hostName; | ||
return `${this.scheme}://raw.${hostName}/${this.repoUser}/${this.repoName}/${this.branchName}/${path}`; | ||
} | ||
getUrl() { | ||
return `${this.scheme}://${this.hostName}/${this.repoUser}/${this.repoName}/tree/${this.branchName}/${this.subFolder}`; | ||
} | ||
getCloneUrl() { | ||
return `${this.scheme}://${this.hostName}/${this.repoUser}/${this.repoName}.git`; | ||
} | ||
getRepoName() { | ||
return this.repoName; | ||
}; | ||
GithubUrl.prototype.getBranchName = function () { | ||
} | ||
getBranchName() { | ||
return this.branchName; | ||
}; | ||
return GithubUrl; | ||
}()); | ||
} | ||
} | ||
exports.GithubUrl = GithubUrl; | ||
//# sourceMappingURL=github-url.js.map |
@@ -24,4 +24,3 @@ /********************************************************************** | ||
export interface InversifyBindingOptions { | ||
pluginRegistryUrl: string; | ||
axiosInstance: AxiosInstance; | ||
} |
"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()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InversifyBinding = void 0; | ||
@@ -50,38 +14,31 @@ /********************************************************************** | ||
require("reflect-metadata"); | ||
var inversify_1 = require("inversify"); | ||
var devfile_module_1 = require("../devfile/devfile-module"); | ||
var fetch_module_1 = require("../fetch/fetch-module"); | ||
var github_module_1 = require("../github/github-module"); | ||
var resolve_module_1 = require("../resolve/resolve-module"); | ||
var plugin_registry_module_1 = require("../plugin-registry/plugin-registry-module"); | ||
var devfile_schema_module_1 = require("../devfile-schema/devfile-schema-module"); | ||
var bitbucket_module_1 = require("../bitbucket/bitbucket-module"); | ||
var bitbucket_server_module_1 = require("../bitbucket-server/bitbucket-server-module"); | ||
const inversify_1 = require("inversify"); | ||
const devfile_module_1 = require("../devfile/devfile-module"); | ||
const fetch_module_1 = require("../fetch/fetch-module"); | ||
const github_module_1 = require("../github/github-module"); | ||
const resolve_module_1 = require("../resolve/resolve-module"); | ||
const editor_module_1 = require("../editor/editor-module"); | ||
const devfile_schema_module_1 = require("../devfile-schema/devfile-schema-module"); | ||
const bitbucket_module_1 = require("../bitbucket/bitbucket-module"); | ||
const bitbucket_server_module_1 = require("../bitbucket-server/bitbucket-server-module"); | ||
/** | ||
* Manage all bindings for inversify | ||
*/ | ||
var InversifyBinding = /** @class */ (function () { | ||
function InversifyBinding() { | ||
class InversifyBinding { | ||
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(bitbucket_module_1.bitbucketModule); | ||
this.container.load(bitbucket_server_module_1.bitbucketServerModule); | ||
this.container.load(resolve_module_1.resolveModule); | ||
this.container.load(editor_module_1.editorModule); | ||
this.container.load(devfile_schema_module_1.devfileSchemaModule); | ||
this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance); | ||
return this.container; | ||
} | ||
InversifyBinding.prototype.initBindings = function (options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
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(bitbucket_module_1.bitbucketModule); | ||
this.container.load(bitbucket_server_module_1.bitbucketServerModule); | ||
this.container.load(resolve_module_1.resolveModule); | ||
this.container.load(plugin_registry_module_1.pluginRegistryModule); | ||
this.container.load(devfile_schema_module_1.devfileSchemaModule); | ||
this.container.bind(Symbol["for"]('AxiosInstance')).toConstantValue(options.axiosInstance); | ||
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL'); | ||
return [2 /*return*/, this.container]; | ||
}); | ||
}); | ||
}; | ||
return InversifyBinding; | ||
}()); | ||
} | ||
exports.InversifyBinding = InversifyBinding; | ||
//# sourceMappingURL=inversify-binding.js.map |
@@ -24,4 +24,3 @@ /********************************************************************** | ||
editorContent?: string; | ||
editorEntry?: string; | ||
pluginRegistryUrl?: string; | ||
editorUrl?: string; | ||
projects: { | ||
@@ -28,0 +27,0 @@ name: string; |
381
lib/main.js
@@ -34,155 +34,96 @@ "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()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Main = void 0; | ||
var axios = __importStar(require("axios")); | ||
var fs = __importStar(require("fs-extra")); | ||
var generate_1 = require("./generate"); | ||
var devfile_schema_validator_1 = require("./devfile-schema/devfile-schema-validator"); | ||
var jsYaml = __importStar(require("js-yaml")); | ||
var inversify_binding_1 = require("./inversify/inversify-binding"); | ||
var url_fetcher_1 = require("./fetch/url-fetcher"); | ||
var plugin_registry_resolver_1 = require("./plugin-registry/plugin-registry-resolver"); | ||
var git_url_resolver_1 = require("./resolve/git-url-resolver"); | ||
var Main = /** @class */ (function () { | ||
const axios = __importStar(require("axios")); | ||
const fs = __importStar(require("fs-extra")); | ||
const generate_1 = require("./generate"); | ||
const devfile_schema_validator_1 = require("./devfile-schema/devfile-schema-validator"); | ||
const jsYaml = __importStar(require("js-yaml")); | ||
const inversify_binding_1 = require("./inversify/inversify-binding"); | ||
const url_fetcher_1 = require("./fetch/url-fetcher"); | ||
const editor_resolver_1 = require("./editor/editor-resolver"); | ||
const git_url_resolver_1 = require("./resolve/git-url-resolver"); | ||
class Main { | ||
/** | ||
* Default constructor. | ||
*/ | ||
function Main() { | ||
constructor() { | ||
// no-op | ||
} | ||
// Generates a devfile context object based on params | ||
Main.prototype.generateDevfileContext = function (params, axiosInstance) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var pluginRegistryUrl, inversifyBinbding, container, devfileContent, editorContent, resolver, url, devfileParsed, jsYamlDevfileContent, schemaVersion, devfileSchemaValidator, validationResult, editorDevfile, generate; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!params.editorPath && !params.editorEntry && !params.editorContent) { | ||
throw new Error('missing editorPath or editorEntry or editorContent'); | ||
} | ||
if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { | ||
throw new Error('missing devfilePath or devfileUrl or devfileContent'); | ||
} | ||
if (params.pluginRegistryUrl) { | ||
pluginRegistryUrl = params.pluginRegistryUrl; | ||
} | ||
else { | ||
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3'; | ||
console.log("No plug-in registry url. Setting to ".concat(pluginRegistryUrl)); | ||
} | ||
inversifyBinbding = new inversify_binding_1.InversifyBinding(); | ||
return [4 /*yield*/, inversifyBinbding.initBindings({ | ||
pluginRegistryUrl: pluginRegistryUrl, | ||
axiosInstance: axiosInstance | ||
})]; | ||
case 1: | ||
container = _a.sent(); | ||
container.bind(generate_1.Generate).toSelf().inSingletonScope(); | ||
if (!params.devfileUrl) return [3 /*break*/, 3]; | ||
resolver = container.get(git_url_resolver_1.GitUrlResolver); | ||
url = resolver.resolve(params.devfileUrl); | ||
return [4 /*yield*/, container.get(url_fetcher_1.UrlFetcher).fetchText(url.getContentUrl('devfile.yaml'))]; | ||
case 2: | ||
// user devfile | ||
devfileContent = _a.sent(); | ||
devfileParsed = jsYaml.load(devfileContent); | ||
// is there projects in the devfile ? | ||
if (devfileParsed && !devfileParsed.projects) { | ||
// no, so add the current project being cloned | ||
devfileParsed.projects = [ | ||
{ | ||
name: url.getRepoName(), | ||
git: { | ||
remotes: { origin: url.getCloneUrl() }, | ||
checkoutFrom: { revision: url.getBranchName() } | ||
} | ||
}, | ||
]; | ||
} | ||
// get back the content | ||
devfileContent = jsYaml.dump(devfileParsed); | ||
return [3 /*break*/, 6]; | ||
case 3: | ||
if (!params.devfilePath) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, fs.readFile(params.devfilePath)]; | ||
case 4: | ||
devfileContent = _a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 5: | ||
devfileContent = params.devfileContent; | ||
_a.label = 6; | ||
case 6: | ||
jsYamlDevfileContent = jsYaml.load(devfileContent); | ||
schemaVersion = jsYamlDevfileContent.schemaVersion; | ||
if (!schemaVersion) { | ||
throw new Error("Devfile is not valid, schemaVersion is required"); | ||
} | ||
devfileSchemaValidator = container.get(devfile_schema_validator_1.DevfileSchemaValidator); | ||
console.log("Validating devfile"); | ||
validationResult = devfileSchemaValidator.validateDevfile(jsYamlDevfileContent, schemaVersion); | ||
if (!validationResult.valid) { | ||
throw new Error("Devfile schema validation failed. Error: ".concat(validationResult.toString())); | ||
} | ||
console.log("Devfile is valid with schema version ".concat(schemaVersion)); | ||
// enhance projects | ||
devfileContent = this.replaceIfExistingProjects(devfileContent, params.projects); | ||
if (!params.editorContent) return [3 /*break*/, 7]; | ||
editorContent = params.editorContent; | ||
return [3 /*break*/, 11]; | ||
case 7: | ||
if (!params.editorEntry) return [3 /*break*/, 9]; | ||
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(params.editorEntry)]; | ||
case 8: | ||
editorDevfile = _a.sent(); | ||
editorContent = jsYaml.dump(editorDevfile); | ||
return [3 /*break*/, 11]; | ||
case 9: return [4 /*yield*/, fs.readFile(params.editorPath)]; | ||
case 10: | ||
editorContent = _a.sent(); | ||
_a.label = 11; | ||
case 11: | ||
generate = container.get(generate_1.Generate); | ||
return [2 /*return*/, generate.generate(devfileContent, editorContent, params.outputFile, params.injectDefaultComponent, params.defaultComponentImage)]; | ||
} | ||
}); | ||
async generateDevfileContext(params, axiosInstance) { | ||
if (!params.editorPath && !params.editorUrl && !params.editorContent) { | ||
throw new Error('missing editorPath or editorUrl or editorContent'); | ||
} | ||
if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { | ||
throw new Error('missing devfilePath or devfileUrl or devfileContent'); | ||
} | ||
const inversifyBinbding = new inversify_binding_1.InversifyBinding(); | ||
const container = await inversifyBinbding.initBindings({ | ||
axiosInstance, | ||
}); | ||
}; | ||
container.bind(generate_1.Generate).toSelf().inSingletonScope(); | ||
let devfileContent; | ||
let editorContent; | ||
// gets the repo URL | ||
if (params.devfileUrl) { | ||
const resolver = container.get(git_url_resolver_1.GitUrlResolver); | ||
const url = resolver.resolve(params.devfileUrl); | ||
// user devfile | ||
devfileContent = await container.get(url_fetcher_1.UrlFetcher).fetchText(url.getContentUrl('devfile.yaml')); | ||
// load content | ||
const devfileParsed = jsYaml.load(devfileContent); | ||
// is there projects in the devfile ? | ||
if (devfileParsed && !devfileParsed.projects) { | ||
// no, so add the current project being cloned | ||
devfileParsed.projects = [ | ||
{ | ||
name: url.getRepoName(), | ||
git: { | ||
remotes: { origin: url.getCloneUrl() }, | ||
checkoutFrom: { revision: url.getBranchName() }, | ||
}, | ||
}, | ||
]; | ||
} | ||
// get back the content | ||
devfileContent = jsYaml.dump(devfileParsed); | ||
} | ||
else if (params.devfilePath) { | ||
devfileContent = await fs.readFile(params.devfilePath); | ||
} | ||
else { | ||
devfileContent = params.devfileContent; | ||
} | ||
const jsYamlDevfileContent = jsYaml.load(devfileContent); | ||
const schemaVersion = jsYamlDevfileContent.schemaVersion; | ||
if (!schemaVersion) { | ||
throw new Error(`Devfile is not valid, schemaVersion is required`); | ||
} | ||
// validate devfile | ||
const devfileSchemaValidator = container.get(devfile_schema_validator_1.DevfileSchemaValidator); | ||
console.log(`Validating devfile`); | ||
const validationResult = devfileSchemaValidator.validateDevfile(jsYamlDevfileContent, schemaVersion); | ||
if (!validationResult.valid) { | ||
throw new Error(`Devfile schema validation failed. Error: ${validationResult.toString()}`); | ||
} | ||
console.log(`Devfile is valid with schema version ${schemaVersion}`); | ||
// enhance projects | ||
devfileContent = this.replaceIfExistingProjects(devfileContent, params.projects); | ||
if (params.editorContent) { | ||
editorContent = params.editorContent; | ||
} | ||
else if (params.editorUrl) { | ||
// devfile of the editor | ||
const editorDevfile = await container.get(editor_resolver_1.EditorResolver).loadEditor(params.editorUrl); | ||
editorContent = jsYaml.dump(editorDevfile); | ||
} | ||
else { | ||
editorContent = await fs.readFile(params.editorPath); | ||
} | ||
const generate = container.get(generate_1.Generate); | ||
return generate.generate(devfileContent, editorContent, params.outputFile, params.injectDefaultComponent, params.defaultComponentImage); | ||
} | ||
// Update project entry based on the projects passed as parameter | ||
Main.prototype.replaceIfExistingProjects = function (devfileContent, projects) { | ||
replaceIfExistingProjects(devfileContent, projects) { | ||
// do nothing if no override | ||
@@ -192,8 +133,8 @@ if (projects.length === 0) { | ||
} | ||
var devfileParsed = jsYaml.load(devfileContent); | ||
const devfileParsed = jsYaml.load(devfileContent); | ||
if (!devfileParsed || !devfileParsed.projects) { | ||
return devfileContent; | ||
} | ||
devfileParsed.projects = devfileParsed.projects.map(function (project) { | ||
var userProjectConfiguration = projects.find(function (p) { return p.name === project.name; }); | ||
devfileParsed.projects = devfileParsed.projects.map(project => { | ||
const userProjectConfiguration = projects.find(p => p.name === project.name); | ||
if (userProjectConfiguration) { | ||
@@ -212,82 +153,72 @@ if (userProjectConfiguration.location.endsWith('.zip')) { | ||
return jsYaml.dump(devfileParsed); | ||
}; | ||
Main.prototype.start = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, injectDefaultComponent, defaultComponentImage, projects, args, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
projects = []; | ||
args = process.argv.slice(2); | ||
args.forEach(function (arg) { | ||
if (arg.startsWith('--devfile-path:')) { | ||
devfilePath = arg.substring('--devfile-path:'.length); | ||
} | ||
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-entry:')) { | ||
editorEntry = arg.substring('--editor-entry:'.length); | ||
} | ||
if (arg.startsWith('--editor-path:')) { | ||
editorPath = arg.substring('--editor-path:'.length); | ||
} | ||
if (arg.startsWith('--output-file:')) { | ||
outputFile = arg.substring('--output-file:'.length); | ||
} | ||
if (arg.startsWith('--project.')) { | ||
var name = arg.substring('--project.'.length, arg.indexOf('=')); | ||
var location = arg.substring(arg.indexOf('=') + 1); | ||
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}'); | ||
projects.push({ name: name, location: location }); | ||
} | ||
if (arg.startsWith('--injectDefaultComponent:')) { | ||
injectDefaultComponent = arg.substring('--injectDefaultComponent:'.length); | ||
} | ||
if (arg.startsWith('--defaultComponentImage:')) { | ||
defaultComponentImage = arg.substring('--defaultComponentImage:'.length); | ||
} | ||
}); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
if (!editorPath && !editorEntry) { | ||
throw new Error('missing --editor-path: or --editor-entry: parameter'); | ||
} | ||
if (!devfilePath && !devfileUrl) { | ||
throw new Error('missing --devfile-path: or --devfile-url: parameter'); | ||
} | ||
if (!outputFile) { | ||
throw new Error('missing --output-file: parameter'); | ||
} | ||
return [4 /*yield*/, this.generateDevfileContext({ | ||
devfilePath: devfilePath, | ||
devfileUrl: devfileUrl, | ||
editorPath: editorPath, | ||
outputFile: outputFile, | ||
pluginRegistryUrl: pluginRegistryUrl, | ||
editorEntry: editorEntry, | ||
projects: projects, | ||
injectDefaultComponent: injectDefaultComponent, | ||
defaultComponentImage: defaultComponentImage | ||
}, axios["default"])]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/, true]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
console.error('stack=' + error_1.stack); | ||
console.error('Unable to start', error_1); | ||
return [2 /*return*/, false]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
} | ||
async start() { | ||
let devfilePath; | ||
let devfileUrl; | ||
let outputFile; | ||
let editorPath; | ||
let editorUrl; | ||
let injectDefaultComponent; | ||
let defaultComponentImage; | ||
const projects = []; | ||
const args = process.argv.slice(2); | ||
args.forEach(arg => { | ||
if (arg.startsWith('--devfile-path:')) { | ||
devfilePath = arg.substring('--devfile-path:'.length); | ||
} | ||
if (arg.startsWith('--devfile-url:')) { | ||
devfileUrl = arg.substring('--devfile-url:'.length); | ||
} | ||
if (arg.startsWith('--editor-url:')) { | ||
editorUrl = arg.substring('--editor-url:'.length); | ||
} | ||
if (arg.startsWith('--editor-path:')) { | ||
editorPath = arg.substring('--editor-path:'.length); | ||
} | ||
if (arg.startsWith('--output-file:')) { | ||
outputFile = arg.substring('--output-file:'.length); | ||
} | ||
if (arg.startsWith('--project.')) { | ||
const name = arg.substring('--project.'.length, arg.indexOf('=')); | ||
let location = arg.substring(arg.indexOf('=') + 1); | ||
location = location.replace('{{_INTERNAL_URL_}}', '{{ INTERNAL_URL }}'); | ||
projects.push({ name, location }); | ||
} | ||
if (arg.startsWith('--injectDefaultComponent:')) { | ||
injectDefaultComponent = arg.substring('--injectDefaultComponent:'.length); | ||
} | ||
if (arg.startsWith('--defaultComponentImage:')) { | ||
defaultComponentImage = arg.substring('--defaultComponentImage:'.length); | ||
} | ||
}); | ||
}; | ||
return Main; | ||
}()); | ||
try { | ||
if (!editorPath && !editorUrl) { | ||
throw new Error('missing --editor-path: or --editor-url: parameter'); | ||
} | ||
if (!devfilePath && !devfileUrl) { | ||
throw new Error('missing --devfile-path: or --devfile-url: parameter'); | ||
} | ||
if (!outputFile) { | ||
throw new Error('missing --output-file: parameter'); | ||
} | ||
await this.generateDevfileContext({ | ||
devfilePath, | ||
devfileUrl, | ||
editorPath, | ||
outputFile, | ||
editorUrl, | ||
projects, | ||
injectDefaultComponent, | ||
defaultComponentImage, | ||
}, axios.default); | ||
return true; | ||
} | ||
catch (error) { | ||
console.error('stack=' + error.stack); | ||
console.error('Unable to start', error); | ||
return false; | ||
} | ||
} | ||
} | ||
exports.Main = Main; | ||
//# sourceMappingURL=main.js.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
}; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GitUrlResolver = void 0; | ||
@@ -20,10 +20,9 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var types_1 = require("../types"); | ||
var Resolver = types_1.TYPES.Resolver; | ||
var GitUrlResolver = /** @class */ (function () { | ||
function GitUrlResolver() { | ||
} | ||
GitUrlResolver.prototype.resolve = function (link) { | ||
var resolver = this.resolvers.find(function (r) { return r.isValid(link); }); | ||
const inversify_1 = require("inversify"); | ||
const types_1 = require("../types"); | ||
const { Resolver } = types_1.TYPES; | ||
let GitUrlResolver = class GitUrlResolver { | ||
resolvers; | ||
resolve(link) { | ||
const resolver = this.resolvers.find(r => r.isValid(link)); | ||
if (resolver) { | ||
@@ -35,12 +34,11 @@ return resolver.resolve(link); | ||
} | ||
}; | ||
__decorate([ | ||
(0, inversify_1.multiInject)(Resolver) | ||
], GitUrlResolver.prototype, "resolvers"); | ||
GitUrlResolver = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], GitUrlResolver); | ||
return GitUrlResolver; | ||
}()); | ||
} | ||
}; | ||
exports.GitUrlResolver = GitUrlResolver; | ||
__decorate([ | ||
(0, inversify_1.multiInject)(Resolver) | ||
], GitUrlResolver.prototype, "resolvers", void 0); | ||
exports.GitUrlResolver = GitUrlResolver = __decorate([ | ||
(0, inversify_1.injectable)() | ||
], GitUrlResolver); | ||
//# sourceMappingURL=git-url-resolver.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveModule = void 0; | ||
@@ -13,5 +13,5 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var inversify_1 = require("inversify"); | ||
var git_url_resolver_1 = require("./git-url-resolver"); | ||
var resolveModule = new inversify_1.ContainerModule(function (bind) { | ||
const inversify_1 = require("inversify"); | ||
const git_url_resolver_1 = require("./git-url-resolver"); | ||
const resolveModule = new inversify_1.ContainerModule((bind) => { | ||
bind(git_url_resolver_1.GitUrlResolver).toSelf().inSingletonScope(); | ||
@@ -18,0 +18,0 @@ }); |
@@ -11,3 +11,3 @@ "use strict"; | ||
***********************************************************************/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=resolver.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
***********************************************************************/ | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=url.js.map |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TYPES = void 0; | ||
@@ -13,6 +13,6 @@ /********************************************************************** | ||
***********************************************************************/ | ||
var TYPES = { | ||
Resolver: Symbol["for"]('Resolver') | ||
const TYPES = { | ||
Resolver: Symbol.for('Resolver'), | ||
}; | ||
exports.TYPES = TYPES; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@eclipse-che/che-devworkspace-generator", | ||
"version": "7.92.0", | ||
"version": "7.93.0-next-8e99f85", | ||
"private": false, | ||
@@ -61,3 +61,3 @@ "description": "Generates DevWorkspaces by transforming existing devfiles", | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.4.4" | ||
"typescript": "^5.6.2" | ||
}, | ||
@@ -64,0 +64,0 @@ "prettier": { |
## DevWorkspace Generator | ||
The library is used by Devfile registry component to generate the DevWorkspace components and DevWorkspace templates. It requires editor definitions from the | ||
[che-plugin-registry](https://github.com/eclipse-che/che-plugin-registry/). | ||
[![Contribute](https://www.eclipse.org/che/contribute.svg)](https://workspaces.openshift.com#https://github.com/devfile/devworkspace-generator) | ||
[![Contribute (nightly)](https://img.shields.io/static/v1?label=nightly%20Che&message=for%20maintainers&logo=eclipseche&color=FDB940&labelColor=525C86)](https://che-dogfooding.apps.che-dev.x6e0.p1.openshiftapps.com#https://github.com/devfile/devworkspace-generator) | ||
## How to use the library | ||
The library can be used as a standalone library. | ||
The library is used by Eclipse Che to generate DevWorkspace components and templates. It requires both the original devfile.yaml and the editor definitions. | ||
## Where is it Published? | ||
This library is available on npm. | ||
You can find the published package here: \ | ||
__npm:__ [@eclipse-che/che-devworkspace-generator](https://www.npmjs.com/package/@eclipse-che/che-devworkspace-generator) | ||
## Usage | ||
### Here’s an example of how to use the @eclipse-che/che-devworkspace-generator library to generate a DevWorkspace and DevWorkspaceTemplate: | ||
```typescript | ||
import { Main as DevworkspaceGenerator } from '@eclipse-che/che-devworkspace-generator/lib/main'; | ||
import { V1alpha2DevWorkspaceTemplate } from '@devfile/api'; | ||
import { dump } from 'js-yaml'; | ||
// Initialize the DevWorkspace generator | ||
const generator = new DevworkspaceGenerator(); | ||
// Example function to generate DevWorkspace resources | ||
async function generateDevWorkspace(devfileContent: string, editorContent: string, axiosInstance: any) { | ||
// Generate the Devfile context | ||
const context = await generator.generateDevfileContext( | ||
{ | ||
devfileContent, | ||
editorContent, | ||
projects: [], | ||
}, | ||
axiosInstance, | ||
); | ||
// Convert templates and DevWorkspace to YAML | ||
const allContentArray = context.devWorkspaceTemplates.map( | ||
(template: V1alpha2DevWorkspaceTemplate) => dump(template), | ||
); | ||
allContentArray.push(dump(context.devWorkspace)); | ||
// Return the YAML content joined by "---" | ||
return allContentArray.join('---\n'); | ||
} | ||
``` | ||
### The library can be used as a standalone library: | ||
``` | ||
USAGE | ||
@@ -17,6 +59,7 @@ $ node lib/entrypoint.js [OPTIONS] | ||
--plugin-registry-url: URL to the plugin registry that contains editor definitions (devfile.yaml) | ||
--editor-entry: editor ID, found on the <plugin-registry-url>, to resolve the devfile.yaml | ||
--editor-url: URL for the editor's definition, should be publicly accessible for download. | ||
or | ||
--editor-path: local file path of the editor devfile.yaml | ||
or | ||
--editor-content: content of the editor devfile.yaml | ||
@@ -33,8 +76,7 @@ --output-file: local file path for the generated devworkspace yaml | ||
# online example, using editor definition from https://che-plugin-registry-main.surge.sh/ | ||
# online example, using editor definition from https://raw.githubusercontent.com/eclipse-che/che-operator/refs/heads/main/editors-definitions/che-code-insiders.yaml | ||
$ node lib/entrypoint.js \ | ||
--devfile-url:https://github.com/che-samples/java-spring-petclinic/tree/main \ | ||
--plugin-registry-url:https://che-plugin-registry-main.surge.sh/v3/ \ | ||
--editor-entry:che-incubator/che-code/latest \ | ||
--editor-url:https://raw.githubusercontent.com/eclipse-che/che-operator/refs/heads/main/editors-definitions/che-code-insiders.yaml \ | ||
--output-file:/tmp/devworkspace-che-code-latest.yaml \ | ||
@@ -41,0 +83,0 @@ --injectDefaultComponent:true \ |
@@ -18,3 +18,3 @@ /********************************************************************** | ||
import { resolveModule } from '../resolve/resolve-module'; | ||
import { pluginRegistryModule } from '../plugin-registry/plugin-registry-module'; | ||
import { editorModule } from '../editor/editor-module'; | ||
import { devfileSchemaModule } from '../devfile-schema/devfile-schema-module'; | ||
@@ -39,7 +39,6 @@ import { bitbucketModule } from '../bitbucket/bitbucket-module'; | ||
this.container.load(resolveModule); | ||
this.container.load(pluginRegistryModule); | ||
this.container.load(editorModule); | ||
this.container.load(devfileSchemaModule); | ||
this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance); | ||
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL'); | ||
@@ -54,4 +53,3 @@ return this.container; | ||
export interface InversifyBindingOptions { | ||
pluginRegistryUrl: string; | ||
axiosInstance: AxiosInstance; | ||
} |
@@ -18,3 +18,3 @@ /********************************************************************** | ||
import { UrlFetcher } from './fetch/url-fetcher'; | ||
import { PluginRegistryResolver } from './plugin-registry/plugin-registry-resolver'; | ||
import { EditorResolver } from './editor/editor-resolver'; | ||
import { V1alpha2DevWorkspaceSpecTemplate } from '@devfile/api'; | ||
@@ -41,4 +41,3 @@ import { DevfileContext } from './api/devfile-context'; | ||
editorContent?: string; | ||
editorEntry?: string; | ||
pluginRegistryUrl?: string; | ||
editorUrl?: string; | ||
projects: { name: string; location: string }[]; | ||
@@ -50,4 +49,4 @@ injectDefaultComponent?: string; | ||
): Promise<DevfileContext> { | ||
if (!params.editorPath && !params.editorEntry && !params.editorContent) { | ||
throw new Error('missing editorPath or editorEntry or editorContent'); | ||
if (!params.editorPath && !params.editorUrl && !params.editorContent) { | ||
throw new Error('missing editorPath or editorUrl or editorContent'); | ||
} | ||
@@ -58,14 +57,4 @@ if (!params.devfilePath && !params.devfileUrl && !params.devfileContent) { | ||
let pluginRegistryUrl: string; | ||
if (params.pluginRegistryUrl) { | ||
pluginRegistryUrl = params.pluginRegistryUrl; | ||
} else { | ||
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3'; | ||
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`); | ||
} | ||
const inversifyBinbding = new InversifyBinding(); | ||
const container = await inversifyBinbding.initBindings({ | ||
pluginRegistryUrl, | ||
axiosInstance, | ||
@@ -132,5 +121,5 @@ }); | ||
editorContent = params.editorContent; | ||
} else if (params.editorEntry) { | ||
} else if (params.editorUrl) { | ||
// devfile of the editor | ||
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(params.editorEntry); | ||
const editorDevfile = await container.get(EditorResolver).loadEditor(params.editorUrl); | ||
editorContent = jsYaml.dump(editorDevfile); | ||
@@ -183,4 +172,3 @@ } else { | ||
let editorPath: string | undefined; | ||
let pluginRegistryUrl: string | undefined; | ||
let editorEntry: string | undefined; | ||
let editorUrl: string | undefined; | ||
let injectDefaultComponent: string | undefined; | ||
@@ -198,8 +186,5 @@ let defaultComponentImage: string | undefined; | ||
} | ||
if (arg.startsWith('--plugin-registry-url:')) { | ||
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length); | ||
if (arg.startsWith('--editor-url:')) { | ||
editorUrl = arg.substring('--editor-url:'.length); | ||
} | ||
if (arg.startsWith('--editor-entry:')) { | ||
editorEntry = arg.substring('--editor-entry:'.length); | ||
} | ||
if (arg.startsWith('--editor-path:')) { | ||
@@ -227,4 +212,4 @@ editorPath = arg.substring('--editor-path:'.length); | ||
try { | ||
if (!editorPath && !editorEntry) { | ||
throw new Error('missing --editor-path: or --editor-entry: parameter'); | ||
if (!editorPath && !editorUrl) { | ||
throw new Error('missing --editor-path: or --editor-url: parameter'); | ||
} | ||
@@ -243,4 +228,3 @@ if (!devfilePath && !devfileUrl) { | ||
outputFile, | ||
pluginRegistryUrl, | ||
editorEntry, | ||
editorUrl, | ||
projects, | ||
@@ -247,0 +231,0 @@ injectDefaultComponent, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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 1 instance in 1 package
127
99
2031693
7
34828
1