forked from ko-aoki/jhreact
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
41 lines (36 loc) · 1.13 KB
/
utils.js
File metadata and controls
41 lines (36 loc) · 1.13 KB
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
const fs = require('fs');
const path = require('path');
module.exports = {
parseVersion,
root,
isExternalLib
};
const parseString = require('xml2js').parseString;
// return the version number from `pom.xml` file
function parseVersion() {
let version = null;
const pomXml = fs.readFileSync('pom.xml', 'utf8');
parseString(pomXml, (err, result) => {
if (result.project.version && result.project.version[0]) {
version = result.project.version[0];
} else if (result.project.parent && result.project.parent[0] && result.project.parent[0].version && result.project.parent[0].version[0]) {
version = result.project.parent[0].version[0];
}
});
if (version === null) {
throw new Error('pom.xml is malformed. No version is defined');
}
return version;
}
const _root = path.resolve(__dirname, '..');
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [_root].concat(args));
}
function isExternalLib(module, check = /node_modules/) {
const req = module.userRequest;
if (typeof req !== 'string') {
return false;
}
return req.search(check) >= 0;
}