From 67a2aca4e99c316f49edd8d985c8b884b31a5507 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 6 Sep 2012 17:27:22 +0800 Subject: [PATCH] add tool --- helper/tools/compress.js | 24 ++++++++++++++++++ helper/tools/get-static.js | 45 ++++++++++++++++++++++++++++++++++ helper/tools/update-version.js | 22 +++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 helper/tools/compress.js create mode 100644 helper/tools/get-static.js create mode 100644 helper/tools/update-version.js diff --git a/helper/tools/compress.js b/helper/tools/compress.js new file mode 100644 index 0000000..b000f8c --- /dev/null +++ b/helper/tools/compress.js @@ -0,0 +1,24 @@ +var fs = require("fs"), +exec = require("child_process").exec; +// js compress +var jsPaths = ["neoease"]; +for (var i = 0; i < jsPaths.length; i++) { + var content = ""; + exec("uglifyjs ../../" + jsPaths[i] + "/js/" + jsPaths[i] + ".js > ../../" + jsPaths[i] + "/js/" + jsPaths[i] + ".min.js", function (error, stdout, stderr) { + if (error !== null) { + console.log(error); + } + }); +} + +// css compress +var skinsCsses = ["andrea", "classic", "community", "favourite", "i-nove", "neoease", "owmx-3.0", "tree-house"]; + +for (var i = 0; i < skinsCsses.length; i++) { + var content = ""; + exec("lessc -compress ../../" + skinsCsses[i] + "/css/" + skinsCsses[i] + ".css > ../../" + skinsCsses[i] + "/css/" + skinsCsses[i] + ".min.css", function (error, stdout, stderr) { + if (error !== null) { + console.log(error); + } + }); +} \ No newline at end of file diff --git a/helper/tools/get-static.js b/helper/tools/get-static.js new file mode 100644 index 0000000..5efb842 --- /dev/null +++ b/helper/tools/get-static.js @@ -0,0 +1,45 @@ +var fs = require('fs'), +path = require('path'); + +var getAllFiles = function (root){ + var res = [], + files = fs.readdirSync(root); + + files.forEach(function(file){ + var pathname = root+'/'+file, + stat = fs.lstatSync(pathname); + + if (!stat.isDirectory()){ + if (file.indexOf(".ftl") < 0 && file.indexOf(".properties") < 0 + && root.indexOf("../../helper") < 0 && root.indexOf("../../.git") < 0) { + res.push(pathname); + } + } else { + res = res.concat(getAllFiles(pathname)); + } + }); + return res; +}; + +var mkdirsSync = function(dirpath) { + if(fs.existsSync(dirpath)){ + return; + } + var dirs = dirpath.split('/'); + var dir = ''; + for(var i = 0; i < dirs.length; i++) { + dir += dirs[i] + '/'; + if(!fs.existsSync(dir)){ + fs.mkdirSync(dir); + } + } +}; + +var skins = getAllFiles("../.."); +(function () { + mkdirsSync("static"); + for (var i = 0; i < skins.length; i++) { + mkdirsSync(path.dirname(skins[i].replace("../..", "static/skins"))); + fs.writeFileSync(skins[i].replace("../..", "static/skins"), fs.readFileSync(skins[i]), "UTF-8"); + } +})(); \ No newline at end of file diff --git a/helper/tools/update-version.js b/helper/tools/update-version.js new file mode 100644 index 0000000..653e6c9 --- /dev/null +++ b/helper/tools/update-version.js @@ -0,0 +1,22 @@ +var version = "", +newVersion = ""; + +process.argv.forEach(function (val, index, array) { + if (index === 2) { + version = val; + } + + if (index === 3) { + newVersion = val; + } +}); + +var fs = require("fs"); +var skins = ["andrea", "classic", "community", "favourite", "i-nove", "neoease", "owmx-3.0", "tree-house"]; + +for (var i = 0; i < skins.length; i++) { + var fileName = "../../" + skins[i] + "/skin.properties"; + + var file = fs.readFileSync(fileName, "UTF-8"); + fs.writeFileSync(fileName, file.replace("forSolo=" + version, "forSolo=" + newVersion), "UTF-8"); +} \ No newline at end of file