Skip to content

Commit

Permalink
Streamline build process
Browse files Browse the repository at this point in the history
  • Loading branch information
riyadhalnur committed May 28, 2016
1 parent 7ab21c7 commit a834070
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 164 deletions.
114 changes: 0 additions & 114 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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({
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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']);
17 changes: 4 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/node-base64-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
28 changes: 0 additions & 28 deletions test/runner.html

This file was deleted.

9 changes: 0 additions & 9 deletions test/setup/browser.js

This file was deleted.

0 comments on commit a834070

Please sign in to comment.