utils.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import fs from 'node:fs';
  2. import path from 'node:path';
  3. const STORE_PATH_NAME = 'store';
  4. const TEMP_PATH_NAME = 'temp';
  5. export function getResourcesDir() {
  6. return process.env.NODE_ENV === 'development'
  7. ? path.join(__dirname, '../../resources/')
  8. : path.join(__dirname, '../../../app.asar.unpacked/resources/');
  9. }
  10. export function getRootDir() {
  11. return process.env.NODE_ENV === 'development'
  12. ? path.join(__dirname, '../../')
  13. : path.join(__dirname, '../../../../');
  14. }
  15. export function getDatabasePath() {
  16. return path.join(getRootDir(), 'database', 'database.sqlite');
  17. }
  18. export function getStoreDir() {
  19. return path.join(getRootDir(), STORE_PATH_NAME);
  20. }
  21. export function getTempPath() {
  22. return path.join(getStoreDir(), TEMP_PATH_NAME);
  23. }
  24. export function getImagicPath() {
  25. return path.join(getResourcesDir(), './imagemagick-7.1.1-11/');
  26. }
  27. export function getGmFontPath() {
  28. // return path.join(getResourcesDir(), './font/STHeiti Medium.ttc');
  29. return path.join(getResourcesDir(), './font/simsun.ttf');
  30. }
  31. export function makeDirSync(pathContent: string) {
  32. const mkPathList: string[] = [];
  33. let curPath = pathContent;
  34. while (!fs.existsSync(curPath)) {
  35. mkPathList.unshift(curPath);
  36. curPath = path.dirname(curPath);
  37. }
  38. mkPathList.forEach((mpath) => {
  39. fs.mkdirSync(mpath);
  40. });
  41. }
  42. makeDirSync(getTempPath());