-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
204 lines (181 loc) · 6.58 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
201
202
203
204
/* ---- THE FOLLOWING CONFIG SHOULD BE EDITED ---- */
const pkg = require( './package.json' );
function parseKeywords( keywords ) {
// These keywords are useful for Packagist/NPM/Bower, but not for the WordPress plugin repository.
const disallowed = [ 'wordpress', 'plugin' ];
return keywords.filter( keyword => ! disallowed.includes( keyword ) );
}
const config = {
pluginSlug: 'torro-forms-protectors-plus',
pluginName: 'Torro Forms Protectors Plus',
textDomain: 'torro-forms-protectors-plus',
domainPath: '/languages/',
pluginURI: pkg.homepage,
author: pkg.author.name,
authorURI: pkg.author.url,
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: parseKeywords( pkg.keywords ).join( ', ' ),
contributors: [ 'mahype', 'awesome-ug' ].join( ', ' ),
donateLink: false,
minRequired: '4.8',
testedUpTo: '4.9',
requiresPHP: '5.6',
translateURI: 'https://translate.wordpress.org/projects/wp-plugins/torro-forms',
network: false
};
/* ---- DO NOT EDIT BELOW THIS LINE ---- */
// WP plugin header for main plugin file
const 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.textDomain + '\n' +
( config.domainPath ? ' * Domain Path: ' + config.domainPath + '\n' : '' ) +
( config.network ? ' * Network: true' + '\n' : '' ) +
' * Tags: ' + config.tags;
// WP plugin header for readme.txt
const 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' +
( config.requiresPHP ? 'Requires PHP: ' + config.requiresPHP + '\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
const assetheader = '/*!\n' +
' * ' + config.pluginName + ' Version ' + config.version + ' (' + config.pluginURI + ')\n' +
' * Licensed under ' + config.license + ' (' + config.licenseURI + ')\n' +
' */\n';
/* ---- REQUIRED DEPENDENCIES ---- */
const gulp = require( 'gulp' );
const rename = require( 'gulp-rename' );
const replace = require( 'gulp-replace' );
const banner = require( 'gulp-banner' );
const sass = require( 'gulp-sass' );
const csscomb = require( 'gulp-csscomb' );
const cleanCss = require( 'gulp-clean-css' );
const jshint = require( 'gulp-jshint' );
const jscs = require( 'gulp-jscs' );
const concat = require( 'gulp-concat' );
const uglify = require( 'gulp-uglify' );
const sort = require( 'gulp-sort' );
const wpPot = require( 'gulp-wp-pot' );
const paths = {
php: {
files: [ './src/*.php', './src/src/**/*.php', './src/templates/**/*.php' ]
},
sass: {
files: [ './src/assets/src/sass/*.scss' ],
src: './src/assets/src/sass/',
dst: './src/assets/dist/css/'
},
js: {
files: [ './src/assets/src/js/*.js' ],
src: './src/assets/src/js/',
dst: './src/assets/dist/js/'
}
};
/* ---- MAIN TASKS ---- */
// general task (compile Sass and JavaScript and refresh POT file)
gulp.task( 'default', [ 'sass', 'js', 'pot' ]);
// watch Sass and JavaScript files
gulp.task( 'watch', () => {
gulp.watch( paths.sass.files, [ 'sass' ]);
gulp.watch( paths.js.files, [ 'js' ]);
});
// build the plugin
gulp.task( 'build', [ 'readme-replace' ], () => {
gulp.start( 'header-replace' );
gulp.start( 'default' );
});
/* ---- SUB TASKS ---- */
// compile Sass
gulp.task( 'sass', done => {
gulp.src( paths.sass.files )
.pipe( sass({
errLogToConsole: true,
outputStyle: 'expanded'
}) )
.pipe( csscomb() )
.pipe( banner( assetheader ) )
.pipe( gulp.dest( paths.sass.dst ) )
.pipe( cleanCss({
keepSpecialComments: 0
}) )
.pipe( banner( assetheader ) )
.pipe( rename({
extname: '.min.css'
}) )
.pipe( gulp.dest( paths.sass.dst ) )
.on( 'end', done );
});
// compile JavaScript
gulp.task( 'js', done => {
gulp.src( paths.js.files )
.pipe( jshint() )
.pipe( jshint.reporter( 'default' ) )
.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 );
});
// generate POT file
gulp.task( 'pot', done => {
gulp.src([
'./src/*.php',
'./src/src/**/*.php',
'./src/templates/**/*.php',
])
.pipe( sort() )
.pipe( wpPot({
domain: config.textDomain,
headers: {
'Project-Id-Version': config.pluginName + ' ' + config.version,
'report-msgid-bugs-to': config.translateURI,
'x-generator': 'gulp-wp-pot',
'x-poedit-basepath': '.',
'x-poedit-language': 'English',
'x-poedit-country': 'UNITED STATES',
'x-poedit-sourcecharset': 'uft-8',
'x-poedit-keywordslist': '__;_e;_x:1,2c;_ex:1,2c;_n:1,2; _nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_attr__; esc_html__;esc_attr_e; esc_html_e;esc_attr_x:1,2c; esc_html_x:1,2c;',
'x-poedit-bookmars': '',
'x-poedit-searchpath-0': '.',
'x-textdomain-support': 'yes',
},
}) )
.pipe( gulp.dest( './src/languages/' + config.textDomain + '.pot' ) )
.on( 'end', done );
});
// replace the plugin header in the main plugin file
gulp.task( 'header-replace', done => {
gulp.src( './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', done => {
gulp.src( './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 );
});