Skip to content

Commit

Permalink
chore: migrate to gulp 4
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Dec 26, 2018
1 parent fcadfd2 commit f64ab93
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 79 deletions.
26 changes: 26 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
##
# The MIT License (MIT)
#
# Copyright (c) 2017-2018 Mickael Jeanroy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
##

# NPM
/dist
6 changes: 4 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
node_modules/

# Do not send dev files
/test/
/src/
/test
/src
/scripts
/.eslintrc
/.eslintignore
/.babelrc
/.nvmrc
/.travis.yml
Expand Down
96 changes: 19 additions & 77 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,81 +22,23 @@
* SOFTWARE.
*/

const path = require('path');
const log = require('fancy-log');
const gulp = require('gulp');
const jasmine = require('gulp-jasmine');
const babel = require('gulp-babel');
const del = require('del');
const eslint = require('gulp-eslint');
const runSequence = require('run-sequence');
const git = require('gulp-git');
const bump = require('gulp-bump');

const ROOT = __dirname;
const PKG_JSON = path.join(ROOT, 'package.json');
const SRC = path.join('src');
const TEST = path.join('test');
const DIST = path.join('dist');

gulp.task('test', ['build'], () => {
const src = [
path.join(TEST, '**', '*.spec.js'),
];

return gulp.src(src).pipe(jasmine());
});

gulp.task('lint', () => {
const src = [
path.join(SRC, '**', '*.js'),
path.join(TEST, '**', '*.js'),
path.join(ROOT, '*.js'),
];

return gulp.src(src)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('clean', () => {
return del(DIST);
});

gulp.task('build', ['lint', 'clean'], () => {
return gulp.src(path.join(SRC, '*.js'))
.pipe(babel())
.pipe(gulp.dest(DIST));
});

gulp.task('pretag', () => {
return gulp.src([PKG_JSON, DIST])
.pipe(git.add({args: '-f'}))
.pipe(git.commit('release: release version'));
});

gulp.task('posttag', () => {
return gulp.src(DIST)
.pipe(git.rm({args: '-r'}))
.pipe(git.commit('release: prepare next release'));
});

gulp.task('tag', (done) => {
const pkg = require(PKG_JSON);
const version = pkg.version;
git.tag(`v${version}`, `release: tag version ${version}`, done);
});

['major', 'minor', 'patch'].forEach((level) => {
gulp.task(`bump:${level}`, () => {
return gulp.src(PKG_JSON)
.pipe(bump({type: level}))
.on('error', (e) => log.error(e))
.pipe(gulp.dest(ROOT));
});

gulp.task('release:' + level, ['build'], () => {
return runSequence(`bump:${level}`, 'pretag', 'tag', 'posttag');
});
});
const clean = require('./scripts/clean');
const lint = require('./scripts/lint');
const build = require('./scripts/build');
const test = require('./scripts/test');
const release = require('./scripts/release');

const prebuild = gulp.series(clean, lint);
const pretest = gulp.series(prebuild, build);
const prerelease = gulp.series(pretest, test);

module.exports = {
'clean': clean,
'lint': lint,
'build': gulp.series(prebuild, build),
'test': gulp.series(pretest, test),
'release:patch': gulp.series(prerelease, release.patch),
'release:minor': gulp.series(prerelease, release.minor),
'release:major': gulp.series(prerelease, release.major),
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"gulp-eslint": "5.0.0",
"gulp-git": "2.8.0",
"gulp-jasmine": "4.0.0",
"gulp-prettier": "2.0.0",
"jasmine-core": "3.3.0",
"q": "1.5.1",
"rollup": "0.67.4",
Expand Down
36 changes: 36 additions & 0 deletions scripts/build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017-2018 Mickael Jeanroy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const path = require('path');
const gulp = require('gulp');
const babel = require('gulp-babel');
const prettier = require('gulp-prettier');
const config = require('../config');

module.exports = function build() {
return gulp.src(path.join(config.src, '*.js'))
.pipe(babel())
.pipe(prettier())
.pipe(gulp.dest(config.dist));
};
30 changes: 30 additions & 0 deletions scripts/clean/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017-2018 Mickael Jeanroy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const del = require('del');
const config = require('../config');

module.exports = function clean() {
return del(config.dist);
};
35 changes: 35 additions & 0 deletions scripts/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016-2018 Mickael Jeanroy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const path = require('path');
const ROOT = path.join(__dirname, '..');

module.exports = {
root: ROOT,
src: path.join(ROOT, 'src'),
test: path.join(ROOT, 'test'),
scripts: path.join(ROOT, 'scripts'),
dist: path.join(ROOT, 'dist'),
pkg: path.join(ROOT, 'package.json'),
};
42 changes: 42 additions & 0 deletions scripts/lint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017-2018 Mickael Jeanroy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const path = require('path');
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const config = require('../config');

module.exports = function lint() {
const src = [
path.join(config.root, '*.js'),
path.join(config.src, '**', '*.js'),
path.join(config.test, '**', '*.js'),
path.join(config.scripts, '**', '*.js'),
];

return gulp.src(src)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
};
Loading

0 comments on commit f64ab93

Please sign in to comment.