forked from nolimits4web/template7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
138 lines (128 loc) · 3.26 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
const fs = require('fs');
const gulp = require('gulp');
const connect = require('gulp-connect');
const open = require('gulp-open');
const rename = require('gulp-rename');
const header = require('gulp-header');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const rollup = require('rollup');
const buble = require('rollup-plugin-buble');
const pkg = require('./package.json');
const paths = {
root: './',
build: 'build/',
dist: 'dist/',
demo: 'demo/',
source: 'src/',
};
const date = {
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 t7 = {
filename: 'template7',
pkg,
banner: [
'/**',
` * Template7 ${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}`,
' */',
''].join('\n'),
};
// Build
gulp.task('build', (cb) => {
fs.copyFileSync('./src/template7.d.ts', './build/template7.d.ts');
rollup.rollup({
input: './src/template7.js',
plugins: [buble()],
}).then((bundle) => { // eslint-disable-line
return bundle.write({
strict: true,
file: './build/template7.js',
format: 'umd',
name: 'Template7',
sourcemap: true,
sourcemapFile: './build/template7.js.map',
});
}).then(() => {
cb();
});
});
function umd(cb) {
rollup.rollup({
input: './src/template7.js',
plugins: [buble()],
}).then((bundle) => { // eslint-disable-line
return bundle.write({
strict: true,
file: './dist/template7.js',
format: 'umd',
name: 'Template7',
sourcemap: true,
sourcemapFile: './dist/template7.js.map',
banner: t7.banner,
});
}).then(() => {
gulp.src('./dist/template7.js')
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(header(t7.banner))
.pipe(rename('template7.min.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/'))
.on('end', () => {
if (cb) cb();
});
});
}
function es(cb) {
rollup.rollup({
input: './src/template7.js',
}).then((bundle) => { // eslint-disable-line
return bundle.write({
strict: true,
file: './dist/template7.esm.js',
format: 'es',
name: 'Template7',
banner: t7.banner,
});
}).then(() => {
cb();
});
}
// Dist
gulp.task('dist', (cb) => {
let cbs = 0;
fs.copyFileSync('./src/template7.d.ts', './dist/template7.d.ts');
umd(() => {
cbs += 1;
if (cbs === 2) cb();
});
es(() => {
cbs += 1;
if (cbs === 2) cb();
});
});
gulp.task('watch', () => {
gulp.watch('./src/*.js', gulp.series(['build']));
});
gulp.task('connect', () => connect.server({
root: [paths.root],
livereload: true,
port: '3000',
}));
gulp.task('open', () => gulp.src(`${paths.demo}index.html`).pipe(open({ uri: `http://localhost:3000/${paths.demo}index.html` })));
gulp.task('server', gulp.parallel(['watch', 'connect', 'open']));
gulp.task('default', gulp.series(['server']));