|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +// This script expects the current working directory to be `client`. |
| 4 | +// Call it using: |
| 5 | +// node updateSharedConfigVersions.mjs src/Try/SharedConfig.purs |
| 6 | + |
| 7 | +import fs from "fs"; |
| 8 | +import path from "path"; |
| 9 | +import process from "process"; |
| 10 | + |
| 11 | +if (process.argv.length <= 2) { |
| 12 | + throw new Error("Script was run with 0 args. The first and only arg should be the path to the 'SharedConfig.purs' file.") |
| 13 | +} |
| 14 | + |
| 15 | +const sharedConfigPath = process.argv[2]; |
| 16 | + |
| 17 | +const stackYamlPath = path.join("..", "stack.yaml"); |
| 18 | +const stagingPackagesDhallPath = path.join("..", "staging", "packages.dhall"); |
| 19 | +const stackYamlContent = fs.readFileSync(stackYamlPath, "utf-8"); |
| 20 | +const packagesContent = fs.readFileSync(stagingPackagesDhallPath, "utf-8"); |
| 21 | + |
| 22 | +const pursVersion = stackYamlContent.split("\n") |
| 23 | + .reduce((acc, nextLine) => { |
| 24 | + if (acc.found) return acc; |
| 25 | + const matchResult = nextLine.match(/ +- purescript-(.+)/); |
| 26 | + return matchResult |
| 27 | + ? { found: true, value: matchResult[1] } |
| 28 | + : acc; |
| 29 | + }, { found: false }) |
| 30 | + .value; |
| 31 | + |
| 32 | +const packageSetVersion = packagesContent |
| 33 | + .match(/https:\/\/github.com\/purescript\/package-sets\/releases\/download\/psc-([^\/]+)\/packages.dhall/)[1]; |
| 34 | + |
| 35 | +if (!pursVersion) { |
| 36 | + throw new Error("Failed to extract the PureScript version from the stack.yaml file. Cannot update SharedConfig.purs file."); |
| 37 | +} |
| 38 | + |
| 39 | +if (!packageSetVersion) { |
| 40 | + throw new Error("Failed to extract the Package Set version from the staging/packages.dhall file. Cannot update SharedConfig.purs file."); |
| 41 | +} |
| 42 | + |
| 43 | +const sharedConfigContent = fs.readFileSync(sharedConfigPath, "utf-8"); |
| 44 | +const newContent = sharedConfigContent.split("\n") |
| 45 | + .map((line) => line |
| 46 | + .replace(/pursVersion =.*/, `pursVersion = "v${pursVersion}"`) |
| 47 | + .replace(/packageSetVersion =.*/, `packageSetVersion = "${packageSetVersion}"`) |
| 48 | + ) |
| 49 | + .join("\n"); |
| 50 | +fs.writeFileSync(sharedConfigPath, newContent); |
0 commit comments