You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2014/11/11 02:16:23 UTC
cordova-plugins git commit: Added install/uninstall plugin hooks. The
hooks modify the project root's config.xml tag.
Repository: cordova-plugins
Updated Branches:
refs/heads/master 8b33bce0b -> eefd80e43
Added install/uninstall plugin hooks. The hooks modify the project root's config.xml <content> tag.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/eefd80e4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/eefd80e4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/eefd80e4
Branch: refs/heads/master
Commit: eefd80e431498d35913fe2dadeadfd62bbf603e8
Parents: 8b33bce
Author: Shazron Abdullah <sh...@apache.org>
Authored: Mon Nov 10 17:16:21 2014 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Nov 10 17:16:21 2014 -0800
----------------------------------------------------------------------
local-webserver/plugin.xml | 9 +++--
local-webserver/scripts/after_install.js | 49 +++++++++++++++++++++++
local-webserver/scripts/before_uninstall.js | 51 ++++++++++++++++++++++++
3 files changed, 106 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/eefd80e4/local-webserver/plugin.xml
----------------------------------------------------------------------
diff --git a/local-webserver/plugin.xml b/local-webserver/plugin.xml
index 0ee6f9b..212a201 100644
--- a/local-webserver/plugin.xml
+++ b/local-webserver/plugin.xml
@@ -22,6 +22,9 @@
<description>Cordova Local Web Server Plugin</description>
<keywords>cordova,local web server</keywords>
<repo>https://git-wip-us.apache.org/repos/asf/cordova-plugins.git</repo>
+
+ <hook type="after_plugin_install" src="scripts/after_install.js" />
+ <hook type="before_plugin_uninstall" src="scripts/before_uninstall.js" />
<engines>
<engine name="cordova" version=">=3.7.0" />
@@ -29,6 +32,7 @@
<!-- ios -->
<platform name="ios">
+
<config-file target="config.xml" parent="/*">
<feature name="CordovaLocalWebServer">
<param name="ios-package" value="SACordovaLocalWebServer"/>
@@ -78,9 +82,8 @@
<framework src="libz.dylib" />
<info>
- Modify your content tag in config.xml to point to a http://localhost location, change the port to whatever you want, e.g. <content src="http:=//localhost:8088" />
- Set the port to "0" to get a randomized port.
- </info>
+ Your content tag in config.xml now points to a http://localhost:0 location (randomized port), e.g. <content src="http://localhost:0" />
+ </info>
</platform>
</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/eefd80e4/local-webserver/scripts/after_install.js
----------------------------------------------------------------------
diff --git a/local-webserver/scripts/after_install.js b/local-webserver/scripts/after_install.js
new file mode 100644
index 0000000..01e8b2a
--- /dev/null
+++ b/local-webserver/scripts/after_install.js
@@ -0,0 +1,49 @@
+#!/usr/bin/env node
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+// This script modifies the project root's config.xml
+// The <content> tag "src" attribute is modified to point to http://localhost:0
+
+var content_src_value = "http://localhost:0";
+var fs = require('fs');
+var path = require('path');
+var old_content_src_value;
+
+module.exports = function(context) {
+ var config_xml = path.join(context.opts.projectRoot, 'config.xml');
+ var et = context.requireCordovaModule('elementtree');
+
+ var data = fs.readFileSync(config_xml).toString();
+ var etree = et.parse(data);
+
+ var content_tags = etree.findall('./content[@src]');
+ if (content_tags.length > 0) {
+ old_content_src_value = content_tags[0].get('src');
+ var backup_json = path.join(context.opts.plugin.dir, 'backup.json');
+ var backup_value = { content_src : old_content_src_value };
+ fs.writeFileSync(backup_json, JSON.stringify(backup_value));
+
+ content_tags[0].set('src', content_src_value);
+ }
+
+ data = etree.write({'indent': 4});
+ fs.writeFileSync(config_xml, data);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/eefd80e4/local-webserver/scripts/before_uninstall.js
----------------------------------------------------------------------
diff --git a/local-webserver/scripts/before_uninstall.js b/local-webserver/scripts/before_uninstall.js
new file mode 100644
index 0000000..ecf43c3
--- /dev/null
+++ b/local-webserver/scripts/before_uninstall.js
@@ -0,0 +1,51 @@
+#!/usr/bin/env node
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+// This script modifies the project root's config.xml
+// This restores the content tag's src attribute to its original value.
+
+var content_src_value = "http://localhost:0";
+var fs = require('fs');
+var path = require('path');
+var old_content_src_value;
+
+module.exports = function(context) {
+ var config_xml = path.join(context.opts.projectRoot, 'config.xml');
+ var et = context.requireCordovaModule('elementtree');
+
+ var data = fs.readFileSync(config_xml).toString();
+ var etree = et.parse(data);
+
+ var content_tags = etree.findall('./content[@src]');
+ if (content_tags.length > 0) {
+ var backup_json = path.join(context.opts.plugin.dir, 'backup.json');
+ var backup_data = JSON.parse(fs.readFileSync(backup_json).toString());
+
+ var config_content_src_value = content_tags[0].get('src');
+ // it's our value, we can restore old value
+ if (config_content_src_value === content_src_value) {
+ content_tags[0].set('src', backup_data.content_src);
+ }
+ }
+
+ data = etree.write({'indent': 4});
+ fs.writeFileSync(config_xml, data);
+}
\ 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