-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.js
58 lines (46 loc) · 1.47 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
'use strict';
const getGitInfo = require('git-repo-info');
const path = require('path');
function gitRepoVersion(options) {
options = options || {};
let shaLength = options.shaLength != null ? options.shaLength : 8;
let includeDate = options.includeDate || false;
let projectPath = options.projectPath || process.cwd();
let info = getGitInfo(projectPath);
let packageVersion = require(path.join(projectPath, 'package.json')).version;
let prefix;
if (info.tag && !(packageVersion && info.tag.includes(packageVersion))) {
prefix = info.tag;
} else if (packageVersion) {
prefix = packageVersion;
} else if (info.branch) {
prefix = info.branch;
} else {
prefix = 'DETACHED_HEAD';
}
let sha = '';
if (shaLength > 0 && info.sha) {
sha = '+' + info.sha.substring(0, shaLength);
}
let authorDate = includeDate ? ' ' + info.authorDate : '';
return prefix + sha + authorDate;
}
module.exports = {
name: require('./package').name,
config(env, baseConfig) {
let config = this._super.config.apply(this, arguments);
if (!baseConfig.APP) {
return config;
}
baseConfig.APP.name = this.project.pkg.name;
if (baseConfig[this.name] && baseConfig[this.name].version) {
baseConfig.APP.version = baseConfig[this.name].version;
return config;
}
let version = gitRepoVersion(null, this.project.root);
if (version && baseConfig.APP) {
baseConfig.APP.version = version;
}
return config;
},
};