-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
199 lines (171 loc) · 5.39 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
var plugin = 'pixproof',
gulp = require('gulp'),
plugins = require('gulp-load-plugins' )(),
fs = require('fs'),
cp = require('child_process'),
del = require('del'),
cleanCSS = require('gulp-clean-css'),
commandExistsSync = require('command-exists').sync;
var u = plugins.util,
c = plugins.util.colors,
log = plugins.util.log;
gulp.task( 'styles', function() {
return gulp.src( 'assets/scss/**/*.scss' )
.pipe(plugins.sass( {sourcemap: false, style: 'nested'} ) )
.pipe(plugins.autoprefixer() )
.pipe(plugins.replace(/^@charset \"UTF-8\";\n/gm, ''))
.pipe(cleanCSS())
.pipe( gulp.dest( './assets/css/' ) );
} );
gulp.task( 'styles-watch', function() {
return gulp.watch( 'assets/scss/**/*.scss', ['styles'] );
} );
/**
* Copy plugin folder outside in a build folder, recreate styles before that
*/
gulp.task( 'copy-folder', function() {
var dir = process.cwd();
return gulp.src( './*' )
.pipe( plugins.exec( 'rm -Rf ./../build; mkdir -p ./../build/' + plugin + ';', {
silent: true,
continueOnError: true // default: false
} ) )
.pipe(plugins.rsync({
root: dir,
destination: '../build/' + plugin + '/',
// archive: true,
progress: false,
silent: false,
compress: false,
recursive: true,
emptyDirectories: true,
clean: true,
exclude: ['node_modules']
}));
} );
/**
* Clean the folder of unneeded files and folders
*/
gulp.task( 'remove-files', function() {
// files that should not be present in build zip
var files_to_remove = [
'node_modules',
'bin',
'tests',
'.travis.yml',
'.babelrc',
'.gitignore',
'.codeclimate.yml',
'.csslintrc',
'.eslintignore',
'.eslintrc',
'circle.yml',
'phpunit.xml.dist',
'.sass-cache',
'config.rb',
'gulpfile.js',
'webpack.config.js',
'package.json',
'package-lock.json',
'pxg.json',
'build',
'.idea',
'**/*.css.map',
'**/.git*',
'*.sublime-project',
'.DS_Store',
'**/.DS_Store',
'__MACOSX',
'**/__MACOSX',
'.csscomb',
'.csscomb.json',
'.codeclimate.yml',
'tests',
'circle.yml',
'.circleci',
'.labels',
'.jscsrc',
'.jshintignore',
'browserslist',
'README.md',
'**/codekit-config.json',
'node_modules',
'config.rb',
'gulpfile.js',
'package.json',
'pxg.json',
'build',
'.idea',
'**/*.css.map',
'**/.sass*',
'.sass*',
'**/.git*',
'*.sublime-project',
'.DS_Store',
'**/.DS_Store',
'__MACOSX',
'**/__MACOSX',
'.labels',
'assets/scss',
];
files_to_remove.forEach( function( e, k ) {
files_to_remove[k] = '../build/' + plugin + '/' + e;
} );
return del(files_to_remove, {force: true});
} );
function maybeFixBuildDirPermissions(done) {
cp.execSync('find ./../build -type d -exec chmod 755 {} \\;');
return done();
}
maybeFixBuildDirPermissions.description = 'Make sure that all directories in the build directory have 755 permissions.';
gulp.task( 'fix-build-dir-permissions', maybeFixBuildDirPermissions );
function maybeFixBuildFilePermissions(done) {
if (!commandExistsSync('dos2unix')) {
log( c.red( 'Could not ensure that line endings are correct on the build files since you are missing the "dos2unix" utility! You should install it.' ) );
log( c.red( 'However, this is not a very big deal. The build task will continue.' ) );
} else {
cp.execSync('find ./../build -type f -print0 | xargs -0 -n 1 -P 4 dos2unix');
}
return done();
}
maybeFixBuildFilePermissions.description = 'Make sure that all files in the build directory have 644 permissions.';
gulp.task( 'fix-build-file-permissions', maybeFixBuildFilePermissions );
function maybeFixIncorrectLineEndings(done) {
cp.execSync('find ./../build -type f -print0 | xargs -0 -n 1 -P 4 dos2unix');
return done();
}
maybeFixIncorrectLineEndings.description = 'Make sure that all line endings in the files in the build directory are UNIX line endings.';
gulp.task( 'fix-line-endings', maybeFixIncorrectLineEndings );
/**
* Create a zip archive out of the cleaned folder and delete the folder
*/
gulp.task( 'make-zip', function() {
var versionString = '';
// get plugin version from the main plugin file
var contents = fs.readFileSync("./" + plugin + ".php", "utf8");
// split it by lines
var lines = contents.split(/[\r\n]/);
function checkIfVersionLine(value, index, ar) {
var myRegEx = /^[\s\*]*[Vv]ersion:/;
if (myRegEx.test(value)) {
return true;
}
return false;
}
// apply the filter
var versionLine = lines.filter(checkIfVersionLine);
versionString = versionLine[0].replace(/^[\s\*]*[Vv]ersion:/, '').trim();
versionString = '-' + versionString.replace(/\./g, '-');
return gulp.src('./')
.pipe(plugins.exec('cd ./../; rm -rf ' + plugin[0].toUpperCase() + plugin.slice(1) + '*.zip; cd ./build/; zip -r -X ./../' + plugin[0].toUpperCase() + plugin.slice(1) + versionString + '.zip ./; cd ./../; rm -rf build'));
} );
function buildSequence(cb) {
return gulp.series( 'copy-folder', 'remove-files', 'fix-build-dir-permissions', 'fix-build-file-permissions', 'fix-line-endings' )(cb);
}
buildSequence.description = 'Sets up the build folder';
gulp.task( 'build', buildSequence );
function zipSequence(cb) {
return gulp.series( 'build', 'make-zip' )(cb);
}
zipSequence.description = 'Creates the zip file';
gulp.task( 'zip', zipSequence );