Skip to content

Commit

Permalink
Merge pull request #3977 from billdawson/timob-9815
Browse files Browse the repository at this point in the history
TIMOB-9815 Anvil: Copy all files/directories under the config directory so things like i18...
  • Loading branch information
ayeung committed Mar 21, 2013
2 parents ca2563b + 2286e4e commit bc38850
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
40 changes: 38 additions & 2 deletions anvil/driver/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ module.exports = new function() {

/*
* makes sure that the newly created harness contains the correct tiapp.xml and resources
* based on the harness template
* based on the harness template, as well as any other files/directories placed in the config
* directory.
*/
var updateHarness = function(platform, successCallback, errorCallback) {
var config = configs[configSetIndex].setConfigs[configIndex];
Expand All @@ -333,7 +334,7 @@ module.exports = new function() {
try {
wrench.copyDirSyncRecursive(path.resolve(configs[configSetIndex].setDir, "Resources"), path.resolve(harnessPlatformDir, "harness", "Resources"), {preserve: true});
driverUtils.log("harness suites updated");
updateTiappCallback();
copyConfigFilesCallback();

} catch(exception) {
driverUtils.log("unable to update the harness suites: " + exception);
Expand All @@ -343,6 +344,41 @@ module.exports = new function() {
}
};

/*
* Copy all files/directories from config directory to harness, so as to allow
* (for example) testing i18n, external modules or assets placed under the special
* platform/ directory.
* Ignore tiapp.xml and app.js, however, since they are handled separately in
* functions that are called after this.
*/
var copyConfigFilesCallback = function() {
var harnessDir = path.resolve(harnessPlatformDir, "harness"),
sourceDirContents = fs.readdirSync(configDir),
length = sourceDirContents.length,
i=0,
fileName,
fileFullPath,
destFullPath,
fileStat;

for (; i < length; i++) {
fileName = sourceDirContents[i];
if (fileName === "app.js" || fileName === "tiapp.xml") {
continue; // they're handled separately
}
fileFullPath = path.resolve(configDir, fileName);
destFullPath = path.resolve(harnessDir, fileName);
fileStat = fs.statSync(fileFullPath);
if (fileStat.isDirectory()) {
wrench.copyDirSyncRecursive(fileFullPath, destFullPath);
} else {
driverUtils.copyFileSync(fileFullPath, destFullPath);
}
}

updateTiappCallback();
};

var updateTiappCallback = function() {
function injectCustomTiappXmlProperties() {
if (self.customTiappXmlProperties.length < 1) {
Expand Down
10 changes: 8 additions & 2 deletions anvil/driver/driverUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,20 @@ module.exports = new function() {
callback(null);
});
sourceStream.on("error", function(exception) {
console.log("error occurred when reading from source stream");
console.log("error occurred when reading from source stream for file " + sourceFilePath);
callback(exception);
});

destStream = fs.createWriteStream(destFilePath);
destStream.on("error", function() {
console.log("error occurred when writing to source stream");
console.log("error occurred when writing to destination stream for file " + destFilePath);
});
sourceStream.pipe(destStream);
};

this.copyFileSync = function(sourceFilePath, destFilePath) {
// It's the caller's responsibility to ensure that the containing
// directory of destFilePath exists.
fs.writeFileSync(destFilePath, fs.readFileSync(sourceFilePath));
};
};

0 comments on commit bc38850

Please sign in to comment.