Create config manager to store part of the config in a json file.
Update the IConfig structure to add new values for API login.
This commit is contained in:
parent
68885db538
commit
b947a110e2
62
src/config.ts
Normal file
62
src/config.ts
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
'use strict';
|
||||||
|
import os = require('os');
|
||||||
|
import fs = require('fs-extra');
|
||||||
|
import path = require('path');
|
||||||
|
|
||||||
|
const configFile = path.join(process.cwd(), "config.json");
|
||||||
|
|
||||||
|
function fileExist(path: string)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fs.statSync(path);
|
||||||
|
return true;
|
||||||
|
} catch (e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function load(): IConfigLine
|
||||||
|
{
|
||||||
|
if (fileExist(configFile))
|
||||||
|
{
|
||||||
|
const data = fs.readFileSync(configFile, 'utf8');
|
||||||
|
return JSON.parse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {args: undefined};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function save(config: IConfig)
|
||||||
|
{
|
||||||
|
const tmp = JSON.parse(JSON.stringify(config));
|
||||||
|
|
||||||
|
// Things added by the command line parser
|
||||||
|
tmp.rawArgs = undefined;
|
||||||
|
tmp.options = undefined;
|
||||||
|
tmp._execs = undefined;
|
||||||
|
tmp._args = undefined;
|
||||||
|
tmp._name = undefined;
|
||||||
|
tmp._version = undefined;
|
||||||
|
tmp._versionOptionName = undefined;
|
||||||
|
tmp._events = undefined;
|
||||||
|
tmp._eventsCount = undefined;
|
||||||
|
tmp.args = undefined;
|
||||||
|
tmp.commands = undefined;
|
||||||
|
tmp._allowUnknownOption = undefined;
|
||||||
|
|
||||||
|
// Things we don't want to save
|
||||||
|
tmp.cache = undefined;
|
||||||
|
tmp.episodes = undefined;
|
||||||
|
tmp.series = undefined;
|
||||||
|
tmp.video_format = undefined;
|
||||||
|
tmp.video_quality = undefined;
|
||||||
|
tmp.rebuildcrp = undefined;
|
||||||
|
tmp.batch = undefined;
|
||||||
|
tmp.verbose = undefined;
|
||||||
|
tmp.debug = undefined;
|
||||||
|
tmp.unlog = undefined;
|
||||||
|
|
||||||
|
fs.writeFileSync(configFile, JSON.stringify(tmp, null, ' '));
|
||||||
|
}
|
||||||
11
src/interface/IConfig.d.ts
vendored
11
src/interface/IConfig.d.ts
vendored
@ -20,4 +20,15 @@ interface IConfig {
|
|||||||
verbose?: boolean;
|
verbose?: boolean;
|
||||||
debug?: boolean;
|
debug?: boolean;
|
||||||
retry?: number;
|
retry?: number;
|
||||||
|
// Login options
|
||||||
|
logUsingApi?: boolean;
|
||||||
|
crSessionUrl?: string;
|
||||||
|
crDeviceType?: string;
|
||||||
|
crAPIVersion?: string;
|
||||||
|
crLocale?: string;
|
||||||
|
crSessionKey?: string;
|
||||||
|
crLoginUrl?: string;
|
||||||
|
// Generated values
|
||||||
|
crDeviceId?: string;
|
||||||
|
crSessionId?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user