Skip to content

Commit

Permalink
fix: the same version is recommended after updating the package
Browse files Browse the repository at this point in the history
Close #84
  • Loading branch information
mob-sakai committed Aug 11, 2020
1 parent 6baba46 commit c766454
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ const hashCode = str => {
.reduce((s, c) => Math.imul(31, s) + c.charCodeAt(0) | 0, 0)
}

const groupBy = (array, property) => {
return array.reduce(
(group, item) => Object.assign(group, {
[item[property]]: (group[item[property]] || []).concat(item)
}),
{}
)

}

const id = hashCode(`${packageName}@${repoUrl}`);
const repoDir = `Library/UGE/packages/${id}`;
const resultDir = `Library/UGE/results`;
Expand All @@ -40,14 +50,14 @@ const mkdirSyncRecrusive = postPath => {
try {
fs.mkdirSync(path);
}
catch (e){
catch (e) {
}
}
return path;
}, "");
};

const IsSupported = (version, unityVersion) => {
const isSupportedVersion = (version, unityVersion) => {
const regVersion = /^(\d+)\.(\d+)\.(\d+)(.*)$/;
const v = version.match(regVersion);
const uv = unityVersion.match(regVersion);
Expand All @@ -60,6 +70,7 @@ const IsSupported = (version, unityVersion) => {
const parseRef = text => {
try {
const regRefName = /^refs\/(tags\/|remotes\/origin\/)([^\/]+)$/;
const hash = text.split(/\s+/)[0];
const ref = text.split(/\s+/)[1];
const refName = ref.match(regRefName)[2];

Expand All @@ -79,15 +90,18 @@ const parseRef = text => {
const unity = p.unity || "2018.3";
const unityRelease = p.unityRelease || "0a0";
const supportedVersion = `${unity}.${unityRelease}`;
if (!IsSupported(supportedVersion, unityVersion)) {
if (!isSupportedVersion(supportedVersion, unityVersion)) {
console.error(
`error: ${unityVersion} is not supported. Supported unity versions are '>=${supportedVersion}'`
);
return undefined;
}

const regId = new RegExp(`((release|v|ver|version)?[.-]?)*${p.version}`);
const id = refName.replace(regId, "");

//
return { packageName: p.name, repoUrl, version: p.version, refName };
return { packageName: p.name, repoUrl, version: p.version, refName, hash, id };
} catch (e) {
return undefined;
}
Expand Down Expand Up @@ -133,10 +147,16 @@ try {

// Get valid package references
console.log("\n>> Get valid package references");
const versions = execSync("git show-ref", { encoding: "utf-8" })
const allVersions = execSync("git show-ref", { encoding: "utf-8" })
.split(/[\r\n]+/)
.map(x => parseRef(x))
.filter(x => x);
.filter(x => x)
.sort((a, b) => a.id < b.id ? -1 : b.id < a.id ? 1 : 0);

// Sort by version id and get first element
const grouped = groupBy(allVersions, "hash");
const versions = Object.keys(grouped)
.map(x => grouped[x].find(_ => true))

// Output valid package references to file
console.log(`\n>> Output valid package (${versions.length} versions) references to file: ${outputFile}`);
Expand Down

0 comments on commit c766454

Please sign in to comment.