Skip to content

Commit

Permalink
feat: writeMastercopyArtifact sorting keys by semver order
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Aug 8, 2024
1 parent 14e9e66 commit 385c881
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/artifact/writeMastercopyArtifact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync, readFileSync, writeFileSync } from "fs";
import semver from "semver";

import { address as erc2470FactoryAddress } from "../factory/erc2470Factory";
import predictSingletonAddress from "../encoding/predictSingletonAddress";
Expand Down Expand Up @@ -80,19 +81,30 @@ export default function extractAndWriteMastercopyArtifact({
compilerInput: minimalCompilerInput || buildArtifact.compilerInput,
};

const nextMastercopies = {
...mastercopies,
[contractName]: {
...(mastercopies[contractName] || {}),
[contractVersion]: mastercopyArtifact,
},
};

let sortedMastercopies: Record<
string,
Record<string, MastercopyArtifact>
> = {};

for (const name of Object.keys(nextMastercopies)) {
sortedMastercopies[name] = {};
const versions = semver.sort(Object.keys(nextMastercopies[name]));
for (const version of versions) {
sortedMastercopies[name][version] = nextMastercopies[name][version];
}
}

writeFileSync(
mastercopyArtifactsFile,
JSON.stringify(
{
...mastercopies,
[contractName]: {
...(mastercopies[contractName] || {}),
[contractVersion]: mastercopyArtifact,
},
},
null,
2
),
JSON.stringify(sortedMastercopies, null, 2),
"utf8"
);
}

0 comments on commit 385c881

Please sign in to comment.