-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
92 lines (85 loc) · 2.46 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cssnano = require('gulp-cssnano');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const del = require('del');
const copy = require('copy');
const zip = require('gulp-zip');
const fs = require('fs-extra');
const replace = require('gulp-replace');
// vars
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};
var config = JSON.parse(fs.readFileSync('./package.json'));
var projectVersion = config.version;
var projectName = config.name.capitalize();
// generate css
function css() {
return gulp
.src(['./*.scss', '!./_*.scss'])
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist'));
}
// generate comporessed css
function minCss() {
return gulp
.src(['./*.scss', '!./_*.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(cssnano())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./dist'));
}
// update plugin version
function updateVersion() {
return gulp
.src('./Plugin.php')
.pipe(replace("/return '.*?'/g", "return '" + projectVersion + "'"))
.pipe(gulp.dest('./'));
}
// dev task
exports.dev = gulp.series(
function(cb) {
del.sync(['../../dist/wwwroot/kanban.me/plugins/' + projectName], {force: true});
cb();
},
gulp.parallel(css, minCss, updateVersion),
function(cb) {
copy(['./Plugin.php'], '../../dist/wwwroot/kanban.me/plugins/' + projectName, cb);
}
);
// build task
exports.build = gulp.series(
function(cb) {
del.sync(['./dist']);
cb();
},
gulp.parallel(css, minCss, updateVersion),
function(cb) {
copy(['./Plugin.php'], './dist', cb);
}
);
// publish task
exports.publish = gulp.series(
function(cb) {
// fs.ensureDirSync(spectreFolderPath);
del.sync('./dist/*.zip');
fs.copy('./dist', './publish/' + projectName, {overwrite: true}, cb);
},
function() {
return gulp
.src(['./publish/**'])
.pipe(zip(projectName + '-' + projectVersion + '.zip'))
.pipe(gulp.dest('./dist'));
},
function(cb) {
del.sync('./publish');
cb();
}
);