rebrand.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env node
  2. /**
  3. * This script is used to rebrand the app to a different UNACMS website.
  4. */
  5. const fs = require("fs");
  6. const path = require("path");
  7. const readline = require("readline");
  8. const root = process.cwd();
  9. const settingsPath = path.join(root, "constants", "settings.ts");
  10. const rl = readline.createInterface({
  11. input: process.stdin,
  12. output: process.stdout,
  13. });
  14. rl.question(
  15. "Your UNA site URL: ",
  16. (answer) => {
  17. const userInput = answer.trim().replace(/\/$/, "").toLowerCase();
  18. // Simple URL validation (domain or https://...)
  19. const urlPattern = /^(https?:\/\/)?([a-z0-9-]+\.)+[a-z]{2,}$/i;
  20. if (!userInput || !urlPattern.test(userInput)) {
  21. console.log("❌ Invalid input. Please enter a valid URL.");
  22. rl.close();
  23. return;
  24. }
  25. const newUrl = userInput.startsWith("http")
  26. ? userInput
  27. : `https://${userInput}`;
  28. // Read settings.ts
  29. fs.readFile(settingsPath, "utf8", (err, data) => {
  30. if (err) {
  31. console.error(`❌ Failed to read settings.ts: ${err.message}`);
  32. rl.close();
  33. return;
  34. }
  35. // Replace the UNA_URL line
  36. const updated = data.replace(
  37. /export const UNA_URL\s*=\s*["'`].*?["'`];/,
  38. `export const UNA_URL = "${newUrl}";`
  39. );
  40. fs.writeFile(settingsPath, updated, "utf8", (err) => {
  41. if (err) {
  42. console.error(`❌ Failed to write settings.ts: ${err.message}`);
  43. } else {
  44. console.log(`✅ UNA_URL updated to: ${newUrl}`);
  45. }
  46. rl.close();
  47. });
  48. });
  49. }
  50. );