diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 00000000..55432a9e --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,64 @@ +'use strict' +const webpack = require('webpack'); +const webpackConfig = require('./webpack.config'); +const del = require('del'); +const exec = require('child_process').exec; + +module.exports = function(grunt) { + grunt.loadNpmTasks('grunt-contrib-copy'); + + function dirFilter(dirsToFilter) { + return (path) => { + for (let dir of dirsToFilter) { + if (path.startsWith(dir + '/') || path == dir) { + return false; + } + } + return true; + } + } + + grunt.initConfig({ + copy: { + resources: { + expand: true, + cwd: 'web', + src: '**', + dest: 'dist/', + filter: dirFilter(['web/app', 'web/test']) + } + } + }); + + grunt.registerTask('clean', function() { + del.sync('dist'); + }); + + grunt.registerTask('build', function() { + const done = this.async(); + webpack(webpackConfig, function (error) { + if (error) { + console.log('webpack failed'); + console.log(error); + } + done(); + }); + }); + + grunt.registerTask('show-revision', function() { + const done = this.async(); + exec('git rev-parse --short HEAD', (err, stdout, stderr) => { + grunt.log.writeln(stdout); + done(); + }); + }); + + grunt.registerTask('mark-revision', function() { + const done = this.async(); + exec('mkdir -p dist && git rev-parse HEAD > dist/.rev', function (err, stdout, stderr) { + done(err); + }); + }); + + grunt.registerTask('default', ['clean', 'build', 'copy:resources', 'mark-revision', 'show-revision']); +}; \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 2bfe5fb5..00000000 --- a/gulpfile.js +++ /dev/null @@ -1,32 +0,0 @@ -const gulp = require('gulp'); -const webpack = require('webpack'); -const webpackConfig = require('./webpack.config'); -const del = require('del'); - -gulp.task('clean', function () { - del('dist') -}); - -gulp.task('build', function () { - webpack(webpackConfig, function (error) { - if (error) { - console.log('webpack failed'); - console.log(error); - } - }); -}); - -gulp.task('resources', function () { - const res = []; - excluding('web/app', res); - excluding('web/test', res); - res.push('web/**/*'); - gulp.src(res).pipe(gulp.dest('dist')); -}); - -function excluding(path, filter) { - filter.push('!' + path + '/**/*', '!' + path); -} - - -gulp.task('default', ['clean', 'build', 'resources']); diff --git a/package.json b/package.json index 721a6ff8..a9a56048 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "webpack-dev-server --content-base web/ --port 3000", "pack": "webpack --config webpack.config.js --progress --profile --colors", - "build": "gulp", + "build": "grunt", "lint": "eslint web/app -c ./build/.eslintrc.json --ignore-path ./build/.eslintignore" }, "repository": { @@ -37,8 +37,8 @@ "style-loader": "0.13.1", "webpack": "1.13.2", "webpack-dev-server": "1.15.0", - "gulp": "3.9.1", - "del": "2.2.2" + "grunt": "1.0.1", + "grunt-contrib-copy": "1.0.0" }, "dependencies": { "sprintf": "0.1.5",