-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ts
50 lines (41 loc) · 2.33 KB
/
setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { exec } from "https://deno.land/x/[email protected]/mod.ts";
import { existsSync } from "https://deno.land/std/fs/mod.ts";
const from_version = Deno.args[0];
if (from_version === undefined) {
throw new Error("Missing from_version argument! Place the version you're updating to as the first argument in `deno task match`. (example: deno task match 1.20 1.20.1)");
}
const to_version = Deno.args[1];
if (to_version === undefined) {
throw new Error("Missing to_version argument! Place the version you're updating to as the second argument in `deno task match`. (example: deno task match 1.20 1.20.1)");
}
console.log("Cleaning up folder...")
if (existsSync("./qm")) {
for (const dirEntry of Deno.readDirSync("./qm")) {
if (dirEntry.isDirectory && existsSync("./qm/" + dirEntry.name + "/mappings")) {
console.log("Deleting old mappings directory " + dirEntry.name + "...")
Deno.removeSync("./qm/" + dirEntry.name, {recursive: true});
}
}
}
// clone
console.log('Cloning old qm version...')
await exec('git clone https://github.com/quiltmc/quilt-mappings.git --depth 1 --branch ' + from_version + ' --single-branch qm/' + from_version);
console.log('Copying to new version...')
await exec('cp -r qm/' + from_version + ' qm/' + to_version);
// update version
console.log('Updating version in new clone...')
const decoder = new TextDecoder('utf-8')
const contents = Deno.readFileSync('qm/' + to_version + '/buildSrc/src/main/java/quilt/internal/Constants.java')
const text = decoder.decode(contents);
const new_text = text.replace(from_version, to_version);
Deno.writeFileSync('qm/' + to_version + '/buildSrc/src/main/java/quilt/internal/Constants.java', new TextEncoder().encode(new_text))
const new_contents = Deno.readFileSync('qm/' + to_version + '/buildSrc/src/main/java/quilt/internal/Constants.java')
const new_raw_text = decoder.decode(new_contents);
if (!new_raw_text.includes(to_version) || new_raw_text.includes(from_version)) {
throw new Error("Failed to update version in new clone! Check that your versions are correct (first version must match current QM default branch), and if yes, please follow manual steps, starting at step 5.");
}
// set up new branch
console.log('Setting up new branch...')
await exec('git -C qm/' + to_version + ' checkout -b ' + to_version)
console.log("Done!");
Deno.exit(0);