konva/gulpfile.js

105 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-04-30 22:24:27 +08:00
import gulp from 'gulp';
import rename from 'gulp-rename';
import uglify from 'gulp-uglify-es';
import replace from 'gulp-replace';
import jsdoc from 'gulp-jsdoc3';
import connect from 'gulp-connect';
import jscpd from 'gulp-jscpd';
import eslint from 'gulp-eslint';
import gutil from 'gulp-util';
2015-04-07 16:03:08 +08:00
2021-04-30 22:24:27 +08:00
import fs from 'fs';
var NodeParams = fs
.readFileSync('./resources/doc-includes/NodeParams.txt')
.toString();
var ContainerParams = fs
.readFileSync('./resources/doc-includes/ContainerParams.txt')
.toString();
var ShapeParams = fs
.readFileSync('./resources/doc-includes/ShapeParams.txt')
.toString();
2015-04-07 16:03:08 +08:00
2021-04-30 22:24:27 +08:00
const conf = JSON.parse(fs.readFileSync('./package.json'));
2015-04-07 16:03:08 +08:00
function build() {
return gulp
2019-01-06 16:01:20 +08:00
.src(['./konva.js'])
.pipe(replace('@@shapeParams', ShapeParams))
.pipe(replace('@@nodeParams', NodeParams))
.pipe(replace('@@containerParams', ContainerParams))
.pipe(replace('@@version', conf.version))
.pipe(replace('@@date', new Date().toDateString()));
2015-04-07 16:03:08 +08:00
}
2020-06-03 01:16:44 +08:00
gulp.task('update-version-lib', function () {
return gulp
.src(['./lib/Global.js'])
.pipe(replace('@@version', conf.version))
.pipe(rename('Global.js'))
.pipe(gulp.dest('./lib'));
2015-04-07 16:03:08 +08:00
});
2015-05-04 17:14:11 +08:00
// create usual build konva.js and konva.min.js
2020-06-03 01:16:44 +08:00
gulp.task('pre-build', function () {
return build()
.pipe(rename('konva.js'))
.pipe(gulp.dest('./'))
2021-04-30 22:24:27 +08:00
.pipe(
uglify.default({ output: { comments: /^!|@preserve|@license|@cc_on/i } })
)
2020-06-03 01:16:44 +08:00
.on('error', function (err) {
2017-08-25 20:00:58 +08:00
gutil.log(gutil.colors.red('[Error]'), err.toString());
})
.pipe(rename('konva.min.js'))
.pipe(gulp.dest('./'));
2015-04-07 16:03:08 +08:00
});
gulp.task('build', gulp.parallel(['update-version-lib', 'pre-build']));
2015-05-04 17:14:11 +08:00
// local server for better development
2020-06-03 01:16:44 +08:00
gulp.task('server', function () {
connect.server();
2015-04-07 16:03:08 +08:00
});
2015-05-04 17:14:11 +08:00
// lint files
2020-06-03 01:16:44 +08:00
gulp.task('lint', function () {
2018-06-20 19:00:18 +08:00
return (
gulp
.src('./src/**/*.js')
.pipe(
eslint({
2020-06-03 01:16:44 +08:00
configFile: './.eslintrc',
})
)
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failOnError last.
2018-06-20 19:00:18 +08:00
.pipe(eslint.failOnError())
);
2015-05-04 17:02:16 +08:00
});
2015-05-04 17:14:11 +08:00
// check code for duplication
2020-06-03 01:16:44 +08:00
gulp.task('inspect', function () {
return gulp.src('./src/**/*.js').pipe(
jscpd({
2015-05-04 17:02:16 +08:00
'min-lines': 10,
2020-06-03 01:16:44 +08:00
verbose: true,
})
);
2015-04-07 16:03:08 +08:00
});
// // generate documentation
2020-06-03 01:16:44 +08:00
gulp.task('api', function () {
2017-09-05 19:30:08 +08:00
return gulp.src('./konva.js').pipe(
jsdoc({
opts: {
2020-06-03 01:16:44 +08:00
destination: './api',
},
})
);
2015-04-07 16:03:08 +08:00
});
gulp.task('default', gulp.parallel(['server']));