This repository was archived by the owner on Feb 15, 2024. It is now read-only.
forked from johngodley/redirection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
107 lines (82 loc) · 2.58 KB
/
gulpfile.js
File metadata and controls
107 lines (82 loc) · 2.58 KB
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
'use strict';
var gulp = require( 'gulp' );
var SVN_SOURCE = [
'./**',
'!package.json',
'!phpunit.xml',
'!gulpfile.js',
'!node_modules/**',
'!tests/**',
'!bin/**',
'!node_modules',
'!tests',
'!bin'
];
var SVN_SOURCE2 = [
'*/**',
'!package.json',
'!phpunit.xml',
'!gulpfile.js',
'!node_modules/**',
'!tests/**',
'!bin/**',
'!node_modules',
'!tests',
'!bin'
];
// Based on gulp-deleted, but with 'force: true'
function cleaner( dest, destPatterns ) {
var path, through, glob, _, del;
glob = require("glob-all");
through = require("through");
path = require("path");
_ = require("underscore");
del = require("del");
var repl = /\\/g
if (destPatterns === undefined) return through(function write(data) {this.emit('data', data)},function end () {this.emit('end')});
var srcFiles, destFiles, files, onEnd, onFile;
files = [];
srcFiles = [];
destFiles = glob.sync( destPatterns, {cwd: path.join(process.cwd(), dest) } );
onFile = function(file) {
srcFiles.push(file.path);
this.push(file);
return files.push(file);
};
onEnd = function() {
for (var i = srcFiles.length -1, l = -1; i > l; i--){
srcFiles[i] = srcFiles[i].replace(repl, "/").substr(process.cwd().length + 1);
if (srcFiles[i] == '') {
srcFiles.splice(i,1);
}
}
//compare source and destination files and delete any missing in source at destination
var deletedFiles = _.difference(destFiles, srcFiles);
_.each(deletedFiles, function(item, index) {
deletedFiles[index] = path.join(process.cwd(), dest, deletedFiles[index]);
del.sync(deletedFiles[index], { force: true });
} );
return this.emit("end");
};
return through(onFile, onEnd);
}
gulp.task( 'pot', function() {
var wpPot = require( 'gulp-wp-pot' );
var sort = require( 'gulp-sort' );
return gulp.src( [ '**/*.php' ] )
.pipe( sort() )
.pipe( wpPot( {
domain: 'redirection',
destFile: 'redirection.pot',
package: 'Redirection',
bugReport: 'https://wordpress.org/plugins/redirection/'
} ) )
.pipe( gulp.dest( 'locale' ) );
} );
gulp.task( 'svn', function() {
var config = require( './.config.json' ); // Local config
var deleted = require( 'gulp-deleted' );
return gulp.src( SVN_SOURCE )
.pipe( cleaner( config.svn_relative, SVN_SOURCE2 ) )
.pipe( gulp.dest( config.svn_target ) );
} );