Write first class, make tests and took a coffee to understand freaking cordova-plugin ecosystem
This commit is contained in:
parent
1cae514078
commit
2198a81f0b
39
package.json
Normal file
39
package.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "cordova-plugin-webserver",
|
||||
"version": "1.0.0",
|
||||
"description": "Cordova Webserver",
|
||||
"homepage": "",
|
||||
"author": {
|
||||
"name": "Michael Bykovski"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-webserver",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": ""
|
||||
},
|
||||
"keywords": [
|
||||
"cordova",
|
||||
"ios",
|
||||
"android",
|
||||
"ecosystem:cordova",
|
||||
"cordova-ios",
|
||||
"cordova:plugin",
|
||||
"webserver",
|
||||
"http",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"devDependencies": {
|
||||
"cordova": "^6.1.1"
|
||||
},
|
||||
"scripts": {
|
||||
"deploy": "cd tests/app && cordova run --device"
|
||||
}
|
||||
}
|
37
plugin.xml
Normal file
37
plugin.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
|
||||
id="cordova-plugin-webserver"
|
||||
version="1.0.0">
|
||||
<engines>
|
||||
<engine name="cordova" version=">=3.0.0" />
|
||||
</engines>
|
||||
|
||||
<dependency id="cordova-plugin-add-swift-support" version="1.6.1"/>
|
||||
|
||||
<name>Webserver for Cordova Apps</name>
|
||||
<keywords>webserver,cordova,http, request, response,server</keywords>
|
||||
<repo></repo>
|
||||
<issue></issue>
|
||||
|
||||
<js-module src="webserver.js" name="webserver">
|
||||
<clobbers target="webserver" />
|
||||
</js-module>
|
||||
|
||||
<platform name="android">
|
||||
<source-file src="src/android/Webserver.java" />
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="Webserver">
|
||||
<param name="android-package" value="Webserver"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
</platform>
|
||||
|
||||
<platform name="ios">
|
||||
<source-file src="src/ios/Webserver.swift" />
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="Webserver">
|
||||
<param name="ios-package" value="Webserver" />
|
||||
</feature>
|
||||
</config-file>
|
||||
</platform>
|
||||
</plugin>
|
21
src/android/Webserver.java
Normal file
21
src/android/Webserver.java
Normal file
@ -0,0 +1,21 @@
|
||||
package org.apache.cordova.plugin;
|
||||
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* This class echoes a string called from JavaScript.
|
||||
*/
|
||||
public class Webserver extends CordovaPlugin {
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
if ("start".equals(action)) {
|
||||
callbackContext.success();
|
||||
return true;
|
||||
}
|
||||
return false; // Returning false results in a "MethodNotFound" error.
|
||||
}
|
||||
}
|
12
src/ios/Webserver.swift
Normal file
12
src/ios/Webserver.swift
Normal file
@ -0,0 +1,12 @@
|
||||
@objc(Webserver) class Webserver : CDVPlugin {
|
||||
func start(command: CDVInvokedUrlCommand) {
|
||||
var pluginResult = CDVPluginResult(
|
||||
status: CDVCommandStatus_OK
|
||||
)
|
||||
|
||||
self.commandDelegate!.sendPluginResult(
|
||||
pluginResult,
|
||||
callbackId: command.callbackId
|
||||
)
|
||||
}
|
||||
}
|
14
tests/package.json
Normal file
14
tests/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "cordova-plugin-webserver-tests",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-webserver-tests",
|
||||
"platforms": []
|
||||
},
|
||||
"keywords": [
|
||||
"ecosystem:cordova"
|
||||
],
|
||||
"author": "Michael Bykovski",
|
||||
"license": "Apache 2.0"
|
||||
}
|
11
tests/plugin.xml
Normal file
11
tests/plugin.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-webserver-tests"
|
||||
version="1.0.0">
|
||||
<name>Cordova Plugin Webserver Tests</name>
|
||||
<license>Apache 2.0</license>
|
||||
|
||||
<js-module src="tests.js" name="tests">
|
||||
</js-module>
|
||||
</plugin>
|
33
tests/tests.js
Normal file
33
tests/tests.js
Normal file
@ -0,0 +1,33 @@
|
||||
exports.defineAutoTests = function() {
|
||||
|
||||
describe('Webserver (window.webserver)', function () {
|
||||
var fns = [
|
||||
'start'
|
||||
];
|
||||
|
||||
it('should exist', function() {
|
||||
expect(webserver).toBeDefined();
|
||||
});
|
||||
|
||||
fns.forEach(function(fn) {
|
||||
it('should contain a ' + fn + ' function', function () {
|
||||
expect(typeof webserver[fn]).toBeDefined();
|
||||
expect(typeof webserver[fn] === 'function').toBe(true);
|
||||
});
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
exports.defineManualTests = function(contentEl, createActionButton) {
|
||||
createActionButton('Start', function() {
|
||||
webserver.start(
|
||||
function() {
|
||||
console.log('Success!');
|
||||
},
|
||||
function() {
|
||||
console.log('Error!');
|
||||
},
|
||||
|
||||
);
|
||||
});
|
||||
};
|
3
webserver.js
Normal file
3
webserver.js
Normal file
@ -0,0 +1,3 @@
|
||||
exports.start = function(success_callback, error_callback) {
|
||||
cordova.exec(success_callback, error_callback, "Webserver", "start", []);
|
||||
};
|
Loading…
Reference in New Issue
Block a user