-
Notifications
You must be signed in to change notification settings - Fork 24
/
gulpfile.js
249 lines (223 loc) · 8.41 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
const fs = require('fs');
const replace = require('gulp-replace');
const fileinclude = require('gulp-file-include');
const slash = require('slash');
const { dest, series, src, watch, parallel } = 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',
kr: './kr'
};
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 DOCFX_ARTICLES = `${DOCFX_PATH}/components`;
const gridsConfigs = {
grid: {
igPath: '/grid',
igMainTopic: 'grid',
igObjectRef: "grid",
igDemoBasePath: "grid",
igComponent: "Grid",
igxName: "IgxGrid",
igTypeDoc: "igxgridcomponent",
igSelector: "igx-grid"
},
treeGrid: {
igPath: '/treegrid',
igMainTopic: 'tree-grid',
igObjectRef: "treeGrid",
igDemoBasePath: "tree-grid",
igComponent: "Tree Grid",
igxName: "IgxTreeGrid",
igTypeDoc: "igxtreegridcomponent",
igSelector: "igx-tree-grid"
},
hierarchicalGrid: {
igPath: '/hierarchicalgrid',
igMainTopic: 'hierarchical-grid',
igObjectRef: "hierarchicalGrid",
igDemoBasePath: "hierarchical-grid",
igComponent: "Hierarchical Grid",
igxName: "IgxHierarchicalGrid",
igTypeDoc: "igxhierarchicalgridcomponent",
igSelector: "igx-hierarchical-grid"
},
pivotGrid: {
igPath: "/pivotGrid",
igMainTopic: "pivot-grid",
igObjectRef: "pivotGrid",
igDemoBasePath: "pivot-grid",
igComponent: "Pivot Grid",
igxName: "IgxPivotGrid",
igTypeDoc: "igxpivotgridcomponent",
igSelector: "igx-pivot-grid"
}
};
const fileInclude = (grid) => {
return src(DOCFX_ARTICLES + '/grids_templates/*.md')
.pipe(fileinclude({
prefix: '@@',
basepath: '@file',
context: {
"igMainTopic": grid.igMainTopic,
"igObjectRef": grid.igObjectRef,
"igDemoBasePath": grid.igDemoBasePath,
"igComponent": grid.igComponent,
"igxName": grid.igxName,
"igTypeDoc": grid.igTypeDoc,
"igSelector": grid.igSelector
}
}))
.pipe(replace(/^\s*\n(?=\S)/, ''))
.pipe(dest(DOCFX_ARTICLES + grid.igPath));
}
const generateGridsTopics = () => {
return fileInclude(gridsConfigs.grid);
};
const generateTreeGridsTopics = () => {
return fileInclude(gridsConfigs.treeGrid);
};
const generateHierarchicalGridsTopics = () => {
return fileInclude(gridsConfigs.hierarchicalGrid);
};
const generatePivotGridsTopics = () => {
return fileInclude(gridsConfigs.pivotGrid);
};
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) => {
const excluded = [
`!${DOCFX_ARTICLES}/grid/**`,
`!${DOCFX_ARTICLES}/treegrid/**`,
`!${DOCFX_ARTICLES}/hierarchicalgrid/**`
];
// All topics that are not auto-generated and are specific to the respective grid, should be here.
const included = [
`${DOCFX_ARTICLES}/grid/grid.md`,
`${DOCFX_ARTICLES}/grid/groupby.md`,
`${DOCFX_ARTICLES}/grid/paste-excel.md`,
`${DOCFX_ARTICLES}/grid/master-detail.md`,
`${DOCFX_ARTICLES}/grid/selection-based-aggregates.md`,
`${DOCFX_ARTICLES}/treegrid/tree-grid.md`,
`${DOCFX_ARTICLES}/treegrid/groupby.md`,
`${DOCFX_ARTICLES}/treegrid/load-on-demand.md`,
`${DOCFX_ARTICLES}/hierarchicalgrid/hierarchical-grid.md`,
`${DOCFX_ARTICLES}/hierarchicalgrid/load-on-demand.md`,
`${DOCFX_ARTICLES}/pivotGrid/pivot-grid.md`,
`${DOCFX_ARTICLES}/pivotGrid/pivot-grid-features.md`,
`${DOCFX_ARTICLES}/pivotGrid/pivot-grid-custom.md`
];
// watch([`${DOCFX_TEMPLATE}/**/*`, `!${DOCFX_TEMPLATE}/styles/css`], series(build));
watch([
`${DOCFX_TEMPLATE_GLOBAL}`,
`${DOCFX_PATH}/components/*.md`,
`${DOCFX_PATH}/general/**/*.md`,
`${DOCFX_PATH}/themes/*.md`,
`${DOCFX_ARTICLES}/**`].concat(excluded).concat(included),
{delay: 3000, queue: false},
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(
parallel(generateGridsTopics, generateTreeGridsTopics, generateHierarchicalGridsTopics, generatePivotGridsTopics),
buildSite, removeHTMLExtensionFromSiteMap, replaceEnvironmentVariables);
const buildCI = series(generateGridsTopics, generateTreeGridsTopics, generateHierarchicalGridsTopics, generatePivotGridsTopics, buildSite);
const copyGitHooks = async (cb) => {
if (process.env.AZURE_PIPELINES || process.env.TRAVIS || process.env.CI || !(await exists('.git'))) {
return;
}
const gitHooksDir = path.join('.git', 'hooks');
const defaultCopyHookDir = path.join(gitHooksDir, 'scripts');
const dirs = [
gitHooksDir,
defaultCopyHookDir,
path.join(defaultCopyHookDir, 'templates'),
path.join(defaultCopyHookDir, 'templateValidators'),
path.join(defaultCopyHookDir, 'utils')
];
try {
for (const dir of dirs) {
if (!(await exists(dir))) {
await fs.mkdir(dir, { recursive: true });
}
}
const defaultHookDir = path.join('.hooks', 'scripts');
await fs.copyFile(path.join(defaultHookDir, 'templates', 'default.js'), path.join(defaultCopyHookDir, 'templates', 'default.js'));
await fs.copyFile(path.join(defaultHookDir, 'templateValidators', 'default-style-validator.js'), path.join(defaultCopyHookDir, 'templateValidators', 'default-style-validator.js'));
await fs.copyFile(path.join(defaultHookDir, 'utils', 'issue-validator.js'), path.join(defaultCopyHookDir, 'utils', 'issue-validator.js'));
await fs.copyFile(path.join(defaultHookDir, 'utils', 'line-limits.js'), path.join(defaultCopyHookDir, 'utils', 'line-limits.js'));
await fs.copyFile(path.join(defaultHookDir, 'common.js'), path.join(defaultCopyHookDir, 'common.js'));
await fs.copyFile(path.join(defaultHookDir, 'validate.js'), path.join(defaultCopyHookDir, 'validate.js'));
await fs.copyFile(path.join('.hooks', 'prepare-commit-msg'), path.join(gitHooksDir, 'prepare-commit-msg'));
await cb();
} catch (err) {
console.error('Error copying git hooks:', err);
throw err;
}
};
const exists = async (path) => {
try {
await fs.access(path);
return true;
} catch {
return false;
}
};
exports.buildCI = buildCI;
exports.build = build;
exports.serve = series(build, init, watchFiles);
exports.copyGitHooks = copyGitHooks;