-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·181 lines (157 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var gulpif = require('gulp-if');
var concat = require('gulp-concat');
var concatCss = require('gulp-concat-css');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var argv = require('yargs').argv;
var del = require('del');
var gulpSequence = require('gulp-sequence').use(gulp);
var zip = require('gulp-zip');
var browserSync = require('browser-sync').create();
var symlink = require('gulp-symlink');
var php = require('gulp-connect-php');
var fs = require('fs');
var path = require('path');
var shell = require('gulp-shell');
require('dotenv').load();
var paths = {
'bower': './bower_components',
'assets': './assets',
'theme': './theme'
}
var configs = {
'port': 9000,
'dir': './theme'
}
var isProduction = (argv.yes === undefined) ? false : true;
var sassFoundation = {
includePaths: [
paths.bower + '/foundation-sites/scss'
]
};
if(isProduction) {
sassFoundation.outputStyle = 'compressed';
}
//Styles
gulp.task('styles', function() {
gulp.src(paths.assets + '/styles/foundation-sites/foundation-sites.scss')
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(plumber())
.pipe(sass(sassFoundation))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie >= 9', 'and_chr >= 2.3']
}))
.pipe(rename('foundation.css'))
.pipe(gulpif(!isProduction, sourcemaps.write('.')))
.pipe(gulp.dest(paths.theme + '/css'));
gulp.src(paths.assets + '/styles/main.scss')
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(plumber())
.pipe(sass(gulpif(isProduction, {outputStyle: 'compressed'})))
.pipe(autoprefixer({
browsers: ['last 10 versions'],
cascade: false
}))
.pipe(gulpif(!isProduction, sourcemaps.write('.')))
.pipe(gulp.dest(paths.theme + '/css'));
});
gulp.task('styles-watch', ['styles'], browserSync.reload);
//Scripts
gulp.task('scripts', function() {
gulp.src(paths.assets + '/scripts/main.js')
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(plumber())
.pipe(gulpif(isProduction, uglify()))
.pipe(gulpif(!isProduction, sourcemaps.write('.')))
.pipe(gulp.dest(paths.theme + '/js'));
gulp.src([
paths.bower + '/foundation-sites/js/foundation.core.js',
paths.bower + '/foundation-sites/js/util.*.js',
paths.bower + '/foundation-sites/js/*.js'
])
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(plumber())
.pipe(gulpif(isProduction, uglify()))
.pipe(concat('foundation.js'))
.pipe(gulpif(!isProduction, sourcemaps.write('.')))
.pipe(gulp.dest(paths.theme + '/js'));
gulp.src(paths.bower + '/what-input/what-input.js')
.pipe(gulpif(!isProduction, sourcemaps.init()))
.pipe(plumber())
.pipe(gulpif(isProduction, uglify()))
.pipe(gulpif(!isProduction, sourcemaps.write('.')))
.pipe(gulp.dest(paths.theme + '/js'));
});
gulp.task('scripts-watch', ['scripts'], browserSync.reload);
//Images
gulp.task('images', function () {
return gulp.src(paths.assets + '/images/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
}))
.pipe(gulp.dest(paths.theme + '/img'));
});
// PHP Server
gulp.task('serve', function() {
var serverConfig = {
base: 'public',
router: path.resolve('./public/router.php')
};
php.server(serverConfig, function (){
browserSync.init({
proxy: {
target: "localhost:8000",
reqHeaders: function (config) {
return {
"host":"localhost:" + configs.port
}
}
},
port: configs.port,
open: true,
watchTask: true,
snippetOptions: {
whitelist: ['/wordpress/wp-admin/admin-ajax.php'],
blacklist: ['/wordpress/wp-admin']
}
});
});
gulp.watch(paths.assets + '/styles/**/*.scss', ['styles-watch']);
gulp.watch(paths.assets + '/scripts/**/*.js', ['scripts-watch']);
gulp.watch('theme/**/*.php').on('change', function () {
browserSync.reload();
});
});
// Symblink of themes inside the content
gulp.task('theme-symblink', function () {
var themePath = 'public/content/themes/' + process.env.THEME_NAME;
fs.lstat(themePath, function(err, stat){
// Create symlink only if not exists
if(stat == 'undefined' || err) {
return gulp.src('theme').pipe(symlink(themePath)).pipe(shell(['vendor/bin/wp theme activate ' + process.env.THEME_NAME + ' --path="'+ path.resolve('./public/wordpress') +'"']));
} else {
return console.log('Symlink exists!');
}
});
});
//Clean Task
gulp.task('clean', function() {
del([paths.theme + '/js/**', '!' + paths.theme + '/js', paths.theme + '/css/**', '!' + paths.theme + '/css' ])
});
//Zip Task
gulp.task('zip', function() {
gulp.src(paths.theme + '/**')
.pipe(zip('morph.zip'))
.pipe(gulp.dest(paths.theme));
})
//Production Task
gulp.task('production', gulpSequence('clean', ['styles', 'scripts']));
//Default Task
gulp.task('default', ['styles', 'scripts', 'images', 'theme-symblink', 'serve']);