This repository was archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
191 lines (165 loc) · 5.5 KB
/
gulpfile.js
File metadata and controls
191 lines (165 loc) · 5.5 KB
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
'use strict';
/* jshint node: true*/
// Project configuration
var project = 'positor', // Project name, used for build zip.
version = '1.5.0', // Version for stylesheets and scripts
build = './temp/buildtheme/', // Files that you want to package into a zip go here
buildInclude = [
'**/*.php',
'**/*.html',
'**/*.css',
'**/*.js',
'**/*.svg',
'**/*.ttf',
'**/*.otf',
'**/*.eot',
'**/*.woff',
'**/*.woff2',
'**/*.pot',
'**/*.mo',
'**/*.po',
'**/*.txt',
// Include specific files and folders
'screenshot.png',
// Exclude files and folders
'!temp/**/*',
'!node_modules/**/*',
'!assets/bower_components/**/*',
'!style.css.map',
'!assets/js/custom/*',
'!assets/css/patrials/*',
'!gulpfile.js'
];
var gulp = require( 'gulp' ),
rimraf = require( 'rimraf' ),
concat = require( 'gulp-concat' ),
sass = require( 'gulp-sass' ),
rename = require( 'gulp-rename' ),
plumber = require( 'gulp-plumber' ),
sourcemaps = require( 'gulp-sourcemaps' ),
clone = require( 'gulp-clone' ),
cssnano = require( 'gulp-cssnano' ),
merge = require( 'gulp-merge' ),
zip = require( 'gulp-zip' ),
wpPot = require( 'gulp-wp-pot' ),
gulpSequence = require( 'gulp-sequence' );
var paths = {
js: 'js/**/*.js',
minJs: 'js/**/*.min.js',
jsSrc: 'js/source/',
jsDest: 'assets/js/',
css: 'css/**/*.css',
cssDest: 'assets/stylesheets/',
minCss: 'css/**/*.min.css',
libSrc: 'node_modules/',
libDest: 'assets/libs/',
bootstrapSassSrc: 'node_modules/bootstrap/scss/',
temp: './temp/'
};
gulp.task( 'clean:js', function( cb ) {
rimraf( paths.jsDest, cb );
});
gulp.task( 'clean:css', function( cb ) {
rimraf( paths.cssDest, cb );
} );
gulp.task( 'clean:lib', function( cb ) {
rimraf( paths.libDest, cb );
} );
gulp.task( 'clean:temp', function( cb ) {
rimraf( paths.temp, cb );
} );
gulp.task( 'clean', ['clean:js', 'clean:css', 'clean:lib', 'clean:temp'] );
// Copy libs to wwwroot/lib folder
gulp.task( 'copy:lib', function( ) {
gulp.src( [
'moment/min/*.js',
'font-awesome/fonts'
], {
cwd: paths.libSrc + '/**'
} )
.pipe( gulp.dest( paths.libDest ) );
} );
// Command gulp sass - Compiles SCSS files in CSS
gulp.task( 'sass', function( ) {
gulp.src( './sass/*.scss' )
.pipe( plumber( ) )
.pipe( sass( ) )
.pipe( gulp.dest( paths.cssDest ) );
} );
// Command gulp make:css - Make both minified and unminified css from scss.
gulp.task( 'make:css', function( ) {
var source = gulp.src( './sass/*.scss' )
.pipe( plumber( ) )
.pipe( sourcemaps.init( {
loadMaps: true
} ) )
.pipe( sass( ) );
var pipe1 = source.pipe( clone( ) )
.pipe( sourcemaps.write( undefined, {
sourceRoot: null
} ) )
.pipe( gulp.dest( paths.cssDest ) );
var pipe2 = source.pipe( clone( ) )
.pipe( cssnano( ) )
.pipe( rename( {
suffix: '.min'
} ) )
.pipe( gulp.dest( paths.cssDest ) );
return merge( pipe1, pipe2 );
} );
// Command gulp make:js - Uglifies and concat all JS files into one
gulp.task( 'make:js', function( ) {
gulp.src( [
paths.libSrc + 'jquery/dist/jquery.min.js',
paths.libSrc + 'popper.js/dist/popper.min.js',
paths.libSrc + 'bootstrap/dist/js/bootstrap.min.js',
paths.libSrc + 'moment/min/moment.min.js',
paths.libSrc + 'moment/locale/nb.js',
paths.jsSrc + 'skip-link-focus-fix.js',
paths.jsSrc + 'comment-reply.min.js',
paths.jsSrc + 'wp-embed.min.js'
] )
.pipe( concat( 'positor.min.js' ) )
.pipe( gulp.dest( paths.jsDest ) );
gulp.src( [
paths.libSrc + 'jquery/dist/jquery.js',
paths.libSrc + 'popper.js/dist/umd/popper.js',
paths.libSrc + 'bootstrap/dist/js/bootstrap.js',
paths.libSrc + 'moment/moment.js',
paths.libSrc + 'moment/locale/nb.js',
paths.jsSrc + 'skip-link-focus-fix.js',
paths.jsSrc + 'comment-reply.min.js',
paths.jsSrc + 'wp-embed.min.js'
] )
.pipe( concat( 'positor.js' ) )
.pipe( gulp.dest( paths.jsDest ) );
} );
// Command gulp build:pot - Make .pot file for translation
gulp.task( 'build:pot', function( ) {
return gulp.src( '**/*.php' )
.pipe( wpPot( {
domain: 'positor'
} ) )
.pipe( gulp.dest( 'languages/positor.pot' ) );
} );
/**
* Build task that moves essential theme files for production-ready sites
*
* build:theme copies all the files in buildInclude to build folder - check variable values at the top
*/
gulp.task( 'build:theme', function( ) {
return gulp.src( buildInclude )
.pipe( gulp.dest( build ) );
} );
/**
* Zipping build directory for distribution
*
* Taking the build folder, which has been cleaned, containing optimized files and zipping it up to send out as an installable theme
*/
gulp.task( 'build:zip', function( ) {
return gulp.src( build + '/**/' )
.pipe( zip( project + 'v' + version + '.zip' ) )
.pipe( gulp.dest( paths.temp ) );
} );
gulp.task( 'build', gulpSequence( 'clean:temp', 'make:css', 'build:pot', 'build:theme', 'build:zip' ) );
gulp.task( 'default', gulpSequence( 'clean', 'copy:lib', 'make:css', 'make:js' ) );