forked from caseproof/members
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
141 lines (122 loc) · 4.55 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
// Style related.
var styleSRC = './css/*.css'; // Path to .css files.
var styleDestination = './css/'; // Path to place the minified CSS files.
// JS related.
var jsSource = './js/*.js'; // Path to JS vendor folder.
var jsDestination = './js/'; // Path to place the minified JS files.
// Translation related.
var text_domain = 'members'; // Your textdomain here.
var translationFile = 'members.pot'; // Name of the transalation file.
var translationDestination = './lang'; // Where to save the translation files.
var packageName = 'members'; // Package name.
var bugReport = 'https://memberpress.com'; // Where can users report bugs.
var lastTranslator = 'Caseproof LLC <[email protected]>'; // Last translator Email ID.
var team = 'Caseproof LLC <[email protected]>'; // Team's Email ID.
// Files to watch
var stylesWatchFiles = './css/*.css'; // Path to all Sass partials.
var scriptsWatchFiles = './js/*.js'; // Path to all custom JS files.
var projectPHPWatchFiles = './**/*.php'; // Path to all PHP files.
/**
* Load Plugins.
*/
var gulp = require('gulp'); // Gulp of-course
// CSS related plugins.
var minifycss = require('gulp-uglifycss'); // Minifies CSS files.
var autoprefixer = require('gulp-autoprefixer'); // Autoprefixing magic.
// JS related plugins.
var uglify = require('gulp-uglify'); // Minifies JS files
// Utility related plugins.
var replace = require('gulp-replace'); // Search and replace text
var rename = require('gulp-rename'); // Renames files E.g. style.css -> style.min.css
var lineec = require('gulp-line-ending-corrector'); // Consistent Line Endings for non UNIX systems. Gulp Plugin for Line Ending Corrector (A utility that makes sure your files have consistent line endings)
var notify = require('gulp-notify'); // Sends message notification to you
var wpPot = require('gulp-wp-pot'); // For generating the .pot file.
var sort = require('gulp-sort'); // Recommended to prevent unnecessary changes in pot-file.
// Browsers you care about for autoprefixing.
// Browserlist https ://github.com/ai/browserslist
const AUTOPREFIXER_BROWSERS = [
'last 2 version'
];
/**
* Task: `styles`.
*
* Compiles Sass, Autoprefixes it and Minifies CSS.
*
* This task does the following:
* 1. Gets the source scss file
* 2. Compiles Sass to CSS
* 3. Autoprefixes it and generates style.css
* 4. Renames the CSS file with suffix .min.css
* 5. Minifies the CSS file and generates .min.css
*/
gulp.task('styles', function () {
gulp.src([
styleSRC,
'!css/*.min.css'
])
.pipe(autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss({
maxLineLen: 0
}))
.pipe(gulp.dest(styleDestination))
.pipe(notify({ message: 'TASK: "styles" Completed! 💯', onLast: true }))
});
/**
* Task: `scripts`.
*
* Concatenate and uglify JS files.
*
* This task does the following:
* 1. Gets the source folder for JS files
* 2. Concatenates all the files
* 3. Renames the concatenated JS file with suffix .min.js
* 4. Uglifes/Minifies the JS file and generates minified JS file
*/
gulp.task('scripts', function () {
gulp.src([
jsSource,
'!js/*.min.js'
])
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(lineec()) // Consistent Line Endings for non UNIX systems.
.pipe(gulp.dest(jsDestination))
.pipe(notify({ message: 'TASK: "scripts" Completed! 💯', onLast: true }));
});
/**
* WP POT Translation File Generator.
*
* * This task does the following:
* 1. Gets the source of all the PHP files
* 2. Search and replace the placeholder text for the text domain
* 3. Sort files in stream by path or any custom sort comparator
* 4. Applies wpPot with the variable set at the top of this file
* 5. Generate a .pot file of i18n that can be used for l10n to build .mo file
*/
gulp.task('pot', function () {
return gulp.src(projectPHPWatchFiles)
.pipe( replace( /(?<="|')(tdomain)(?="|')/g, text_domain ) )
.pipe(gulp.dest("./"))
.pipe(sort())
.pipe(wpPot({
domain: text_domain,
package: packageName,
bugReport: bugReport,
lastTranslator: lastTranslator,
team: team
}))
.pipe(gulp.dest(translationDestination + '/' + translationFile))
.pipe(notify({ message: 'TASK: "pot" Completed! 💯', onLast: true }))
});
/**
* Watch Tasks.
*
* Watches for file changes and runs specific tasks.
*/
gulp.task('default', ['styles', 'scripts'], function () {
gulp.watch([stylesWatchFiles, './css/*.css'], ['styles']);
gulp.watch(scriptsWatchFiles, ['scripts']);
});