This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
175 lines (154 loc) · 5.23 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
var pkg = require( './package.json' );
var config = {
pluginSlug: 'facebook-fanpage-import',
pluginName: 'Facebook Fanpage import',
pluginURI: pkg.homepage,
author: pkg.author.name,
authorURI: pkg.author.url,
description: pkg.description,
version: pkg.version,
license: pkg.license.name,
licenseURI: pkg.license.url,
tags: pkg.keywords.join( ', ' ),
contributors: [ 'mahype', 'awesome-ug' ].join( ', ' ),
minRequired: '4.1.1',
testedUpTo: '4.6.0',
translateURI: 'https://translate.wordpress.org/projects/wp-plugins/facebook-fanpage-import'
};
/* ---- 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' +
'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' +
'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 + ' Version ' + config.version + ' (' + config.pluginURI + ')\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', './components/**/*.php', './core/**/*.php', './includes/**/*.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' ]);
// 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', [ 'version-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 version header in all PHP files
gulp.task( 'version-replace', function( done ) {
gulp.src( paths.php.files, { base: './' })
.pipe( replace( /\* @version ([^\s])+/, '* @version ' + config.version ) )
.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( /((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/, '/*\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 );
});
});