Merge pull request #1 from robwormald/master

chore(build): switch to typescript
This commit is contained in:
Max Lynch 2015-11-24 18:45:47 -06:00
commit 6463f2f510
16 changed files with 164 additions and 1229 deletions

1221
dist/cordova-wrap.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

2
dist/cordova.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare const promisifyCordova: (pluginObj: any, pluginName: any, methodName: any) => (...args: any[]) => any;
export { promisifyCordova };

27
dist/cordova.js vendored Normal file
View File

@ -0,0 +1,27 @@
var promisifyCordova = function (pluginObj, pluginName, methodName) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return new Promise(function (resolve, reject) {
if (!cordova) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment');
reject({
error: 'cordova_not_available'
});
return;
}
if (!pluginObj.installed()) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but the ' + pluginObj.plugin + ' plugin is not installed.');
reject({
error: 'plugin_not_installed'
});
return;
}
console.log('Cordova: exec(' + pluginName + ', ' + methodName + ')');
cordova.exec(resolve, reject, pluginName, methodName, args);
});
};
};
exports.promisifyCordova = promisifyCordova;

2
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare let wrappedPlugins: {};
export default wrappedPlugins;

35
dist/index.js vendored Normal file
View File

@ -0,0 +1,35 @@
var plugin_config_1 = require('./plugin-config');
var cordova_1 = require('./cordova');
var util_1 = require('./util');
var wrappedPlugins = {};
var promised;
function newPluginClass(config) {
var obj = {
installed: function () {
return !!obj.plugin();
},
// Get the plugin by checking the plugin ref path on window
plugin: function () {
return util_1.get(window, config.pluginRef);
},
pluginName: config.plugin
};
return obj;
}
// Go through each registered plugin
for (var i = 0; i < plugin_config_1.PluginConfig.length; i++) {
var plugin = plugin_config_1.PluginConfig[i];
// Create the wrapped class
var cls = newPluginClass(plugin);
promised = plugin.promise || [];
for (var j = 0; j < promised.length; j++) {
var method = promised[j];
var p = cordova_1.promisifyCordova(cls, plugin.id, method);
cls[method] = p;
}
// Save the plugin object
wrappedPlugins[plugin.className] = cls;
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = wrappedPlugins;
window['Native'] = wrappedPlugins;

8
dist/plugin-config.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
export interface CordovaPlugin {
id: string;
className: string;
plugin: string;
pluginRef: string;
promise?: any;
}
export declare var PluginConfig: CordovaPlugin[];

43
dist/plugin-config.js vendored Normal file
View File

@ -0,0 +1,43 @@
exports.PluginConfig = [
{
id: 'device',
className: 'Device',
plugin: 'cordova-plugin-device',
pluginRef: 'device'
},
{
id: 'camera',
className: 'Camera',
plugin: 'cordova-plugin-camera',
promise: ['takePicture'],
pluginRef: 'navigator.camera'
},
{
id: 'statusbar',
className: 'StatusBar',
plugin: 'cordova-plugin-statusbar',
pluginRef: 'StatusBar',
promise: ['show', 'hide', 'styleDefault', 'styleLightContent', 'styleBlackTranslucent', 'styleBlackOpaque']
},
{
id: 'applinks',
className: 'AppLinks',
plugin: 'com.lampa.startapp',
pluginRef: 'navigator.startApp',
promise: ['start', 'check']
},
{
id: 'barcode',
className: 'Barcode',
plugin: 'phonegap-plugin-barcodescanner',
pluginRef: 'cordova.plugins.barcodeScanner',
promise: ['scan', 'encode']
},
{
id: 'camera-roll',
className: 'CameraRoll',
plugin: 'cordova-plugin-camera-roll',
pluginRef: 'CameraRoll',
promise: ['saveToCameraRoll', 'getPhotos']
},
];

1
dist/util.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export declare function get(obj: any, path: any): any;

8
dist/util.js vendored Normal file
View File

@ -0,0 +1,8 @@
function get(obj, path) {
for (var i = 0, path = path.split('.'), len = path.length; i < len; i++) {
obj = obj[path[i]];
}
return obj;
}
exports.get = get;
;

View File

@ -26,7 +26,8 @@
"babel-preset-stage-0": "^6.1.18" "babel-preset-stage-0": "^6.1.18"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
"build": "rm -rf dist && tsc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -37,5 +38,6 @@
"bugs": { "bugs": {
"url": "https://github.com/driftyco/ionic-native/issues" "url": "https://github.com/driftyco/ionic-native/issues"
}, },
"homepage": "https://github.com/driftyco/ionic-native" "homepage": "https://github.com/driftyco/ionic-native",
"typings": "./dist/index.d.ts"
} }

View File

@ -1,10 +1,11 @@
import {Promise} from 'es6-promise'; //patch the window definition
declare var Promise;
declare var cordova;
const promisifyCordova = (pluginObj, pluginName, methodName) => { const promisifyCordova = (pluginObj, pluginName, methodName) => {
return (...args) => { return (...args) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if(!window.cordova) { if(!cordova) {
console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment'); console.warn('Cordova: tried calling', '"' + pluginName + '.' + methodName + '"', 'but Cordova is not defined. Please make sure you have cordova.js included in your index.html file and you are running in a proper cordova environment');
reject({ reject({
error: 'cordova_not_available' error: 'cordova_not_available'

View File

@ -1,3 +1,5 @@
interface Window { Native: any }
import {PluginConfig} from './plugin-config' import {PluginConfig} from './plugin-config'
import {promisifyCordova} from './cordova'; import {promisifyCordova} from './cordova';
@ -45,4 +47,4 @@ for(let i = 0; i < PluginConfig.length; i++) {
export default wrappedPlugins; export default wrappedPlugins;
window.Native = wrappedPlugins; window['Native'] = wrappedPlugins;

View File

@ -1,4 +1,13 @@
export var PluginConfig = [ export interface CordovaPlugin {
id: string,
className: string;
plugin: string;
pluginRef: string;
promise?: any //should really be Promise
}
export var PluginConfig:CordovaPlugin[] = [
{ {
id: 'device', id: 'device',
className: 'Device', className: 'Device',

17
tsconfig.json Normal file
View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"outDir": "dist",
"rootDir": ".",
"sourceMap": false,
"declaration": true
},
"files": [
"src/index.ts"
],
"exclude": [
"node_modules"
]
}