-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
226 lines (207 loc) · 7.69 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
'use strict';
const packageInfo = require('./package.json');
const gulp = require('gulp');
const fs = require('fs');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const notify = require('gulp-notify');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const browserify = require('browserify');
const babelify = require('babelify');
const fetchify = require('fetchify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const reactify = require('reactify');
const wpPot = require('gulp-wp-pot');
const sort = require('gulp-sort');
const gulpIf = require('gulp-if');
var $ = require('gulp-load-plugins')();
const dos2unix = require('gulp-dos2unix-js');
gulp.task('admin_sass', function () {
return gulp.src(['./assets/src/scss/admin/**/*.scss'])
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(rename('clientdash-admin.min.css'))
.pipe(gulp.dest('./assets/dist/css'))
.pipe(notify({message: 'SASS complete'}));
});
gulp.task('customize_sass', function () {
return gulp.src('./assets/src/scss/customize/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(rename({
dirname: '',
suffix: '.min'
}))
.pipe(gulp.dest('./assets/dist/css'))
.pipe(notify({message: 'SASS Customize complete'}));
});
gulp.task('customize_inpreview_sass', function () {
return gulp.src('./assets/src/scss/customize-inpreview/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(rename({
dirname: '',
suffix: '.min'
}))
.pipe(gulp.dest('./assets/dist/css'))
.pipe(notify({message: 'SASS Customize Inpreview complete'}));
});
gulp.task('admin_js', function () {
return gulp.src([
'./assets/vendor/select2/dist/js/select2.full.js',
'./assets/src/js/admin/**/*.js'
])
.pipe(concat('clientdash-admin.min.js'))
.pipe(gulp.dest('./assets/dist/js/'))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('/'))
.pipe(gulp.dest('./assets/dist/js/'))
.pipe(notify({message: 'JS Admin complete'}));
});
gulp.task('customize_inpreview_js', function () {
return gulp.src('./assets/src/js/customize-inpreview/*.js')
.pipe(concat('clientdash-customize-inpreview.min.js'))
.pipe(gulp.dest('./assets/dist/js/'))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('/'))
.pipe(gulp.dest('./assets/dist/js/'))
.pipe(notify({message: 'JS Customize inpreview complete'}));
});
gulp.task('customize_js', function () {
return browserify({
transform: [
[babelify, {
presets: ["es2015", "stage-2", "react"]
}]
],
entries: ['./assets/src/js/customize/customize.js'],
debug: true
})
.bundle()
.pipe(source('clientdash-customize.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpIf(process.env.NODE_ENV === 'production', uglify()
.on('error', e => {
console.log(e);
})
))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./assets/dist/js/'))
.pipe(notify({message: 'JS Customize complete'}));
});
gulp.task('apply-prod-environment', function ( done ) {
process.stdout.write("Setting NODE_ENV to 'production'" + "\n");
process.env.NODE_ENV = 'production';
if ( process.env.NODE_ENV != 'production' ) {
throw new Error("Failed to set NODE_ENV to production!!!!");
done();
} else {
process.stdout.write("Successfully set NODE_ENV to production" + "\n");
done();
}
});
gulp.task('remove-prod-environment', function ( done ) {
process.stdout.write("Setting NODE_ENV to 'dev'" + "\n");
process.env.NODE_ENV = 'dev';
if ( process.env.NODE_ENV != 'dev' ) {
throw new Error("Failed to set NODE_ENV to dev!!!!");
done();
} else {
process.stdout.write("Successfully set NODE_ENV to dev" + "\n");
done();
}
});
gulp.task('version', function () {
return gulp.src([
'admin/**/*',
'assets/src/**/*',
'core/**/*',
'!core/library/**/*',
'languages/**/*',
'templates/**/*',
'client-dash.php',
'client-dash-bootstrapper.php',
'readme.txt',
'README.md'
], {base: './'})
// Doc block versions
.pipe($.replace(/\{\{VERSION}}/g, packageInfo.version))
// Plugin header
.pipe($.replace(/(\* Version: )\d+\.\d+\.\d+/, "$1" + packageInfo.version))
// Version constant
.pipe($.replace(/(define\( 'CLIENTDASH_VERSION', ')\d+\.\d+\.\d+/, "$1" + packageInfo.version))
// readme.txt
.pipe($.replace(/(Stable tag: )\d+\.\d+\.\d+/, "$1" + packageInfo.version))
// README.md
.pipe($.replace(/(\#\sv)\d+\.\d+\.\d+/, "$1" + packageInfo.version))
.pipe(gulp.dest('./'));
});
gulp.task('generate_pot', function () {
return gulp.src(['./**/*.php', '!client-dash-svn/**/*.php'])
.pipe(sort())
.pipe(wpPot({
domain: 'client-dash',
package: 'ClientDash',
}))
.pipe(gulp.dest('./languages/client-dash.pot'));
});
gulp.task('default', gulp.parallel( 'admin_sass', 'admin_js', 'customize_sass', 'customize_inpreview_sass', 'customize_inpreview_js', 'customize_js', function () {
gulp.watch(['./assets/src/scss/admin/**/*.scss'], gulp.parallel( 'admin_sass' ) );
gulp.watch(['./assets/src/scss/customize/*.scss'], gulp.parallel( 'customize_sass' ) );
gulp.watch(['./assets/src/scss/customize-inpreview/*.scss'], gulp.parallel( 'customize_inpreview_sass' ) );
gulp.watch(['./assets/src/js/admin/**/*.js'], gulp.parallel( 'admin_js' ) );
gulp.watch(['./assets/src/js/customize/*.js'], gulp.parallel( 'customize_js' ) );
gulp.watch(['./assets/src/js/customize-inpreview/customize-inpreview.js'], gulp.parallel( 'customize_inpreview_js' ) );
} ) );
gulp.task('build', gulp.series( 'admin_sass', 'admin_js', 'customize_sass', 'customize_inpreview_sass', 'customize_inpreview_js', 'customize_js', 'generate_pot' ) );
gulp.task( 'svn_copy', function() {
return gulp.src( [
'admin/**/*',
'assets/**/*',
'!assets/vendor/**',
'core/**/*',
'core/library/**/*',
'languages/**/*',
'templates/**/*',
'client-dash.php',
'client-dash-bootstrapper.php',
'readme.txt',
'!core/library/rbm-field-helpers/assets/{src,src/**}',
'!core/library/rbm-field-helpers/{bin,bin/**}',
'!./**/.babelrc',
'!./**/.gitignore',
'!./**/.git',
'!./**/config.yml',
'!./**/config-default.yml',
'!./**/gulpfile.js',
'!./**/gulpfile.babel.js',
'!./**/grunfile.js',
'!./**/package.json',
'!./**/package-lock.json',
'!./**/README.md',
'!./**/webpack.config.js',
], { base: '*' } )
.pipe( dos2unix() )
.pipe(rename(function(file) {
file.dirname = file.dirname.replace( '..', '' );
return file;
}))
.pipe( gulp.dest( 'client-dash-svn/trunk/' ) );
} );
gulp.task( 'svn_build', gulp.series( 'version', 'apply-prod-environment', 'build', 'svn_copy', 'remove-prod-environment', 'build' ) );