diff --git a/gulpfile.babel.js b/gulpfile.babel.js index ed7c068..86a61cc 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -2,34 +2,13 @@ import gulp from 'gulp'; import loadPlugins from 'gulp-load-plugins'; import {execFile} from 'child_process'; import flow from 'flow-bin'; -import del from 'del'; -import glob from 'glob'; -import path from 'path'; import {Instrumenter} from 'isparta'; -import webpack from 'webpack'; -import webpackStream from 'webpack-stream'; -// import source from 'vinyl-source-stream'; import mochaGlobals from './test/setup/.globals'; -import manifest from './package.json'; // Load all of our Gulp plugins const $ = loadPlugins(); -// Gather the library data from `package.json` -const config = manifest.babelBoilerplateOptions; -const mainFile = manifest.main; -const destinationFolder = path.dirname(mainFile); -const exportFileName = path.basename(mainFile, path.extname(mainFile)); - -function cleanDist(done) { - del([destinationFolder]).then(() => done()); -} - -function cleanTmp(done) { - del(['tmp']).then(() => done()); -} - function onError() { $.util.beep(); } @@ -56,31 +35,6 @@ function lintGulpfile() { return lint('gulpfile.babel.js'); } -function build() { - return gulp.src(path.join('src', config.entryFileName + '.js')) - .pipe($.plumber()) - .pipe(webpackStream({ - output: { - filename: exportFileName + '.js', - libraryTarget: 'umd', - library: config.mainVarName - }, - module: { - loaders: [ - { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' } - ] - }, - devtool: 'source-map' - })) - .pipe(gulp.dest(destinationFolder)) - .pipe($.filter(['*', '!**/*.js.map'])) - .pipe($.rename(exportFileName + '.min.js')) - .pipe($.sourcemaps.init({ loadMaps: true })) - .pipe($.uglify()) - .pipe($.sourcemaps.write('./')) - .pipe(gulp.dest(destinationFolder)); -} - function _mocha() { return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false}) .pipe($.mocha({ @@ -147,65 +101,6 @@ function generateDocs() { .pipe(gulp.dest('docs')); } -const watchFiles = ['src/**/*', 'test/**/*', 'package.json', '**/.eslintrc']; - -// Run the headless unit tests as you make changes. -function watch() { - gulp.watch(watchFiles, ['test']); -} - -function testBrowser() { - // Our testing bundle is made up of our unit tests, which - // should individually load up pieces of our application. - // We also include the browser setup file. - const testFiles = glob.sync('./test/unit/**/*.js'); - const allFiles = ['./test/setup/browser.js'].concat(testFiles); - - // Lets us differentiate between the first build and subsequent builds - let firstBuild = true; - - // This empty stream might seem like a hack, but we need to specify all of our files through - // the `entry` option of webpack. Otherwise, it ignores whatever file(s) are placed in here. - return gulp.src('') - .pipe($.plumber()) - .pipe(webpackStream({ - watch: true, - entry: allFiles, - output: { - filename: '__spec-build.js' - }, - module: { - loaders: [ - // This is what allows us to author in future JavaScript - { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' }, - // This allows the test setup scripts to load `package.json` - { test: /\.json$/, exclude: /node_modules/, loader: 'json-loader' } - ] - }, - plugins: [ - // By default, webpack does `n=>n` compilation with entry files. This concatenates - // them into a single chunk. - new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }) - ], - devtool: 'inline-source-map' - }, null, function () { - if (firstBuild) { - $.livereload.listen({port: 35729, host: 'localhost', start: true}); - // let watcher = gulp.watch(watchFiles, ['lint']); - } else { - $.livereload.reload('./tmp/__spec-build.js'); - } - firstBuild = false; - })) - .pipe(gulp.dest('./tmp')); -} - -// Remove the built files -gulp.task('clean', cleanDist); - -// Remove our temporary files -gulp.task('clean-tmp', cleanTmp); - // Lint our source code gulp.task('lint-src', lintSrc); @@ -218,9 +113,6 @@ gulp.task('lint-gulpfile', lintGulpfile); // Lint everything gulp.task('lint', ['lint-src', 'lint-test', 'lint-gulpfile']); -// Build two versions of the library -gulp.task('build', ['lint', 'clean'], build); - // Lint and run our tests gulp.task('test', ['lint', 'flow'], test); @@ -236,11 +128,5 @@ gulp.task('tag', gitTag); // Generate documentation gulp.task('doc', generateDocs); -// Set up a livereload environment for our spec runner `test/runner.html` -gulp.task('test-browser', ['lint', 'clean-tmp'], testBrowser); - -// Run the headless unit tests as you make changes. -gulp.task('watch', watch); - // An alias of test gulp.task('default', ['test']); diff --git a/package.json b/package.json index 9280364..6b41a60 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,13 @@ "name": "node-base64-image", "version": "1.0.0", "description": "Download images from remote URLs and encode/decode them to base64", - "main": "dist/index.js", + "main": "dist/node-base64-image.js", "scripts": { "test": "gulp", "lint": "gulp lint", "test-browser": "gulp test-browser", "watch": "gulp watch", - "build": "gulp build", + "build": "babel src --presets babel-preset-es2015 --out-dir dist", "coverage": "gulp coverage", "tag": "gulp tag", "doc": "gulp doc", @@ -34,6 +34,7 @@ }, "homepage": "http://riyadhalnur.github.io/node-base64-image/", "devDependencies": { + "babel-cli": "6.9.0", "babel-core": "^6.3.26", "babel-eslint": "6.0.4", "babel-loader": "^6.2.0", @@ -43,34 +44,24 @@ "babel-register": "^6.3.13", "chai": "^3.4.1", "coveralls": "2.11.9", - "del": "^2.2.0", "eslint": "2.10.2", "eslint-plugin-flow-vars": "0.4.0", "flow-bin": "0.25.0", - "glob": "^6.0.3", "gulp": "^3.9.0", "gulp-babel": "^6.1.1", "gulp-documentation": "2.2.0", "gulp-eslint": "^2.0.0", "gulp-filter": "^3.0.0", "gulp-istanbul": "^0.10.3", - "gulp-livereload": "^3.8.1", "gulp-load-plugins": "^1.1.0", "gulp-mocha": "^2.2.0", "gulp-plumber": "^1.0.1", - "gulp-rename": "^1.2.2", - "gulp-sourcemaps": "^1.6.0", "gulp-tag-version": "1.3.0", - "gulp-uglify": "^1.5.1", "gulp-util": "^3.0.7", "isparta": "^4.0.0", - "json-loader": "^0.5.3", "mocha": "^2.3.4", "sinon": "^1.17.2", - "sinon-chai": "^2.8.0", - "vinyl-source-stream": "^1.1.0", - "webpack": "^1.12.9", - "webpack-stream": "^3.1.0" + "sinon-chai": "^2.8.0" }, "babelBoilerplateOptions": { "entryFileName": "node-base64-image", diff --git a/src/node-base64-image.js b/src/node-base64-image.js index 8f7e6f9..509dd1f 100644 --- a/src/node-base64-image.js +++ b/src/node-base64-image.js @@ -87,3 +87,10 @@ export function decode(imageBuffer: any, options: Object = {filename: 'saved-ima return callback(null, 'Image saved successfully to disk!'); }); } + +const base64 = { + encode: encode, + decode: decode +}; + +export default base64; diff --git a/test/runner.html b/test/runner.html deleted file mode 100644 index 371619b..0000000 --- a/test/runner.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - Tests - - - - - - - - - - - - - - - - - - - -
- - diff --git a/test/setup/browser.js b/test/setup/browser.js deleted file mode 100644 index a87155b..0000000 --- a/test/setup/browser.js +++ /dev/null @@ -1,9 +0,0 @@ -let mochaGlobals = require('./.globals.json').globals; - -window.mocha.setup('bdd'); -window.onload = function () { - window.mocha.checkLeaks(); - window.mocha.globals(Object.keys(mochaGlobals)); - window.mocha.run(); - require('./setup')(window); -};