forked from felixarntz/wp-gdpr-cookie-notice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
82 lines (69 loc) · 3.05 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
/* ---- 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: 'wp-gdpr-cookie-notice',
pluginName: 'WP GDPR Cookie Notice',
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: [ 'flixos90' ].join( ', ' ),
donateLink: false,
minRequired: '4.9.6',
testedUpTo: '5.1',
requiresPHP: '7.0',
translateURI: 'https://translate.wordpress.org/projects/wp-plugins/wp-gdpr-cookie-notice',
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.pluginSlug + '\n' +
( config.network ? ' * Network: true' + '\n' : '' );
// WP plugin header for readme.txt
const readmeheader ='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' +
'License: ' + config.license + '\n' +
'License URI: ' + config.licenseURI + '\n' +
'Tags: ' + config.tags;
/* ---- REQUIRED DEPENDENCIES ---- */
const gulp = require( 'gulp' );
const replace = require( 'gulp-replace' );
// build the plugin
gulp.task( 'build', [ 'readme-replace' ], () => {
gulp.start( 'header-replace' );
});
// 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 );
});