forked from apache/cordova-node-xcode
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathguidMapper.js
More file actions
52 lines (44 loc) · 1.23 KB
/
Copy pathguidMapper.js
File metadata and controls
52 lines (44 loc) · 1.23 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
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs');
const path = require('path');
function guidMapper(filePath) {
this.filePath = filePath;
this.data = this.loadFromFile();
}
guidMapper.prototype.loadFromFile = function () {
try {
const rawData = fs.readFileSync(this.filePath, 'utf8');
return JSON.parse(rawData);
} catch (error) {
// If file doesn't exist or there's an error parsing it, initialize with an empty object.
return {};
}
};
guidMapper.prototype.writeFileSync = function () {
const jsonData = JSON.stringify(this.data, null, 2);
fs.writeFileSync(this.filePath, jsonData, 'utf8');
};
guidMapper.prototype.addEntry = function (guid, path, name) {
if(!!guid && !! path && !!name){
this.data[guid] = { path: path, name: name };
}
};
guidMapper.prototype.removeEntry = function (guid) {
if (this.data[guid]) {
delete this.data[guid];
}
};
guidMapper.prototype.getEntries = function () {
return this.data;
};
guidMapper.prototype.findEntryGuid = function (name, path) {
for (const guid in this.data) {
if (this.data.hasOwnProperty(guid)) {
const entry = this.data[guid];
if (entry.path === path && entry.name === name) {
return guid;
}
}
}
return null;
};
module.exports = guidMapper;