forked from yairEO/tagify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
191 lines (164 loc) · 4.82 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
185
186
187
188
189
190
191
var gulp = require('gulp'),
$ = require( "gulp-load-plugins" )({ pattern:['*', 'gulp-'] }),
pkg = require('./package.json');
var uglifyOptions = {
compress: {
sequences : true,
conditionals : true,
booleans : true,
unused : true,
if_return : true,
join_vars : true,
properties : true,
dead_code : true
},
mangle : true,
"screw-ie8" : true
};
var eslint_settings = {
rulePaths: [],
rules: {
"no-mixed-spaces-and-tabs" : [2, "smart-tabs"],
"block-spacing" : [2, "always"],
"comma-style" : [2, "last"],
"no-debugger" : [1],
"no-alert" : [1],
"indent" : [1, 4, {"SwitchCase":1}],
'strict' : 0,
'no-undef' : 1
},
ecmaFeatures : {
modules: true,
sourceType: "module"
},
"parserOptions": {
"ecmaVersion" : 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": false,
"experimentalObjectRestSpread": true
}
},
globals : [
'FB',
'ga',
'jQuery',
'$',
'_',
'd3',
'Router',
'ttip',
'Cookies',
'fastdom',
'describe',
'beforeEach',
'it',
'expect',
'assert',
'done',
'dataLayer',
'validator'
],
baseConfig: {
//parser: 'babel-eslint',
},
envs: [
'browser', 'es6'
]
};
var banner = `/**
* Tagify (v ${pkg.version})- tags input component
* By ${pkg.author.name} (2016)
* Don't sell this code. (c)
* ${pkg.homepage}
*/
`;
var jQueryPluginWrap = [`;(function($){
// just a jQuery wrapper for the vanilla version of this component
$.fn.tagify = function(settings = {}){
return this.each(function() {
var $input = $(this),
tagify;
if( $input.data("tagify") ) // don't continue if already "tagified"
return this;
settings.isJQueryPlugin = true;
tagify = new Tagify($input[0], settings);
$input.data("tagify", tagify);
});
}
`
,
`
})(jQuery);
`];
////////////////////////////////////////////////////
// Compile main app SCSS to CSS
gulp.task('scss', () => {
return gulp.src('src/*.scss')
.pipe($.cssGlobbing({
extensions: '.scss'
}))
.pipe(
$.sass().on('error', $.sass.logError)
)
// .pipe($.combineMq()) // combine media queries
.pipe($.autoprefixer({ browsers:['last 7 versions'] }) )
.pipe($.cleanCss())
.pipe(gulp.dest('./dist'))
});
gulp.task('build_js', ['lint_js'], () => {
var jsStream = gulp.src('src/tagify.js');
return jsStream
.pipe( $.babel({presets: ['env']}) )
.pipe( $.umd() )
.pipe( $.insert.prepend(banner) )
.pipe( gulp.dest('./dist/') )
});
gulp.task('build_jquery_version', () => {
return gulp.src('src/tagify.js')
.pipe($.insert.wrap(banner + jQueryPluginWrap[0], jQueryPluginWrap[1]))
.pipe( $.babel({presets: ['env']}) )
.pipe($.rename('jQuery.tagify.js'))
.pipe(gulp.dest('./dist/'))
});
gulp.task('minify', () => {
gulp.src('dist/tagify.js')
.pipe($.uglify())
.on('error', handleError)
.pipe($.rename('tagify.min.js'))
.pipe(gulp.dest('./dist/'))
return gulp.src('dist/jQuery.tagify.js')
.pipe($.uglify())
.on('error', handleError)
.pipe($.rename('jQuery.tagify.min.js'))
.pipe(gulp.dest('./dist/'))
});
function handleError(err) {
$.util.log( err.toString() );
this.emit('end');
}
/**
* lints the javscript source code using "eslint"
*/
gulp.task('lint_js', () => {
return gulp.src('src/tagify.js')
// eslint() attaches the lint output to the eslint property
// of the file object so it can be used by other modules.
.pipe($.cached('linting'))
.pipe($.eslint(eslint_settings))
// $.eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe($.eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe($.eslint.failAfterError())
.on('error', $.beepbeep)
});
gulp.task('watch', () => {
//gulp.watch('./images/sprite/**/*.png', ['sprite']);
gulp.watch('./src/*.scss', ['scss']);
gulp.watch('./src/tagify.js').on('change', ()=>{ $.runSequence('build_js', 'build_jquery_version', 'minify') });
});
gulp.task('default', ( done ) => {
$.runSequence(['build_js', 'scss'], 'build_jquery_version', 'minify', 'watch', done);
});