forked from fourkitchens/emulsify-gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
165 lines (144 loc) · 4.44 KB
/
index.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
/* globals require */
module.exports = (gulp, config) => {
// General
// eslint-disable-next-line no-redeclare, no-var
var gulp = require('gulp-help')(gulp);
const _ = require('lodash');
const portscanner = require('portscanner');
const browserSync = require('browser-sync').create();
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const defaultConfig = require('./gulp-config');
// eslint-disable-next-line no-redeclare, no-var
var config = _.defaultsDeep(config, defaultConfig);
// scripts
const concat = require('gulp-concat');
// Image Minification
const imagemin = require('gulp-imagemin');
// icons
const svgSprite = require('gulp-svg-sprite');
// deploy
const ghpages = require('gh-pages');
const tasks = {
compile: [],
watch: [],
validate: [],
clean: [],
default: [],
};
// SCSS/CSS
require('./gulp-tasks/gulp-css.js')(gulp, config, tasks, browserSync);
// Tests
require('./gulp-tasks/gulp-tests.js')(gulp, config, tasks);
/**
* Script Task
*/
gulp.task('scripts', () => {
gulp.src(config.paths.js)
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['env'],
}))
.pipe(sourcemaps.write(config.themeDir))
.pipe(gulp.dest(config.paths.dist_js));
});
gulp.task('styleguide-scripts', () => {
gulp.src(config.paths.js)
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['env'],
}))
// Concatenate everything within the JavaScript folder.
.pipe(concat('scripts-styleguide.js'))
.pipe(sourcemaps.write(config.themeDir))
.pipe(gulp.dest(config.paths.dist_js));
});
/**
* Task for minifying images.
*/
gulp.task('imagemin', () => {
gulp.src(`${config.paths.img}/**/*`)
.pipe(imagemin({
progressive: true,
svgoPlugins: [
{ removeViewBox: false },
{ cleanupIDs: false },
],
}))
.pipe(gulp.dest(config.paths.dist_img));
});
/**
* Task for generating icon colors/png fallbacks from svg.
*/
gulp.task('icons', () => {
gulp.src('**/*.svg', { cwd: `${config.paths.img}/icons/src` })
.pipe(svgSprite(config.iconConfig))
.pipe(gulp.dest(`${config.themeDir}/images/icons`));
});
tasks.compile.push('icons');
// Pattern Lab
require('./gulp-tasks/gulp-pattern-lab.js')(gulp, config, tasks, browserSync);
// Find open port using portscanner.
let openPort = '';
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', (error, port) => {
openPort = port;
});
/**
* Task for running browserSync.
*/
gulp.task('serve', ['css', 'scripts', 'styleguide-scripts', 'watch:pl'], () => {
if (config.browserSync.domain) {
browserSync.init({
injectChanges: true,
open: config.browserSync.openBrowserAtStart,
proxy: config.browserSync.domain,
startPath: config.browserSync.startPath,
});
} else {
browserSync.init({
injectChanges: true,
server: {
baseDir: config.browserSync.baseDir,
},
startPath: config.browserSync.startPath,
notify: config.browserSync.notify,
ui: config.browserSync.ui,
open: config.browserSync.openBrowserAtStart,
reloadOnRestart: config.browserSync.reloadOnRestart,
port: openPort,
});
}
gulp.watch(config.paths.js, ['scripts', 'styleguide-scripts']).on('change', browserSync.reload);
gulp.watch(`${config.paths.sass}/**/*.scss`, ['css']);
gulp.watch(config.patternLab.scssToYAML[0].src, ['pl:scss-to-yaml']);
});
/**
* Theme task declaration
*/
gulp.task('theme', ['serve']);
gulp.task('compile', tasks.compile);
gulp.task('clean', tasks.clean);
gulp.task('validate', tasks.validate);
gulp.task('watch', tasks.watch);
tasks.default.push('watch');
gulp.task('default', tasks.default);
/**
* Theme task declaration
*/
gulp.task('build', ['imagemin', 'clean', 'scripts', 'styleguide-scripts', 'css', 'icons']);
/**
* Deploy
*/
gulp.task('ghpages-deploy', () => {
// Create build directory.
gulp.src([`${config.paths.dist_js}/**/*`, `${config.paths.pattern_lab}/**/*`], { base: config.themeDir }).pipe(gulp.dest('build'));
// Publish the build directory to github pages.
ghpages.publish(`${config.themeDir}build`, (err) => {
if (err === undefined) {
console.log('Successfully deployed!');
} else {
console.log(err);
}
});
});
};