You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2015/02/26 10:12:14 UTC

[2/2] cordova-medic git commit: CB-8544 made iOS builder to wait for tests to complete, refactored builder scripts

CB-8544 made iOS builder to wait for tests to complete, refactored builder scripts

github close #34


Project: http://git-wip-us.apache.org/repos/asf/cordova-medic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-medic/commit/3c2ad531
Tree: http://git-wip-us.apache.org/repos/asf/cordova-medic/tree/3c2ad531
Diff: http://git-wip-us.apache.org/repos/asf/cordova-medic/diff/3c2ad531

Branch: refs/heads/master
Commit: 3c2ad53171a4016d565f0c1cfb39d80e48ac2854
Parents: aa2f08b
Author: alsorokin <al...@akvelon.com>
Authored: Thu Feb 26 10:08:36 2015 +0300
Committer: sgrebnov <v-...@microsoft.com>
Committed: Thu Feb 26 12:11:36 2015 +0300

----------------------------------------------------------------------
 build_android.js             | 24 ++++++-----
 build_ios.js                 | 66 +++++++++++++++-------------
 build_windows.js             | 76 ++++++++++++++++++---------------
 build_wp8.js                 | 76 ++++++++++++++++++---------------
 src/build/makers/android.js  | 29 +++----------
 src/build/makers/ios.js      | 55 ++++++++----------------
 src/build/makers/windows.js  | 90 +++++++++++++++++----------------------
 src/build/makers/wp8.js      | 53 ++++++++++-------------
 src/utils/createMedicJson.js |  8 ++++
 9 files changed, 224 insertions(+), 253 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/build_android.js
----------------------------------------------------------------------
diff --git a/build_android.js b/build_android.js
index b852572..71f9e80 100644
--- a/build_android.js
+++ b/build_android.js
@@ -1,10 +1,11 @@
-var path         = require('path'),
-    buildinfo    = require('./buildinfo'),
-    config       = require('./config'),
-    android      = require('./src/build/makers/android'),
-    argv         = require('optimist').argv,
-    testcheck    = require('./testchecker'),
-    error_writer = require('./src/build/makers/error_writer');
+var path            = require('path'),
+    buildinfo       = require('./buildinfo'),
+    config          = require('./config'),
+    android         = require('./src/build/makers/android'),
+    argv            = require('optimist').argv,
+    testcheck       = require('./testchecker'),
+    error_writer    = require('./src/build/makers/error_writer'),
+    createMedicJson = require('./src/utils/createMedicJson');
 
 // this assumes that you start it in the sandbox
 
@@ -24,10 +25,13 @@ buildinfo('Android', BRANCH, function (error, sha) {
     if (error) {
         TEST_OK = false;
     } else {
-        android(output_location, sha, config.couchdb, test_timeout)
-            .then(function () {
+        // add medic configuration (sha, host) to destination folder
+        createMedicJson(path.join(MSPEC_DIR, 'www'), sha, config);
+
+        android(output_location, sha, test_timeout)
+            .then(function onSuccess() {
                 return testcheck(sha, config.couchdb.host);
-            }, function (err) {
+            }, function onError(err) {
                 TEST_OK = false;
                 error_writer('android', sha, 'Android tests execution failed.', err);
             }).then(function (testCheckResult) {

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/build_ios.js
----------------------------------------------------------------------
diff --git a/build_ios.js b/build_ios.js
index 8eba73c..21ba58d 100644
--- a/build_ios.js
+++ b/build_ios.js
@@ -1,41 +1,47 @@
-var path = require ('path');
-var shell = require('shelljs');
-var buildinfo = require('./buildinfo');
-var config = require('./config');
-var ios  = require('./src/build/makers/ios');
-var argv = require('optimist').argv;
-var testcheck = require('./testchecker');
+var path            = require('path'),
+    buildinfo       = require('./buildinfo'),
+    config          = require('./config'),
+    ios             = require('./src/build/makers/ios'),
+    argv            = require('optimist').argv,
+    testcheck       = require('./testchecker'),
+    createMedicJson = require('./src/utils/createMedicJson');
 
 // this assumes that you start it in the sandbox
 
-var TEST_DIR=process.cwd();
-var BRANCH='master';
-var TOOL_DIR=path.join(TEST_DIR,'medic');
-var MSPEC_DIR=path.join(TEST_DIR,'mobilespec');
-var output_location = path.join(MSPEC_DIR,'platforms','ios');
-var library_location = path.join(TEST_DIR,'cordova-ios');
+var branch = 'master',
+    mspec_dir = path.join(process.cwd(), 'mobilespec'),
+    output_location = path.join(mspec_dir, 'platforms', 'ios'),
+    test_timeout = config.app.timeout || 10 * 60,
+    TEST_OK = true;
 
-var TEST_OK=true;
+if (argv.branch) {
+    branch = argv.branch;
+}
 
-if(argv.branch) BRANCH=argv.branch;
-
-buildinfo('ios', BRANCH, function (error, sha ) {
-    if(error) {
-               TEST_OK=false;
+buildinfo('ios', branch, function (error, sha) {
+    if (error) {
+        TEST_OK = false;
     } else {
-       ios(output_location, library_location,TOOL_DIR, sha,'', config.app.entry, config.couchdb, function(err){
-           if(err) {
-               console.log('iOS test prepare failed')
-               TEST_OK=false;
-           } else {
-               console.log('iOS tests complete')
-               TEST_OK = true;
-           }
-       });
+        // add medic configuration (sha, host) to destination folder
+        createMedicJson(path.join(mspec_dir, 'www'), sha, config);
+
+        ios(output_location, sha, test_timeout)
+            .then(function () {
+                return testcheck(sha, config.couchdb.host);
+            }, function (err) {
+                TEST_OK = false;
+                error_writer('ios', sha, 'iOS tests execution failed.', err);
+            }).then(function (testCheckResult) {
+                TEST_OK = testCheckResult;
+                if (TEST_OK) {
+                    console.log('ios test execution completed');
+                }
+            });
     }
 });
 
 process.once('exit', function () {
-    if(!TEST_OK) process.exit(1);
+    if (!TEST_OK) {
+        process.exit(1);
+    }
 });
-

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/build_windows.js
----------------------------------------------------------------------
diff --git a/build_windows.js b/build_windows.js
index 1ab94a9..4cb5f01 100644
--- a/build_windows.js
+++ b/build_windows.js
@@ -1,27 +1,28 @@
-var fs = require('fs');
-var path = require ('path');
-var shell = require('shelljs');
-var buildinfo = require('./buildinfo');
-var config = require('./config');
-var windows  = require('./src/build/makers/windows');
-var argv = require('optimist').argv;
-var error_writer = require('./src/build/makers/error_writer');
-var testcheck = require('./testchecker');
+var fs              = require('fs'),
+    path            = require('path'),
+    buildinfo       = require('./buildinfo'),
+    config          = require('./config'),
+    windows         = require('./src/build/makers/windows'),
+    argv            = require('optimist').argv,
+    error_writer    = require('./src/build/makers/error_writer'),
+    testcheck       = require('./testchecker'),
+    createMedicJson = require('./src/utils/createMedicJson');
 
 // this assumes that you start it in the sandbox
 
-var TEST_DIR=process.cwd().replace(/\\/g, '\\\\');
-var BRANCH='master';
-var TOOL_DIR=path.join(TEST_DIR,'medic');
-var MSPEC_DIR=path.join(TEST_DIR,'mobilespec');
+var TEST_DIR = process.cwd().replace(/\\/g, '\\\\'),
+    BRANCH = 'master',
+    TOOL_DIR = path.join(TEST_DIR, 'medic'),
+    MSPEC_DIR = path.join(TEST_DIR, 'mobilespec'),
+    TEST_OK = true;
 
-var TEST_OK=true;
+if (argv.branch) {
+    BRANCH = argv.branch;
+}
 
-if(argv.branch) BRANCH=argv.branch;
+var output_location = path.join(MSPEC_DIR, 'platforms', 'windows');
 
-var output_location = path.join(MSPEC_DIR,'platforms','windows');
-
-buildinfo('Windows', BRANCH, function (error, sha ) {
+buildinfo('Windows', BRANCH, function (error, sha) {
 
     function log(msg) {
         console.log('[WINDOWS] ' + msg + ' (sha: ' + sha + ')');
@@ -30,48 +31,53 @@ buildinfo('Windows', BRANCH, function (error, sha ) {
     function setTargetStoreVersion(version) {
         log('setting target store version to ' + version);
 
-        var configPath = 'mobilespec/config.xml';
-        configContent = fs.readFileSync(configPath, "utf8");
+        var configPath = 'mobilespec/config.xml',
+            configContent = fs.readFileSync(configPath, "utf8"),
+            versionPreference = '<preference name="windows-target-version" value="' + version + '" />';
 
-        var versionPreference = '<preference name="windows-target-version" value="' + version + '" />';
-        configContent = configContent.replace ('</widget>', versionPreference + '\r\n</widget>')
+        configContent = configContent.replace('</widget>', versionPreference + '\r\n</widget>');
 
         fs.writeFileSync(configPath, configContent, "utf8");
     }
 
-    if(error) {
-        TEST_OK=false;
+    if (error) {
+        TEST_OK = false;
     } else {
         // timeout to execute tests, 10 min by default
-        var test_timeout = config.app.timeout ? config.app.timeout : 10 * 60;
+        var test_timeout = config.app.timeout || 10 * 60,
+            build_target = argv.phone ? "phone" : argv.store80 ? "store80" : "store";
+
         log(argv);
-        var build_target = argv.phone ? "phone" : argv.store80 ? "store80" : "store";
         log(build_target);
 
-        if (build_target == "store80") {
-            build_target == "store";
+        if (build_target === "store80") {
             //setTargetStoreVersion('8.0'); // this value is used by default
-        } else if (build_target == "store") {
+        } else if (build_target === "store") {
             // store target configuration is specified via config.xml 
             setTargetStoreVersion('8.1');
         }
 
-        windows(output_location, sha, config.app.entry, config.couchdb.host, test_timeout, build_target).then(function() {
+        // add medic configuration (sha, host) to destination folder
+        createMedicJson(path.join(MSPEC_DIR, 'www'), sha, config);
+
+        windows(output_location, sha, config.app.entry, test_timeout, build_target)
+            .then(function onSuccess() {
                 return testcheck(sha, config.couchdb.host);
+            }, function onError(err) {
+                TEST_OK = false;
+                error_writer('windows', sha, 'Windows tests execution failed.', err);
             }).then(function (testCheckResult) {
                 TEST_OK = testCheckResult;
 
                 if (TEST_OK) {
                     console.log('Windows test execution completed');
                 }
-            }).catch(function (err) {
-                TEST_OK=false;
-                error_writer('windows', sha, 'Windows tests execution failed.', err);
             });
     }
 });
 
 process.once('exit', function () {
-    if(!TEST_OK) process.exit(1);
+    if (!TEST_OK) {
+        process.exit(1);
+    }
 });
-

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/build_wp8.js
----------------------------------------------------------------------
diff --git a/build_wp8.js b/build_wp8.js
index 0b3c00c..356ff4c 100644
--- a/build_wp8.js
+++ b/build_wp8.js
@@ -1,48 +1,54 @@
-var path = require ('path');
-var shell = require('shelljs');
-var buildinfo = require('./buildinfo');
-var config = require('./config');
-var wp8  = require('./src/build/makers/wp8');
-var argv = require('optimist').argv;
-var error_writer = require('./src/build/makers/error_writer');
-var testcheck = require('./testchecker');
+var path            = require('path'),
+    buildinfo       = require('./buildinfo'),
+    config          = require('./config'),
+    wp8             = require('./src/build/makers/wp8'),
+    argv            = require('optimist').argv,
+    error_writer    = require('./src/build/makers/error_writer'),
+    testcheck       = require('./testchecker'),
+    createMedicJson = require('./src/utils/createMedicJson');
 
 // this assumes that you start it in the sandbox
 
-var TEST_DIR=process.cwd().replace(/\\/g, '\\\\');
-var BRANCH='master';
-var TOOL_DIR=path.join(TEST_DIR,'medic');
-var MSPEC_DIR=path.join(TEST_DIR,'mobilespec');
+var TEST_DIR = process.cwd().replace(/\\/g, '\\\\'),
+    BRANCH = 'master',
+    TOOL_DIR = path.join(TEST_DIR, 'medic'),
+    MSPEC_DIR = path.join(TEST_DIR, 'mobilespec'),
+    TEST_OK = true;
 
-var TEST_OK=true;
+if (argv.branch) {
+    BRANCH = argv.branch;
+}
 
-if(argv.branch) BRANCH=argv.branch;
+var output_location = path.join(MSPEC_DIR, 'platforms', 'wp8');
 
-var output_location = path.join(MSPEC_DIR,'platforms','wp8');
-
-buildinfo('WP8', BRANCH, function (error, sha ) {
-    if(error) {
-        TEST_OK=false;
+buildinfo('WP8', BRANCH, function (error, sha) {
+    if (error) {
+        TEST_OK = false;
     } else {
+        // add medic configuration (sha, host) to destination folder
+        createMedicJson(path.join(MSPEC_DIR, 'www'), sha, config);
+
         // timeout to execute tests, 10 min by default
-        var test_timeout = config.app.timeout ? config.app.timeout : 10 * 60;
-
-        wp8(output_location, sha, config.wp8.target, config.app.entry, config.couchdb.host, test_timeout).then(function() {
-            return testcheck(sha, config.couchdb.host);
-        }).then(function (testCheckResult) {
-            TEST_OK = testCheckResult;
-
-            if (TEST_OK) {
-                console.log('WP8 test execution completed');
-            }
-        }).catch(function (err) {
-            TEST_OK=false;
-            error_writer('wp8', sha, 'WP8 tests execution failed.', err);
-        });
+        var test_timeout = config.app.timeout || 10 * 60;
+
+        wp8(output_location, sha, config.wp8.target, config.app.entry, test_timeout)
+            .then(function onSuccess() {
+                return testcheck(sha, config.couchdb.host);
+            }, function onError(err) {
+                TEST_OK = false;
+                error_writer('wp8', sha, 'WP8 tests execution failed.', err);
+            }).then(function (testCheckResult) {
+                TEST_OK = testCheckResult;
+
+                if (TEST_OK) {
+                    console.log('WP8 test execution completed');
+                }
+            });
     }
 });
 
 process.once('exit', function () {
-    if(!TEST_OK) process.exit(1);
+    if (!TEST_OK) {
+        process.exit(1);
+    }
 });
-

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/src/build/makers/android.js
----------------------------------------------------------------------
diff --git a/src/build/makers/android.js b/src/build/makers/android.js
index 90886a1..bf81df9 100644
--- a/src/build/makers/android.js
+++ b/src/build/makers/android.js
@@ -7,7 +7,7 @@ var shell        = require('shelljs'),
     device       = require('../../../../mobilespec/platforms/android/cordova/lib/device'),
     emulator     = require('../../../../mobilespec/platforms/android/cordova/lib/emulator');
 
-module.exports = function (output, sha, couchdb_cfg, test_timeout) {
+module.exports = function (output, sha, test_timeout) {
 
     var noBuildMarker = '<!-- no build marker -->',
         manifestFile = path.join('platforms', 'android', 'bin', 'AndroidManifest.xml'),
@@ -17,24 +17,6 @@ module.exports = function (output, sha, couchdb_cfg, test_timeout) {
         console.log('[ANDROID] ' + msg + ' (sha: ' + sha + ')');
     }
 
-    function prepareMobileSpec() {
-        var d = q.defer();
-        try {
-            // make sure android app got created first.
-            if (!fs.existsSync(output)) {
-                throw new Error('create must have failed as output path does not exist.');
-            }
-            // add the medic configuration (sha, host) to destination folder
-            var medic_config = '{"sha":"' + sha + '","couchdb":"' + couchdb_cfg.host + '","couchdbext":"' + couchdb_cfg.exthost + '"}';
-            fs.writeFileSync(path.join(output, '..', '..', 'www', 'medic.json'), medic_config, 'utf-8');
-            d.resolve();
-        } catch (e) {
-            error_writer('android', sha, 'Exception thrown modifying Android mobile spec application.', e.message);
-            d.reject();
-        }
-        return d.promise;
-    }
-
     function build() {
         var d = q.defer(),
             build_cmd = path.join('..', 'cordova-cli', 'bin', 'cordova') + ' build -- --debug --ant';
@@ -123,14 +105,13 @@ module.exports = function (output, sha, couchdb_cfg, test_timeout) {
         }
     }
 
-    return prepareMobileSpec()
-        .then(function () {
-            shell.cd(mobilespecPath);
-        }).then(build)
+    shell.cd(mobilespecPath);
+
+    return build()
         .then(prepareDevice)
         .then(run)
         .then(function () {
             log('Waiting for tests to complete...');
             return testRunner.waitTestsCompleted(sha, 1000 * test_timeout);
         }).then(testNoBuild);
-}
+};

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/src/build/makers/ios.js
----------------------------------------------------------------------
diff --git a/src/build/makers/ios.js b/src/build/makers/ios.js
index ae0b116..72b6a5c 100644
--- a/src/build/makers/ios.js
+++ b/src/build/makers/ios.js
@@ -1,58 +1,37 @@
 var shell        = require('shelljs'),
     path         = require('path'),
-    deploy       = require('./ios/deploy'),
-    scan         = require('./ios/devices'),
     error_writer = require('./error_writer'),
-    config       = require('../../../config'),
-    fs           = require('fs');
-    mspec        = require('./mobile_spec');
+    q            = require('q'),
+    testRunner   = require('./testRunner');
 
-var keychain_location = config.ios.keychainLocation;
-var keychain_password = config.ios.keychainPassword;
-
-
-module.exports = function(output,lib_location,test_dir, sha, devices, entry_point, couchdb_cfg, callback) {
+module.exports = function (output, sha, test_timeout) {
     function log(msg) {
         console.log('[IOS] ' + msg + ' (sha: ' + sha + ')');
     }
-    log('starting iOS prepare');
-    try {
-        var projectWww = path.join(output, 'www');
-        // add the medic configuration (sha,host) to destination folder
-        var medic_config='{"sha":"'+sha+'","couchdb":"'+couchdb_cfg.host+'","couchdbext":"'+couchdb_cfg.exthost+'"}';
-        fs.writeFileSync(path.join(output, '..', '..', 'www', 'medic.json'),medic_config,'utf-8');
-
-        //  modify config.xml
-        var configFile = path.join(output, 'mobilespec', 'config.xml');
-        fs.writeFileSync(configFile, fs.readFileSync(configFile, 'utf-8').replace(/<content\s*src=".*"/gi, '<content src="'+entry_point+'"'), 'utf-8');
-        // make sure the couch db server is whitelisted
-        fs.writeFileSync(configFile, fs.readFileSync(configFile, 'utf-8').replace(/<access origin="http:..audio.ibeat.org" *.>/gi,'<access origin="http://audio.ibeat.org" /><access origin="'+couchdb_cfg.host+'" />', 'utf-8'));
-
-    } catch(e) {
-        error_writer('ios', sha, 'Exception thrown modifying mobile spec application for iOS.', e.message);
-        callback(true);
-        return;
-    }
     // compile
     log('Compiling.');
     log(output);
 
-    var mobileSpecDir = path.join(output, '..', '..');
+    var mobileSpecDir = path.join(output, '..', '..'),
+        buildCommand = 'cd ' + mobileSpecDir + ' && ./cordova build';
     log(mobileSpecDir);
-
-    var buildCommand = 'cd ' + mobileSpecDir + ' && ./cordova build';
     log(buildCommand);
-    var build = shell.exec(buildCommand, {silent: false});
+
+    var build = shell.exec(buildCommand, {silent: true});
     if (build.code > 0) {
-        error_writer('ios', sha, 'Compilation error.', build.output);
-        callback(true);
+        error_writer('ios', sha, 'Build error.', build.output);
+        return q.reject('Error while building, exit code: ' + build.code);
     }
 
     var runCommand = 'cd ' + mobileSpecDir + ' && ./cordova run';
     log(runCommand);
-    var run = shell.exec(runCommand, {silent: false});
+    var run = shell.exec(runCommand, {silent: true});
     if (run.code > 0) {
-        error_writer('ios', sha, 'Compilation error.', run.output);
-        callback(true);
+        error_writer('ios', sha, 'Error while deploying.', run.output);
+        return q.reject('Error while deploying, exit code: ' + run.code);
     }
-}
+
+    log('Waiting for tests to complete...');
+
+    return testRunner.waitTestsCompleted(sha, 1000 * test_timeout);
+};

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/src/build/makers/windows.js
----------------------------------------------------------------------
diff --git a/src/build/makers/windows.js b/src/build/makers/windows.js
index 71a91c6..aa4a1cb 100644
--- a/src/build/makers/windows.js
+++ b/src/build/makers/windows.js
@@ -1,38 +1,40 @@
-var shell        = require('shelljs'),
-    path         = require('path'),
-    n            = require('ncallbacks'),
-    fs           = require('fs'),
-    mspec        = require('./mobile_spec'),
-    couch        = require('../../couchdb/interface'),
-    q            = require('q'),
-    testRunner   = require('./testRunner'),
-    util         = require('util');
-
-module.exports = function(output, sha, entry_point, couchdb_host, test_timeout, build_target) {
-
-    var target_folder = ((build_target == 'store') ? 'windows' : ((build_target == 'store80') ? 'windows80' : 'phone')),
+var shell      = require('shelljs'),
+    path       = require('path'),
+    fs         = require('fs'),
+    mspec      = require('./mobile_spec'),
+    q          = require('q'),
+    testRunner = require('./testRunner'),
+    util       = require('util');
+
+module.exports = function (output, sha, entry_point, test_timeout, build_target) {
+
+    var target_folder = ((build_target === 'store') ? 'windows' : ((build_target === 'store80') ? 'windows80' : 'phone')),
         noBuildMarker = '<!-- no build marker -->',
         manifestFile = path.join('platforms', 'windows', 'build', target_folder, 'debug', 'anycpu', 'AppxManifest.xml');
-    
-    build_target = (build_target == 'store' || build_target == 'store80') ? 'win' : build_target;
 
+    build_target = (build_target === 'store' || build_target === 'store80') ? 'win' : build_target;
+
+    function log(msg) {
+        console.log('[WINDOWS] ' + msg + ' (sha: ' + sha + ')');
+    }
 
     function run() {
-        var d = q.defer();
-        log('Running app...');       
-        var cmd = '..\\cordova-cli\\bin\\cordova.cmd run windows -- --' + build_target + ' --nobuild',
+        var d = q.defer(),
+            cmd = '..\\cordova-cli\\bin\\cordova.cmd run windows -- --' + build_target + ' --nobuild',
             logFile = sha + '.log',
             errFile = sha + '.err',
             endFile = sha + '.end',
             runner = 'run.bat';
 
+        log('Running app...');
+
         // create commands that should be started from bat file:
         //  1. cd to project folder
         //  2. start 'cmd' defined earlier and redirect its stdout and stderr to files
         //  3. print exit code of 'cmd' to 'endfile'
         var runnerContent = util.format('cd /d "%s"\n%s 1>%s 2>%s & echo "%ERRORLEVEL%" >%s',
             shell.pwd(), cmd, logFile, errFile, endFile);
-        
+
         fs.writeFileSync(runner, runnerContent, 'utf-8');
 
         // the following hack with explorer.exe usage is required to start the tool w/o Admin privileges;
@@ -43,12 +45,12 @@ module.exports = function(output, sha, entry_point, couchdb_host, test_timeout,
         // and exits immediately after starting bat file we are waiting for
         // special marker - 'endfile' - to be created when cordova run exits.
         var waitForRunner = setInterval(function () {
-            if (fs.existsSync(endFile)){
+            if (fs.existsSync(endFile)) {
                 clearInterval(waitForRunner);
                 log(fs.readFileSync(logFile));
                 // read 'cordova run' exit code from endfile, that was written by run.bat
                 var exitCode = parseInt(fs.readFileSync(endFile, 'utf-8'), 10);
-                if (exitCode > 0){
+                if (exitCode > 0) {
                     log(fs.readFileSync(errFile));
                     d.reject('Unable to run application. Exit code: ' + exitCode);
                 }
@@ -58,37 +60,26 @@ module.exports = function(output, sha, entry_point, couchdb_host, test_timeout,
         return d.promise;
     }
 
-    function log(msg) {
-        console.log('[WINDOWS] ' + msg + ' (sha: ' + sha + ')');
-    }
-
     function prepareMobileSpec() {
         // make sure windows app got created first.
-        var defer = q.defer();
+        var defer = q.defer(),
+            mspec_out = path.join(output, 'www');
         try {
             if (!fs.existsSync(output)) {
                 throw new Error('create must have failed as output path does not exist.');
             }
-            var mspec_out = path.join(output, 'www');
 
-            log('Modifying Cordova Mobilespec application at:'+mspec_out);
+            log('Modifying Cordova Mobilespec application at:' + mspec_out);
 
-            mspec(mspec_out,sha,'',entry_point, function(err){
-                if(err) {
+            mspec(mspec_out, sha, '', entry_point, function (err) {
+                if (err) {
                     throw new Error('Error while modifying Windows mobile spec application.');
                 }
 
-                // specify couchdb server and sha for cordova medic plugin via medic.json
-                log('Write medic.json to autotest folder');
-                var medic_config='{"sha":"'+sha+'","couchdb":"'+couchdb_host+'"}';
-                fs.writeFileSync(path.join(output, '..', '..', 'www','autotest','pages', 'medic.json'),medic_config,'utf-8');
-                // Put medic.json to www to make plugin-test-framework working
-                fs.writeFileSync(path.join(output, '..', '..', 'www', 'medic.json'),medic_config,'utf-8');
-                
                 // patch WindowsStoreAppUtils script to allow app run w/out active desktop/remote session
-                if (build_target == "win") {
+                if (build_target === "win") {
                     log('Patching WindowsStoreAppUtils to allow app to be run in automated mode');
-                    shell.cp('-f', path.join(output, '..', '..', '..','medic','src', 'utils', 'EnableDebuggingForPackage.ps1'),
+                    shell.cp('-f', path.join(output, '..', '..', '..', 'medic', 'src', 'utils', 'EnableDebuggingForPackage.ps1'),
                              path.join(output, 'cordova', 'lib'));
                     shell.sed('-i', /^\s*\$appActivator .*$/gim,
                               '$&\n' +
@@ -100,35 +91,34 @@ module.exports = function(output, sha, entry_point, couchdb_host, test_timeout,
 
                 defer.resolve();
             });
-        }
-        catch (e) {
+        } catch (e) {
             defer.reject(e);
         }
         return defer.promise;
     }
-    
+
     function build() {
         log('Building app...');
-        
-        cmd = '..\\cordova-cli\\bin\\cordova.cmd build windows -- --' + build_target;
 
+        var cmd = '..\\cordova-cli\\bin\\cordova.cmd build windows -- --' + build_target;
         shell.exec(cmd);
-        
+
         fs.appendFileSync(manifestFile, noBuildMarker, 'utf-8');
     }
-    
+
     function testNoBuild() {
         var manifestContent = fs.readFileSync(manifestFile, 'utf-8');
-        
+
         if (manifestContent.indexOf(noBuildMarker) === -1) {
             throw new Error('NoBuild parameter test failed.');
         }
     }
 
-    return prepareMobileSpec().then(function() {
+    return prepareMobileSpec()
+        .then(function () {
             shell.cd(path.join(output, '..', '..'));
             return build();
-        }).then(run).then(function() {
+        }).then(run).then(function () {
             return testRunner.waitTestsCompleted(sha, 1000 * test_timeout);
         }).then(testNoBuild);
-};
\ No newline at end of file
+};

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/src/build/makers/wp8.js
----------------------------------------------------------------------
diff --git a/src/build/makers/wp8.js b/src/build/makers/wp8.js
index fa0f583..b302473 100644
--- a/src/build/makers/wp8.js
+++ b/src/build/makers/wp8.js
@@ -1,32 +1,29 @@
-var shell        = require('shelljs'),
-    path         = require('path'),
-    n            = require('ncallbacks'),
-    fs           = require('fs'),
-    mspec        = require('./mobile_spec'),
-    couch        = require('../../couchdb/interface'),
-    q            = require('q'),
-    testRunner   = require('./testRunner');
+var shell      = require('shelljs'),
+    path       = require('path'),
+    fs         = require('fs'),
+    mspec      = require('./mobile_spec'),
+    q          = require('q'),
+    testRunner = require('./testRunner');
 
-module.exports = function(output, sha, devices, entry_point, couchdb_host, test_timeout, callback) {
+module.exports = function (output, sha, devices, entry_point, test_timeout, callback) {
 
     function log(msg) {
         console.log('[WP8] ' + msg + ' (sha: ' + sha + ')');
     }
 
     function deploy(path, sha, devices) {
-        var cmd = 'cd ' + path + '\\..\\..\\ && node ..\\cordova-cli\\bin\\cordova run';
+        var cmd = 'cd ' + path + '\\..\\..\\ && node ..\\cordova-cli\\bin\\cordova run',
+            defer = q.defer();
         // run option: --device, --emulator, other
         if (devices !== '') {
             cmd += ' --' + devices;
         }
         cmd += ' wp8';
-        log ('starting deploy via command: ' + cmd);
-        var defer = q.defer();
-        shell.exec(cmd, {silent:true, async:true}, function(code, output) {
+        log('starting deploy via command: ' + cmd);
+        shell.exec(cmd, {silent: true, async: true}, function (code, output) {
             if (code > 0) {
                 defer.reject('deploy failed with code: ' + code);
-            }
-            else {
+            } else {
                 defer.resolve();
             }
         });
@@ -35,17 +32,16 @@ module.exports = function(output, sha, devices, entry_point, couchdb_host, test_
 
     function prepareMobileSpec() {
         // make sure wp8 app got created first.
-        var defer = q.defer();
+        var defer = q.defer(),
+            mspec_out = path.join(output, 'www');
         try {
             if (!fs.existsSync(output)) {
                 throw new Error('create must have failed as output path does not exist.');
             }
-            var mspec_out = path.join(output, 'www');
-
-            log('Modifying Cordova Mobilespec application at:'+mspec_out);
 
-            mspec(mspec_out,sha,devices,entry_point, function(err){
-                if(err) {
+            log('Modifying Cordova Mobilespec application at: ' + mspec_out);
+            mspec(mspec_out, sha, devices, entry_point, function (err) {
+                if (err) {
                     throw new Error('Error thrown modifying WP8 mobile spec application.');
                 }
 
@@ -57,9 +53,9 @@ module.exports = function(output, sha, devices, entry_point, couchdb_host, test_
                 }
 
                 // set permanent guid to prevent multiple installations
-                var guid = '{8449DEEE-16EB-4A4A-AFCC-8446E8F06FF7}';
-                var appManifestXml = path.join(output, 'Properties', 'WMAppManifest.xml');
-                var xml = fs.readFileSync(appManifestXml).toString().split('\n');
+                var guid = '{8449DEEE-16EB-4A4A-AFCC-8446E8F06FF7}',
+                    appManifestXml = path.join(output, 'Properties', 'WMAppManifest.xml'),
+                    xml = fs.readFileSync(appManifestXml).toString().split('\n');
                 for (var i in xml) if (xml[i].indexOf('<App') != -1) {
                     if (xml[i].toLowerCase().indexOf('productid') != -1) {
                         var index = xml[i].toLowerCase().indexOf('productid');
@@ -74,12 +70,6 @@ module.exports = function(output, sha, devices, entry_point, couchdb_host, test_
                 }
                 fs.writeFileSync(appManifestXml, xml.join('\n'));
 
-
-                // specify couchdb server and sha for cordova medic plugin via medic.json
-                log('Write medic.json to autotest folder');
-                var medic_config='{"sha":"'+sha+'","couchdb":"'+couchdb_host+'"}';
-                fs.writeFileSync(path.join(output, '..', '..', 'www','autotest','pages', 'medic.json'),medic_config,'utf-8');
-
                 defer.resolve();
             });
         }
@@ -90,7 +80,8 @@ module.exports = function(output, sha, devices, entry_point, couchdb_host, test_
         return defer.promise;
     }
 
-    return prepareMobileSpec().then(function() {
+    return prepareMobileSpec()
+        .then(function() {
             return deploy(output, sha, devices);
         }).then(function() {
             return testRunner.waitTestsCompleted(sha, 1000 * test_timeout);

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/3c2ad531/src/utils/createMedicJson.js
----------------------------------------------------------------------
diff --git a/src/utils/createMedicJson.js b/src/utils/createMedicJson.js
new file mode 100644
index 0000000..4098403
--- /dev/null
+++ b/src/utils/createMedicJson.js
@@ -0,0 +1,8 @@
+var fs   = require('fs'),
+    path = require('path');
+
+module.exports = function createMedicJson(output, sha, cfg) {
+    console.log('Writing medic.json to ' + output);
+    var medic_config = '{"sha":"' + sha + '","couchdb":"' + cfg.couchdb.host + '","couchdbext":"' + cfg.couchdb.exthost + '"}';
+    fs.writeFileSync(path.join(output, 'medic.json'), medic_config, 'utf-8');
+};


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org