-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
194 lines (172 loc) · 6.32 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
var path = require('path');
var name = path.basename(__dirname);
var basePaths = { // Paths for source and bundled parts of app
src: 'src/', dest: 'assets/', npm: 'node_modules/'
},
gulp = require( 'gulp' ), // Require plugins
es = require( 'event-stream' ),
zip = require('gulp-zip');
gutil = require( 'gulp-util' ),
prettier = require('gulp-prettier'),
bourbon = require( 'node-bourbon' ),
path = require( 'relative-path' ),
runSequence = require( 'run-sequence' ),
eol = require( 'gulp-line-ending-corrector' ),
plugins = require( 'gulp-load-plugins' )({ // Plugins - load gulp-* plugins without direct calls
pattern: [ 'gulp-*', 'gulp.*' ], replaceString: /\bgulp[\-.]/
}),
concat = require('gulp-concat'),
jsImport = require('gulp-js-import'),
// Env - call gulp --prod to go into production mode
sassStyle = 'expanded', // SASS syntax
sourceMap = false, // Wheter to build source maps
isProduction = false, // Mode flag
changeEvent = function( evt ) { // Log
gutil.log( 'File', gutil.colors.cyan( evt.path.replace( new RegExp( '/.*(?=/' + basePaths.src + ')/' ), '' ) ), 'was', gutil.colors.magenta( evt.type ) );
};
if ( true === gutil.env.prod ) {
isProduction = true;
sassStyle = 'compressed';
sourceMap = false;
}
const run = require('gulp-run');
var jsImport = require('gulp-js-import');
//js
gulp.task( 'js', function() {
var vendorFiles = [
//basePaths.npm + 'imagesloaded/imagesloaded.pkgd.js'
], appFiles = [ basePaths.src + 'js/*' ]; //our own JS files
return gulp.src( vendorFiles.concat( appFiles ) ) //join them
.pipe( plugins.filter( '*.js' ) )//select only .js ones
.pipe( plugins.concat( 'scripts.js' ) )//combine them into bundle.js
.pipe(jsImport({
hideConsole: true,
importStack: false
}))
.pipe( plugins.size() ) //print size for log
.on( 'error', console.log ) //log
.pipe( gulp.dest( basePaths.dest + 'js' ) ); //write results into file
});
// CSS
gulp.task( 'css', function() {
// Paths for mdl and bourbon
var paths = require( 'node-bourbon' ).includePaths;
paths.push( basePaths.npm + 'modularscale-sass/stylesheets' );
var vendorFiles = gulp.src('.', {allowEmpty: true}),//gulp.src( [] ), // Components
appFiles = gulp.src( basePaths.src + 'sass/styles.scss' ) // Main file with @import-s
.pipe( plugins.sass( {
outputStyle: sassStyle, // SASS syntax
indentType: 'tab',
indentWidth: 1,
includePaths: paths // Add bourbon
} ).on( 'error', plugins.sass.logError ) ) // SASS own error log
.pipe( plugins.autoprefixer( { // Aautoprefixer
browsers: [ 'last 4 versions' ], cascade: false
} ) )
.on( 'error', console.log ); // Log
return es.concat( appFiles, vendorFiles ) // Combine vendor CSS files and our files after-SASS
.pipe( plugins.concat( 'style.css' ) ) // Combine into file
.pipe( isProduction ? plugins.cssmin() : gutil.noop() ) // Minification on production
.pipe( plugins.size() ) // Display size
.pipe( gulp.dest( basePaths.dest + 'css' ) ) // Write file
.on( 'error', console.log ); // Log
});
// Editor CSS
gulp.task( 'css-editor', function() {
// Paths for mdl and bourbon
var paths = require( 'node-bourbon' ).includePaths;
paths.push( basePaths.npm + 'modularscale-sass/stylesheets' );
var vendorFiles = gulp.src('.', {allowEmpty: true}),
appFiles = gulp.src( basePaths.src + 'sass/style-editor.scss' )
.pipe( plugins.sass( {
outputStyle: sassStyle, // SASS syntax
indentType: 'tab',
indentWidth: 1,
includePaths: paths // Add bourbon
} ).on( 'error', plugins.sass.logError ) ) // SASS own error log
.pipe( plugins.autoprefixer( { // Aautoprefixer
browsers: [ 'last 4 versions' ], cascade: false
} ) )
.on( 'error', console.log );
return es.concat( appFiles, vendorFiles ) // Combine vendor CSS files and our files after-SASS
.pipe( plugins.concat( 'style-editor.css' ) ) // Combine into file
.pipe( isProduction ? plugins.cssmin() : gutil.noop() ) // Minification on production
.pipe( plugins.size() ) // Display size
.pipe( gulp.dest( basePaths.dest + 'css' ) ) // Write file
.on( 'error', console.log ); // Log
});
// Admin CSS
gulp.task( 'css-admin', function() {
// Paths for mdl and bourbon
var paths = require( 'node-bourbon' ).includePaths;
paths.push( basePaths.npm + 'modularscale-sass/stylesheets' );
var vendorFiles = gulp.src('.', {allowEmpty: true}),//gulp.src( [] ), // Components
appFiles = gulp.src( basePaths.src + 'sass/admin.scss' ) // Main file with @import-s
.pipe( plugins.sass( {
outputStyle: sassStyle, // SASS syntax
indentType: 'tab',
indentWidth: 1,
includePaths: paths // Add bourbon
} ).on( 'error', plugins.sass.logError ) ) // SASS own error log
.pipe( plugins.autoprefixer( { // Aautoprefixer
browsers: [ 'last 4 versions' ], cascade: false
} ) )
.on( 'error', console.log ); // Log
return es.concat( appFiles, vendorFiles ) // Combine vendor CSS files and our files after-SASS
.pipe( plugins.concat( 'admin.css' ) ) // Combine into file
.pipe( isProduction ? plugins.cssmin() : gutil.noop() ) // Minification on production
.pipe( plugins.size() ) // Display size
.pipe( gulp.dest( basePaths.dest + 'css' ) ) // Write file
.on( 'error', console.log ); // Log
});
// Builds
gulp.task( 'full-build',
gulp.series( 'css', 'css-editor', 'css-admin', 'js' )
);
// Watchers
gulp.task( 'watch', () => {
gulp.watch(
[ basePaths.src + 'js/*.js', basePaths.src + 'js/**/*.js' ],
gulp.series( [ 'js' ] )
);
gulp.watch(
[ basePaths.src + 'sass/*.scss', basePaths.src + 'sass/**/*.scss' ],
gulp.series([ 'css', 'css-editor', 'css-admin' ] )
);
});
// check encoding + line-endings
gulp.task('eol', function() {
gulp.src(['./src/**' ])
.pipe(eol({verbose: true, eolc: 'LF', encoding: 'utf8'}))
.pipe(gulp.dest('./src/'));
});
// Default
gulp.task( 'default', gulp.series( 'full-build', 'watch' ) );
// Archive
gulp.task('zip', function(){
const distFiles = [
'**',
'!src/**',
'!node_modules/**',
'!vendor/**',
'!TEMP/**',
'!.gitignore',
'!gulpfile.js',
'!LICENSE.txt',
'!backlog.txt',
'!README.md',
'!CHANGELOG.md',
'!package.json',
'!package-lock.json',
'!composer.json',
'!composer.lock',
'!phpcs.xml',
'!security.xml',
'!phpcs-result.txt',
'!phpcs-security-result.txt',
'!**.zip'
];
return gulp.src( distFiles, { base: '../' } )
.pipe( zip( name + '.zip' ) )
.pipe( gulp.dest( './' ) )
});