utils.ts 713 B

12345678910111213141516171819202122232425262728293031323334353637
  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 getRootPath() {
  6. return __dirname;
  7. }
  8. export function getTempPath() {
  9. return path.join(getRootPath(), TEMP_PATH_NAME);
  10. }
  11. export function getImagicPath() {
  12. return path.join(
  13. getRootPath(),
  14. '../../resources/imagemagick-7.1.1-11/magick.exe'
  15. );
  16. }
  17. export function makeDirSync(pathContent: string) {
  18. const mkPathList: string[] = [];
  19. let curPath = pathContent;
  20. while (!fs.existsSync(curPath)) {
  21. mkPathList.unshift(curPath);
  22. curPath = path.dirname(curPath);
  23. }
  24. mkPathList.forEach((mpath) => {
  25. fs.mkdirSync(mpath);
  26. });
  27. }
  28. makeDirSync(getTempPath());