Skip to content

Commit e8e95c0

Browse files
authored
more dry refactorings
1 parent cde1479 commit e8e95c0

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

scripts/version.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,23 @@ import dateFormat from "dateformat";
44
import path from 'path';
55
import { fileURLToPath } from 'url';
66

7-
const __filename = fileURLToPath(import.meta.url);
8-
const __dirname = path.dirname(__filename);
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
const resolve = (...args) => path.resolve(__dirname, ...args);
99

10-
var src = {
11-
git: simpleGit(__dirname + "/../binaryen"),
10+
const createRepo = (path, regex, mapVersion) => ({
11+
git: simpleGit(path),
1212
filter: tag => {
13-
var match = /^version_(\d+)$/.exec(tag); // see: https://github.com/WebAssembly/binaryen/issues/1156
13+
const match = regex.exec(tag);
1414
return match ? {
1515
tag,
16-
version: match[1] + ".0.0",
16+
version: mapVersion(match),
1717
} : null;
1818
}
19-
};
19+
});
2020

21-
var dst = {
22-
git: simpleGit(__dirname + "/.."),
23-
filter: tag => {
24-
var match = /^v(\d+\.\d+\.\d+)(?:\-|$)/.exec(tag);
25-
return match ? {
26-
tag,
27-
version: match[1]
28-
} : null;
29-
}
30-
};
21+
// see: https://github.com/WebAssembly/binaryen/issues/1156
22+
const src = createRepo(resolve('../binaryen'), /^version_(\d+)$/, ([, maj]) => `${maj}.0.0`);
23+
const dst = createRepo(resolve('..'), /^v(\d+\.\d+\.\d+)(?:\-|$)/, ([, maj]) => maj);
3124

3225
async function latest(repo) {
3326
try {

0 commit comments

Comments
 (0)