utils.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/simsun.ttf');
  29. }
  30. export function makeDirSync(pathContent: string) {
  31. const mkPathList: string[] = [];
  32. let curPath = pathContent;
  33. while (!fs.existsSync(curPath)) {
  34. mkPathList.unshift(curPath);
  35. curPath = path.dirname(curPath);
  36. }
  37. mkPathList.forEach((mpath) => {
  38. fs.mkdirSync(mpath);
  39. });
  40. }
  41. makeDirSync(getTempPath());