-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: The user can disable or enable the translation engine and save …
…the configuration to ~/.fanyirc under user's home directory
- Loading branch information
Showing
4 changed files
with
144 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const homedir = process.env.HOME || require('os').homedir(); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const configPath = path.resolve(homedir, '.fanyirc'); | ||
|
||
const config = { | ||
async load(path = configPath) { | ||
const emptyObj = {}; | ||
if (fs.existsSync(path) && fs.statSync(path).isFile()) { | ||
const content = fs.readFileSync(path, 'utf-8'); | ||
try { | ||
return JSON.parse(content.toString()); | ||
} catch (e) { | ||
return emptyObj; | ||
} | ||
} else { | ||
return emptyObj; | ||
} | ||
}, | ||
async write(options = {}, path = configPath) { | ||
const defaultOptions = await config.load(path); | ||
const mergedOptions = { ...defaultOptions, ...options }; | ||
const content = JSON.stringify(mergedOptions); | ||
return fs.writeFileSync(path, content); | ||
}, | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters