-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hyj1991
committed
Aug 10, 2018
1 parent
d65ad3e
commit 3e2f5e8
Showing
2 changed files
with
55 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const config = {}; | ||
|
||
function createConfigs() { | ||
let root; | ||
if (process.platform === 'win32') { | ||
root = process.env.USERPROFILE || process.env.APPDATA || process.env.TMP || process.env.TEMP; | ||
} else { | ||
root = process.env.HOME || process.env.TMPDIR || '/tmp'; | ||
} | ||
let userConfig = path.join(root, '.cnpmrc'); | ||
if (!fs.existsSync(userConfig)) return; | ||
let userConfigContent = fs.readFileSync(userConfig).toString(); | ||
let configs = typeof userConfigContent === 'string' && userConfigContent.split('\n'); | ||
configs.reduce((pre, next) => { | ||
if (typeof next === 'string') { | ||
let map = next.split('='); | ||
let key = map[0]; | ||
let value = map[1]; | ||
if (value === 'true') value = true; | ||
if (value === 'false') value = false; | ||
pre[key] = value; | ||
} | ||
return pre; | ||
}, config); | ||
|
||
} | ||
|
||
createConfigs(); | ||
|
||
module.exports = { | ||
get(key) { | ||
return config[key]; | ||
} | ||
} |
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