mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-03-17 00:51:07 +08:00
This just might work
This commit is contained in:
parent
f1fcbc079b
commit
d27dd35dd6
61
gulpfile.js
61
gulpfile.js
@ -1,24 +1,55 @@
|
|||||||
var gulp = require("gulp");
|
var gulp = require("gulp"),
|
||||||
sourcemaps = require("gulp-sourcemaps"),
|
source = require('vinyl-source-stream'),
|
||||||
babel = require("gulp-babel"),
|
buffer = require('vinyl-buffer'),
|
||||||
|
sourcemaps = require("gulp-sourcemaps"),
|
||||||
concat = require("gulp-concat"),
|
concat = require("gulp-concat"),
|
||||||
connect = require('gulp-connect');
|
connect = require('gulp-connect'),
|
||||||
|
browserify = require('browserify'),
|
||||||
|
watchify = require('watchify'),
|
||||||
|
babel = require('babelify');
|
||||||
|
|
||||||
gulp.task("default", ['build'], function () {
|
|
||||||
});
|
function compile(watch) {
|
||||||
|
var bundler = watchify(browserify()
|
||||||
|
.require('./src/index.js', {
|
||||||
|
entry: true,
|
||||||
|
expose: 'ionic-native'
|
||||||
|
})
|
||||||
|
.transform(babel, {presets: ['es2015']}));
|
||||||
|
|
||||||
|
function rebundle() {
|
||||||
|
bundler.bundle()
|
||||||
|
.on('error', function(err) { console.error(err); this.emit('end'); })
|
||||||
|
.pipe(source('ionic-native.js'))
|
||||||
|
.pipe(buffer())
|
||||||
|
.pipe(sourcemaps.init({ loadMaps: true }))
|
||||||
|
.pipe(sourcemaps.write('./'))
|
||||||
|
.pipe(gulp.dest('./dist'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (watch) {
|
||||||
|
bundler.on('update', function() {
|
||||||
|
console.log('-> bundling...');
|
||||||
|
rebundle();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
rebundle();
|
||||||
|
}
|
||||||
|
|
||||||
|
function watch() {
|
||||||
|
return compile(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
gulp.task("default", ['build'], function () { });
|
||||||
|
|
||||||
gulp.task('build', function() {
|
gulp.task('build', function() {
|
||||||
return gulp.src("src/**/*.js")
|
return compile();
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(babel())
|
|
||||||
.pipe(concat("ionic-native.js"))
|
|
||||||
.pipe(sourcemaps.write("."))
|
|
||||||
.pipe(gulp.dest("dist"));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test', ['build', 'serve'], function() {
|
gulp.task('watch', function() {
|
||||||
|
return watch();
|
||||||
})
|
});
|
||||||
|
|
||||||
gulp.task('serve', function() {
|
gulp.task('serve', function() {
|
||||||
connect.server({
|
connect.server({
|
||||||
|
39
package.json
Normal file
39
package.json
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"name": "ionic-native",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Native plugins to replace ngCordova",
|
||||||
|
"main": "gulpfile.js",
|
||||||
|
"directories": {
|
||||||
|
"test": "test"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"babel-preset-es2015": "^6.1.18",
|
||||||
|
"babelify": "^7.2.0",
|
||||||
|
"browserify": "^12.0.1",
|
||||||
|
"gulp": "^3.9.0",
|
||||||
|
"gulp-concat": "^2.6.0",
|
||||||
|
"gulp-connect": "^2.2.0",
|
||||||
|
"gulp-sourcemaps": "^1.6.0",
|
||||||
|
"vinyl-buffer": "^1.0.0",
|
||||||
|
"vinyl-source-stream": "^1.1.0",
|
||||||
|
"watchify": "^3.6.1",
|
||||||
|
"gulp-babel": "^6.1.0",
|
||||||
|
"gulp-serve": "^1.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-preset-stage-0": "^6.1.18"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/driftyco/ionic-native.git"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/driftyco/ionic-native/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/driftyco/ionic-native"
|
||||||
|
}
|
16
src/cordova.js
vendored
Normal file
16
src/cordova.js
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const promisifyCordova = (pluginName, methodName) => {
|
||||||
|
return (...args) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if(!window.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;
|
||||||
|
}
|
||||||
|
cordova.exec(resolve, reject, pluginName, methodName, args);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {promisifyCordova};
|
35
src/index.js
Normal file
35
src/index.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import {Plugins} from './plugins';
|
||||||
|
import {PluginConfig} from './plugin-config'
|
||||||
|
import {promisifyCordova} from './cordova';
|
||||||
|
|
||||||
|
class IonicNative {
|
||||||
|
constructor() {
|
||||||
|
let pluginData, promised;
|
||||||
|
for(let plugin in PluginConfig) {
|
||||||
|
|
||||||
|
pluginData = PluginConfig[plugin];
|
||||||
|
console.log('Plugin', plugin, pluginData);
|
||||||
|
|
||||||
|
promised = pluginData.promise;
|
||||||
|
|
||||||
|
for(let method of promised) {
|
||||||
|
|
||||||
|
|
||||||
|
let p = promisifyCordova(plugin, method)
|
||||||
|
p().then((resp) => {
|
||||||
|
console.log('Thing');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let Native = new IonicNative;
|
||||||
|
|
||||||
|
export default Native;
|
||||||
|
|
||||||
|
// Because require isn't exporting properly, who the fuck knows
|
||||||
|
window.IonicNative = Native
|
7
src/plugin-config.js
Normal file
7
src/plugin-config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export var PluginConfig = {
|
||||||
|
"camera": {
|
||||||
|
'name': 'Camera',
|
||||||
|
'plugin': 'cordova-plugin-camera',
|
||||||
|
"promise": ["takePicture"],
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
export var Native = {
|
|
||||||
thing: true,
|
export var Plugins = {
|
||||||
};
|
getPlugin(name) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
13
test.js
Normal file
13
test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/src/index.js":[function(require,module,exports){
|
||||||
|
|
||||||
|
class Native {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Doing a thing');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default Native;
|
||||||
|
|
||||||
|
},{}]},{},["/src/index.js"]);
|
1
test/app/app.js
Normal file
1
test/app/app.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
console.log(window.require);
|
@ -2,6 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script src="../../dist/ionic-native.js"></script>
|
<script src="../../dist/ionic-native.js"></script>
|
||||||
|
<script src="app.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>Test</h2>
|
<h2>Test</h2>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user