-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
253 lines (224 loc) · 8.18 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* ---- 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-double-opt-in',
pluginName: 'Torro Forms Double Opt In',
textDomain: 'torro-forms-double-opt-in',
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', 'flixos90', 'awesome-ug' ].join( ', ' ),
donateLink: false,
minRequired: '4.8',
testedUpTo: '5.2',
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: [ './*.php', './src/**/*.php', './templates/**/*.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', '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( jscs() )
.pipe( jscs.reporter() )
.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([
'./*.php',
'./src/**/*.php',
'./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( './languages/' + config.textDomain + '.pot' ) )
.on( 'end', done );
});
// replace the plugin header in the main plugin file
gulp.task( 'header-replace', 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', 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 );
});
/* ---- INITIAL SETUP TASK: Change the replacements, run the command once and then delete it from here ---- */
gulp.task( 'init-replace', done => {
const replacements = {
'torro-forms-double-opt-in': 'torro-forms-double-opt-in',
'TORRO_FORMS_DOUBLE_OPT_IN': 'TORRO_FORMS_DOUBLE_OPT_IN',
'torro_forms_double_opt_in': 'torro_forms_double_opt_in',
'Torro_Forms_Double_Opt_In': 'Torro_Forms_Double_Opt_In',
'Torro Forms Double Opt In': 'Torro Forms Double Opt In',
'TorroFormsDoubleOptIn' : 'TorroFormsDoubleOptIn',
'torroFormsDoubleOptIn' : 'torroFormsDoubleOptIn',
'awsmug' : 'awsmug', // PHP Namespace vendor.
'https://torro-forms.com' : 'https://torro-forms.com', // Plugin website.
'Awesome UG' : 'Awesome UG', // Plugin author name.
'support@awesome.ug' : 'support@awesome.ug', // Plugin author email.
'https://awesome.ug' : 'https://awesome.ug', // Plugin author website.
};
const files = [
'./*.php',
'./src/**/*.php',
'./templates/**/*.php',
'./tests/**/*.php',
'./assets/dist/js/**/*.js',
'./assets/src/js/**/*.js',
'./assets/dist/css/**/*.css',
'./assets/src/sass/**/*.scss',
'./composer.json',
'./gulpfile.js',
'./package.json',
'./phpcs.xml',
'./phpmd.xml',
'./phpunit.xml',
'./tests/phpunit/multisite.xml',
'./readme.txt',
];
let task = gulp.src( files, { base: './' });
Object.keys( replacements ).forEach( key => {
task = task.pipe( replace( key, replacements[ key ] ) );
});
task.pipe( gulp.dest( './' ) )
.on( 'end', done );
});