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 53 54 55 56
|
// Changes the Dojo version in a file. Used during the release process.
var
version = "" + arguments[0],
revision = "" + arguments[1],
filename = "" + arguments[2],
writeFile= function(filename, contents){
var
outFile = new java.io.File(filename),
outWriter;
outWriter = new java.io.OutputStreamWriter(new java.io.FileOutputStream(outFile), "UTF-8");
var os = new java.io.BufferedWriter(outWriter);
try{
os.write(contents);
}finally{
os.close();
}
},
changeVersion = function(/*String*/version, /*String*/fileContents){
// summary:
// Changes the version number for dojo. Input should be the fileContents
// of a file that contains the version number.
//Set version number.
//First, break apart the version string.
var verSegments = version.match(/^(\d*)\.?(\d*)\.?(\d*)\.?(.*)$/);
var majorValue = verSegments[1] || 0;
var minorValue = verSegments[2] || 0;
var patchValue = verSegments[3] || 0;
var flagValue = verSegments[4] || "";
// Do the final version replacement.
if(/package/.test(filename)){
fileContents = fileContents.replace(
/['"](version|dojo|dijit)['"]\s*\:\s*['"][\w\.\-]+?["']/g,
'"$1":"' + version + '"'
);
}else{
fileContents = fileContents.replace(
/major:\s*\d*,\s*minor:\s*\d*,\s*patch:\s*\d*,\s*flag:\s*".*?"\s*,/g,
"major: " + majorValue + ", minor: " + minorValue + ", patch: " + patchValue + ", flag: \"" + flagValue + "\","
);
fileContents = fileContents.replace(/\$Rev(: [0-9a-f]* )?\$/, revision ? "$Rev: " + revision + " $" : "$Rev$");
}
return fileContents; //String
};
print(version);
print(filename);
var fileContents = readFile(filename, "utf-8");
fileContents = changeVersion(version, fileContents);
writeFile(filename, fileContents);
|