-
Notifications
You must be signed in to change notification settings - Fork 18
/
gulpfile.js
200 lines (174 loc) · 6.08 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
195
196
197
198
199
200
/* ---- THE FOLLOWING CONFIG SHOULD BE EDITED ---- */
var pkg = require( './package.json' );
function parseKeywords( keywords ) {
// These keywords are useful for Packagist/NPM/Bower, but not for the WordPress plugin repository.
var disallowed = [ 'wordpress', 'plugin' ];
k = keywords;
for ( var i in disallowed ) {
var index = k.indexOf( disallowed[ i ] );
if ( -1 < index ) {
k.splice( index, 1 );
}
}
return k;
}
var keywords = parseKeywords( pkg.keywords );
var config = {
pluginSlug: pkg.name,
pluginName: 'Bootstrap for Contact Form 7',
pluginURI: pkg.homepage,
author: pkg.author.name,
authorURI: pkg.author.url,
authorEmail: pkg.author.email,
description: pkg.description,
version: pkg.version,
license: 'GNU General Public License v2 (or later)',
licenseURI: 'http://www.gnu.org/licenses/gpl-2.0.html',
tags: keywords.join( ', ' ),
contributors: [ 'flixos90', 'gidomanders' ].join( ', ' ),
donateLink: 'https://leaves-and-love.net/wordpress-plugins/',
minRequired: '3.6',
testedUpTo: '4.9',
translateURI: 'https://translate.wordpress.org/projects/wp-plugins/' + pkg.name,
network: false
};
/* ---- DO NOT EDIT BELOW THIS LINE ---- */
// WP plugin header for main plugin file
var pluginheader = ' * Plugin Name: ' + config.pluginName + '\n' +
' * Plugin URI: ' + config.pluginURI + '\n' +
' * Description: ' + config.description + '\n' +
' * Version: ' + config.version + '\n' +
' * Author: ' + config.author + '\n' +
' * Author URI: ' + config.authorURI + '\n' +
' * License: ' + config.license + '\n' +
' * License URI: ' + config.licenseURI + '\n' +
' * Text Domain: ' + config.pluginSlug + '\n' +
( config.network ? ' * Network: true' + '\n' : '' ) +
' * Tags: ' + config.tags;
// WP plugin header for readme.txt
var readmeheader = 'Plugin Name: ' + config.pluginName + '\n' +
'Plugin URI: ' + config.pluginURI + '\n' +
'Author: ' + config.author + '\n' +
'Author URI: ' + config.authorURI + '\n' +
'Contributors: ' + config.contributors + '\n' +
( config.donateLink ? 'Donate link: ' + config.donateLink + '\n' : '' ) +
'Requires at least: ' + config.minRequired + '\n' +
'Tested up to: ' + config.testedUpTo + '\n' +
'Stable tag: ' + config.version + '\n' +
'Version: ' + config.version + '\n' +
'License: ' + config.license + '\n' +
'License URI: ' + config.licenseURI + '\n' +
'Tags: ' + config.tags;
// header for minified assets
var assetheader = '/*!\n' +
' * ' + config.pluginName + ' (' + config.pluginURI + ')\n' +
' * By ' + config.author + ' (' + config.authorURI + ')\n' +
' * Licensed under ' + config.license + ' (' + config.licenseURI + ')\n' +
' */\n';
/* ---- REQUIRED DEPENDENCIES ---- */
var gulp = require( 'gulp' );
var sass = require( 'gulp-sass' );
var csscomb = require( 'gulp-csscomb' );
var minifyCSS = require( 'gulp-minify-css' );
var jshint = require( 'gulp-jshint' );
var concat = require( 'gulp-concat' );
var uglify = require( 'gulp-uglify' );
var gutil = require( 'gulp-util' );
var rename = require( 'gulp-rename' );
var replace = require( 'gulp-replace' );
var sort = require( 'gulp-sort' );
var banner = require( 'gulp-banner' );
var composer = require( 'gulp-composer' );
var bower = require( 'bower' );
var paths = {
php: {
files: [ './*.php', './inc/**/*.php' ]
},
sass: {
files: [ './assets/src/sass/**/*.scss' ],
src: './assets/src/sass/',
dst: './assets/dist/css/'
},
js: {
files: [ './assets/src/js/**/*.js' ],
src: './assets/src/js/',
dst: './assets/dist/js/'
}
};
/* ---- MAIN TASKS ---- */
// general task (compile Sass and JavaScript and refresh POT file)
gulp.task( 'default', [ 'sass', 'js' ]);
// watch Sass and JavaScript files
gulp.task( 'watch', function() {
gulp.watch( paths.sass.files, [ 'sass' ]);
gulp.watch( paths.js.files, [ 'js' ]);
});
// build the plugin
gulp.task( 'build', [ 'author-replace', 'readme-replace' ], function() {
gulp.start( 'header-replace' );
gulp.start( 'default' );
});
/* ---- SUB TASKS ---- */
// compile Sass
gulp.task( 'sass', function( done ) {
gulp.src( paths.sass.files )
.pipe( sass({
errLogToConsole: true
}) )
.pipe( csscomb() )
.pipe( banner( assetheader ) )
.pipe( gulp.dest( paths.sass.dst ) )
.pipe( minifyCSS({
keepSpecialComments: 0
}) )
.pipe( banner( assetheader ) )
.pipe( rename({
extname: '.min.css'
}) )
.pipe( gulp.dest( paths.sass.dst ) )
.on( 'end', done );
});
// compile JavaScript
gulp.task( 'js', function( done ) {
gulp.src( paths.js.files )
.pipe( jshint({
lookup: true
}) )
.pipe( banner( assetheader ) )
.pipe( gulp.dest( paths.js.dst ) )
.pipe( uglify() )
.pipe( banner( assetheader ) )
.pipe( rename({
extname: '.min.js'
}) )
.pipe( gulp.dest( paths.js.dst ) )
.on( 'end', done );
});
// replace the author header in all PHP files
gulp.task( 'author-replace', function( done ) {
gulp.src( paths.php.files, { base: './' })
.pipe( replace( /\*\s@author\s[^\r\n]+/, '* @author ' + config.author + ' <' + config.authorEmail + '>' ) )
.pipe( gulp.dest( './' ) )
.on( 'end', done );
});
// replace the plugin header in the main plugin file
gulp.task( 'header-replace', function( done ) {
gulp.src( './' + config.pluginSlug + '.php' )
.pipe( replace( /(?:\s\*\s@wordpress-plugin\s(?:[^*]|(?:\*+[^*\/]))*\*+\/)/, ' * @wordpress-plugin\n' + pluginheader + '\n */' ) )
.pipe( gulp.dest( './' ) )
.on( 'end', done );
});
// replace the plugin header in readme.txt
gulp.task( 'readme-replace', function( done ) {
gulp.src( './readme.txt' )
.pipe( replace( /\=\=\= (.+) \=\=\=([\s\S]+)\=\= Description \=\=/m, '=== ' + config.pluginName + ' ===\n\n' + readmeheader + '\n\n' + config.description + '\n\n== Description ==' ) )
.pipe( gulp.dest( './' ) )
.on( 'end', done );
});
// install Bower components
gulp.task( 'bower-install', function() {
return bower.commands.install()
.on( 'log', function( data ) {
gutil.log( 'bower', gutil.colors.cyan( data.id ), data.message );
});
});