-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
78 lines (69 loc) · 2.29 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const { src, dest, series, parallel, watch, task } = require('gulp');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
const header = require('gulp-header');
const shell = require('gulp-shell');
const pkg = require('./package.json');
const sourceBranch = 'main';
const targetBranch = 'gh-pages';
const folderToCopy = 'demo';
/* Copy folder between branches */
const copyFolder = () => {
return shell.task([
`git checkout ${targetBranch}`,
`git checkout ${sourceBranch} -- ${folderToCopy}`,
`git add ${folderToCopy}`,
`git commit -m "Copy '${folderToCopy}' folder from ${sourceBranch}"`,
`git push origin ${targetBranch}`,
`git checkout ${sourceBranch}`
]);
}
/* Set banner for dist files */
const setBanner = () => {
const banner = [
'/**',
` * Judo Spin`,
` * @name ${pkg.name}`,
` * @description ${pkg.description}`,
` * @link ${pkg.homepage}`,
` * @author ${pkg.author.name}, ${pkg.author.web}`,
` * @version v${pkg.version}`,
` * @created Jul 20, 2023`,
` * @updated Aug 15, ${new Date().getFullYear()}`,
` * @copyright Copyright (C) 2023-${new Date().getFullYear()}, ${pkg.author.name}`,
` * @license ${pkg.license}`,
` * @licenseMIT ${pkg.homepage}/blob/main/LICENSE`,
` * @demoExample https://rodgath.github.io/judo-spin/demo/`,
' */',
''
].join('\n');
return src('./dist/{css,js}/**/*.{js,css}')
.pipe(header(banner))
.pipe(dest('./dist'))
}
const compressJs = () => {
return src('src/*.js')
.pipe(dest('./demo/js')) // Send original script file to /demo
.pipe(dest('./dist/js')) // Send original script file to /dist
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(rename( { suffix: '.min' } ))
.pipe(dest('./demo/js'))
.pipe(dest('./dist/js'))
}
const watchTask = () => {
watch(['./src/*.js', './demo/*.html'], { events: 'all' }, series(compressJs, setBanner))
}
const buildTask = () => {
return series(compressJs, setBanner)
}
/* Tasks */
task('copy:demo', copyFolder());
task('set:banner', setBanner);
task('compress:js', compressJs);
task('watch', watchTask);
task('build', buildTask());
exports.default = buildTask();