config.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. tmp.parent = undefined;
  43. tmp._scriptPath = undefined;
  44. tmp._optionValues = undefined;
  45. tmp._storeOptionsAsProperties = undefined;
  46. tmp._passCommandToAction = undefined;
  47. tmp._actionResults = undefined;
  48. tmp._actionHandler = undefined;
  49. tmp._executableHandler = undefined;
  50. tmp._executableFile = undefined;
  51. tmp._defaultCommandName = undefined;
  52. tmp._exitCallback = undefined;
  53. tmp._alias = undefined;
  54. tmp._noHelp = undefined;
  55. tmp._helpFlags = undefined;
  56. tmp._helpDescription = undefined;
  57. tmp._helpShortFlag = undefined;
  58. tmp._helpLongFlag = undefined;
  59. tmp._hasImplicitHelpCommand = undefined;
  60. tmp._helpCommandName = undefined;
  61. tmp._helpCommandnameAndArgs = undefined;
  62. tmp._helpCommandDescription = undefined;
  63. // Things we don't want to save
  64. tmp.cache = undefined;
  65. tmp.episodes = undefined;
  66. tmp.series = undefined;
  67. tmp.video_format = undefined;
  68. tmp.video_quality = undefined;
  69. tmp.rebuildcrp = undefined;
  70. tmp.batch = undefined;
  71. tmp.verbose = undefined;
  72. tmp.debug = undefined;
  73. tmp.unlog = undefined;
  74. tmp.ignoredub = undefined;
  75. fs.writeFileSync(configFile, JSON.stringify(tmp, null, ' '));
  76. }