You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
996 B

2 months ago
  1. import fs from 'fs'
  2. import path from 'path'
  3. // 移除未使用的导入
  4. /**
  5. * 是否是 dev 环境
  6. * @export
  7. * @param {string} mode
  8. * @return {boolean}
  9. */
  10. export function isDevFn(mode) {
  11. return mode === 'development';
  12. }
  13. /**
  14. * 是否是 prod 环境
  15. * @export
  16. * @param {string} mode
  17. * @return {boolean}
  18. */
  19. export function isProdFn(mode) {
  20. return mode === 'production';
  21. }
  22. /**
  23. * Read all environment variable configuration files to process.env
  24. */
  25. export function wrapperEnv(envConf) {
  26. const ret = {};
  27. for (const envName of Object.keys(envConf)) {
  28. let realName = envConf[envName].replace(/\\n/g, '\n');
  29. realName = realName === 'true' ? true : realName === 'false' ? false : realName;
  30. ret[envName] = realName;
  31. if (typeof realName === 'string') {
  32. process.env[envName] = realName;
  33. } else if (typeof realName === 'object') {
  34. process.env[envName] = JSON.stringify(realName);
  35. }
  36. }
  37. return ret;
  38. }