-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
132 lines (118 loc) · 3.24 KB
/
gulpfile.js
File metadata and controls
132 lines (118 loc) · 3.24 KB
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
// Include Gulp and all required plugins
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var postcss = require('gulp-postcss');
var gutil = require('gulp-util');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var handlebars = require('gulp-compile-handlebars');
var header = require('gulp-header');
var uglify = require('gulp-uglify');
var del = require('del');
var pkg = require('./package.json');
var templateData = require('./views/social_popups.json');
var pump = require('pump');
var zip = require('gulp-zip');
gulp.task('compress', function(cb) {
pump([
gulp.src('lib/*.js'),
uglify(),
gulp.dest('dist')
],
cb
);
});
templateData.plugin = "Social Popups"
templateData.plug = templateData.plugin.split(' ').join('-');
templateData.slug = templateData.plug.toLowerCase();
templateData.widget = templateData.slug.split('-').join('');
templateData.class = "social-share";
templateData.prefix = 'sc-';
templateData.size = '20px';
templateData.height = '570';
templateData.width = '570';
/* Prepare banner text */
var banner = ['/**',
' * <%= pkg.name %>',
' * v<%= pkg.version %>',
' * <%= pkg.author %>',
' * <%= pkg.repository.url %>',
' */',
''
].join('\n');
/* Prepare PHP banner text */
var banner2 = ['<?php',
'/**',
'Plugin Name: <%= pkg.name %>',
'Plugin URI: <%= pkg.repository.url %>',
'Description: <%= pkg.description %>',
'Version: <%= pkg.version %>',
'Author: <%= pkg.author %>',
'License: <%= pkg.license %>',
' */',
'?>',
''
].join('\n');
/**
* Clean compiled files.
*/
gulp.task('clean:styles', function() {
return del(['./pre/*.css', './branded/*.css', './inlined/*.css', './dist/*.css'])
});
gulp.task("branded", ['gen'], function() {
var processors = [
require("postcss-brand-colors")
];
return gulp.src("./pre/*.css")
.pipe(postcss(processors))
.pipe(gulp.dest('./branded'));
});
gulp.task("inline", ['branded'], function() {
var processors = [
require("postcss-inline-svg")
];
return gulp.src("./branded/*.css")
.pipe(postcss(processors))
.pipe(gulp.dest('./inlined'));
});
gulp.task("dist", ['inline', 'source'], function() {
var processors = [
require("postcss-svgo"),
require("postcss-ordered-values"),
require("postcss-merge-longhand")
];
return gulp.src("./inlined/*.css")
.pipe(postcss(processors))
.pipe(gulp.dest('./dist'))
.pipe(cleanCSS())
.pipe(header(banner, { pkg: pkg }))
.pipe(gulp.dest(templateData.slug+'/css'));
});
gulp.task('gen', function() {
return gulp.src(['views/*'])
.pipe(handlebars(templateData))
.pipe(rename(function(path) {
path.extname = path.extname.replace('.hbs', '');
}))
.pipe(gulp.dest('pre/'));
});
gulp.task('source', ['gen'], function() {
return gulp.src(['pre/*.php'])
.pipe(header(banner2, { pkg: pkg }))
.pipe(gulp.dest(templateData.slug+'/views'))
});
gulp.task('compress', ['dist'], function(cb) {
pump([
gulp.src('pre/widget.js'),
uglify(),
gulp.dest(templateData.slug+'/js')
],
cb
);
});
gulp.task('zip',['compress'], function(){
return gulp.src(templateData.slug+'/**/*')
.pipe(zip(templateData.slug+'.zip'))
.pipe(gulp.dest('./'))
});
gulp.task('default', [ 'dist']);