-
Notifications
You must be signed in to change notification settings - Fork 70
/
gulpfile.js
135 lines (117 loc) · 3.7 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
(function() {
'use strict';
// utils
var gulp = require('gulp');
var argv = require('yargs').argv;
var cache = require('gulp-cached');
var print = require('gulp-print');
var rename = require('gulp-rename');
var gulpif = require('gulp-if');
var gutil = require('gulp-util');
var watch = require('gulp-watch');
var webpack = require('webpack');
// js
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
// html
var htmlhint = require('gulp-htmlhint');
// json
var jsonlint = require('gulp-jsonlint');
// scss
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
// Files will be output here
var staticBuildDestination = 'orchestra/static/dist/';
var files = {
scss: [
'orchestra/static/orchestra/timing/timer/timer.scss',
'orchestra/static/orchestra/common/css/orchestra.scss',
],
all_scss: [],
jslint: [
'./gulpfile.js', // Lint ourselves!
'!**/common/js/lib/**',
'!**/dist2/**'
],
jsonlint: [
'!node_modules/**',
'**/*.json',
],
htmllint: [],
};
var installedApps = [
'orchestra',
];
for (var i = 0; i < installedApps.length; i++) {
var appName = installedApps[i];
files.all_scss.push(appName + '/static/**/*.scss');
// jslint
files.jslint.push(appName + '/static/**/*.js');
files.jslint.push('!' + appName + '/static/dist/**/*.js');
files.jslint.push('!' + appName + '/static/**/*.min.js');
files.jslint.push('!' + appName + '/static/**/*.es6.js');
// htmllint
files.htmllint.push(appName + '/static/**/*.html');
}
gulp.task('scss', function() {
return gulp.src(files.scss, {
base: './'
})
.pipe(gulpif(!argv.production, sourcemaps.init()))
.pipe(sass())
.pipe(gulpif(!argv.production, sourcemaps.write()))
.pipe(rename(function(path) {
// move to a css dir if it is in a scss dir
var dirname = path.dirname;
dirname = dirname.replace('/scss', '/css');
var chopPath = '/static/';
dirname = dirname.substring(dirname.indexOf(chopPath) + chopPath.length);
path.dirname = dirname;
return path;
}))
.pipe(gulp.dest(staticBuildDestination));
});
gulp.task('jslint', function() {
return gulp.src(files.jslint)
.pipe(cache('jslint'))
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(gulpif(argv.production, jshint.reporter('fail')))
.pipe(jscs())
.pipe(jscs.reporter());
});
gulp.task('jsonlint', function() {
return gulp.src(files.jsonlint)
.pipe(cache('jsonlint'))
.pipe(jsonlint())
.pipe(jsonlint.reporter())
.pipe(gulpif(argv.production, jsonlint.failOnError()));
});
gulp.task('htmllint', function() {
return gulp.src(files.htmllint)
.pipe(cache('htmllint'))
.pipe(htmlhint('.htmlhintrc'))
.pipe(htmlhint.reporter())
.pipe(gulpif(argv.production, htmlhint.failReporter()));
});
// TODO(joshblum): add css and scss linting
gulp.task('lint', ['jslint', 'jsonlint', 'htmllint']);
gulp.task('watch', function() {
var all_lint_files = [].concat.apply([], [files.jslint, files.jsonlint]);
gulp.watch(all_lint_files, ['lint']);
gulp.watch(files.all_scss, ['scss']);
gulp.watch(all_lint_files, ['webpack']);
});
gulp.task('webpack', function(callback) {
webpack(require('./webpack.config.js'), function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
gutil.log('[webpack]', stats.toString());
callback();
});
});
gulp.task('default', ['build', 'watch']);
gulp.task('build', ['lint', 'scss']);
})();