utils.ts 808 B

123456789101112131415161718192021222324252627282930313233343536
  1. import fs from 'node:fs';
  2. import path from 'node:path';
  3. const TEMP_PATH_NAME = 'temp';
  4. console.log(__dirname);
  5. export function getResourcesDir() {
  6. return process.env.NODE_ENV === 'development'
  7. ? path.join(__dirname, '../../')
  8. : path.join(__dirname, './app.asar.unpacked/');
  9. }
  10. export function getTempPath() {
  11. return path.join(__dirname, TEMP_PATH_NAME);
  12. }
  13. export function getImagicPath() {
  14. return path.join(getResourcesDir(), './imagemagick-7.1.1-11/magick.exe');
  15. }
  16. export function makeDirSync(pathContent: string) {
  17. const mkPathList: string[] = [];
  18. let curPath = pathContent;
  19. while (!fs.existsSync(curPath)) {
  20. mkPathList.unshift(curPath);
  21. curPath = path.dirname(curPath);
  22. }
  23. mkPathList.forEach((mpath) => {
  24. fs.mkdirSync(mpath);
  25. });
  26. }
  27. makeDirSync(getTempPath());