swap-engines.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. let fs = require('fs')
  2. let path = require('path')
  3. let engines = {
  4. stable: {
  5. files: [
  6. path.resolve(__dirname, '..', 'package.stable.json'),
  7. path.resolve(__dirname, '..', 'package-lock.stable.json'),
  8. ],
  9. },
  10. oxide: {
  11. files: [
  12. path.resolve(__dirname, '..', 'package.oxide.json'),
  13. path.resolve(__dirname, '..', 'package-lock.oxide.json'),
  14. ],
  15. },
  16. }
  17. // Find out what the current engine is that we are using:
  18. let [otherEngine, info] = Object.entries(engines).find(([, info]) =>
  19. info.files.every((file) => fs.existsSync(file))
  20. )
  21. let currentEngine = otherEngine === 'oxide' ? 'stable' : 'oxide'
  22. console.log(`Current engine: \`${currentEngine}\`, swapping to \`${otherEngine}\``)
  23. // Swap the engines
  24. for (let file of info.files) {
  25. fs.renameSync(
  26. file.replace(`.${otherEngine}`, ''),
  27. file.replace(`.${otherEngine}`, `.${currentEngine}`)
  28. )
  29. }
  30. for (let file of engines[otherEngine].files) {
  31. fs.renameSync(file, file.replace(`.${otherEngine}`, ''))
  32. }
  33. console.log(
  34. 'Engines have been swapped. Make sure to run `npm install` to update your dependencies.'
  35. )