-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
188 lines (165 loc) · 5.37 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
181
182
183
184
185
186
187
188
// Define requirements
var importOnce = require('node-sass-import-once'),
gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
browserSync = require('browser-sync').create(),
// gulp-load-plugins will report "undefined" error unless you load gulp-sass manually.
sass = require('gulp-sass'),
rename = require('gulp-rename'),
path = require('path'),
imagemin = require('gulp-imagemin'),
autoprefixer = require('gulp-autoprefixer'),
handlebars = require('gulp-compile-handlebars'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
webpack = require('webpack-stream'),
svg2png = require('gulp-svg2png'),
sassGlob = require('gulp-sass-glob');
// Add later
//del = require('del'),
//kss = require('kss');
// Options
var paths = {};
var rootPath = {};
var options = {};
rootPath = {
theme : __dirname + '/',
protoSrc : __dirname + '/build/src/',
protoDist : __dirname + '/build/dist/',
styleGuide : __dirname + '/build/styleguide/'
}
paths = {
proto: {
imagesSrc: rootPath.protoSrc + 'img',
sassSrc: rootPath.protoSrc + 'sass',
jsSrc: rootPath.protoSrc + 'js',
pagesSrc: rootPath.protoSrc,
imagesDist: rootPath.protoDist + 'img',
cssDist: rootPath.protoDist + 'css',
jsDist: rootPath.protoDist + 'js',
pagesDist: rootPath.protoDist
},
theme: {
images: rootPath.theme + 'images',
sass: rootPath.theme + 'sass',
css: rootPath.theme + 'css',
js: rootPath.theme + 'js',
uikit: rootPath.theme + 'ui-kit'
}
}
options = {
autoprefixer: {
browsers: ['last 2 versions', 'ie 7-10', 'iOS >= 4']
},
imagemin: {
optimizationLevel: 3,
progressive: true,
interlaced: true
},
handlebars: {
batch : [paths.proto.pagesSrc + 'partials']
},
sass: {
importer: importOnce,
errLogToConsole: true,
sourcemap: true
},
webpack: {
output: {
filename: 'ui-kit.js'
},
}
}
// #########################
// High-level tasks
// #########################
gulp.task('default', ['build']);
gulp.task('build', ['build:proto','build:theme']);
gulp.task('build:proto', ['html', 'ui-kit.styles:proto', 'ui-kit.js:proto', 'ui-kit.images:proto']);
gulp.task('build:theme', ['ui-kit.styles:theme', 'ui-kit.js:theme', 'ui-kit.images:theme']);
// #########################
// Prototype only tasks
// #########################
gulp.task('html', function () {
return gulp.src(paths.proto.pagesSrc + '*.hbs')
.pipe(handlebars({}, options.handlebars))
.pipe(rename({
extname: '.html'
}))
.pipe(gulp.dest(paths.proto.pagesDist))
.pipe(browserSync.reload({stream: true}));
});
// Spin up a server and live reload anytime a file changes
gulp.task("watch", function() {
browserSync.init({
server: {
baseDir: paths.proto.pagesDist
}
});
gulp.watch(paths.proto.imagesSrc, ['ui-kit.images:proto']);
gulp.watch(paths.proto.sassSrc + '/**/*.scss', ['ui-kit.styles:proto']);
gulp.watch(paths.proto.jsSrc + '/**/*.js', ['ui-kit.js:proto']);
gulp.watch(paths.proto.pagesSrc + '**/*.hbs', ['html']);
gulp.watch(paths.proto.pagesDist + '*.html').on('change', browserSync.reload);
});
// #########################
// UI Kit tasks
// #########################
// Sass/CSS
gulp.task('ui-kit.styles', ['ui-kit.styles:proto', 'ui-kit.styles:theme']);
gulp.task('ui-kit.styles:proto', function() {
return gulp.src(paths.proto.sassSrc + '/ui-kit.scss')
.pipe(sass(options.sass).on('error', sass.logError))
.pipe($.autoprefixer(options.autoprefixer))
.pipe(gulp.dest(paths.proto.cssDist))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('ui-kit.styles:theme', function() {
return gulp.src(paths.theme.sass + '/ui-kit.scss')
.pipe(sassGlob())
.pipe(sass(options.sass).on('error', sass.logError))
.pipe($.autoprefixer(options.autoprefixer))
.pipe(gulp.dest(paths.theme.css));
});
// Still to add compilation and copy of IE6,7,8 SCSS
// JS
gulp.task('ui-kit.js', ['ui-kit.js:proto','ui-kit.js:theme']);
gulp.task('ui-kit.js:proto', function () {
return gulp.src(paths.theme.uikit + '/assets/js/ui-kit.js')
.pipe(webpack(options.webpack))
//.pipe(uglify())
//.pipe(rename({
// suffix: '.min'
//}))
.pipe(gulp.dest(paths.proto.jsDist));
});
gulp.task('ui-kit.js:theme', function () {
return gulp.src(paths.theme.uikit + '/assets/js/ui-kit.js')
.pipe(webpack(options.webpack))
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.theme.js));
});
// Images
gulp.task('ui-kit.images', ['ui-kit.images:proto','ui-kit.images:theme']);
gulp.task('ui-kit.images:proto', function () {
return gulp.src(paths.theme.uikit + '/assets/img/**/*')
// SUB-THEME - add inclusion of theme images
.pipe(imagemin())
.pipe(gulp.dest(paths.proto.imagesDist));
});
gulp.task('ui-kit.images:theme', function () {
return gulp.src(paths.theme.uikit + '/assets/img/**/*')
// SUB-THEME - add inclusion of theme images
.pipe(imagemin())
.pipe(gulp.dest(paths.theme.images));
});
// Copy the UI kit from mode_modules to workable locations
var DIR_NPM = path.join(__dirname, 'node_modules');
// Copy UI kit to selected locations
gulp.task('ui-kit.install', function() {
return gulp.src(path.join(DIR_NPM, 'gov-au-ui-kit/**/*'))
.pipe(gulp.dest(paths.theme.uikit));
});