utils.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 makeDirSync(pathContent: string) {
  28. const mkPathList: string[] = [];
  29. let curPath = pathContent;
  30. while (!fs.existsSync(curPath)) {
  31. mkPathList.unshift(curPath);
  32. curPath = path.dirname(curPath);
  33. }
  34. mkPathList.forEach((mpath) => {
  35. fs.mkdirSync(mpath);
  36. });
  37. }
  38. makeDirSync(getTempPath());