forked from LearnPress/learnpress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGulpfile.js
169 lines (147 loc) · 5.2 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
/**
* Gulp tasks
*
* 1/ Run "npm install gulp -g" if you did not run it any time in the past.
* 2/ Run "npm install gulp --save-dev" to install gulp in your project directory.
* 3/ Run "npm install package-name[ package-name...] --save-dev
*
* EX: npm install gulp-zip gulp-copy gulp-clean gulp-sass gulp-livereload gulp-sourcemaps read-file gulp-replace mkdirp gulp-concat gulp-uglify pump --save-dev
*/
'use strict';
const zip = require('gulp-zip');
var gulp = require('gulp'),
gulpCopy = require('gulp-copy'),
clean = require('gulp-clean'),
scss = require('gulp-sass'),
liveReload = require('gulp-livereload'),
sourceMaps = require('gulp-sourcemaps'),
readFile = require('read-file'),
replace = require('gulp-replace'),
mkdirp = require("mkdirp"),
concat = require('gulp-concat'),
cleanCSS = require('gulp-clean-css');
gulp.task('scss', function () {
return gulp.src(['assets/scss/**/*.scss'])
.pipe(sourceMaps.init())
.pipe(scss())
.pipe(sourceMaps.write())
.pipe(gulp.dest('assets/css'))
.pipe(liveReload());
});
gulp.task('watch', function () {
liveReload.listen();
gulp.watch(['assets/scss/**/*.scss'], ['scss']);
gulp.watch(['assets/js/admin/utils/*.js'], ['compress-js']);
});
gulp.task('default', ['scss', 'watch', 'compress-js']);
var uglify = require('gulp-uglify');
var pump = require('pump');
gulp.task('compress-js', function (cb) {
return gulp.src('assets/js/admin/utils/*.js')
.pipe(concat('utils.js'))
.pipe(uglify())
.pipe(gulp.dest('assets/js/admin'))
});
gulp.task('minify-css', function () {
return gulp.src('./assets/**/*.css')
.pipe(cleanCSS())
.pipe(gulp.dest('./assets'));
});
/*
* SVN: Copy working directory to SVN and prepare something before submitting.
*/
var rootPath = '/Users/tu/Documents/foobla',
svnPath = rootPath + '/svn/learnpress',
releasePath = rootPath + '/releases/learnpress',
svnTrunkPath = svnPath + '/trunk',
svnTagsPath = svnPath + '/tags',
currentVer = null,
copySvnFiles = [
'assets/**/*',
'dummy-data/**/*',
'inc/**/*',
'languages/**/*',
'templates/**/*',
'index.php',
'learnpress.php'
],
getCurrentVer = function (force) {
if (currentVer === null || force === true) {
currentVer = readFile.sync('learnpress.php', {encoding: 'utf8'}).match(/Version:\s*(.*)/);
currentVer = currentVer ? currentVer[1] : null;
}
return currentVer;
},
updateReadme = function (version, callback) {
return gulp.src(['readme.txt'])
.pipe(replace(/Stable tag: (.*)/g, 'Stable tag: ' + version))
.pipe(gulp.dest(svnTrunkPath, {overwrite: true}))
.on('end', function () {
callback ? callback() : 'do nothing';
});
};
// Clear trunk/tag path
gulp.task('clr-tag', function () {
return gulp.src(svnTagsPath + '/' + getCurrentVer() + '/', {read: false}).pipe(clean({force: true}));
});
gulp.task('clr-trunk', function () {
return gulp.src(svnTrunkPath + '/', {read: false}).pipe(clean({force: true}));
});
// Copy working dir to trunk
gulp.task('copy-trunk', ['clr-trunk'], function () {
mkdirp(svnTrunkPath);
return gulp.src(copySvnFiles).pipe(gulpCopy(svnTrunkPath));
});
// Copy trunk to current tag
gulp.task('copy-tag', ['clr-tag'], function () {
var tagPath = svnTagsPath + '/' + getCurrentVer();
mkdirp(tagPath);
process.chdir(svnTrunkPath);
var copyFiles = copySvnFiles;
copyFiles.push('readme.txt');
return gulp.src(copyFiles).pipe(gulpCopy(tagPath));
});
gulp.task('clr-release', function () {
return gulp.src(releasePath + '/', {read: false}).pipe(clean({force: true}));
});
gulp.task('copy-release', ['clr-release'], function () {
mkdirp(releasePath);
process.chdir(svnTrunkPath);
var copyFiles = copySvnFiles;
copyFiles.push('readme.txt');
return gulp.src(copyFiles).pipe(gulpCopy(releasePath));
});
gulp.task('release', ['copy-release'], function () {
process.chdir(releasePath);
var zipPath = releasePath.replace(/learnpress/, '');
return gulp.src(zipPath + '/**/learnpress/**/*')
.pipe(zip('learnpress.' + getCurrentVer(true) + '.zip'))
.pipe(gulp.dest(zipPath));
});
// main task
gulp.task('svn', ['scss', 'copy-trunk'], function () {
updateReadme(getCurrentVer(true), function () {
return gulp.start('release', ['copy-tag']);
})
});
// Create zipped version
gulp.task('clr-zip', function () {
return gulp.src(releasePath + '/', {read: false}).pipe(clean({force: true}));
});
gulp.task('copy-zip', ['clr-zip'], function () {
mkdirp(releasePath);
//process.chdir(svnTrunkPath);
var copyFiles = copySvnFiles;
copyFiles.push('readme.txt');
return gulp.src(copyFiles).pipe(gulpCopy(releasePath));
});
gulp.task('mk-zip', ['copy-zip'], function () {
process.chdir(releasePath);
var zipPath = releasePath.replace(/learnpress/, '');
return gulp.src(zipPath + '/**/learnpress/**/*')
.pipe(zip('learnpress.' + getCurrentVer(true) + '.zip'))
.pipe(gulp.dest(zipPath));
});
gulp.task('zip', ['mk-zip'], function () {
})
// end of the world!