forked from andresgalante/patternfly-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
151 lines (138 loc) · 4.47 KB
/
gulpfile.js
File metadata and controls
151 lines (138 loc) · 4.47 KB
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
const path = require('path');
const { src, dest, series, watch } = require('gulp');
const rename = require('gulp-rename');
const sass = require('node-sass');
const through2 = require('through2');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const sourcemaps = require('gulp-sourcemaps');
const iconfont = require('gulp-iconfont');
const iconfontCss = require('gulp-iconfont-css');
const fs = require('fs-extra');
const generateIcons = require('./src/icons/generateIcons.js');
const convertForIE = require('./build/npm-scripts/ie-convert-all.js');
const stylelint = require('stylelint');
const pficonFontName = 'pficon';
const config = {
sourceFiles: [
'./src/patternfly/patternfly*.scss',
'./src/patternfly/{components,layouts,patterns,utilities}/**/*.scss',
'!./src/patternfly/**/_all.scss'
]
};
function pfIconFont() {
return src(['./src/icons/PfIcons/*.svg'])
.pipe(
iconfontCss({
fontName: pficonFontName,
path: 'scss',
targetPath: 'pficon.scss',
fontPath: './',
cssClass: 'pf-icon'
})
)
.pipe(
iconfont({
fontName: pficonFontName,
formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'],
timestamp: Math.round(Date.now() / 1000)
})
)
.pipe(dest('./src/patternfly/assets/pficon/'));
}
function copyFA() {
return src(require.resolve('@fortawesome/fontawesome/styles.css'))
.pipe(rename('fontawesome.css'))
.pipe(dest('./dist/assets/icons'));
}
function minifyCSS() {
return src('./dist/patternfly.css')
.pipe(rename('patternfly.min.css'))
.pipe(sourcemaps.init())
.pipe(postcss([cssnano()]))
.pipe(sourcemaps.write('.'))
.pipe(dest('./dist'));
}
function compileSASS() {
return src(config.sourceFiles)
.pipe(
through2.obj((chunk, _, cb2) => {
const scss = chunk.contents.toString();
try {
const css = sass.renderSync({
// Pass filename for import resolution. Contents are not compiled.
file: chunk.history[0],
// This hack is to not include sass-utilities/placeholders.scss CSS more than once
// in our production patternfly.css BUT still be able to compile individual SCSS files.
// As soon as node-sass is updated to a libsass version that supports @use rule, we should
// change `// @import "../../sass-utilities/all";` to `@use "../../sass-utilities/all";`
data: scss.replace('// @import "../../sass-utilities/all";', '@import "../../sass-utilities/all";')
});
chunk.contents = Buffer.from(css.css);
stylelint
.lint({
files: chunk.history[0],
formatter: 'string'
})
.then(data => {
if (data.errored) {
console.error(data.output);
}
});
} catch (error) {
console.error(`Problem in ${path.relative(__dirname, chunk.history[0])}: ${error}`);
}
chunk.history.push(chunk.history[0].replace(/.scss$/, '.css'));
cb2(null, chunk);
})
)
.pipe(dest('./dist'));
}
function watchSASS() {
module.exports.build();
// TODO: track files and only rebuild what's changed. Requires tracking `css.stats.includedFiles`.
watch(
['./src/patternfly/patternfly*.scss', './src/patternfly/{components,layouts,patterns,utilities}/**/*.scss'],
{},
compileSASS
);
}
function copySource() {
return Promise.all([
// Copy source files
src(config.sourceFiles).pipe(dest('./dist')),
src('./src/patternfly/_*.scss').pipe(dest('./dist')),
src('./src/patternfly/sass-utilities/*').pipe(dest('./dist/sass-utilities')),
// Assets
src('./static/assets/images/**/*').pipe(dest('./dist/assets/images/')),
src('./src/patternfly/assets/**/*').pipe(dest('./dist/assets/')),
// Icons
src('./src/icons/definitions/*').pipe(dest('./dist/icons/')),
src('./src/icons/PfIcons/*').pipe(dest('./dist/icons/PfIcons/')),
// For NPM
src('./README.md').pipe(dest('./dist')),
src('./package.json').pipe(dest('./dist'))
]);
}
function clean(cb) {
['./dist', './src/icons/PfIcons'].forEach(dir => fs.removeSync(dir));
cb();
}
function pfIcons() {
return generateIcons();
}
function buildIE() {
return convertForIE();
}
module.exports = {
build: series(clean, compileSASS, minifyCSS, pfIcons, copyFA, copySource),
compileSASS,
minifyCSS,
buildIE,
watchSASS,
clean,
pfIconFont,
pfIcons,
copyFA,
copySource
};