Skip to content

Commit

Permalink
admin: added diff scripts for build page
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent fc49ffc commit 5dfcbbd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src.ts/_admin/generate-diffs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import fs from "fs";

import { getVersions } from "./utils/npm.js";
import { resolve } from "./utils/path.js";
import { getDiff } from "./utils/git.js";

function escver(v: string): string {
return v.replace(/\./, "-");
}

(async function() {
let versions = await getVersions("ethers");
versions = versions.filter((h) => (h.version.match(/^6\.[0-9]+\.[0-9]+$/)));
for (let i = 1; i < versions.length; i++) {
const tag0 = versions[i - 1].gitHead, tag1 = versions[i].gitHead;
const diff = await getDiff(resolve("dist/ethers.js"), tag0, tag1);
console.log(diff);
fs.writeFileSync(resolve("misc/diffs/versions.txt"), versions.map((h) => h.version).join(","));
for (let i = 0; i < versions.length; i++) {
for (let j = i + 1; j < versions.length; j++) {
const filename = resolve(`misc/diffs/diff-${ escver(versions[i].version) }_${ escver(versions[j].version) }.txt`);
if (fs.existsSync(filename)) { continue; }
const tag0 = versions[i].gitHead, tag1 = versions[j].gitHead;
const diff = await getDiff(resolve("src.ts"), tag0, tag1);
console.log({ diff });
fs.writeFileSync(filename, diff);
}
}
})();
7 changes: 7 additions & 0 deletions src.ts/_admin/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export async function getModifiedTime(filename: string): Promise<null | number>

return null;
}

export interface GitLog {
commit: string;
author: string;
Expand Down Expand Up @@ -89,3 +90,9 @@ export async function getDiff(filename: string, tag0: string, tag1: string): Pro
if (!result.ok) { throw new Error(`git log error`); }
return result.stdout.trim();
}

export async function getTags(): Promise<Array<string>> {
const result = await run("git", [ "tag" ]);
if (!result.ok) { throw new Error(`git log error`); }
return result.stdout.trim().split("\n");
}

0 comments on commit 5dfcbbd

Please sign in to comment.