1 | const Common = require('./common.js');
|
2 |
|
3 |
|
4 | module.exports = {
|
5 | /*
|
6 | HASHSTR := newType('HASHSTR', str)
|
7 | description : function to get vcs hash
|
8 | requires : None
|
9 | returns : Optional[HASHSTR]
|
10 | */
|
11 | getHash: function(root_path) {
|
12 | try{
|
13 | var git_hash = Common.systemSync('git rev-parse HEAD', root_path);
|
14 | return git_hash;
|
15 | }
|
16 | catch(error){
|
17 | console.error(error)
|
18 | return null
|
19 | }
|
20 | },
|
21 |
|
22 |
|
23 | /*
|
24 | description : function to get git url
|
25 | requires : None
|
26 | returns : Optional[str]
|
27 | */
|
28 | getURL: function(root_path) {
|
29 | try{
|
30 | var git_url = Common.systemSync('git config --get remote.origin.url', root_path);
|
31 | return git_url;
|
32 | }
|
33 | catch(error){
|
34 | console.error(error)
|
35 | return null
|
36 | }
|
37 | },
|
38 |
|
39 |
|
40 |
|
41 | /*
|
42 | description : function to get project name
|
43 | requires : None
|
44 | returns : Optional[str]
|
45 | */
|
46 | getProject: function(root_path) {
|
47 | try{
|
48 | var project_name = Common.systemSync('basename \`git rev-parse --show-toplevel\`', root_path);
|
49 | return project_name;
|
50 | }
|
51 | catch(error){
|
52 | console.error(error)
|
53 | return null
|
54 | }
|
55 | },
|
56 |
|
57 |
|
58 | /*
|
59 | description : function to get blm info
|
60 | requires : root_path -> str
|
61 | returns : Optional[str]
|
62 | */
|
63 | getBlame: function(root_path) {
|
64 | try{
|
65 | var blame_info = Common.systemSync('git blame -l ' + root_path + '/package.json', root_path);
|
66 | return blame_info;
|
67 | }
|
68 | catch(error){
|
69 | console.error(error)
|
70 | return null
|
71 | }
|
72 | },
|
73 |
|
74 |
|
75 | /*
|
76 | DEPNAME := newType('DEPNAME', str)
|
77 | BLMINFO := newType('BLMINFO', str)
|
78 | description : function to get blm info
|
79 | requires : raw_blame -> Optional[str],
|
80 | dep_list -> Optional[Sequence[str]]
|
81 | returns : Optional[Dict[DEPNAME, BLMINFO]]
|
82 | */
|
83 | parseBlm: function(raw_blame, dep_list){
|
84 | if ((raw_blame == null) || (dep_list == null)) return null;
|
85 |
|
86 | var dep_list = Object.keys(dep_list);
|
87 | var blm_list = raw_blame.split('\n');
|
88 | var result = {};
|
89 | var i = 0;;
|
90 |
|
91 | for(var line in blm_list){
|
92 | if (blm_list[line].includes(dep_list[i])){
|
93 | result[dep_list[i]] = blm_list[line];
|
94 | i++;
|
95 | }
|
96 | }
|
97 | return result
|
98 | }
|
99 | };
|
100 |
|
101 |
|
102 |
|