-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(all): Add build process, release browser platform as a UMD library
The new build process makes it possible to bundle the entire browser platform implementation as a library which can be used without cordova-browser. This is particularly valuable for projects which bundle apps with Electron or NW.js and do not use the Cordova Browser platform, but still need an API compatible implementation for desktop. The build process also makes it possible for the Web Worker code to be bundled with the plugin code, the adapter.js and qrcode-reader dependencies to be fully managed by NPM, and all released code to be minified. This change also adds a simple manual test for the library and some documentation. Fixes #30, removes some unused code in the browser implementation.
- Loading branch information
Showing
18 changed files
with
331 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
node_modules/ | ||
dist/ | ||
|
||
# generated files | ||
src/browser/plugin.min.js | ||
www/www.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ language: node_js | |
sudo: false | ||
node_js: | ||
- "4" | ||
- "6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const gulp = require('gulp'); | ||
const insert = require('gulp-insert'); | ||
const fs= require('fs'); | ||
|
||
const remap = fs.readFileSync('src/common/src/cordova-remap.js', 'utf-8'); | ||
|
||
function webpack(config, callback){ | ||
const exec = require('child_process').exec; | ||
exec('node_modules/.bin/webpack --config ' + config, (error, stdout, stderr) => { | ||
console.log(stdout); | ||
console.log(stderr); | ||
callback(error); | ||
}); | ||
} | ||
|
||
gulp.task('prepack', function(cb){ | ||
webpack('webpack.prepack.config.js', cb); | ||
}); | ||
|
||
gulp.task('webpack-cordova', ['prepack'], function(cb){ | ||
webpack('webpack.cordova.config.js', cb); | ||
}); | ||
|
||
gulp.task('dist', ['prepack'], function(cb){ | ||
webpack('webpack.library.config.js', cb); | ||
}); | ||
|
||
gulp.task('remap', ['webpack-cordova'], function () { | ||
return gulp.src(['dist/plugin.min.js', 'dist/www.min.js']) | ||
.pipe(insert.prepend(remap)) | ||
.pipe(gulp.dest('dist')); | ||
}); | ||
|
||
gulp.task('plugin', ['remap'], function () { | ||
return gulp.src(['dist/plugin.min.js']) | ||
.pipe(gulp.dest('src/browser')); | ||
}); | ||
|
||
gulp.task('www', ['remap'], function () { | ||
return gulp.src(['dist/www.min.js']) | ||
.pipe(gulp.dest('www')); | ||
}); | ||
|
||
gulp.task('default', ['dist', 'plugin', 'www']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var cordovaRequire = require('webpack/cordova/require'); | ||
var cordovaModule = require('webpack/cordova/module'); | ||
|
||
var createQRScannerInternal = require('./createQRScannerInternal.js'); | ||
|
||
cordovaModule.exports = createQRScannerInternal(); | ||
cordovaRequire('cordova/exec/proxy').add('QRScanner', cordovaModule.exports); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function QRScanner() { | ||
var createQRScannerAdapter = require('../../common/src/createQRScannerAdapter.js'); | ||
var createQRScannerInternal = require('./createQRScannerInternal.js'); | ||
|
||
var internal = createQRScannerInternal(); | ||
var functionList = { | ||
prepare: internal.prepare, | ||
show: internal.show, | ||
hide: internal.hide, | ||
scan: internal.scan, | ||
cancelScan: internal.cancelScan, | ||
pausePreview: internal.pausePreview, | ||
resumePreview: internal.resumePreview, | ||
enableLight: internal.enableLight, | ||
disableLight: internal.disableLight, | ||
useCamera: internal.useCamera, | ||
openSettings: internal.openSettings, | ||
getStatus: internal.getStatus, | ||
destroy: internal.destroy | ||
} | ||
|
||
// shim cordova's functionality for library usage | ||
var shimCordova = { | ||
exec: function(successCallback, errorCallback, className, functionName, inputArray){ | ||
if(className !== 'QRScanner' || !functionList[functionName]){ | ||
return errorCallback(0); | ||
} | ||
if(inputArray){ | ||
functionList[functionName](successCallback, errorCallback, inputArray); | ||
} else { | ||
functionList[functionName](successCallback, errorCallback); | ||
} | ||
} | ||
} | ||
|
||
var adapter = createQRScannerAdapter(shimCordova); | ||
return adapter; | ||
}; | ||
|
||
module.exports = new QRScanner(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This file is generated by `npm run build`. | ||
|
||
// remap parameter names from cordova.define | ||
// see `externals` in webpack.cordova.config.js | ||
var cordovaRequire = require; | ||
var cordovaExports = exports; | ||
var cordovaModule = module; |
Oops, something went wrong.