forked from IgniteUI/igniteui-docfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
205 lines (183 loc) · 6.13 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
const path = require('path');
const del = require('del');
const {dest, series, src, watch, parallel} = require('gulp');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const argv = require('yargs').argv;
const fs = require('fs');
const environmentVariablesPreConfig = require('./node_modules/igniteui-docfx-template/post-processors/PostProcessors/EnvironmentVariables/preconfig.json');
const fileinclude = require('gulp-file-include');
const slash = require("slash");
const { exec, spawnSync } = require('child_process');
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_CONF = `${DOCFX_PATH}/docfx.json`;
const DOCFX_TEMPLATE = slash(path.join(__dirname, 'node_modules', 'igniteui-docfx-template', 'template'));
const DOCFX_SITE = `${DOCFX_PATH}/_site`;
const DOCFX_ARTICLES = `${DOCFX_PATH}/components`;
const gridsConfigs = {
grid: {
igPath: '/grid',
igMainTopic: 'grid',
igObjectRef: "grid",
igComponent: "Grid",
igxName: "IgxGrid",
igTypeDoc: "igxgridcomponent",
igSelector: "igx-grid"
},
treeGrid: {
igPath: '/treegrid',
igMainTopic: 'tree_grid',
igObjectRef: "treeGrid",
igComponent: "Tree Grid",
igxName: "IgxTreeGrid",
igTypeDoc: "igxtreegridcomponent",
igSelector: "igx-tree-grid"
},
hierarchicalGrid: {
igPath: '/hierarchicalgrid',
igMainTopic: 'hierarchical_grid',
igObjectRef: "hierarchicalGrid",
igComponent: "Hierarchical Grid",
igxName: "IgxHierarchicalGrid",
igTypeDoc: "igxhierarchicalgridcomponent",
igSelector: "igx-hierarchical-grid"
}
};
const cleanup = () => {
return del(`${DOCFX_SITE}`);
};
const environmentVariablesConfig = (done) => {
var environmentVariablesConfig = JSON.parse(JSON.stringify(environmentVariablesPreConfig));
if (process.env.NODE_ENV) {
environmentVariablesConfig.environment = process.env.NODE_ENV.trim();
}
environmentVariablesConfig.variables =
environmentVariablesConfig.variables[LANG.toLowerCase().trim()][
environmentVariablesConfig.environment
];
if (!fs.existsSync(`${DOCFX_SITE}`)) {
fs.mkdirSync(`${DOCFX_SITE}`);
}
fs.writeFileSync(
`${DOCFX_SITE}/${environmentVariablesConfig._configFileName}`,
JSON.stringify(environmentVariablesConfig)
);
done();
};
const fileInclude = (grid) => {
return src([DOCFX_ARTICLES + '/grids_templates/*.md'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file',
context: {
"igMainTopic": grid.igMainTopic,
"igObjectRef": grid.igObjectRef,
"igComponent": grid.igComponent,
"igxName": grid.igxName,
"igTypeDoc": grid.igTypeDoc,
"igSelector": grid.igSelector
}
}))
.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 styles = () => {
return src(`${DOCFX_TEMPLATE}/styles/sass/main.scss`)
.pipe(sass().on('error', sass.logError))
.pipe(
autoprefixer({
overrideBrowserslist: ['last 2 versions'],
cascase: false
})
)
.pipe(dest(`${DOCFX_TEMPLATE}/styles/css`));
};
const buildSite = (done) => {
exec(`docfx build ${DOCFX_CONF}`, (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
done(err);
});
};
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}/treegrid/tree_grid.md`,
`${DOCFX_ARTICLES}/treegrid/aggregations.md`,
`${DOCFX_ARTICLES}/treegrid/load_on_demand.md`,
`${DOCFX_ARTICLES}/hierarchicalgrid/hierarchical_grid.md`,
`${DOCFX_ARTICLES}/hierarchicalgrid/load_on_demand.md`
];
// watch([`${DOCFX_TEMPLATE}/**/*`, `!${DOCFX_TEMPLATE}/styles/css`], series(build));
watch([
`${DOCFX_TEMPLATE}/**/*`,
`!${DOCFX_TEMPLATE}/styles/css/main.css`,
`${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 postProcessorConfigs = series(cleanup, environmentVariablesConfig);
const build = series(
styles,
postProcessorConfigs,
parallel(generateGridsTopics, generateTreeGridsTopics, generateHierarchicalGridsTopics),
buildSite);
const buildTravis = series(styles, postProcessorConfigs, generateGridsTopics);
exports.buildTravis = buildTravis;
exports.build = build;
exports.serve = series(build, init, watchFiles);