-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtag-parser.js
36 lines (33 loc) · 881 Bytes
/
tag-parser.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
module.exports = (tags) => {
const tagHashMap = tags
.map((tag) => {
if (tag.startsWith('~@')) {
return { tag: tag.slice(1), negated: true };
}
return { tag, negated: false };
})
.reduce((map, item) => {
const hash = map;
hash[item.tag] = !!item.negated;
return hash;
}, {});
const expressionParts = Object.keys(tagHashMap).reduce(
(parts, tag) => {
if (tagHashMap[tag]) {
parts.excludes.push(tag);
} else {
parts.includes.push(tag);
}
return parts;
},
{ includes: [], excludes: [] }
);
const expression = (expressionParts.includes.length
? [`(${expressionParts.includes.join(' or ')})`]
: []
)
.concat(expressionParts.excludes.map(tag => `not ${tag}`))
.join(' and ');
return expression;
};
const t = module.exports(['@test', '~@mock']);