replaceEnv.js 565 B

1234567891011121314151617181920212223
  1. "use strict";
  2. const fs = require("fs");
  3. const path = require("path");
  4. let jsonPath = path.resolve(__dirname, "./config.json");
  5. function replaceText(originalUrl, replaceUrl) {
  6. let copyContent = fs.readFileSync(originalUrl, "utf8");
  7. fs.writeFileSync(replaceUrl, copyContent, "utf8");
  8. }
  9. function replaceSettings() {
  10. const str = process.env.PLAT_ENV;
  11. const commandLines = str.split("-");
  12. const defaulJsonPath = path.resolve(
  13. __dirname,
  14. `./config.${commandLines[0]}.${commandLines[1]}.json`
  15. );
  16. replaceText(defaulJsonPath, jsonPath);
  17. }
  18. replaceSettings();