cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgreb...@apache.org
Subject [4/8] git commit: new script to write test configuration to config.xml
Date Wed, 05 Nov 2014 22:38:52 GMT
new script to write test configuration to config.xml


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

Branch: refs/heads/master
Commit: 36a7967059d76eabac504aedb7baa33930797d47
Parents: fe88e35
Author: sgrebnov <v-segreb@microsoft.com>
Authored: Tue Aug 5 18:04:02 2014 +0400
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Wed Oct 1 12:07:51 2014 +0400

----------------------------------------------------------------------
 updateconfig.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/36a79670/updateconfig.js
----------------------------------------------------------------------
diff --git a/updateconfig.js b/updateconfig.js
new file mode 100644
index 0000000..c3d7661
--- /dev/null
+++ b/updateconfig.js
@@ -0,0 +1,50 @@
+// /usr/bin/env node
+ 
+var fs   = require('fs'),
+    path = require('path'),
+    config = require('./config'),
+    argv = require('optimist').argv;
+
+//get parameters, that should been written to config.xml
+var entry_point = config.app.entry,
+    couch_host = config.couchdb.host;
+
+var configFile = path.join('mobilespec', 'config.xml');
+if (!fs.existsSync(configFile)){
+    console.log('Config.xml file doesn\'t exists');
+    process.exit(2);
+} else {
+    try {
+        var configContent = fs.readFileSync(configFile, 'utf-8');
+        // replace/add start page preference
+        // check if config.xml already contains <content /> element
+        console.log('Setting entry point to ' + entry_point + ' in config.xml');
+        if (configContent.match(/<content\s*src=".*"\s*\/>/gi)){
+            configContent = configContent.replace(
+                /<content\s*src=".*"\s*\/>/gi,
+                '<content src="' + entry_point + '" />');
+        } else {
+            // add entry point to config
+            configContent = configContent.split('</widget>').join('') +
+                '    <content src="' + entry_point + '"/>\n</widget>';
+        }
+
+        // Whitelists support on windows 8 is broken and cause build errors
+        if (argv.windows || argv.windows8){
+            console.warn('Current platform is windows. Removing all whitelist rules.');
+            configContent = configContent.replace(/\s*<access\s+origin=.*\/>/gim, '');
+            //cleanup doubled line ends
+            configContent = configContent.replace('\n\n', '\n');
+        } else {
+            // add whitelisting rule allow access to couch server
+            console.log('Adding whitelist rule for CouchDB host: ' + couch_host);
+            configContent = configContent.split('</widget>').join('') +
+                '    <access origin="' + couch_host + '" />\n</widget>';
+        }
+
+        fs.writeFileSync(configFile, configContent, 'utf-8');
+    } catch (e) {
+        console.log(e);
+        process.exit(2);
+    }
+}
\ No newline at end of file


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


Mime
View raw message