This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
index.js
179 lines (157 loc) · 4.62 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* 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');
const pa11y = require('./gulp-tasks/pa11y');
// eslint-disable-next-line no-redeclare, no-var
var config = _.defaultsDeep(config, defaultConfig);
// 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: [],
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', 'minify'],
})
)
.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([
imagemin.jpegtran({ progressive: true }),
imagemin.svgo({
plugins: [{ removeViewBox: false }, { cleanupIDs: false }, { removeTitle: false }],
}),
])
)
.pipe(gulp.dest(file => file.base));
});
tasks.compile.push('imagemin');
/**
* Task for generating icon colors/png fallbacks from svg.
*/
gulp.task('icons', () => {
gulp
.src('**/*.svg', { cwd: `${config.paths.icons}` })
.pipe(svgSprite(config.iconConfig))
.pipe(gulp.dest('.'));
});
tasks.compile.push('icons');
// Find open port using portscanner.
let openPort = '';
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', (error, port) => {
openPort = port;
});
// Pattern Lab
require('./gulp-tasks/gulp-pattern-lab.js')(gulp, config, tasks, browserSync, openPort);
/**
* Task for running browserSync.
*/
gulp.task('serve', ['css', 'scripts', 'watch:pl'], () => {
if (config.browserSync.domain) {
browserSync.init({
injectChanges: true,
open: config.browserSync.openBrowserAtStart,
proxy: config.browserSync.domain,
startPath: config.browserSync.startPath,
ghostMode: config.browserSync.ghostMode
});
} 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,
ghostMode: config.browserSync.ghostMode
});
}
gulp.watch(config.paths.js, ['scripts']);
gulp.watch(`${config.paths.sass}/**/*.scss`, ['css']).on('change', (event) => {
pa11y.pa11yTest(event.path, browserSync, config);
});
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('validate', tasks.validate);
gulp.task('watch', tasks.watch);
tasks.default.push('watch');
gulp.task('default', tasks.default);
/**
* Theme task declaration
*/
gulp.task('build', ['compile', 'scripts', 'css']);
/**
* Deploy
*/
gulp.task('createBuild', () => {
gulp
.src(
[
`${config.paths.dist_js}/**/*`,
`${config.paths.pattern_lab}/**/*`,
`${config.paths.theme_images}/**/*`,
`!${config.paths.theme_images}/{icons,icons/**/*}`,
`${config.paths.logo}`,
`${config.themeDir}/CNAME`,
],
{ base: config.themeDir }
)
.pipe(gulp.dest('build'));
});
gulp.task('githubPublish', () => {
// Publish the build directory to github pages.
ghpages.publish(`${config.themeDir}build`, (err) => {
if (err === undefined) {
// eslint-disable-next-line no-console
console.log('Successfully deployed!');
} else {
// eslint-disable-next-line no-console
console.log(err);
}
});
});
gulp.task('ghpages-deploy', ['createBuild', 'githubPublish']);
};