-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
156 lines (128 loc) · 3.98 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
changed = require('gulp-changed'),
notify = require('gulp-notify'),
clean = require('gulp-clean'),
git = require('gulp-git'),
jscs = require('gulp-jscs'),
header = require('gulp-header'),
rename = require('gulp-rename'),
browserSync = require('browser-sync');
var vars = {
devDir: 'dev/',
distDir: 'dist/',
bowerJquery: 'bower_components/jquery/dist/jquery.js',
markerClusterer: 'bower_components/google-marker-clusterer-plus/src/markerclusterer.js',
bowerNormalize: 'bower_components/normalize-scss',
pluginName: 'reppam'
}
//////////////////////////////////////////
// HEADER
//////////////////////////////////////////
var pkg = require('./package.json'),
banner = [
'/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @author <%= pkg.author %>',
' * @license <%= pkg.license %>',
' */',
'',
].join('\n');
//////////////////////////////////////////
// PUBLISHING
//////////////////////////////////////////
gulp.task('clean-live', function() {
return gulp.src(vars.distDir+'*', {read: false})
.pipe(clean());
});
gulp.task('update-index', ['clean-live'], function() {
return gulp.src([vars.devDir+'index.html'])
.pipe(gulp.dest(vars.distDir));
})
gulp.task('update-scss', ['clean-live'], function() {
return gulp.src([vars.devDir+'css/sass/_'+vars.pluginName+'.scss'])
.pipe(gulp.dest(vars.distDir+'css'));
})
gulp.task('update-js', ['clean-live'], function() {
return gulp.src([vars.devDir+'js/'+vars.pluginName+'.js'])
.pipe(gulp.dest(vars.distDir+'js'));
})
gulp.task('publish-css', ['clean-live'], function() {
return gulp.src(vars.devDir+'css/main.css')
.pipe(minifycss({keepBreaks: true}))
.pipe(gulp.dest(vars.distDir+'css'));
})
gulp.task('publish-js', ['clean-live'], function() {
return gulp.src(vars.devDir+'js/'+vars.pluginName+'.js')
.pipe(uglify())
.pipe(header(banner, {pkg: pkg}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(vars.distDir+'js'));
})
// Publish
gulp.task('publish', function() {
gulp.start('update-index', 'update-js', 'update-scss', 'publish-css', 'publish-js');
})
//////////////////////////////////////////
// WATCHING
//////////////////////////////////////////
gulp.task('browser-sync', function() {
browserSync.init(null, {
proxy: vars.pluginName+".dev"
});
});
gulp.task('main-css', function() {
return gulp.src('dev/css/sass/*.scss')
.pipe(
sass({
outputStyle: 'expanded',
/*sourceComments: 'map',*/
includePaths: [vars.bowerNormalize],
errLogToConsole: false,
onError: function(err) {
return notify().write(err);
}
})
)
.pipe(
autoprefixer(
["> 1%", "last 2 versions", "Firefox ESR", "Opera 12.1"],
{
map: true,
from: 'main.scss',
to: 'main.css'
}
)
)
.pipe(gulp.dest(vars.devDir+'css')) //Dev version has compiled SCSS but not minified
.pipe(browserSync.reload({stream:true}));
});
gulp.task('plugin-js', function() {
return gulp.src([vars.devDir+'js/'+vars.pluginName+'.js', vars.devDir+'js/styling-example.js'])
.pipe(jscs().on("error", notify.onError("JSCS: <%= error %>")))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('init-js', function() {
return gulp.src([vars.bowerJquery, vars.markerClusterer])
.pipe(gulp.dest(vars.devDir+'js'));
});
gulp.task('bs-reload', function() {
browserSync.reload();
});
// Watch
gulp.task('default', ['plugin-js', 'init-js', 'main-css', 'browser-sync'], function() {
//Watch files
gulp.watch(vars.devDir+'css/sass/**/*.scss', ['main-css']);
gulp.watch(vars.devDir+'js/'+vars.pluginName+'.js', ['plugin-js']);
gulp.watch(vars.devDir+"*.html", ['bs-reload']);
gulp.watch(vars.devDir+"*.js", ['bs-reload']);
});