add helper tool for starting new mode
This commit is contained in:
parent
badade8f4e
commit
dbeeea2dd9
3 changed files with 150 additions and 14 deletions
57
tool/lib.js
57
tool/lib.js
|
|
@ -1,38 +1,73 @@
|
|||
var plist = require("plist");
|
||||
var util = require("util");
|
||||
var url = require("url");
|
||||
|
||||
var https = require("https");
|
||||
var http = require("http");
|
||||
|
||||
exports.parsePlist = function(themeXml, callback) {
|
||||
var result = ""
|
||||
var result = "";
|
||||
plist.parseString(themeXml, function(_, theme) {
|
||||
result = theme[0];
|
||||
callback && callback(theme[0]);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
exports.formatJSON = function(object, initialIndent) {
|
||||
return util.inspect(object, false, 40).replace(/^/gm, initialIndent||"")
|
||||
|
||||
}
|
||||
return util.inspect(object, false, 40).replace(/^/gm, initialIndent||"");
|
||||
};
|
||||
|
||||
|
||||
exports.fillTemplate = function(template, replacements) {
|
||||
return template.replace(/%(.+?)%/g, function(str, m) {
|
||||
return replacements[m] || "";
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.hyphenate = function(str) {
|
||||
return str.replace(/([A-Z])/g, "-$1").replace(/_/g, "-").toLowerCase();
|
||||
}
|
||||
return str.replace(/([A-Z])/g, "-$1").replace(/[_\s\-]+/g, "-").toLowerCase();
|
||||
};
|
||||
|
||||
exports.camelCase = function(str) {
|
||||
return str.replace(/[\-_\s]+(.?)/g, function(x, y) {return y.toUpperCase()});
|
||||
};
|
||||
|
||||
exports.snakeCase = function(str) {
|
||||
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s\-]+/g, "_").toLowerCase();
|
||||
};
|
||||
|
||||
exports.quoteString = function(str) {
|
||||
return '"' + str.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.restoreJSONComments = function(objStr) {
|
||||
return objStr.replace(/^(\s*)comment: '(.*)'/gm, function(_, i, c) {
|
||||
return i + "//" + c.replace(/\\n(\\t)*/g, "\n" + i + "//") + "\n" + i
|
||||
return i + "//" + c.replace(/\\n(\\t)*/g, "\n" + i + "//") + "\n" + i;
|
||||
}).replace(/ \/\/ ERROR/g, '", // ERROR');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.download = function(href, callback) {
|
||||
var options = url.parse(href);
|
||||
var protocol = options.protocol === "https:" ? https : http;
|
||||
console.log("connecting to " + options.host + " " + options.path);
|
||||
var request = protocol.get(options, function(res) {
|
||||
var data = "";
|
||||
res.setEncoding("utf-8");
|
||||
|
||||
res.on("data", function(chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on("end", function(){
|
||||
callback(data);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
exports.AceRoot = __dirname + "/../";
|
||||
exports.AceLib = __dirname + "/../lib/";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue