This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
gulpfile.js
167 lines (150 loc) · 5.37 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
/**
* @fileoverview Primary gulp file.
*/
'use strict';
const del = require('del');
const gulp = require('gulp');
const chalk = require('chalk');
const gutil = require('gulp-util');
const minimist = require('minimist');
const requireDir = require('require-dir');
requireDir('./gulp-tasks');
requireDir('./gulp-tasks/workbox');
requireDir('./gulp-tasks/puppeteer');
gutil.log('---------------------------------');
gutil.log(`${chalk.dim('Web')}${chalk.bold('Fundamentals')} Gulp`);
gutil.log('---------------------------------');
/** ***************************************************************************
* Global config
*****************************************************************************/
global.WF = {
gae: 'appengine-config',
src: {
content: 'src/content/en/',
data: 'src/data/',
templates: 'src/templates/',
},
maxArticlesInFeed: 10,
minFeedDate: 2010,
langs: [
'en', 'ar', 'de', 'es', 'fr', 'he', 'hi', 'id', 'it', 'ja',
'ko', 'nl', 'pl', 'pt-br', 'ru', 'th', 'tr', 'vi', 'zh-cn', 'zh-tw',
],
};
/** ***************************************************************************
* Default options
*****************************************************************************/
const defaultOptions = {
boolean: ['buildRSS', 'verbose', 'testAll', 'testTests', 'testWarnOnly'],
string: ['lang', 'buildType'],
default: {
lang: null,
verbose: false,
buildRSS: false,
buildType: 'dev',
testAll: false,
testTests: false,
testWarnOnly: false,
},
};
/** ***************************************************************************
* Argument Parser
*****************************************************************************/
// Parse arguments using minimist
global.WF.options = minimist(process.argv.slice(2), defaultOptions);
// What languages should it handle
if (global.WF.options.lang) {
const langs = global.WF.options.lang.split(',');
langs.forEach(function(lang) {
if (global.WF.langs.indexOf(lang) === -1) {
const msg = `Language ${chalk.red(lang)} not supported.`;
gutil.log(' ', chalk.red('ERROR:'), msg);
process.exit(1);
}
});
global.WF.options.lang = langs;
gutil.log('Language: ', gutil.colors.cyan(global.WF.options.lang));
} else {
global.WF.options.lang = global.WF.langs;
}
// Build RSS
gutil.log('Build RSS Files:', gutil.colors.cyan(global.WF.options.buildRSS));
// Show verbose output
if (global.WF.options.verbose) {
gutil.log('Verbose: ', gutil.colors.cyan(global.WF.options.verbose));
}
// Test all files
if (global.WF.options.testAll) {
gutil.log('testAll:', chalk.cyan('true'));
}
// Test test files
if (global.WF.options.testTests) {
gutil.log('testTests:', chalk.cyan('true'));
}
// Warn only, no errors
if (global.WF.options.testWarnOnly) {
gutil.log('testWarnOnly: ', gutil.colors.cyan('true'));
}
gutil.log('');
/** ***************************************************************************
* Gulp Tasks
*****************************************************************************/
/**
* Cleans any generated files.
*/
gulp.task('clean', function() {
const filesToDelete = [
'test-results.json',
'src/content/en/_shared/contributors/*',
'src/content/en/_shared/latest_*.html',
'src/content/**/rss.xml',
'src/content/**/atom.xml',
'src/content/**/_files.json',
'src/content/*/_index-latest-*.html',
'src/content/en/sitemap.xml',
'src/content/*/fundamentals/glossary.md',
'src/content/*/resources/contributors/*',
'src/content/*/showcase/_index.yaml',
'src/content/*/showcase/*/_toc.yaml',
'src/content/*/showcase/*/index.md',
'src/content/*/showcase/tags/*',
'src/content/*/shows/_index.yaml',
'src/content/*/shows/index.md',
'src/content/*/shows/**/feed.xml',
'src/content/*/shows/http203/podcast/index.md',
'src/content/*/shows/designer-vs-developer/podcast/index.md',
'src/content/*/tools/puppeteer/_src',
'src/content/*/updates/_index.yaml',
'src/content/*/updates/*/index.md',
'src/content/*/updates/20??/_toc.yaml',
'src/content/*/updates/tags/*',
'src/data/codelabs/*/*.md',
'src/data/codelabs/*/img/**',
'src/data/ilt-pwa/*/*.md',
'src/data/ilt-pwa/*/img/**',
'!src/content/*/**/_generated.md',
];
const opts = {dryRun: false, dot: true};
const deletedFiles = del.sync(filesToDelete, opts);
gutil.log(' ', 'Deleted', chalk.magenta(deletedFiles.length + ' files'));
});
/**
* Shows help.
*/
gulp.task('default', function(cb) {
gutil.log(chalk.red('ERROR:'), 'no command specified.');
gutil.log('Usage: gulp <command> [arguments]');
gutil.log(' ', 'Commands:');
gutil.log(' ', chalk.cyan('build'), 'Builds all auto-generated files');
gutil.log(' ', chalk.cyan('clean'), 'Removes all auto-generated files');
gutil.log(' ', chalk.cyan('test'), 'Checks the files for any issues');
gutil.log(' ', 'Optional Arguments:');
const langDesc = 'Comma separated list of languages to use';
const langExamp = chalk.gray('eg: --lang=en,fr');
gutil.log(' ', chalk.cyan('--lang'), langDesc, langExamp);
gutil.log(' ', chalk.cyan('--buildRSS'), 'Build RSS/ATOM files');
gutil.log(' ', chalk.cyan('--verbose'), 'Log with verbose output');
gutil.log(' ', chalk.cyan('--testAll'), 'Test all files, not just open');
gutil.log(' ', chalk.cyan('--testTests'), 'Test the test files');
gutil.log(' ', chalk.cyan('--testWarnOnly'), 'Only throw warnings');
});