-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
98 lines (86 loc) · 2.79 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
const fs = require('fs');
const replace = require('gulp-replace');
const slash = require('slash');
const {dest, series, src, watch} = require('gulp');
const { buildDocfx } = require('igniteui-docfx-template');
const path = require('path');
const browserSync = require('browser-sync').create();
const argv = require('yargs').argv;
const LANG = argv.lang === undefined ? "en" : argv.lang;
const DOCFX_BASE = {
en: './en',
jp: './jp'
};
const DOCFX_PATH =`${DOCFX_BASE[LANG]}`;
const DOCFX_TEMPLATE_GLOBAL = slash(path.join(__dirname, 'node_modules', 'igniteui-docfx-template', 'template', 'bundling.global.json'));
const DOCFX_SITE = `${DOCFX_PATH}/_site`;
const buildSite = () => {
return buildDocfx({
siteDir: DOCFX_SITE,
projectDir: DOCFX_PATH,
environment: process.env.NODE_ENV ? process.env.NODE_ENV.trim() : null
});
}
const removeHTMLExtensionFromSiteMap = () => {
return src([DOCFX_SITE + '/sitemap.xml'])
.pipe(replace(/\.html/g, ''))
.pipe(dest(DOCFX_SITE));
};
const replaceEnvironmentVariables = () => {
const environment = process.env.NODE_ENV ? process.env.NODE_ENV.trim() : 'development';
const config = require(`./${LANG}/environment.json`);
return src(`${DOCFX_SITE}/**/*.html`)
.pipe(replace(/(\{|\%7B)environment:([a-zA-Z]+)(\}|\%7D)/g, function (match, brace1, environmentVarable, brace2) {
const value = config[environment][environmentVarable];
return value || match;
}))
.pipe(dest(DOCFX_SITE));
}
const watchFiles = (done) => {
watch([
`${DOCFX_TEMPLATE_GLOBAL}`,
`${DOCFX_PATH}/*.md`,
`${DOCFX_PATH}/app-themes/**/*`,
`${DOCFX_PATH}/flex-layouts/**/*`,
`${DOCFX_PATH}/generate-app/**/*`,
`${DOCFX_PATH}/indigo-design-components/**/*`,
`${DOCFX_PATH}/spa-and-navigation/**/*`,
`${DOCFX_PATH}/using-data-in-your-app/**/*`],
{delay: 3000},
series(build, browserSyncReload));
done();
}
const init = (done) => {
browserSync.init({
server: {
baseDir: `${DOCFX_SITE}`
},
notify: {
styles: {
top: 'auto',
bottom: '0',
margin: '0px',
padding: '5px',
position: 'fixed',
fontSize: '10px',
zIndex: '9999',
borderRadius: '5px 0px 0px',
color: 'white',
textAlign: 'center',
display: 'block',
backgroundColor: 'rgba(60, 197, 31, 0.498039)'
}
}
});
done();
};
const browserSyncReload = (done) => {
browserSync.reload();
done();
};
const build = series(
buildSite,
removeHTMLExtensionFromSiteMap,
replaceEnvironmentVariables);
exports.build = build;
exports.serve = series(build, init, watchFiles);