-
Notifications
You must be signed in to change notification settings - Fork 746
/
gulpfile.js
184 lines (161 loc) · 5.17 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var sass = require('gulp-sass');
var pkg = require('./package');
var pump = require('pump');
var scripts = {
name: 'jquery.contextMenu.js',
min: 'jquery.contextMenu.min.js',
all: [
'gulpfile.js',
'src/jquery.contextMenu.js',
'dist/jquery.contextMenu.js'
],
main: 'dist/jquery.contextMenu.js',
src: [
'src/jquery.contextMenu.js'
],
dest: 'dist',
libs: [
]
};
var styles = {
name: 'jquery.contextMenu.css',
min: 'jquery.contextMenu.min.css',
all: [
'src/sass/**/*.scss'
],
main: 'dist/jquery.contextMenu.css',
src: 'src/sass/jquery.contextMenu.scss',
dest: 'dist'
};
var icons = {
src: 'src/icons/*.svg',
templateFileFont: 'src/sass/icons/_variables.scss.tpl',
templateFileIconClasses: 'src/sass/icons/_icon_classes.scss.tpl',
fontOutputPath: 'dist/font',
scssOutputPath: 'src/sass/icons/'
};
var replacement = {
regexp: /@\w+/g,
filter: function (placeholder) {
switch (placeholder) {
case '@VERSION':
placeholder = pkg.version;
break;
case '@YEAR':
placeholder = (new Date()).getFullYear();
break;
case '@DATE':
placeholder = (new Date()).toISOString();
break;
}
return placeholder;
}
};
gulp.task('jshint', function (cb) {
pump([
gulp.src(scripts.src),
plugins.jshint('src/.jshintrc'),
plugins.jshint.reporter('default')
],cb);
});
gulp.task('jsdist', function (cb) {
pump([
gulp.src(scripts.src),
plugins.sourcemaps.init(),
plugins.replace(replacement.regexp, replacement.filter),
gulp.dest(scripts.dest),
plugins.rename(scripts.min),
plugins.uglify(),
plugins.sourcemaps.write('.'),
gulp.dest(scripts.dest)
], cb);
});
gulp.task('jslibs', function (cb){
pump([
gulp.src(scripts.libs),
plugins.rename({prefix: 'jquery.ui.'}),
gulp.dest('src'),
gulp.dest('dist'),
plugins.rename({extname: '.min.js'}),
gulp.dest('dist'),
plugins.uglify(),
plugins.sourcemaps.write('.'),
gulp.dest(scripts.dest)
], cb);
});
gulp.task('css', function (cb) {
return pump([
gulp.src(styles.src),
sass(),
plugins.csslint('src/.csslintrc'),
plugins.csslint.formatter(),
plugins.sourcemaps.init(),
plugins.replace(replacement.regexp, replacement.filter),
plugins.autoprefixer(),
plugins.csscomb('src/.csscomb.json'),
plugins.rename(styles.name),
gulp.dest(styles.dest),
plugins.rename(styles.min),
plugins.cleanCss(),
plugins.sourcemaps.write('.'),
gulp.dest(styles.dest)
], cb);
});
gulp.task('build-icons', function (done) {
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');
return gulp.src(icons.src)
.pipe(iconfont({
fontName: 'context-menu-icons',
fontHeight: 1024,
descent: 64,
normalize: true,
appendCodepoints: false,
startCodepoint: 0xE001,
formats: ['ttf', 'eot', 'woff', 'woff2']
}))
.on('glyphs', function (glyphs) {
var options = {
glyphs: glyphs,
className: 'context-menu-icon',
mixinName: 'context-menu-item-icon'
};
gulp.src(icons.templateFileFont)
.pipe(consolidate('lodash', options))
.pipe(plugins.rename({basename: '_variables', extname: '.scss'}))
.pipe(gulp.dest(icons.scssOutputPath));
gulp.src(icons.templateFileIconClasses)
.pipe(consolidate('lodash', options))
.pipe(plugins.rename('_icons.scss'))
.pipe(gulp.dest('src/sass')); // set path to export your sample HTML
})
.pipe(gulp.dest(icons.fontOutputPath));
});
/**
* Update paths in integration tests that are generated by the documentation
* generator so they use the local source.
*/
gulp.task('integration-test-paths', function(){
return gulp.src('test/integration/html/*.html').
pipe(plugins.replace('https\:\/\/swisnl\.github\.io\/jQuery-contextMenu\/dist\/jquery\.ui\.position\.min\.js', '\.\.\/\.\.\/\.\.\/dist\/jquery\.ui\.position\.min\.js')).
pipe(plugins.replace('https\:\/\/swisnl\.github\.io\/jQuery\-contextMenu\/dist\/', '\.\.\/\.\.\/\.\.\/src\/')).
pipe(plugins.replace('\/src\/jquery.contextMenu.css', '\/dist\/jquery.contextMenu.css')).
pipe(gulp.dest('test/integration/html/'));
});
gulp.task('js', gulp.series('jshint', 'jsdist', (done) => {
done();
}));
gulp.task('watch', gulp.parallel('js', 'css', function (done) {
gulp.watch(scripts.src,gulp.series('js'));
gulp.watch(styles.all, gulp.series('css'));
done();
}));
gulp.task('build', gulp.series('build-icons', 'css', 'js', 'integration-test-paths', (done) => {
done();
}));
gulp.task('default', gulp.series('watch', (done) => {
done();
}));