forked from blitze/phpBB-ext-sitemaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (104 loc) · 3.01 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
var gulp = require('gulp'),
argv = require('yargs').argv,
plugins = require("gulp-load-plugins")({
pattern: ['gulp-*', 'gulp.*', 'main-bower-files', 'jshint-stylish', 'del'],
scope: ['devDependencies'],
replaceString: /^gulp(-|\.)/,
camelize: true,
lazy: true
}),
supportedBrowsers = ["last 1 version", "> 1%", "ie 8"],
sassOptions = {
errLogToConsole: true,
outputStyle: 'expanded'
},
sourceMapsDir = './',
theme = argv.theme || 'all',
paths = {
'dev': {
'scripts': 'develop/',
'vendor': 'bower_components/'
},
'prod': {
'scripts': 'styles/' + theme + '/theme/assets/',
'vendor': 'styles/' + theme + '/theme/vendor/'
}
};
// Bower
gulp.task('bower', function() {
return plugins.bower()
.pipe(gulp.dest(paths.dev.vendor));
});
// JS
gulp.task('js', function() {
return gulp.src(paths.dev.scripts + '**/*.js')
.pipe(plugins.changed(paths.prod.scripts))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.jscs())
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter(plugins.jshintStylish))
.pipe(plugins.rename({ suffix: '.min' }))
.pipe(plugins.uglify())
.pipe(plugins.sourcemaps.write(sourceMapsDir))
.pipe(gulp.dest(paths.prod.scripts));
});
// SASS
gulp.task('sass', function() {
gulp.src(paths.dev.scripts + '**/*.scss')
.pipe(plugins.changed(paths.prod.scripts))
.pipe(plugins.sourcemaps.init())
.pipe(plugins.sass(sassOptions).on('error', plugins.sass.logError))
.pipe(plugins.csscomb())
.pipe(plugins.csslint({
'adjoining-classes': false,
'box-sizing': false,
'order-alphabetical': false,
'regex-selectors': false,
'unqualified-attributes': false
}))
.pipe(plugins.csslint.formatter())
.pipe(plugins.autoprefixer(supportedBrowsers))
.pipe(plugins.rename({ suffix: '.min' }))
.pipe(plugins.cleanCss())
.pipe(plugins.sourcemaps.write(sourceMapsDir))
.pipe(gulp.dest(paths.prod.scripts));
});
// Vendor
gulp.task('vendor', function() {
var mainFiles = plugins.mainBowerFiles();
if (!mainFiles.length) {
return;
}
var jsFilter = plugins.filter(['**/*.js', '!**/*.min.js'], {restore: true});
var cssFilter = plugins.filter(['**/*.css', '!**/*.min.css'], {restore: true});
return gulp.src(mainFiles, {base: paths.dev.vendor })
.pipe(plugins.changed(paths.prod.vendor))
.pipe(jsFilter)
.pipe(gulp.dest(paths.prod.vendor))
.pipe(jsFilter.restore)
.pipe(cssFilter)
.pipe(plugins.cleanCss())
.pipe(gulp.dest(paths.prod.vendor))
.pipe(cssFilter.restore)
.pipe(gulp.dest(paths.prod.vendor));
});
// Clean up
gulp.task('clean', function() {
return plugins.del([
paths.prod.scripts + '**',
paths.prod.vendor + '**'
]);
});
gulp.task('watch', function() {
// Watch js files
gulp.watch(paths.dev.scripts + '**/*.js', ['js']);
// Watch sass files
gulp.watch(paths.dev.scripts + '**/*.scss', ['sass']);
// Watch Vendor files
gulp.watch(paths.dev.vendor + '**', ['vendor']);
// Watch bower.json
gulp.watch('./bower.json', ['bower']);
});
gulp.task('build', ['clean'], function() {
gulp.start('js', 'sass', 'vendor');
});