forked from liferay/clay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
262 lines (217 loc) · 5.4 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
var async = require('async');
var del = require('del');
var filter = require('gulp-filter');
var fs = require('fs-extra');
var gulp = require('gulp-help')(require('gulp'));
var path = require('path');
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var sass = require('node-sass');
var _ = require('./tasks/lib/lodash_utils');
var config = {
SRC_GLOB: 'src/**/*'
};
var bootstrapPath = path.dirname(require.resolve('bootstrap/package.json'));
var tasks = require('require-dir')('./tasks');
_.invoke(tasks, 'call', tasks, gulp, plugins, _, config);
gulp.task('default', ['compile']);
gulp.task('build', function(cb) {
runSequence(
'build:svg',
'build:svg:scss-icons',
'build:metalsmith',
'build:rtl',
'build:sassdoc',
'get:file-size',
function(err) {
gulp.emit('build:finished', err);
cb(err);
}
);
});
gulp.task(
'compile',
function(cb) {
runSequence(
'compile:clean',
'compile:files',
'compile:bootstrap:js',
'compile:bootstrap:scss',
'compile:popper',
'build:svg:scss-icons',
'compile:prep-scss',
'compile:css',
'compile:clean-scss',
'compile:svg',
'copy:licenses',
function(err) {
cb(err);
}
);
}
);
gulp.task(
'compile:bootstrap:js',
function() {
var src = [
path.join(bootstrapPath, 'dist/js/bootstrap.js'),
path.join(bootstrapPath, 'dist/js/bootstrap.js.map')
];
return gulp.src(src)
.pipe(gulp.dest('./src/js'));
}
);
gulp.task(
'compile:bootstrap:scss',
function() {
return gulp.src(path.join(bootstrapPath, 'scss/**/*'))
.pipe(gulp.dest('./src/scss/bootstrap'));
}
);
gulp.task(
'compile:files',
function(cb) {
var assetFilter = filter(['**/*.js', '!**/bootstrap.js', '!**/popper.js', '!**/svg4everybody.js'], {
restore: true
});
var src = [
'src/fonts/**/*',
'src/images/icons/*',
'src/js/{,bootstrap/}*.js',
'src/js/{,bootstrap/}*.js.map'
];
return gulp.src(src, {
base: './src'
})
.pipe(assetFilter)
.pipe(assetFilter.restore)
.pipe(gulp.dest('./lib'));
}
);
gulp.task(
'compile:clean',
function() {
del.sync(['./lib']);
}
);
gulp.task(
'compile:clean-scss',
function() {
del.sync([
'./lib/css/**/*.scss',
'./lib/css/atlas/',
'./lib/css/bootstrap/',
'./lib/css/components/',
'./lib/css/functions/',
'./lib/css/mixins/',
'./lib/css/site/',
'./lib/css/variables/'
]);
}
);
gulp.task(
'compile:css',
function(cb) {
fs.ensureDirSync(path.resolve('./lib/css'));
var filesNames = ['atlas.scss', 'bootstrap.scss', 'base.scss'];
async.each(filesNames, function(fileName, cb) {
var fileDestName = path.basename(fileName, '.scss') + '.css';
var destName = path.resolve('./lib/css/' + fileDestName);
sass.render({
file: path.resolve('./lib/css/' + fileName),
outFile: './' + fileDestName,
sourceMap: true,
sourceMapContents: true,
sourceMapRoot: '../../'
}, function(err, results) {
fs.writeFileSync(destName, results.css);
fs.writeFileSync(destName + '.map', results.map);
cb(err);
});
}, function(err) {
cb(err);
});
}
);
gulp.task(
'compile:popper',
function() {
var popperPath = path.dirname(require.resolve('popper.js/package.json'));
var src = [
path.join(popperPath, 'dist/umd/popper.js'),
path.join(popperPath, 'dist/umd/popper.js.map')
];
return gulp.src(src)
.pipe(gulp.dest('./src/js'));
}
);
gulp.task(
'compile:prep-scss',
function() {
var entryFilter = filter(['atlas.scss', 'base.scss'], {
restore: true
});
return gulp.src('src/scss/**/*')
.pipe(entryFilter)
.pipe(entryFilter.restore)
.pipe(gulp.dest('./lib/css'));
}
);
gulp.task(
'compile:svg',
function() {
return require('./tasks/lib/svgstore')(gulp, plugins, _, {
dest: './lib/images/icons',
});
}
);
gulp.task('copy:licenses', function() {
var newLicenseDir = 'LICENSES';
var originalLicenseDir = path.join('..', '..', 'LICENSES');
return gulp.src([
path.join(originalLicenseDir, 'BSD-3-Clause.txt'),
path.join(originalLicenseDir, 'LicenseRef-MIT-Bootstrap.txt'),
path.join(originalLicenseDir, 'MIT.txt')
]).pipe(
gulp.dest(newLicenseDir)
);
});
gulp.task('version', function() {
var VERSION = JSON.parse(
fs.readFileSync(path.join('.', 'package.json'))
).version;
var scssDir = path.join('.', 'src', 'scss');
var clayFiles = [
path.join(scssDir, '_license-text.scss'),
];
function changeVersion(filePath, regex = /\*\s+Clay\s(.+)\n/g, value = `* Clay ${VERSION}\n`) {
fs.readFile(filePath, 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(regex, value);
fs.writeFile(filePath, result, 'utf8', function(err) {
if (err) return console.log(err);
});
});
}
fs.readdirSync(scssDir).forEach(function(file) {
var filePath = path.join(scssDir, file);
if (clayFiles.includes(filePath)) {
changeVersion(filePath);
}
});
var libIconsSvg = path.join('.', 'lib', 'images', 'icons', 'icons.svg');
var regex = /<\?xml version="1.0" encoding="UTF-8"\?(.+-->|>)/gs;
var license = `<?xml version="1.0" encoding="UTF-8"?>
<!--
* Clay ${VERSION}
*
* SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
* SPDX-FileCopyrightText: © 2020 Contributors to the project Clay <https://github.com/liferay/clay/graphs/contributor
*
* SPDX-License-Identifier: BSD-3-Clause
-->`;
changeVersion(libIconsSvg, regex, license);
});
gulp.task('serve', ['serve:start', 'watch']);