forked from ericduran/drupalcores
-
Notifications
You must be signed in to change notification settings - Fork 38
/
gulpfile.js
180 lines (156 loc) · 4.89 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
/*jshint strict:false */
var gulp = require('gulp');
var usemin = require('gulp-usemin');
var minifycss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var del = require('del');
var sass = require('gulp-sass');
var bower = require('gulp-bower');
var runSequence = require('run-sequence');
var shell = require('gulp-shell');
var minifyHTML = require('gulp-minify-html');
var uncss = require('gulp-uncss');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var gulpif = require('gulp-if');
var paths = {
scripts: 'app/js/**/*.js',
images: 'app/images/**/*',
scss: 'app/scss/**/*.scss',
drupal: 'app/drupalcore'
};
// Run bower install
gulp.task('bower', function() {
return bower();
});
gulp.task('lint', function() {
return gulp.src([paths.scripts, 'gulpfile.js'])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
// Clone or update drupalcore repo
gulp.task('drupalcore', function () {
var fs = require('fs');
return gulp.src('')
.pipe(gulpif(!fs.existsSync(paths.drupal), shell(['git clone http://git.drupal.org/project/drupal.git ' + paths.drupal])))
.pipe(shell(['git remote update', 'git remote set-head origin -a', 'git checkout origin/HEAD'],{ 'ignoreErrors': true, 'cwd': './app/drupalcore'}));
});
// Build contributors page
gulp.task('buildcontributors', function () {
return gulp.src('')
.pipe(shell(['./cores.rb > ../../tmp/index.html'], { 'cwd': './app/bin'}));
});
// Build companies page
gulp.task('buildcompanies', function () {
return gulp.src('')
.pipe(shell(['./companies.rb > ../../tmp/companies.html'], { 'cwd': './app/bin'}));
});
// Build companies page
gulp.task('companyinfo', function () {
return gulp.src('')
.pipe(shell(['./companies.rb --update-all'], { 'cwd': './app/bin'}));
});
// Build countries page
gulp.task('buildcountries', function () {
return gulp.src('')
.pipe(shell(['./countries.rb > ../../tmp/countries.html'], { 'cwd': './app/bin'}));
});
// Build json data
gulp.task('buildjson', function () {
return gulp.src('')
.pipe(shell(['mkdir ../../tmp', './json.rb > ../../tmp/data.json'], { 'cwd': './app/bin'}));
});
// Populate test json data
gulp.task('testjson', function () {
return gulp.src('')
.pipe(shell(['mkdir ./tmp', 'cp ./test/data.json ./tmp/data.json'], { 'cwd': './'}));
});
// Clean dist assets
gulp.task('cleandist', function(cb) {
return del(['dist'], cb);
});
// Clean tmp assets
gulp.task('cleantmp', function(cb) {
return del(['tmp'], cb);
});
// Copy tmp to dist
gulp.task('copytmpdist', function(cb) {
return gulp.src(['./tmp/**/*'])
.pipe(gulp.dest('./dist'));
});
// Copy all javascripts
gulp.task('javascripts', function() {
return gulp.src(paths.scripts)
.pipe(gulp.dest('tmp/js'));
});
// Copy all static images
gulp.task('images', function() {
return gulp.src(paths.images)
// Pass in options to the task
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest('tmp/images'));
});
// Compile Sass
gulp.task('sass', function() {
return gulp.src(paths.scss)
.pipe(sass())
.pipe(gulp.dest('./tmp/css'));
});
// Parse the html for groups of assets and compress
gulp.task('usemin', ['sass', 'javascripts'], function () {
return gulp.src('./tmp/*.html')
.pipe(usemin({
js: [uglify()],
css: [minifycss({keepBreaks:true})]
}))
.pipe(gulp.dest('tmp/'));
});
// UNCSS
gulp.task('uncss', function() {
return gulp.src('./css/style.css')
.pipe(uncss({
html: ['./tmp/*.html']
}))
.pipe(gulp.dest('./css'));
});
// Minify HTML
gulp.task('minifyhtml', function() {
var opts = {comments:true,spare:true};
gulp.src('./tmp/*.html')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('./tmp'));
});
// The whole shebang
gulp.task('default', function(callback) {
runSequence(['cleantmp', 'bower', 'drupalcore'],
'buildjson',
['buildcontributors', 'buildcompanies', 'buildcountries', 'javascripts', 'images', 'sass'],
'usemin',
'minifyhtml',
'cleandist',
'copytmpdist',
callback);
});
// Run contributors only, because companies can take ages the first time
gulp.task('contributors', function(callback) {
runSequence(['cleantmp', 'bower', 'drupalcore'],
'buildjson',
['buildcontributors', 'javascripts', 'images', 'sass'],
'usemin',
'minifyhtml',
'cleandist',
'copytmpdist',
callback);
});
// The load test data instead of real data.
gulp.task('test', function(callback) {
runSequence(['cleantmp', 'bower', 'drupalcore'],
'testjson',
['buildcontributors', 'buildcompanies', 'buildcountries', 'javascripts', 'images', 'sass'],
'usemin',
'minifyhtml',
'cleandist',
'copytmpdist',
callback);
});