forked from nolimits4web/dom7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
162 lines (149 loc) · 3.99 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const fs = require('fs');
const gulp = require('gulp');
const connect = require('gulp-connect');
const open = require('gulp-open');
const header = require('gulp-header');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const rollup = require('rollup');
const resolve = require('rollup-plugin-node-resolve');
const buble = require('rollup-plugin-buble');
const rename = require('gulp-rename');
const modifyFile = require('gulp-modify-file');
const pkg = require('./package.json');
const date = (function date() {
return {
year: new Date().getFullYear(),
month: ('January February March April May June July August September October November December').split(' ')[new Date().getMonth()],
day: new Date().getDate(),
};
}());
const banner = `
/**
* Dom7 ${pkg.version}
* ${pkg.description}
* ${pkg.homepage}
*
* Copyright ${date.year}, ${pkg.author}
* The iDangero.us
* http://www.idangero.us/
*
* Licensed under ${pkg.license}
*
* Released on: ${date.month} ${date.day}, ${date.year}
*/
`.trim();
// UMD DIST
function umd(cb) {
const env = process.env.NODE_ENV || 'development';
const output = env === 'development' ? './build' : './dist';
rollup.rollup({
input: './src/dom7.js',
plugins: [resolve(), buble()],
}).then((bundle) => {
return bundle.write({
strict: true,
file: `${output}/dom7.js`,
format: 'umd',
name: 'Dom7',
sourcemap: env === 'development',
sourcemapFile: `${output}/dom7.js.map`,
banner,
});
}).then(() => {
if (env === 'development') {
if (cb) cb();
return;
}
gulp.src('./dist/dom7.js')
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(header(banner))
.pipe(rename('dom7.min.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'))
.on('end', () => {
if (cb) cb();
});
});
}
// ES MODULE DIST
function es(cb) {
const env = process.env.NODE_ENV || 'development';
const output = env === 'development' ? './build' : './dist';
let cbs = 0;
rollup.rollup({
input: './src/dom7.js',
external: ['ssr-window'],
}).then((bundle) => {
return bundle.write({
strict: true,
file: `${output}/dom7.module.js`,
format: 'es',
name: 'Dom7',
sourcemap: env === 'development',
sourcemapFile: `${output}/dom7.module.js.map`,
banner,
});
}).then(() => {
cbs += 1;
if (cb && cbs === 2) cb();
});
rollup.rollup({
input: './src/dom7.modular.js',
external: ['ssr-window'],
}).then((bundle) => {
return bundle.write({
strict: true,
file: `${output}/dom7.modular.js`,
format: 'es',
name: 'Dom7',
sourcemap: env === 'development',
sourcemapFile: `${output}/dom7.modular.js.map`,
banner,
});
}).then(() => {
cbs += 1;
if (cb && cbs === 2) cb();
});
}
gulp.task('build', (cb) => {
let cbs = 0;
const env = process.env.NODE_ENV || 'development';
const output = env === 'development' ? './build' : './dist';
fs.copyFileSync('./src/dom7.d.ts', `${output}/dom7.d.ts`);
umd(() => {
cbs += 1;
if (cbs === 2) cb();
});
es(() => {
cbs += 1;
if (cbs === 2) cb();
});
});
gulp.task('demo', (cb) => {
const env = process.env.NODE_ENV || 'development';
gulp.src('./demo/index.html')
.pipe(modifyFile((content) => {
if (env === 'development') {
return content
.replace('../dist/dom7.min.js', '../build/dom7.js');
}
return content
.replace('../build/dom7.js', '../dist/dom7.min.js');
}))
.pipe(gulp.dest('./demo/'))
.on('end', () => {
if (cb) cb();
});
});
gulp.task('watch', () => {
gulp.watch('./src/*.js', gulp.series(['build']));
});
gulp.task('connect', () => connect.server({
root: ['./'],
livereload: true,
port: '3000',
}));
gulp.task('open', () => gulp.src('./demo/index.html').pipe(open({ uri: 'http://localhost:3000/demo/index.html' })));
gulp.task('server', gulp.parallel(['watch', 'connect', 'open']));