-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgulpfile.js
185 lines (162 loc) · 4.6 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
const gulp = require('gulp')
const del = require('del');
const livereload = require('gulp-livereload')
const rename = require('gulp-rename')
const less = require('gulp-less')
const autoprefixer = require('gulp-autoprefixer')
// const combineMq = require('gulp-combine-mq') // error with fs.js primordial something
const cssnano = require('gulp-cssnano')
const concat = require('gulp-concat')
const uglify = require('gulp-uglify')
const cssbeautify = require('gulp-cssbeautify')
var replace = require('gulp-replace');
const dist = '../HESH-WordPress-Plugin-dist';
const compileCSS = () => {
return gulp.src('./src/hesh.less')
.pipe(less({
plugins: [require('less-plugin-glob')]
}))
.pipe(autoprefixer({
flexbox: 'no-2009'
// cascade: false
}))
// .pipe(combineMq({
// beautify: true
// }))
// .pipe(cssnano({
// discardComments: false
// }))
.pipe(cssbeautify({
indent: ' ',
autosemicolon: true
}))
// .pipe(rename('hesh.css'))
.pipe(gulp.dest(dist))
.pipe(livereload())
}
const minifyCSS = () => {
return gulp.src(dist + '/hesh.css')
.pipe(cssnano())
// we beautify afterward so the file is editable in the WP Plugin Editor
.pipe(cssbeautify({
indent: ' ',
autosemicolon: true
}))
// .pipe(rename(path => path.basename += '.min'))
.pipe(gulp.dest(dist))
}
const compileJS = () => {
const codemirrorPath = './node_modules/codemirror/'
const customModesPath = './src/modes/'
return gulp.src([
// CodeMirror Core
codemirrorPath + 'lib/codemirror.js',
// Modes
codemirrorPath + 'mode/xml/xml.js',
codemirrorPath + 'mode/javascript/javascript.js',
codemirrorPath + 'mode/css/css.js',
codemirrorPath + 'mode/htmlmixed/htmlmixed.js',
codemirrorPath + 'mode/clike/clike.js',
codemirrorPath + 'mode/php/php.js',
// Custom Modes
customModesPath + 'shortcode.js',
customModesPath + 'wordpresspost.js',
// AddOns
codemirrorPath + 'addon/selection/active-line.js',
codemirrorPath + 'addon/search/searchcursor.js',
codemirrorPath + 'addon/search/search.js',
codemirrorPath + 'addon/dialog/dialog.js',
codemirrorPath + 'addon/scroll/simplescrollbars.js',
codemirrorPath + 'addon/comment/comment.js',
codemirrorPath + 'addon/fold/foldcode.js',
codemirrorPath + 'addon/fold/foldgutter.js',
codemirrorPath + 'addon/fold/xml-fold.js',
// codemirrorPath + 'addon/fold/brace-fold.js', // for JS
// codemirrorPath + 'addon/fold/comment-fold.js',
codemirrorPath + 'addon/fold/indent-fold.js',
codemirrorPath + 'addon/edit/matchbrackets.js',
codemirrorPath + 'addon/edit/matchtags.js',
codemirrorPath + 'addon/search/match-highlighter.js',
codemirrorPath + 'addon/edit/closetag.js',
codemirrorPath + 'addon/edit/closebrackets.js',
codemirrorPath + 'keymap/sublime.js',
codemirrorPath + 'keymap/emacs.js',
codemirrorPath + 'keymap/vim.js',
// ... and finally ...
// HESH
'./src/hesh.js',
])
.pipe(concat('hesh.js'))
.pipe(gulp.dest(dist))
.pipe(livereload())
}
const minifyJS = () => {
return gulp.src(dist + '/hesh.js')
.pipe(uglify())
// .pipe(rename(path => path.basename += '.min'))
.pipe(gulp.dest(dist))
}
const copyPluginFiles = () => {
return gulp.src([
'./src/*.php',
'./src/readme.txt'
])
.pipe(gulp.dest(dist))
.pipe(livereload())
}
const copyAssets = () => {
return gulp.src([
'./assets/banner-772x250.*',
'./assets/banner-1544x500.*',
'./assets/icon-128x128.*',
'./assets/icon-256x256.*',
'./assets/icon.svg',
'./assets/screenshot-*',
])
.pipe(gulp.dest(dist + '/assets'))
}
const removeDevTitle = () => {
return gulp.src([
dist + '/*.php',
dist + '/readme.txt'
])
.pipe(replace('!DEV!', ''))
.pipe(gulp.dest(dist))
}
const buildReadMeTxt = () => {
/* TODO: merge:
- the comments in the head of the php file
- the features and description from Readme.md
- the FAQ.md
- the list of screenshot captions
- regex replace # TITLES with === TITLES ===
*/
}
const clean = () => {
return del([
dist + '/[^.]*.*', // anything that is not .hidden
], { force: true });
}
const watch = () => {
livereload.listen()
gulp.watch([
'./src/*.php',
], copyPluginFiles)
gulp.watch([
'./src/**/*.css',
'./src/**/*.less',
], compileCSS)
gulp.watch([
'./src/**/*.js'
], compileJS)
}
const compile = gulp.parallel(compileCSS, compileJS, copyPluginFiles)
const minify = gulp.parallel(minifyCSS, minifyJS)
const dev = gulp.series(clean, compile, watch)
const build = gulp.series(clean, compile, minify)
const package = gulp.series(build, removeDevTitle, copyAssets)
gulp.task('compile', compile)
gulp.task('build', build)
gulp.task('package', package)
gulp.task('dev', dev)
gulp.task('default', dev)