1.0.0-beta10.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.10...");
  6. try {
  7. // Determine which config file exists
  8. const filePaths = [configFilePath1, configFilePath2];
  9. let filePath = "";
  10. for (const path of filePaths) {
  11. if (fs.existsSync(path)) {
  12. filePath = path;
  13. break;
  14. }
  15. }
  16. if (!filePath) {
  17. throw new Error(
  18. `No config file found (expected config.yml or config.yaml).`
  19. );
  20. }
  21. // Read and parse the YAML file
  22. let rawConfig: any;
  23. const fileContents = fs.readFileSync(filePath, "utf8");
  24. rawConfig = yaml.load(fileContents);
  25. delete rawConfig.server.secure_cookies;
  26. // Write the updated YAML back to the file
  27. const updatedYaml = yaml.dump(rawConfig);
  28. fs.writeFileSync(filePath, updatedYaml, "utf8");
  29. console.log(`Removed deprecated config option: secure_cookies.`);
  30. } catch (e) {
  31. console.log(
  32. `Was unable to remove deprecated config option: secure_cookies. Error: ${e}`
  33. );
  34. return;
  35. }
  36. console.log("Done.");
  37. }