3434 Required modules
3535 ========================================================================== */
3636var gulp = require ( 'gulp' ) ,
37- less = require ( 'gulp-less' ) ,
38- sourcemaps = require ( 'gulp-sourcemaps' ) ,
39- cssmin = require ( 'gulp-cssmin' ) ,
40- livereload = require ( 'gulp-livereload' ) ,
41- gulpif = require ( 'gulp-if' ) ,
42- colors = require ( 'colors' ) ,
43- clean = require ( 'gulp-clean' ) ,
44- exec = require ( 'child_process' ) . exec ;
37+ less = require ( 'gulp-less' ) ,
38+ sourcemaps = require ( 'gulp-sourcemaps' ) ,
39+ cssmin = require ( 'gulp-cssmin' ) ,
40+ livereload = require ( 'gulp-livereload' ) ,
41+ gulpif = require ( 'gulp-if' ) ,
42+ colors = require ( 'colors' ) ,
43+ clean = require ( 'gulp-clean' ) ,
44+ exec = require ( 'child_process' ) . exec ;
4545
4646
4747
@@ -54,7 +54,7 @@ var gulp = require('gulp'),
5454
5555
5656var themesConfig = require ( './dev/tools/grunt/configs/themes' ) ,
57- lessConfig = require ( './dev/tools/grunt/configs/less' ) . options ;
57+ lessConfig = require ( './dev/tools/grunt/configs/less' ) . options ;
5858
5959
6060/* ==========================================================================
@@ -63,16 +63,14 @@ var themesConfig = require('./dev/tools/grunt/configs/themes'),
6363
6464// Get all arguments
6565var devArguments = [ ] ;
66- for ( i = 3 ; i <= process . argv . length - 1 ; i ++ ) {
67-
68- if ( ! process . argv [ i ] ) {
69- return false ;
70- }
71-
72- else {
73- var argument = process . argv [ i ] . toString ( ) . replace ( '--' , '' ) ;
74- devArguments . push ( argument ) ;
75- }
66+ for ( i = 3 ; i <= process . argv . length - 1 ; i ++ ) {
67+
68+ if ( ! process . argv [ i ] ) {
69+ return false ;
70+ } else {
71+ var argument = process . argv [ i ] . toString ( ) . replace ( '--' , '' ) ;
72+ devArguments . push ( argument ) ;
73+ }
7674}
7775
7876// Get theme name from Array of arguments
@@ -89,26 +87,26 @@ var lessFiles = [];
8987 * Get all themes, create paths for less files and push them to the Array.
9088 */
9189if ( ! themeName ) {
92- for ( var i in themesConfig ) {
93- // Create path
94- var path = './pub/static/' + themesConfig [ i ] . area + '/' + themesConfig [ i ] . name + '/' + themesConfig [ i ] . locale + '/' ;
95-
96- // Push names of less files to the Array
97- for ( var j in themesConfig [ i ] . files ) {
98- lessFiles . push ( path + themesConfig [ i ] . files [ j ] + '.' + themesConfig [ i ] . dsl ) ;
99- }
100- }
90+ for ( var i in themesConfig ) {
91+ // Create path
92+ var path = './pub/static/' + themesConfig [ i ] . area + '/' + themesConfig [ i ] . name + '/' + themesConfig [ i ] . locale + '/' ;
93+
94+ // Push names of less files to the Array
95+ for ( var j in themesConfig [ i ] . files ) {
96+ lessFiles . push ( path + themesConfig [ i ] . files [ j ] + '.' + themesConfig [ i ] . dsl ) ;
97+ }
98+ }
10199}
102100
103101// Get certain theme, create paths for less files and push them to the Array.
104102else {
105- // Create path
106- var path = './pub/static/' + themesConfig [ themeName ] . area + '/' + themesConfig [ themeName ] . name + '/' + themesConfig [ themeName ] . locale + '/' ;
103+ // Create path
104+ var path = './pub/static/' + themesConfig [ themeName ] . area + '/' + themesConfig [ themeName ] . name + '/' + themesConfig [ themeName ] . locale + '/' ;
107105
108- // Push names of less files to the Array
109- for ( var i in themesConfig [ themeName ] . files ) {
110- lessFiles . push ( path + themesConfig [ themeName ] . files [ i ] + '.' + themesConfig [ themeName ] . dsl )
111- }
106+ // Push names of less files to the Array
107+ for ( var i in themesConfig [ themeName ] . files ) {
108+ lessFiles . push ( path + themesConfig [ themeName ] . files [ i ] + '.' + themesConfig [ themeName ] . dsl )
109+ }
112110}
113111
114112/* ==========================================================================
@@ -120,109 +118,103 @@ gulp.task('default', ['less']);
120118
121119// Less task
122120gulp . task ( 'less' , function ( ) {
123- // Console info
124- console . log ( '\x1b[32m' , '====================================' , '\x1b[0m' ) ;
125- console . log ( 'Running \x1b[36mLess\x1b[0m compilation for \x1b[36m' + lessFiles . length + ' files:\x1b[0m' ) ;
121+ // Console info
122+ console . log ( '\x1b[32m' , '====================================' , '\x1b[0m' ) ;
123+ console . log ( 'Running \x1b[36mLess\x1b[0m compilation for \x1b[36m' + lessFiles . length + ' files:\x1b[0m' ) ;
126124
127- for ( var i in lessFiles ) {
128- console . log ( '\x1b[32m' , lessFiles [ i ] , '\x1b[0m' ) ;
129- }
125+ for ( var i in lessFiles ) {
126+ console . log ( '\x1b[32m' , lessFiles [ i ] , '\x1b[0m' ) ;
127+ }
130128
131- // Get Array with files
132- return gulp . src ( lessFiles )
129+ // Get Array with files
130+ return gulp . src ( lessFiles )
133131
134- // Source map
135- . pipe ( gulpif ( sourceMapArg >= 0 , sourcemaps . init ( ) ) )
132+ // Source map
133+ . pipe ( gulpif ( sourceMapArg >= 0 , sourcemaps . init ( ) ) )
136134
137- // Less compilation
138- . pipe ( less ( ) . on ( 'error' , function ( err ) {
139- console . log ( err ) ;
140- } ) )
135+ // Less compilation
136+ . pipe ( less ( ) . on ( 'error' , function ( err ) {
137+ console . log ( err ) ;
138+ } ) )
141139
142- // Minify css
143- . pipe ( gulpif ( minCssArg >= 0 , cssmin ( ) ) )
140+ // Minify css
141+ . pipe ( gulpif ( minCssArg >= 0 , cssmin ( ) ) )
144142
145- . pipe ( gulpif ( sourceMapArg >= 0 , sourcemaps . write ( '.' ) ) )
143+ . pipe ( gulpif ( sourceMapArg >= 0 , sourcemaps . write ( '.' ) ) )
146144
147- // Destination folder
148- . pipe ( gulp . dest ( path + 'css/' ) )
145+ // Destination folder
146+ . pipe ( gulp . dest ( path + 'css/' ) )
149147
150- // Live reload
151- . pipe ( gulpif ( liveReload >= 0 , livereload ( ) ) ) ;
148+ // Live reload
149+ . pipe ( gulpif ( liveReload >= 0 , livereload ( ) ) ) ;
152150} ) ;
153151
154152// Watcher task
155153gulp . task ( 'watch' , function ( ) {
156- console . log ( '\x1b[32m' , '====================================' , '\x1b[0m' ) ;
157- console . log ( ' Watching:\x1b[32m' , themesConfig [ themeName ] . area + '/' + themesConfig [ themeName ] . name , '\x1b[0m' ) ;
154+ console . log ( '\x1b[32m' , '====================================' , '\x1b[0m' ) ;
155+ console . log ( ' Watching:\x1b[32m' , themesConfig [ themeName ] . area + '/' + themesConfig [ themeName ] . name , '\x1b[0m' ) ;
158156
159- if ( liveReload > 0 ) {
160- console . log ( ' LiveReload:\x1b[32m' , ' enabled' , '\x1b[0m' ) ;
161- livereload . listen ( ) ;
162- }
157+ if ( liveReload > 0 ) {
158+ console . log ( ' LiveReload:\x1b[32m' , ' enabled' , '\x1b[0m' ) ;
159+ livereload . listen ( ) ;
160+ }
163161
164- console . log ( '\x1b[32m' , '====================================' , '\x1b[0m' ) ;
162+ console . log ( '\x1b[32m' , '====================================' , '\x1b[0m' ) ;
165163
166- gulp . watch ( [ path + '**/*.less' ] , [ 'less' ] ) ;
164+ gulp . watch ( [ path + '**/*.less' ] , [ 'less' ] ) ;
167165} ) ;
168166
169167// Exec task
170- gulp . task ( 'exec' , function ( cb ) {
171-
172- if ( themeName ) {
173- exec ( 'php bin/magento dev:source-theme:deploy --locale="' + themesConfig [ themeName ] . locale + '" --area="' + themesConfig [ themeName ] . area + '" --theme="' + themesConfig [ themeName ] . name + '"' , function ( err , stdout , stderr ) {
174- console . log ( stdout ) ;
175- console . log ( stderr ) ;
176- cb ( err ) ;
177- } ) ;
178- }
179-
180- else {
181- console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
182- }
168+ gulp . task ( 'exec' , function ( cb ) {
169+
170+ if ( themeName ) {
171+ exec ( 'php bin/magento dev:source-theme:deploy --locale="' + themesConfig [ themeName ] . locale + '" --area="' + themesConfig [ themeName ] . area + '" --theme="' + themesConfig [ themeName ] . name + '"' , function ( err , stdout , stderr ) {
172+ console . log ( stdout ) ;
173+ console . log ( stderr ) ;
174+ cb ( err ) ;
175+ } ) ;
176+ } else {
177+ console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
178+ }
183179} ) ;
184180
185181// Static content deploy task
186- gulp . task ( 'deploy' , function ( cb ) {
187- if ( themeName ) {
188- exec ( 'php bin/magento setup:static-content:deploy ' + themesConfig [ themeName ] . locale + '' , function ( err , stdout , stderr ) {
189- console . log ( stdout ) ;
190- console . log ( stderr ) ;
191- cb ( err ) ;
192- } ) ;
193- }
194-
195- else {
196- console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
197- }
182+ gulp . task ( 'deploy' , function ( cb ) {
183+ if ( themeName ) {
184+ exec ( 'php bin/magento setup:static-content:deploy ' + themesConfig [ themeName ] . locale + '' , function ( err , stdout , stderr ) {
185+ console . log ( stdout ) ;
186+ console . log ( stderr ) ;
187+ cb ( err ) ;
188+ } ) ;
189+ } else {
190+ console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
191+ }
198192} ) ;
199193
200194// Cache flush task
201- gulp . task ( 'cache-flush' , function ( cb ) {
202- exec ( 'php bin/magento cache:flush' , function ( err , stdout , stderr ) {
203- console . log ( stdout ) ;
204- console . log ( stderr ) ;
205- cb ( err ) ;
206- } ) ;
195+ gulp . task ( 'cache-flush' , function ( cb ) {
196+ exec ( 'php bin/magento cache:flush' , function ( err , stdout , stderr ) {
197+ console . log ( stdout ) ;
198+ console . log ( stderr ) ;
199+ cb ( err ) ;
200+ } ) ;
207201} ) ;
208202
209203// Clean static files cache
210- gulp . task ( 'clean' , function ( cb ) {
211- if ( themeName ) {
204+ gulp . task ( 'clean' , function ( cb ) {
205+ if ( themeName ) {
212206 var folders = [
213- 'var/cache' ,
214- 'var/view_preprocessed' ,
215- 'pub/static/' + themesConfig [ themeName ] . area + '/' + themesConfig [ themeName ] . name + '/'
207+ 'var/cache' ,
208+ 'var/view_preprocessed' ,
209+ 'pub/static/' + themesConfig [ themeName ] . area + '/' + themesConfig [ themeName ] . name + '/'
216210 ] ;
217211
218212 for ( var i = 0 ; i < folders . length ; i ++ ) {
219- console . log ( 'Removing: ' + folders [ i ] ) ;
220- gulp . src ( folders [ i ] , { read : false } )
221- . pipe ( clean ( ) ) ;
222- }
223- }
224-
225- else {
226- console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
227- }
228- } ) ;
213+ console . log ( 'Removing: ' + folders [ i ] ) ;
214+ gulp . src ( folders [ i ] , { read : false } )
215+ . pipe ( clean ( ) ) ;
216+ }
217+ } else {
218+ console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
219+ }
220+ } ) ;
0 commit comments