-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
105 lines (89 loc) · 2.51 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const gulp = require("gulp");
const replace = require("gulp-replace");
const header = require("gulp-header");
const uglify = require("gulp-uglify");
const browserify = require("browserify");
const babelify = require("babelify");
const source = require("vinyl-source-stream");
const buffer = require("vinyl-buffer");
const paths = {
browser: {
src: "src/browser_translit.js",
name: "translit.min.js",
dest: "dist/",
},
npm: {
src: "src/translit.js",
name: "translit_dist.min.js",
dest: "dist/",
},
copyright: {
src: "src/translit.js",
dest: "src/",
},
};
const packageJson = require("./package.json");
const currentYear = new Date().getFullYear();
// Copyright banner for the minified files
const copyrightBanner = `/*!
* Translit v${packageJson.version} (Rusyn transliteration)
* Copyright 2014–${currentYear} Braňo Šandala (https://brano.me)
*
* app: https://tota.sk/translit
* src: https://github.com/surfinzap/translit-rue
*
* Licensed under MIT (https://github.com/surfinzap/translit-rue/blob/main/LICENSE.txt)
*/
`;
function updateCopyrightBanner() {
const bannerRegex = /\/\*![\s\S]*?\*\/\s*/;
return gulp
.src(paths.copyright.src)
.pipe(replace(bannerRegex, ""))
.pipe(header(copyrightBanner))
.pipe(gulp.dest(paths.copyright.dest));
}
/*
* Define our tasks using plain functions
*/
function browserBuild() {
return browserify({ entries: paths.browser.src, debug: false })
.transform(babelify)
.bundle()
.pipe(source(paths.browser.name))
.pipe(buffer())
.pipe(uglify())
.pipe(header(copyrightBanner))
.pipe(gulp.dest(paths.browser.dest));
}
function npmBuild() {
return browserify({
entries: paths.npm.src,
debug: false,
standalone: "translit",
})
.transform(babelify, { presets: ["@babel/preset-env"] })
.bundle()
.pipe(source(paths.npm.name))
.pipe(buffer())
.pipe(uglify())
.pipe(header(copyrightBanner))
.pipe(gulp.dest(paths.npm.dest));
}
function watch() {
gulp.watch(paths.npm.src, npmBuild);
gulp.watch(paths.browser.src, browserBuild);
}
/*
* Specify if tasks run in series or parallel using `gulp.series` and `gulp.parallel`
*/
const build = gulp.parallel(npmBuild, browserBuild);
/*
* You can use CommonJS `exports` module notation to declare tasks
*/
exports.scripts = npmBuild;
exports.watch = watch;
exports.build = build;
// default task that can be called by just running `gulp` from cli
exports.default = build;
exports.updateCopyrightBanner = updateCopyrightBanner;