1.0.0-beta3.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { configFilePath1, configFilePath2 } from "@server/lib/consts";
  2. import fs from "fs";
  3. import yaml from "js-yaml";
  4. export default async function migration() {
  5. console.log("Running setup script 1.0.0-beta.3...");
  6. // Determine which config file exists
  7. const filePaths = [configFilePath1, configFilePath2];
  8. let filePath = "";
  9. for (const path of filePaths) {
  10. if (fs.existsSync(path)) {
  11. filePath = path;
  12. break;
  13. }
  14. }
  15. if (!filePath) {
  16. throw new Error(
  17. `No config file found (expected config.yml or config.yaml).`
  18. );
  19. }
  20. // Read and parse the YAML file
  21. let rawConfig: any;
  22. const fileContents = fs.readFileSync(filePath, "utf8");
  23. rawConfig = yaml.load(fileContents);
  24. // Validate the structure
  25. if (!rawConfig.gerbil) {
  26. throw new Error(`Invalid config file: gerbil is missing.`);
  27. }
  28. // Update the config
  29. rawConfig.gerbil.site_block_size = 29;
  30. // Write the updated YAML back to the file
  31. const updatedYaml = yaml.dump(rawConfig);
  32. fs.writeFileSync(filePath, updatedYaml, "utf8");
  33. console.log("Done.");
  34. }