@@ -15,110 +15,81 @@ const merge = require('merge-stream')
15
15
const rename = require ( 'gulp-rename' )
16
16
17
17
const configPaths = require ( '../../config/paths.js' )
18
- const { destination, isDist, isPublic } = require ( '../task-arguments.js' )
18
+ const { destination, isDist, isPackage } = require ( '../task-arguments.js' )
19
19
20
20
// Compile CSS and JS task --------------
21
21
// --------------------------------------
22
22
23
- // Set the destination
24
- const destinationPath = function ( ) {
25
- // Public & Dist directories not namespaced with `govuk`
26
- if ( isDist || isPublic ) {
27
- return destination
28
- } else {
29
- return `${ destination } /govuk/`
30
- }
31
- }
32
-
33
- const errorHandler = function ( error ) {
34
- // Log the error to the console
35
- console . error ( error . message )
36
-
37
- // Ensure the task we're running exits with an error code
38
- this . once ( 'finish' , ( ) => process . exit ( 1 ) )
39
- this . emit ( 'end' )
40
- }
41
-
42
- function compileStyles ( ) {
43
- const compileStylesheet = isDist ? configPaths . src + 'all.scss' : configPaths . app + 'assets/scss/app.scss'
44
-
45
- return gulp . src ( compileStylesheet )
46
- . pipe ( plumber ( errorHandler ) )
47
- . pipe ( sass ( ) )
48
- . pipe ( gulpif ( isDist ,
49
- rename ( {
50
- basename : 'govuk-frontend' ,
51
- extname : '.min.css'
52
- } )
53
- ) )
54
- . pipe ( postcss ( ) )
55
- . pipe ( gulp . dest ( `${ destination } /` ) )
23
+ // Determine destination namespace
24
+ function destinationPath ( ) {
25
+ return isPackage ? `${ destination } /govuk` : destination
56
26
}
57
27
58
- function compileOldIE ( ) {
59
- const compileOldIeStylesheet = isDist ? configPaths . src + 'all-ie8.scss' : configPaths . app + 'assets/scss/app-ie8.scss'
60
-
61
- return gulp . src ( compileOldIeStylesheet )
62
- . pipe ( plumber ( errorHandler ) )
63
- . pipe ( sass ( ) )
64
- . pipe ( gulpif ( isDist ,
65
- rename ( {
66
- basename : 'govuk-frontend-ie8' ,
67
- extname : '.min.css'
68
- } )
69
- ) )
70
- . pipe ( postcss ( ) )
71
- . pipe ( gulp . dest ( `${ destination } /` ) )
72
- }
28
+ gulp . task ( 'scss:compile' , function ( ) {
29
+ /**
30
+ * Release distribution
31
+ */
32
+ if ( isDist ) {
33
+ return merge (
34
+ compileStyles (
35
+ gulp . src ( `${ configPaths . src } all.scss` )
36
+ . pipe ( rename ( {
37
+ basename : 'govuk-frontend' ,
38
+ extname : '.min.css'
39
+ } ) ) ) ,
40
+
41
+ compileStyles (
42
+ gulp . src ( `${ configPaths . src } all-ie8.scss` )
43
+ . pipe ( rename ( {
44
+ basename : 'govuk-frontend-ie8' ,
45
+ extname : '.min.css'
46
+ } ) ) )
47
+ )
48
+ . pipe ( gulp . dest ( destination ) )
49
+ }
73
50
74
- function compileLegacy ( ) {
75
- return gulp . src ( path . join ( configPaths . app , 'assets/scss/app-legacy.scss' ) )
76
- . pipe ( plumber ( errorHandler ) )
77
- . pipe ( sass ( {
78
- includePaths : [ 'node_modules/govuk_frontend_toolkit/stylesheets' , 'node_modules' ]
79
- } ) )
80
- . pipe ( postcss ( ) )
81
- . pipe ( gulp . dest ( `${ destination } /` ) )
82
- }
51
+ /**
52
+ * Review application
53
+ */
54
+ return merge (
55
+ compileStyles (
56
+ gulp . src ( `${ configPaths . app } assets/scss/app?(-ie8).scss` ) ) ,
57
+
58
+ compileStyles (
59
+ gulp . src ( `${ configPaths . app } assets/scss/app-legacy?(-ie8).scss` ) , {
60
+ includePaths : [ 'node_modules/govuk_frontend_toolkit/stylesheets' , 'node_modules' ]
61
+ } ) ,
62
+
63
+ compileStyles (
64
+ gulp . src ( `${ configPaths . fullPageExamples } **/styles.scss` )
65
+ . pipe ( rename ( ( path ) => {
66
+ path . basename = path . dirname
67
+ path . dirname = 'full-page-examples'
68
+ } ) ) )
69
+ )
70
+ . pipe ( gulp . dest ( destinationPath ( ) ) )
71
+ } )
83
72
84
- function compileLegacyIE ( ) {
85
- return gulp . src ( path . join ( configPaths . app , 'assets/scss/app-legacy-ie8.scss' ) )
86
- . pipe ( plumber ( errorHandler ) )
87
- . pipe ( sass ( {
88
- includePaths : [ 'node_modules/govuk_frontend_toolkit/stylesheets' , 'node_modules' ]
73
+ /**
74
+ * Compile Sass to CSS
75
+ *
76
+ * @param {NodeJS.ReadWriteStream } stream - Input file stream
77
+ * @param {import('node-sass').Options } [options] - Sass options
78
+ * @returns {NodeJS.ReadWriteStream } Output file stream
79
+ */
80
+ function compileStyles ( stream , options = { } ) {
81
+ return stream
82
+ . pipe ( plumber ( ( error ) => {
83
+ console . error ( error . message )
84
+
85
+ // Ensure the task we're running exits with an error code
86
+ this . once ( 'finish' , ( ) => process . exit ( 1 ) )
87
+ this . emit ( 'end' )
89
88
} ) )
89
+ . pipe ( sass ( options ) )
90
90
. pipe ( postcss ( ) )
91
- . pipe ( gulp . dest ( `${ destination } /` ) )
92
- }
93
-
94
- function compileFullPageStyles ( ) {
95
- const compileFullPageExampleStylesheets = configPaths . fullPageExamples + '**/styles.scss'
96
-
97
- return gulp . src ( compileFullPageExampleStylesheets )
98
- . pipe ( plumber ( errorHandler ) )
99
- . pipe ( sass ( ) )
100
- . pipe ( rename ( function ( location ) {
101
- location . basename = location . dirname
102
- location . dirname = ''
103
- } ) )
104
- . pipe ( gulp . dest ( `${ destination } /full-page-examples/` ) )
105
91
}
106
92
107
- gulp . task ( 'scss:compile' , function ( done ) {
108
- // Default tasks if compiling for dist
109
- const tasks = [ compileStyles ( ) , compileOldIE ( ) ]
110
-
111
- if ( isPublic || ! isDist ) {
112
- tasks . push ( compileLegacy ( ) , compileLegacyIE ( ) )
113
-
114
- if ( isPublic ) {
115
- tasks . push ( compileFullPageStyles ( ) )
116
- }
117
- }
118
-
119
- return Promise . all ( tasks )
120
- } )
121
-
122
93
// Compile js task for preview ----------
123
94
// --------------------------------------
124
95
gulp . task ( 'js:compile' , ( ) => {
0 commit comments