-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditorStyles.js
92 lines (79 loc) · 2 KB
/
editorStyles.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
'use strict';
/**
* External dependencies
*/
import { src, dest } from 'gulp';
import postcssPresetEnv from 'postcss-preset-env';
import cssnano from 'cssnano';
import stylelint from 'stylelint';
import reporter from 'postcss-reporter';
import calc from 'postcss-calc';
import { pipeline } from 'mississippi';
import postcss from 'gulp-postcss';
import gulpIf from 'gulp-if';
import tabify from 'gulp-tabify';
import rename from 'gulp-rename';
/**
* Internal dependencies
*/
import {
paths,
isProd,
} from './constants';
import { getMainConfig } from './utils';
import {
getPostCSSAtImport,
getPresetEnv,
sniffStyle,
} from './styles';
import {
sourcemaps,
startStringReplace,
} from './helper/base';
import { server } from './browserSync';
/** The user configuration. */
const config = getMainConfig( isProd );
/**
* Lints editor styles.
*
* @return {Object} Pumpify pipeline object.
*/
export const lintEditorStyle = () => {
const postcssPlugins = [
stylelint(),
postcssPresetEnv( getPresetEnv( true, false ) ),
calc( { preserve: false } ),
cssnano(),
];
// Skip minifying files during development and debug is enabled.
if ( config.dev.debug.styles && ! isProd ) {
postcssPlugins.pop();
}
// Report messages from other postcss plugins.
postcssPlugins.push(
reporter( { clearReportedMessages: true } )
);
// Single stream with postCSS events.
return pipeline.obj( [
postcss( [ getPostCSSAtImport ] ),
postcss( postcssPlugins ),
gulpIf( config.dev.debug.styles, tabify( 2, true ) ),
rename( { suffix: '.min' } ),
server.stream( { match: '**/*.css' } ),
] );
};
/**
* Lints CSS via PostCSS and CSSNext.
*
* Includes Autoprefixer by default.
*
* @return {NodeJS.ReadWriteStream} NodeJS stream.
*/
const editorStyles = () => {
return src( paths.styles.editorSrc, { sourcemaps } )
.pipe( sniffStyle( true ) )
.pipe( gulpIf( isProd, startStringReplace() ) )
.pipe( lintEditorStyle() )
.pipe( dest( paths.styles.editorDest, { sourcemaps } ) );
};
export default editorStyles;