Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Cleans gulpfile and updates release depdencies #16

Merged
merged 2 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 80 additions & 52 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
const gulp = require('gulp');
const path = require('path');
const fs = require('fs');

const cache = require('gulp-cached');
const babel = require('gulp-babel');
const codecov = require('gulp-codecov');
const loadPlugins = require('gulp-load-plugins');
const eslint = require('gulp-eslint');
const notify_ = require('gulp-notify');
const codecov = require('gulp-codecov');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');

const path = require('path');
const fs = require('fs');
const runSequence = require('run-sequence');
const webpack = require('webpack');
const manifest = require('./package.json');
const DeepMerge = require('deep-merge');
const deepMerge = require('deep-merge');
const isparta = require('isparta');

const mochaGlobals = require('./test/setup/.globals');
const $ = loadPlugins();

const release = process.env.NODE_ENV === 'production';
const Instrumenter = isparta.Instrumenter;
const babelOptions = JSON.parse(fs.readFileSync('.babelrc', 'utf-8'))
const deepmerge = DeepMerge(function(target, source, key) {
const deepmerge = deepMerge(function(target, source, key) {
if(target instanceof Array) {
return [].concat(target, source);
}
return source;
});

const release = process.env.NODE_ENV === 'production';
const Instrumenter = isparta.Instrumenter;
const babelOptions = JSON.parse(fs.readFileSync('.babelrc', 'utf-8'));

const watchFiles = ['src/**/*', 'test/**/*'];
const lintWatchFiles = ['**/*.js', '!node_modules/**', '!coverage/**', '!gulpfile.js', '!build/**'];

const lintWatchFiles = ['**/*.js', '!node_modules/**',
'!coverage/**', 'gulpfile.js', '!build/**'];

const defaultConfig = {
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loaders: ['babel-loader','eslint-loader'] },
]
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader', 'eslint-loader'],
},
],
},
devtool: release ? '' : 'source-map',
};
Expand All @@ -47,45 +57,78 @@ const backendConfig = config_({
output: {
path: path.join(__dirname, 'build'),
filename: `index.js`,
libraryTarget: 'commonjs2'
libraryTarget: 'commonjs2',
},
node: {
__dirname: false,
__filename: false
__filename: false,
},
externals: [
function(context, request, callback) {
const pathStart = request.split('/')[0];
if (nodeModules.indexOf(pathStart) >= 0 ) {
return callback(null, "commonjs " + request);
};
return callback(null, 'commonjs ' + request);
}
callback();
}
},
],
recordsPath: path.join(__dirname, 'build/_records'),
plugins: [
new webpack.IgnorePlugin(/\.(css|less)$/),
new webpack.BannerPlugin({banner:'require("source-map-support").install();', raw: true, entryOnly: false })
]
new webpack.BannerPlugin(
{
banner: 'require("source-map-support").install();',
raw: true, entryOnly: false,
}
),
],
});

notify_.logLevel(0);

/**
* Merge default config with param
* @param {Object} overrides
* @return {Object}
*/
function config_(overrides) {
return deepmerge(defaultConfig, overrides || {});
}

function registerBabel_() {
/**
* Requires babel register
*/
function babelRegister_() {
require('babel-register');
}

/**
* Mocha configuration halper
* @return {WritableStream}
*/
function mocha_() {
return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
.pipe($.mocha({
.pipe(mocha({
reporter: 'spec',
globals: Object.keys(mochaGlobals.globals),
ignoreLeaks: false
ignoreLeaks: false,
}));
}

/**
* Notification helper
* @param {string} msg
* @return {Function}
*/
function notify(msg) {
return notify_({
title: '❂ Magnet',
message: msg,
icon: false,
onLast: true,
});
}

/**
* On build callback.
* @param {Function} done
Expand All @@ -95,23 +138,22 @@ function onBuild_(done) {
return function(err, stats) {
if(err) {
console.log('Error', err);
}
else {
} else {
console.log(stats.toString());
}

if(done) {
done();
}
}
};
}

/**
* Test helper
* @return {Function}
*/
function test() {
registerBabel_();
babelRegister_();
return mocha_();
}

Expand All @@ -138,15 +180,15 @@ gulp.task('build', (done) => {

gulp.task('watch-backend', function() {
return gulp.watch('src/*', [
'build-backend'
'build-backend',
]);
});

gulp.task('watch-bin', () => {
return gulp.watch('src/bin/*', [
'build-bin'
'build-bin',
]);
})
});

gulp.task('watch', ['watch-backend', 'watch-bin', 'lint']);

Expand All @@ -162,43 +204,29 @@ gulp.task('test:coverage:travis', () => {
});

gulp.task('coverage', (done) => {
registerBabel_();
babelRegister_();
gulp.src(['src/**/*.js'])
.pipe($.istanbul({
.pipe(istanbul({
instrumenter: Instrumenter,
includeUntested: true
includeUntested: true,
}))
.pipe($.istanbul.hookRequire())
.pipe(notify('Generating coverage'))
.pipe(istanbul.hookRequire())
.on('finish', () => {
return test()
.pipe($.istanbul.writeReports())
.pipe(istanbul.writeReports())
.on('end', done);
});
});

gulp.task('lint', () => {
return gulp.src(lintWatchFiles)
.pipe(eslint())
.pipe(notify('Lint performed'))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('lint:watch', () => {
gulp.watch(lintWatchFiles, ['lint']);
});

notify_.logLevel(0);

/**
* Notification helper
* @param {string} msg
* @return {Function}
*/
function notify(msg) {
return notify_({
title: '❂ Magnet',
message: msg,
icon: false,
onLast: true
});
}
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"test": "./node_modules/.bin/gulp coverage",
"test:watch": "./node_modules/.bin/gulp test:watch",
"test:coverage:travis": "./node_modules/.bin/gulp test:coverage:travis",
"generate-changelog": "github-changes --owner wedeploy --repository magnet -a --only-pulls --use-commit-body",
"generate-changelog": "./node_modules/.bin/auto-changelog",
"preversion": "npm test",
"postversion": "git push && git push --tags && rm -rf dist",
"version": "npm run generate-changelog && git add CHANGELOG.md",
"prepublish": "npm run build"
},
Expand Down Expand Up @@ -47,11 +48,11 @@
"winston": "^1.0.0"
},
"devDependencies": {
"auto-changelog": "^0.3.1",
"babel-core": "^6.22.1",
"babel-loader": "^6.3.0",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.22.0",
"babel-plugin-transform-async-to-module-method": "^6.22.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"chai": "^3.5.0",
Expand All @@ -60,15 +61,13 @@
"eslint": "^3.13.1",
"eslint-config-google": "^0.7.1",
"eslint-loader": "^1.6.1",
"github-changes": "^1.0.4",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-cached": "^1.1.1",
"gulp-codecov": "^2.0.2",
"gulp-concat": "^2.6.1",
"gulp-eslint": "^3.0.1",
"gulp-istanbul": "^1.1.1",
"gulp-load-plugins": "^1.4.0",
"gulp-mocha": "^3.0.1",
"gulp-notify": "^3.0.0",
"isparta": "^4.0.0",
Expand All @@ -77,7 +76,6 @@
"run-sequence": "^1.2.2",
"sinon": "^1.17.7",
"sinon-chai": "^2.8.0",
"supertest": "^2.0.1",
"webpack": "^2.2.0"
}
}