-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
135 lines (120 loc) · 3.12 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const gulp = require('gulp');
const browsersync = require("browser-sync").create();
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const replace = require('gulp-replace');
const header = require('gulp-header');
const packageJson = require('./package.json');
const currentYear = new Date().getFullYear();
var paths = {
dev: {
html: 'demo/typopo-demo.html',
index: 'typopo-demo.html',
name: 'typopo_browser.built.js',
dest: 'build/'
},
browser: {
src: 'src/browser_typopo.js',
name: 'typopo.min.js',
dest: 'dist/'
},
npm: {
src: 'src/typopo.js',
name: 'typopo_dist.min.js',
dest: 'dist/'
},
root: {
src: 'src/typopo.js',
dest: 'src/'
}
};
// Copyright banner for the minified files
const copyrightBanner = `/*!
* Typopo v${packageJson.version} (https://typopo.org)
* Copyright 2015–${currentYear} Braňo Šandala (https://brano.me)
* Licensed under MIT (https://github.com/surfinzap/typopo/blob/main/LICENSE.txt)
*/
`;
// Update version in typopo.js
function updateTypopoJsCopyrightBanner() {
const bannerRegex = /\/\*\![\s\S]*?\*\/\s*/;
return gulp.src(paths.root.src)
.pipe(replace(bannerRegex, ''))
.pipe(header(copyrightBanner))
.pipe(gulp.dest(paths.root.dest));
}
function devBrowserBuild() {
return browserify({entries: paths.browser.src, debug: true})
.transform("babelify")
.bundle()
.pipe(source(paths.dev.name))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(paths.dev.dest))
}
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)) // Add the header
.pipe(gulp.dest(paths.browser.dest));
}
function npmBuild() {
return browserify({entries: paths.npm.src}, {standalone: 'typopo'})
.transform("babelify")
.bundle()
.pipe(source(paths.npm.name))
.pipe(buffer())
.pipe(uglify())
.pipe(header(copyrightBanner)) // Add the header
.pipe(gulp.dest(paths.npm.dest));
}
function copyHtmlToDest() {
return gulp
.src(paths.dev.html)
.pipe(gulp.dest(paths.dev.dest));
}
function watchFiles() {
gulp.watch(
[
paths.npm.src,
paths.browser.src,
paths.dev.html,
"./src/**/*",
],
gulp.series(devBrowserBuild, copyHtmlToDest, browserSyncReload)
);
}
// BrowserSync
function browserSync(done) {
browsersync.init({
server: {
baseDir: 'build/',
index: 'typopo-demo.html'
},
port: 3000
});
done();
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
const watch = gulp.parallel(watchFiles, browserSync);
const build = gulp.parallel(npmBuild, browserBuild, copyHtmlToDest);
exports.watch = watch;
exports.build = build;
exports.updateTypopoJsCopyrightBanner = updateTypopoJsCopyrightBanner;
/*
* Define default task that can be called by just running `gulp` from cli
*/
exports.default = build;