-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
145 lines (123 loc) · 3.29 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
const gulp = require('gulp')
const nib = require('nib')
const plugins = require('gulp-load-plugins')()
const argv = require('yargs').argv
const sourcemaps = require('gulp-sourcemaps')
const del = require('del')
const minimist = require('minimist')
const log = require('fancy-log')
const browserSync = require('browser-sync').create()
const defaultOptions = {
importance: null,
version: null
}
const options = minimist(process.argv.slice(2), { default: defaultOptions })
log.info('Options:', options)
function start(done) {
const port = argv.port || 8890
const host = argv.host || 'localhost'
let projectUrl = 'https://' + host
if (port) {
projectUrl += ':' + port
}
projectUrl += '/wp-admin/admin.php?page=ninja-forms'
// http://www.browsersync.io/docs/options/
browserSync.init({
proxy: projectUrl,
browser: 'google chrome',
port,
https: true,
host,
open: 'external',
injectChanges: true
})
done()
}
function lint() {
return gulp
.src(['src/js/main.js'])
.pipe(plugins.standard())
.pipe(
plugins.standard.reporter('default', {
breakOnError: true,
quiet: true
})
)
}
function bundle() {
return (
gulp
.src('src/js/main.js')
.pipe(sourcemaps.init())
.pipe(plugins.uglify())
.pipe(plugins.rename({ suffix: '.min' }))
// todo fix, sourcemaps do not seem to work (switch to webpack?)
.pipe(sourcemaps.write())
.pipe(gulp.dest('target/js'))
)
}
const js = gulp.series(lint, bundle)
function copyVideomailClient() {
return gulp
.src('node_modules/videomail-client/prototype/js/videomail-client.js')
.pipe(gulp.dest('target/js/videomail-client'))
}
function css() {
return gulp
.src('src/styl/main.styl')
.pipe(plugins.plumber())
.pipe(
plugins.stylus({
use: [nib()],
errors: true
})
)
.pipe(
plugins.autoprefixer(
'last 3 versions',
'> 2%',
'Explorer >= 11',
'Chrome >= 46',
'Firefox >= 52',
'iOS >= 9',
'android >= 4'
)
)
.pipe(plugins.bytediff.start())
.pipe(plugins.cssnano())
.pipe(plugins.rename({ suffix: '.min' }))
.pipe(plugins.bytediff.stop())
.pipe(browserSync.stream())
.pipe(gulp.dest('target/css'))
}
function cleanPhp() {
return del(['target/**/*.{php,html}'])
}
function copyPhp() {
return gulp.src('src/**/*.{php,html}').pipe(gulp.dest('target'))
}
const php = gulp.series(cleanPhp, copyPhp)
function watch() {
gulp.watch('src/**/*.{php,html}', php).on('change', browserSync.reload)
gulp.watch('src/js/**/*.js', js).on('change', browserSync.reload)
gulp.watch('src/styl/**/*.styl', css).on('change', browserSync.reload)
}
function todo() {
return gulp
.src(['videomail-for-ninja-forms.php', 'src/**/*.{php,js,styl}', 'gulpfile.js'])
.pipe(plugins.todo())
.pipe(gulp.dest('./'))
}
function zip() {
return gulp
.src(['index.php', 'readme.txt', 'videomail-for-ninja-forms.php', 'target/**'], {
base: './'
})
.pipe(plugins.zip('videomail-for-ninja-forms.zip'))
.pipe(gulp.dest('dist'))
}
// just builds assets once, nothing else
const build = gulp.series(css, js, copyVideomailClient, todo, php)
exports.build = build
exports.zip = zip
exports.watch = gulp.series(build, start, watch)