You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.7 KiB

import * as semver from "semver";
import { svnGetLatestTag, svnPropGet } from "./promises";
export class SolutionImplementation {
constructor(url) {
this.url = "";
this.baseUrl = "";
this.repository = "";
this.repositoryUrl = "";
this.componentFolder = null;
this._isSolutionComponent = false;
this._isImplementation = false;
this.implementationUrl = "";
this.type = "";
this.version = null;
this.nextVersion = null;
this.component = "";
this.parseUrl(url);
}
getBaseUrl() {
return this.baseUrl;
}
getUrl() {
return this.url;
}
getImplementationUrl() {
return this.implementationUrl;
}
getRepository() {
return this.repository;
}
getRepositoryUrl() {
return this.repositoryUrl;
}
getComponentFolder() {
return this.componentFolder;
}
isSolutionComponent() {
return this._isSolutionComponent;
}
isImplementation() {
return this._isImplementation;
}
getType() {
return this.type;
}
getVersion() {
return this.version;
}
async getNextVersion(semVerIncrementType) {
await this.getLatestTag()
.then((result) => {
if (semver.valid(semver.coerce(result))) {
const sv = result;
this.nextVersion = semver.inc(sv, semVerIncrementType);
} else {
this.nextVersion = null;
}
})
.catch((error) => {
// Handle error
});
return this.nextVersion;
}
async getLatestTag() {
try {
const lastTagOrBranch = await svnGetLatestTag(this.implementationUrl);
return lastTagOrBranch.name;
} catch (error) {
console.error("Error retrieving last tag or branch:", error);
throw error;
}
}
getTypeAndVersion() {
if ((this.type === "tags" || this.type === "branches") && this.version) {
return `${this.type}/${this.version}`;
}
return `${this.type}`;
}
getComponent() {
return this.component;
}
getComponentDecoded() {
return decodeURIComponent(this.component);
}
getExternalsRaw() {
return decodeURIComponent(this.component);
}
// GetExternalsCollection(): externalsCollection {
// return decodeURIComponent(this.component);
// }
async getExternals() {
const svnOptions = { trustServerCert: true };
try {
const response = await svnPropGet("svn:externals", this.url, svnOptions);
const rawExternals = response.target.property._;
return rawExternals;
} catch (error) {
console.error("Error retrieving last tag or branch:", error);
throw error;
}
}
parseUrl(url) {
this.url = url;
const regex = /^(https?:\/\/[^\/]+\/svn\/)/;
const match = regex.exec(url);
if (match && match.length > 1) {
this.baseUrl = match[1];
} else {
throw new Error("Invalid URL");
}
const segments = url.split("/");
const svnIndex = segments.indexOf("svn");
const trunkTagBranchIndex = segments.findIndex(
(segment, index) =>
index > svnIndex &&
(segment === "trunk" || segment === "tags" || segment === "branches")
);
this._isSolutionComponent = trunkTagBranchIndex - svnIndex > 2;
if (svnIndex !== -1 && svnIndex + 1 < segments.length) {
this.repository = segments[svnIndex + 1];
this.repositoryUrl = `${this.baseUrl}${this.repository}`;
if (trunkTagBranchIndex !== -1 && trunkTagBranchIndex - 1 > svnIndex) {
const nextSegment = segments[trunkTagBranchIndex - 1];
if (
nextSegment !== "trunk" &&
nextSegment !== "tags" &&
nextSegment !== "branches"
) {
if (this._isSolutionComponent) {
this.componentFolder = nextSegment;
}
}
}
if (trunkTagBranchIndex !== -1 && trunkTagBranchIndex < segments.length) {
this.type = segments[trunkTagBranchIndex];
if (this.type === "tags" || this.type === "branches") {
if (trunkTagBranchIndex + 1 < segments.length) {
this.version = segments[trunkTagBranchIndex + 1];
if (trunkTagBranchIndex + 2 < segments.length) {
this.component = segments[trunkTagBranchIndex + 2];
}
}
} else if (trunkTagBranchIndex + 1 < segments.length) {
this.component = segments[trunkTagBranchIndex + 1];
}
}
this._isImplementation =
this.componentFolder === null && this.component === "";
this.implementationUrl = segments
.slice(0, trunkTagBranchIndex + (this.version === null ? 1 : 2))
.join("/");
if (this._isImplementation) {
const rawExternals = this.getExternals();
}
} else {
throw new Error("Invalid URL");
}
}
}
// Helper function to retrieve the last tag or branch
// async function getLastTagOrBranch(url: string): Promise<string> {
// try {
// const list = await svnListPromise(url);
// const sortedList = list.sort((a, b) => b.date.getTime() - a.date.getTime());
// const lastTagOrBranch = sortedList[0].name;
// return lastTagOrBranch;
// } catch (error) {
// throw error;
// }
// }
//# sourceMappingURL=SolutionImplementation.js.map

Powered by TurnKey Linux.