forked from swisnl/jQuery-contextMenu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
184 lines (164 loc) · 5.4 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 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 () {
return gulp.src(scripts.src).
pipe(plugins.jshint('src/.jshintrc')).
pipe(plugins.jshint.reporter('default'));
});
gulp.task('jscs', function () {
return gulp.src(scripts.src).
pipe(plugins.jscs()).
pipe(plugins.jscs.reporter());
});
gulp.task('js', ['jshint', 'jscs', 'jslibs'], function () {
return gulp.src(scripts.src).
pipe(plugins.sourcemaps.init()).
pipe(plugins.replace(replacement.regexp, replacement.filter)).
pipe(gulp.dest(scripts.dest)).
pipe(plugins.rename(scripts.min)).
pipe(plugins.uglify({
preserveComments: 'some'
})).
pipe(plugins.sourcemaps.write('.')).
pipe(gulp.dest(scripts.dest));
});
gulp.task('jslibs', function (){
return gulp.src(scripts.libs).
pipe(plugins.rename({prefix: 'jquery.ui.'})).
pipe(gulp.dest('src')).
pipe(gulp.dest('dist')).
pipe(plugins.rename({extname: '.min.js'})).
pipe(gulp.dest('dist')).
pipe(plugins.uglify({
preserveComments: 'some'
})).
pipe(plugins.sourcemaps.write('.')).
pipe(gulp.dest(scripts.dest));
});
gulp.task('css', function () {
return gulp.src(styles.src).
pipe(sass()).
pipe(plugins.csslint('src/.csslintrc')).
pipe(plugins.csslint.formatter()).
pipe(plugins.sourcemaps.init()).
pipe(plugins.replace(replacement.regexp, replacement.filter)).
pipe(plugins.autoprefixer({
browsers: [
'Android 2.3',
'Android >= 4',
'Chrome >= 20',
'Firefox >= 24',
'Explorer >= 8',
'iOS >= 6',
'Opera >= 12',
'Safari >= 6'
]
})).
pipe(plugins.csscomb('src/.csscomb.json')).
pipe(plugins.rename(styles.name)).
pipe(gulp.dest(styles.dest)).
pipe(plugins.rename(styles.min)).
pipe(plugins.cleanCss()).
pipe(plugins.sourcemaps.write('.')).
pipe(gulp.dest(styles.dest));
});
gulp.task('build-icons', function () {
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');
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('watch', ['js', 'css'], function () {
gulp.watch(scripts.src, ['js']);
gulp.watch(styles.all, ['css']);
});
gulp.task('build', ['build-icons', 'css', 'js', 'integration-test-paths']);
gulp.task('default', ['watch']);