forked from Alex-D/Trumbowyg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
174 lines (147 loc) · 5.77 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
var gulp = require('gulp'),
del = require('del'),
vinylPaths = require('vinyl-paths'),
$ = require('gulp-load-plugins')(),
spritesmith = require('gulp.spritesmith');
var paths = {
scripts: ['src/trumbowyg.js'],
langs: ['src/langs/**.js', '!src/langs/en.js'],
plugins: ['plugins/*/**.js', '!plugins/*/Gulpfile.js'],
sprites: {
'icons-white': 'src/ui/images/icons-white/**.png',
'icons-white-2x': 'src/ui/images/icons-white-2x/**.png',
'icons-black': 'src/ui/images/icons-black/**.png',
'icons-black-2x': 'src/ui/images/icons-black-2x/**.png'
},
mainStyle: 'src/ui/sass/trumbowyg.scss',
styles: {
sass: 'src/ui/sass'
}
};
var pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
' * <%= description %>',
' * ------------------------',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' * @author <%= pkg.author.name %>',
' * Twitter : @AlexandreDemode',
' * Website : <%= pkg.author.url.replace("http://", "") %>',
' */',
'\n'].join('\n');
var bannerLight = ['/** <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
' - <%= pkg.homepage.replace("http://", "") %>',
' - License <%= pkg.license %>',
' - Author : <%= pkg.author.name %>',
' / <%= pkg.author.url.replace("http://", "") %>',
' */',
'\n'].join('');
gulp.task('clean', function(){
return gulp.src(['dist/*', 'src/ui/sass/_sprite*.scss'])
.pipe(vinylPaths(del));
});
gulp.task('test', ['test-scripts', 'test-langs', 'test-plugins']);
gulp.task('test-scripts', function(){
return gulp.src(paths.scripts)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('test-langs', function(){
return gulp.src(paths.langs)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('test-plugins', function(){
return gulp.src(paths.plugins)
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});
gulp.task('scripts', ['test-scripts'], function(){
return gulp.src(paths.scripts)
.pipe($.header(banner, { pkg: pkg, description: 'Trumbowyg core file' }))
.pipe($.newer('dist/trumbowyg.js'))
.pipe($.concat('trumbowyg.js', { newLine: '\r\n\r\n' }))
.pipe(gulp.dest('dist/'))
.pipe($.size({ title: 'trumbowyg.js' }))
.pipe($.rename({ suffix: '.min' }))
.pipe($.uglify())
.pipe($.header(bannerLight, { pkg: pkg }))
.pipe(gulp.dest('dist/'))
.pipe($.size({ title: 'trumbowyg.min.js' }))
});
gulp.task('langs', ['test-langs'], function(){
return gulp.src(paths.langs)
.pipe($.rename({ suffix: '.min' }))
.pipe($.uglify({
preserveComments: 'all'
}))
.pipe(gulp.dest('dist/langs/'))
});
gulp.task('plugins', ['test-plugins'], function(){
return gulp.src(paths.plugins)
.pipe(gulp.dest('dist/plugins/'))
.pipe($.rename({ suffix: '.min' }))
.pipe($.uglify())
.pipe(gulp.dest('dist/plugins/'))
});
gulp.task('sprites', function(){
return makeSprite('white') && makeSprite('white', '-2x') && makeSprite('black') && makeSprite('black', '-2x');
});
function makeSprite(color, resolution){
var suffix = '-' + color + (resolution ? resolution : '');
var sprite = gulp.src(paths.sprites['icons' + suffix])
.pipe(spritesmith({
imgName: 'icons' + suffix + '.png',
cssName: '_sprite' + suffix + '.scss',
cssTemplate: function(params){
var output = '', e;
for(var i in params.items){
e = params.items[i];
output += '$' + e.name + suffix + ': ' + e.px.offset_x + ' ' + e.px.offset_y + ';\n';
}
if(params.items.length > 0){
output += '\n\n';
output += '$sprite-height' + suffix + ': ' + params.items[0].px.total_height + ';\n';
output += '$sprite-width' + suffix + ': ' + params.items[0].px.total_width + ';\n';
output += '$icons' + suffix + ': "./images/icons' + suffix + '.png";';
}
return output;
}
}));
sprite.img.pipe(gulp.dest('dist/ui/images/'));
sprite.css.pipe(gulp.dest(paths.styles.sass));
return sprite.css;
}
gulp.task('styles', ['sprites'], function(){
return gulp.src(paths.mainStyle)
.pipe($.sass({
sass: paths.styles.sass
}))
.pipe($.autoprefixer(['last 1 version', '> 1%', 'ff >= 20', 'ie >= 8', 'opera >= 12', 'Android >= 2.2'], { cascade: true }))
.pipe($.header(banner, { pkg: pkg, description: 'Default stylesheet for Trumbowyg editor' }))
.pipe(gulp.dest('dist/ui/'))
.pipe($.size({ title: 'trumbowyg.css' }))
.pipe($.rename({ suffix: '.min' }))
.pipe($.minifyCss())
.pipe($.header(bannerLight, { pkg: pkg }))
.pipe(gulp.dest('dist/ui/'))
.pipe($.size({ title: 'trumbowyg.min.css' }));
});
gulp.task('sass-dist', ['styles'], function(){
return gulp.src('src/ui/sass/**/*.scss')
.pipe($.header(banner, { pkg: pkg, description: 'Default stylesheet for Trumbowyg editor' }))
.pipe(gulp.dest('dist/ui/sass'))
});
gulp.task('watch', function(){
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(paths.langs, ['langs']);
gulp.watch(paths.plugins, ['plugins']);
gulp.watch(paths.mainStyle, ['styles']);
gulp.watch(['dist/**', 'dist/*/**'], function(file){
$.livereload.changed(file);
});
$.livereload.listen();
});
gulp.task('build', ['scripts', 'langs', 'plugins', 'sass-dist']);
gulp.task('default', ['build', 'watch']);