Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
JodusNodus committed May 12, 2017
1 parent 6ebe9db commit 008cdb9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
37 changes: 18 additions & 19 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
const gulp = require('gulp');
const fs = require('fs');
const del = require('del');
const inlineStr = require('gulp-inline-str');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const gulp = require('gulp')
const fs = require('fs')
const del = require('del')
const inlineStr = require('gulp-inline-str')
const babel = require('gulp-babel')
const uglify = require('gulp-uglify')
const concat = require('gulp-concat')

const babelOptions = JSON.parse(fs.readFileSync('./.babelrc', 'utf8'));
const babelOptions = JSON.parse(fs.readFileSync('./.babelrc', 'utf8'))

const paths = {
scripts: [ 'src/index.js', 'src/getDeviceId.js', 'src/havePropsChanged.js' ],
scripts: [ 'src/index.js', 'src/getDeviceId.js', 'src/havePropsChanged.js', 'src/errors.js' ],
worker: 'src/worker.js',
jsQR: 'node_modules/jsqr/dist/jsQR.js',
destination: './lib',
};
}

gulp.task('clean', function() {
return del([ paths.destination + '/*.js' ]);
});
return del([ paths.destination + '/*.js' ])
})

gulp.task('worker', [ 'clean' ], function() {
return gulp
.src([ paths.jsQR, paths.worker ])
.pipe(concat('worker.js'))
.pipe(gulp.dest(paths.destination));
});
.pipe(gulp.dest(paths.destination))
})

gulp.task('build', [ 'worker' ], function() {
return gulp
.src(paths.scripts)
.pipe(inlineStr({ basePath: paths.destination }))
.pipe(babel(babelOptions))
.pipe(gulp.dest(paths.destination));
});
.pipe(gulp.dest(paths.destination))
})

// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, [ 'build' ]);
});
gulp.watch(paths.scripts, [ 'build' ])
})

// The default task (called when you run `gulp` from cli)
gulp.task('default', [ 'watch', 'build' ]);
gulp.task('default', [ 'watch', 'build' ])
11 changes: 11 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

function NoVideoInputDevicesError() {
this.name = 'NoVideoInputDevicesError';
this.message = 'No video input devices found';
}
NoVideoInputDevicesError.prototype = new Error();

module.exports = {
NoVideoInputDevicesError: NoVideoInputDevicesError
};
13 changes: 11 additions & 2 deletions lib/getDeviceId.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
'use strict';

var _require = require('./errors'),
NoVideoInputDevicesError = _require.NoVideoInputDevicesError;

module.exports = function getDeviceId(facingMode) {
// Get manual deviceId from available devices.
return new Promise(function (resolve, reject) {
navigator.mediaDevices.enumerateDevices().then(function (devices) {
var enumerateDevices = void 0;
try {
enumerateDevices = navigator.mediaDevices.enumerateDevices();
} catch (err) {
reject(new NoVideoInputDevicesError());
}
enumerateDevices.then(function (devices) {
// Filter out non-videoinputs
var videoDevices = devices.filter(function (device) {
return device.kind == 'videoinput';
});

if (videoDevices.length < 1) {
reject(new Error('No video input devices found'));
reject(new NoVideoInputDevicesError());
return;
} else if (videoDevices.length == 1) {
// Only 1 video device available thus stop here
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion story.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Wrapper extends Component {
)
}
{
selectDelay && (
(selectDelay || legacyMode) && (
<div>
<button onClick={() => this.setState({ delay: false })}>
Disable Delay
Expand Down

0 comments on commit 008cdb9

Please sign in to comment.