-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchmanifest.js
executable file
·51 lines (42 loc) · 1.35 KB
/
chmanifest.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
45
46
47
48
49
50
51
#!/usr/bin/env node
var fs=require("fs");
var jsxml = require("node-jsxml"), XML = jsxml.XML;
var device = "";
var fetchUrl = "";
function readXML(xmlName) {
var path = ".repo/manifests/" + xmlName;
var data=fs.readFileSync(path,"utf-8");
return data;
}
function writeXML(xmlName, data) {
var path = ".repo/manifests/" + xmlName;
fs.writeFileSync(path, '<?xml version="1.0" ?>\n', "utf-8");
fs.appendFileSync(path, data, "utf-8");
}
function parseAndChange(xmlName) {
var xml = new XML(readXML(xmlName));
var includeNodes = xml.child("include");
var remoteNodes = xml.child("remote");
remoteNodes.each(function(item, index){
item.attribute("fetch").setValue("git://10.240.8.43/" + device + "/");
});
if (remoteNodes.length() != 0) {
writeXML(xmlName, xml.toXMLString());
console.log(xmlName + " changed to fetch git://10.240.8.43/" + device + "/");
}
if (includeNodes.length() == 0) return;
includeNodes.each(function(item, index){
var includeXMLName = item.attribute("name").getValue();
parseAndChange(includeXMLName);
});
}
function main() {
if (process.argv.length < 3) {
console.log("Please input device name!");
return;
}
device = process.argv[2];
//fetchUrl = process.argv[3] + device;
parseAndChange(device + ".xml");
}
main();