forked from nm90/strike-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenParser.js
44 lines (34 loc) · 1.23 KB
/
tokenParser.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
exports.createLinesToInsert = function (strikeToken, remoteToken){
var tokenElementRegex = /^\s*<aura:token\s(\n|.)*?\/>/gm;
var matches = strikeToken.match(tokenElementRegex); //these are the token elements we have found
var ourTokenMap = createMapfromTokenMatches(matches);
var theirMatches = remoteToken.match(tokenElementRegex); //these are the token elements we have found
var theirTokenMap = createMapfromTokenMatches(theirMatches);
var diffMap = {};
for(var prop in ourTokenMap){
if(!theirTokenMap.hasOwnProperty(prop)){
diffMap[prop] = ourTokenMap[prop];
}
}
var linesToInsert = [];
for(var prop in diffMap){
var tmpStr = '';
tmpStr = "\t<aura:token name=\"" + prop + "\" value=\"" + diffMap[prop] + "\" />\n";
linesToInsert.push(tmpStr);
}
if(!linesToInsert.length == 0){
linesToInsert.push('</aura:tokens>');
linesToInsert.unshift('\t<!--Below generated by Strike-CLI -->\n');
linesToInsert.unshift('\n');
}
return linesToInsert;
}
function createMapfromTokenMatches(matches){
var tmpMap = {};
matches.forEach(function(a){
var nameMatch = a.match(/name=(\"|\')(.+?)(\"|\')/);
var valueMatch = a.match(/value=(\"|\')(.+?)(\"|\')/);
tmpMap[nameMatch[2]] = valueMatch[2];
});
return tmpMap;
}