forked from cnpm/mirrors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
32 lines (27 loc) · 861 Bytes
/
utils.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
26
27
28
29
30
31
32
'use strict';
var utility = require('utility');
var crypto = require('crypto');
var path = require('path');
var util = require('util');
var config = require('../config');
exports.getTarballFilepath = function getTarballFilepath(filename) {
// ensure download file path unique
// TODO: not only .tgz, and also other extname
var name = filename.replace(/\.tgz$/, '.' + crypto.randomBytes(16).toString('hex') + '.tgz');
return path.join(config.uploadDir, name);
};
exports.getGithubBasicAuth = function (argument) {
return config.githubToken
? 'Basic ' + utility.base64encode(util.format('%s:x-oauth-basic', config.githubToken))
: '';
};
exports.nodePlatforms = [
'linux',
'darwin',
'win32',
];
exports.template = function (text, params) {
return text.replace(/\{(\w+)\}/g, function (total, name) {
return params[name];
});
};