config.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. import os = require('os');
  3. import fs = require('fs-extra');
  4. import path = require('path');
  5. const configFile = path.join(process.cwd(), 'config.json');
  6. function fileExist(path: string)
  7. {
  8. try
  9. {
  10. fs.statSync(path);
  11. return true;
  12. } catch (e)
  13. {
  14. return false;
  15. }
  16. }
  17. export function load(): IConfigLine
  18. {
  19. if (fileExist(configFile))
  20. {
  21. const data = fs.readFileSync(configFile, 'utf8');
  22. return JSON.parse(data);
  23. }
  24. return {args: undefined};
  25. }
  26. export function save(config: IConfig)
  27. {
  28. const tmp = JSON.parse(JSON.stringify(config));
  29. // Things added by the command line parser
  30. tmp.rawArgs = undefined;
  31. tmp.options = undefined;
  32. tmp._execs = undefined;
  33. tmp._args = undefined;
  34. tmp._name = undefined;
  35. tmp._version = undefined;
  36. tmp._versionOptionName = undefined;
  37. tmp._events = undefined;
  38. tmp._eventsCount = undefined;
  39. tmp.args = undefined;
  40. tmp.commands = undefined;
  41. tmp._allowUnknownOption = undefined;
  42. // Things we don't want to save
  43. tmp.cache = undefined;
  44. tmp.episodes = undefined;
  45. tmp.series = undefined;
  46. tmp.video_format = undefined;
  47. tmp.video_quality = undefined;
  48. tmp.rebuildcrp = undefined;
  49. tmp.batch = undefined;
  50. tmp.verbose = undefined;
  51. tmp.debug = undefined;
  52. tmp.unlog = undefined;
  53. tmp.ignoredub = undefined;
  54. fs.writeFileSync(configFile, JSON.stringify(tmp, null, ' '));
  55. }