-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
25 lines (24 loc) · 691 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var fs = require('fs');
var path = require('path');
var npmrcPath = path.resolve(require('home-dir').directory, '.npmrc');
var registryEntry = [
'',
'; npmjs.us registry directive added automatically by the npmjs.us module',
'registry = https://registry.npmjs.us/public',
''
].join('\n');
var npmrcFile;
try {
npmrcFile = fs.readFileSync(npmrcPath).toString();
}
catch (e) {
// file doesn't exist; that's fine, we're about to create it anyway
}
try {
if (!/npmjs.us registry directive/.test(npmrcFile)) {
fs.appendFileSync(npmrcPath, registryEntry);
}
}
catch (e) {
throw new Error('Sorry! I was unable to add the npmjs.us registry to your ~/.npmrc; ' + e.message);
}