forked from PatrickJS/PatrickJS-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (48 loc) · 1.33 KB
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const helpers = require('../helpers');
const execSync = require('child_process').execSync;
const REPO_NAME_RE = /Push {2}URL: https:\/\/fanyv88.com:443\/https\/github\.com\/.*\/(.*)\.git/;
function getWebpackConfigModule() {
if (helpers.hasProcessFlag('github-dev')) {
return require('../webpack.dev.js');
} else if (helpers.hasProcessFlag('github-prod')) {
return require('../webpack.prod.js');
} else {
throw new Error('Invalid compile option.');
}
}
function getRepoName(remoteName) {
remoteName = remoteName || 'origin';
var stdout = execSync('git remote show ' + remoteName),
match = REPO_NAME_RE.exec(stdout);
if (!match) {
throw new Error('Could not find a repository on remote ' + remoteName);
} else {
return match[1];
}
}
function stripTrailing(str, char) {
if (str[0] === char) {
str = str.substr(1);
}
if (str.substr(-1) === char) {
str = str.substr(0, str.length - 1);
}
return str;
}
/**
* Given a string remove trailing slashes and adds 1 slash at the end of the string.
*
* Example:
* safeUrl('/value/')
* // 'value/'
*
* @param url
* @returns {string}
*/
function safeUrl(url) {
const stripped = stripTrailing(url || '', '/');
return stripped ? stripped + '/' : '';
}
exports.getWebpackConfigModule = getWebpackConfigModule;
exports.getRepoName = getRepoName;
exports.safeUrl = safeUrl;