-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathupdateSharedConfigVersions.mjs
executable file
·50 lines (40 loc) · 1.82 KB
/
updateSharedConfigVersions.mjs
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
#!/usr/bin/env node
// This script expects the current working directory to be `client`.
// Call it using:
// node updateSharedConfigVersions.mjs src/Try/SharedConfig.purs
import fs from "fs";
import path from "path";
import process from "process";
if (process.argv.length <= 2) {
throw new Error("Script was run with 0 args. The first and only arg should be the path to the 'SharedConfig.purs' file.")
}
const sharedConfigPath = process.argv[2];
const stackYamlPath = path.join("..", "stack.yaml");
const stagingPackagesDhallPath = path.join("..", "staging", "packages.dhall");
const stackYamlContent = fs.readFileSync(stackYamlPath, "utf-8");
const packagesContent = fs.readFileSync(stagingPackagesDhallPath, "utf-8");
const pursVersion = stackYamlContent.split("\n")
.reduce((acc, nextLine) => {
if (acc.found) return acc;
const matchResult = nextLine.match(/ +- purescript-(.+)/);
return matchResult
? { found: true, value: matchResult[1] }
: acc;
}, { found: false })
.value;
const packageSetVersion = packagesContent
.match(/https:\/\/github.com\/purescript\/package-sets\/releases\/download\/psc-([^\/]+)\/packages.dhall/)[1];
if (!pursVersion) {
throw new Error("Failed to extract the PureScript version from the stack.yaml file. Cannot update SharedConfig.purs file.");
}
if (!packageSetVersion) {
throw new Error("Failed to extract the Package Set version from the staging/packages.dhall file. Cannot update SharedConfig.purs file.");
}
const sharedConfigContent = fs.readFileSync(sharedConfigPath, "utf-8");
const newContent = sharedConfigContent.split("\n")
.map((line) => line
.replace(/pursVersion =.*/, `pursVersion = "v${pursVersion}"`)
.replace(/packageSetVersion =.*/, `packageSetVersion = "${packageSetVersion}"`)
)
.join("\n");
fs.writeFileSync(sharedConfigPath, newContent);