From bcae8b5543863d9583d9eb0da9d527d4256cba10 Mon Sep 17 00:00:00 2001 From: Mickael Jeanroy Date: Wed, 26 Dec 2018 20:56:30 +0100 Subject: [PATCH] chore: migrate to gulp 4 --- gulpfile.js | 109 +++++++----------------------------- package.json | 1 - scripts/build/index.js | 34 +++++++++++ scripts/changelog/index.js | 35 ++++++++++++ scripts/clean/index.js | 30 ++++++++++ scripts/config.js | 35 ++++++++++++ scripts/lint/index.js | 42 ++++++++++++++ scripts/release/index.js | 112 +++++++++++++++++++++++++++++++++++++ scripts/test/index.js | 37 ++++++++++++ 9 files changed, 346 insertions(+), 89 deletions(-) create mode 100644 scripts/build/index.js create mode 100644 scripts/changelog/index.js create mode 100644 scripts/clean/index.js create mode 100644 scripts/config.js create mode 100644 scripts/lint/index.js create mode 100644 scripts/release/index.js create mode 100644 scripts/test/index.js diff --git a/gulpfile.js b/gulpfile.js index e6ba3518..350cfe38 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -22,92 +22,25 @@ * 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 conventionalChangelog = require('gulp-conventional-changelog'); -const git = require('gulp-git'); -const bump = require('gulp-bump'); -const runSequence = require('run-sequence'); - -const ROOT = __dirname; -const SRC = path.join(ROOT, 'src'); -const TEST = path.join(ROOT, 'test'); -const DIST = path.join(ROOT, 'dist'); - -gulp.task('test', ['build'], () => { - const src = [ - path.join(TEST, 'base.spec.js'), - path.join(TEST, '**', '*.spec.js'), - ]; - - return gulp.src(src).pipe(jasmine()); -}); - -gulp.task('clean', () => { - return del([DIST]); -}); - -gulp.task('build', ['clean', 'lint'], () => { - return gulp.src(path.join(SRC, '*.js')) - .pipe(babel()) - .pipe(gulp.dest(DIST)); -}); - -gulp.task('lint', () => { - const src = [ - path.join(ROOT, '*.js'), - path.join(SRC, '**', '*.js'), - path.join(TEST, '**', '*.js'), - ]; - - return gulp.src(src) - .pipe(eslint()) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); -}); - -gulp.task('changelog', () => { - const changelog = path.join(ROOT, 'CHANGELOG.md'); - return gulp.src(changelog, {buffer: false}) - .pipe(conventionalChangelog({ - releaseCount: 0, - })) - .pipe(gulp.dest(ROOT)); -}); - -gulp.task('commit:pre', () => { - const packageJson = path.join(ROOT, 'package.json'); - return gulp.src([packageJson, DIST]) - .pipe(git.add({args: '-f'})) - .pipe(git.commit('release: release version')); -}); - -gulp.task('commit:post', () => { - return gulp.src(DIST) - .pipe(git.rm({args: '-r'})) - .pipe(git.commit('release: prepare next release')); -}); - -gulp.task('tag', (done) => { - const pkg = require(path.join(ROOT, 'package.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(path.join(ROOT, 'package.json')) - .pipe(bump({type: level})) - .on('error', (e) => log.error(e)) - .pipe(gulp.dest(ROOT)); - }); - - gulp.task('release:' + level, ['build'], () => { - return runSequence(`bump:${level}`, 'commit:pre', 'tag', 'commit:post'); - }); -}); +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 changelog = require('./scripts/changelog'); + +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), + 'changelog': changelog, + 'release:patch': gulp.series(prerelease, release.patch), + 'release:minor': gulp.series(prerelease, release.minor), + 'release:major': gulp.series(prerelease, release.major), +}; diff --git a/package.json b/package.json index 37bef79e..56cc7c34 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "rollup": "0.67.4", "rollup-plugin-commonjs": "9.2.0", "rollup-plugin-node-resolve": "4.0.0", - "run-sequence": "2.2.1", "tmp": "0.0.33" } } diff --git a/scripts/build/index.js b/scripts/build/index.js new file mode 100644 index 00000000..95780bdb --- /dev/null +++ b/scripts/build/index.js @@ -0,0 +1,34 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 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 config = require('../config'); + +module.exports = function build() { + return gulp.src(path.join(config.src, '**', '*.js')) + .pipe(babel()) + .pipe(gulp.dest(config.dist)); +}; diff --git a/scripts/changelog/index.js b/scripts/changelog/index.js new file mode 100644 index 00000000..e34a7adf --- /dev/null +++ b/scripts/changelog/index.js @@ -0,0 +1,35 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 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 conventionalChangelog = require('gulp-conventional-changelog'); +const config = require('../config'); + +module.exports = function changelog() { + const changelog = path.join(config.root, 'CHANGELOG.md'); + return gulp.src(changelog, {buffer: false}) + .pipe(conventionalChangelog({releaseCount: 0})) + .pipe(gulp.dest(config.root)); +}; diff --git a/scripts/clean/index.js b/scripts/clean/index.js new file mode 100644 index 00000000..f397fcbe --- /dev/null +++ b/scripts/clean/index.js @@ -0,0 +1,30 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 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]); +}; diff --git a/scripts/config.js b/scripts/config.js new file mode 100644 index 00000000..3712a8d8 --- /dev/null +++ b/scripts/config.js @@ -0,0 +1,35 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 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'), +}; diff --git a/scripts/lint/index.js b/scripts/lint/index.js new file mode 100644 index 00000000..89c35709 --- /dev/null +++ b/scripts/lint/index.js @@ -0,0 +1,42 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 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()); +}; diff --git a/scripts/release/index.js b/scripts/release/index.js new file mode 100644 index 00000000..a4830fb1 --- /dev/null +++ b/scripts/release/index.js @@ -0,0 +1,112 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 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 gulp = require('gulp'); +const git = require('gulp-git'); +const bump = require('gulp-bump'); +const log = require('fancy-log'); +const config = require('../config'); + +/** + * Update version in number in `package.json` file. + * + * @param {string} level The semver level identifier (`major`, `minor` or `patch`). + * @return {WritableStream} The stream pipeline. + */ +function bumpLevel(level) { + return gulp.src(config.pkg) + .pipe(bump({type: level})) + .on('error', (e) => log.error(e)) + .pipe(gulp.dest(config.root)); +} + +/** + * Commit the current changes: + * - The `dist` directory containing final bundle. + * - The `package.json` containing the new version number. + * + * @return {WritableStream} The stream pipeline. + */ +function performRelease() { + return gulp.src([config.pkg, config.dist]) + .pipe(git.add({args: '-f'})) + .pipe(git.commit('release: release version')); +} + +/** + * Prepare the next release cycle: + * - Remove the `dist` directory containing bundle tagged on given version. + * - Create a new commit preparing the next release. + * + * @return {WritableStream} The stream pipeline. + */ +function prepareNextRelease() { + return gulp.src(config.dist) + .pipe(git.rm({args: '-r'})) + .pipe(git.commit('release: prepare next release')); +} + +/** + * Tag current version: the tag name will be extracted from + * the `version` field in the `package.json` file. + * + * @param {function} done The `done` callback. + * @return {void} + */ +function tagRelease(done) { + const pkg = require(config.pkg); + const version = pkg.version; + git.tag(`v${version}`, `release: tag version ${version}`, done); +} + +/** + * Create the release task. + * + * @param {string} level The version level upgrade. + * @return {function} The release task function. + */ +function createReleaseTask(level) { + /** + * Prepare the release: upgrade version number according to + * the specified level. + * + * @return {WritableStream} The stream pipeline. + */ + function prepareRelease() { + return bumpLevel(level); + } + + return gulp.series( + prepareRelease, + performRelease, + tagRelease, + prepareNextRelease + ); +} + +module.exports = { + patch: createReleaseTask('patch'), + minor: createReleaseTask('minor'), + major: createReleaseTask('major'), +}; diff --git a/scripts/test/index.js b/scripts/test/index.js new file mode 100644 index 00000000..46ebe25f --- /dev/null +++ b/scripts/test/index.js @@ -0,0 +1,37 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2016 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 jasmine = require('gulp-jasmine'); +const config = require('../config'); + +module.exports = function test() { + const src = [ + path.join(config.test, 'base.spec.js'), + path.join(config.test, '**', '*.spec.js'), + ]; + + return gulp.src(src).pipe(jasmine()); +};