-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
95 lines (86 loc) · 3.86 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
const gulp = require('gulp')
const sass = require('gulp-sass')(require('node-sass'))
const sassConfig = {
includePaths: ['node_modules'],
// functions: require('./scripts/sass-custom-functions'), // svg-icon()
importer: [
require('node-sass-tilde-importer')
],
// outputStyle: 'compressed',
}
const rename = require("gulp-rename")
const postcss = require('gulp-postcss')
const cssBeautify = require('gulp-cssbeautify')
const extractCssVarsToAllFormats = require('./scripts/gulp-extract-css-vars-to-all-formats');
const blueprintName = 'blueprint'
const dirname = (styleName)=> styleName === blueprintName ? '/base' : `/overrides/${styleName.split('.')[0]}`
/*
// RETRIEVE POSTCSS CONFIG FROM CREATE REACT APP //
// this seems like it takes a long time?
process.env.NODE_ENV = 'production'
const createReactAppWebpackConfigProduction = require('react-scripts/config/webpack.config.js')('production')
const createReactAppPostCssConfig = createReactAppWebpackConfigProduction.module.rules[1].oneOf[6].use[2].options // WOW! // needs update
const createReactAppPostCssPlugins = createReactAppPostCssConfig.plugins()
// copy-paste from ./node_modules/react-scripts/config/webpack.config.js:130 might be more consistent?
// console.log(createReactAppPostCssConfig.plugins());
*/
const scssOutput = () => (
// gulp.src('./src/styles/_blueprin*/index.scss') // for testing
gulp.src('./src/styles/_*/index.scss')
.pipe(sass(sassConfig).on('error', sass.logError))
.pipe(rename(path => {
const styleName = path.dirname.split('/')[0].substring(1);
path.basename = styleName
}))
// .pipe(postcss(createReactAppPostCssPlugins)) // make sure we are consistent with create-react-app?
)
const compileStylesheetTask = function (cb) {
scssOutput()
.pipe(postcss([
// require('postcss-combine-duplicated-selectors'), // ...could change cascade order...
// require('postcss-custom-properties'), // fallback values for --vars // this is already coming from createReactAppPostCssPlugins?
require('postcss-remove-root'), // remove :root{} with --vars
require('cssnano')({
preset: ['default', {
colormin: false, // keep hsl color formats
discardComments: {
removeAll: true,
},
}]
}),
]))
.pipe(cssBeautify())
.pipe(rename(path => {
path.dirname = dirname(path.basename)
path.basename = path.basename === blueprintName ? 'blueprint' : 'override';
}))
.pipe(gulp.dest('./'))
.pipe(rename(path => { console.log(`>> Saved ${path.dirname}/${path.basename}${path.extname}`); }))
cb();
}
const compileVarsTask = function (cb) {
scssOutput()
.pipe(postcss([
require('cssnano'), // not sure we need this
require('postcss-combine-duplicated-selectors') // combine :root{}
]))
.pipe(cssBeautify())
.pipe(extractCssVarsToAllFormats()) // build variable files
.pipe(rename(path => {
if (path.basename.includes('.')) { // fix multiple extensions, ie .cjs.js
path.extname = path.basename.substring(path.basename.indexOf('.')) + path.extname
path.basename = path.basename.split('.')[0]
}
path.dirname = dirname(path.basename)
if (path.extname === '.css') {
path.basename = path.basename === blueprintName ? 'blueprint-tokens' : 'override-tokens';
} else {
path.basename = path.basename === blueprintName ? 'tokens' : 'custom-tokens';
}
}))
.pipe(gulp.dest('./'))
cb();
}
exports.styles = compileStylesheetTask
exports.vars = compileVarsTask
exports.default = gulp.series(compileStylesheetTask, compileVarsTask)