-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgulpfile.js
366 lines (339 loc) · 11.2 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
const {dest, parallel, series, src} = require('gulp');
const print = require('gulp-print').default;
const replace = require('gulp-replace');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const fs = require('fs-extra');
const path = require('path');
const log = require('fancy-log');
const shell = require('shelljs');
// Task to git clone and build the component packages to retrieve build artifacts.
const retrieveAssets = async () => {
const assetsPath = path.resolve(__dirname, 'gulp-assets');
const packages = [
'dash-core-components',
'dash-html-components',
'dash-table',
'dash-bootstrap-components',
];
shell.cd(assetsPath);
shell.exec('git clone --single-branch --branch fix-prop-order https://github.com/plotly/dash');
shell.exec(
'git clone https://github.com/facultyai/dash-bootstrap-components && cd dash-bootstrap-components && npm i && pip install -r requirements-dev.txt && cd ../'
);
shell.cd(path.resolve(assetsPath, 'dash'));
shell.exec('npm i && npm run build');
shell.exec(
'pip install -r requires-dev.txt -r requires-ci.txt && pip install -e .'
);
shell.mv(
path.resolve(assetsPath, 'dash', 'components', '*'),
path.resolve(assetsPath)
);
shell.cd(assetsPath);
for (const element of packages) {
shell.cd(path.resolve(assetsPath, element));
shell.exec('npm run build');
}
};
// Update the inst directories for each of the component packages.
function copyCoreInstDirectory() {
if (
fs.existsSync(
path.resolve(__dirname, 'gulp-assets/dash-core-components/inst')
)
) {
return src(['gulp-assets/dash-core-components/inst/deps/**/*'])
.pipe(print())
.pipe(dest('inst/deps/dcc', {overwrite: true}));
}
return log('Unable to find dash-core-components inst directory.');
}
function copyHtmlInstDirectory() {
if (
fs.existsSync(
path.resolve(__dirname, 'gulp-assets/dash-html-components/inst')
)
) {
return src('gulp-assets/dash-html-components/inst/deps/**/*')
.pipe(print())
.pipe(dest('inst/deps/html', {overwrite: true}));
}
return log('Unable to find dash-html-components inst directory.');
}
function copyTableInstDirectory() {
if (fs.existsSync(path.resolve(__dirname, 'gulp-assets/dash-table/inst'))) {
return src([
'gulp-assets/dash-table/inst/deps/**/*',
'!gulp-assets/dash-table/inst/deps/index.html',
])
.pipe(print())
.pipe(dest('inst/deps/dash_table', {overwrite: true}));
}
return log('Unable to find dash-table `inst` directory.');
}
function copyBootstrapInstDirectory() {
if (
fs.existsSync(
path.resolve(
__dirname,
'gulp-assets/dash-bootstrap-components/inst'
)
)
) {
return src(['gulp-assets/dash-bootstrap-components/inst/deps/**/*'])
.pipe(print())
.pipe(dest('inst/deps', {overwrite: true}));
}
return log('Unable to find dash-bootstrap-components `inst` directory.');
}
// // Update the man directories for each of the component packages.
function copyCoreManDirectory() {
if (
fs.existsSync(
path.relative(__dirname, 'gulp-assets/dash-core-components/man')
)
) {
return src([
'gulp-assets/dash-core-components/man/**/*',
'!gulp-assets/dash-core-components/man/*-package.Rd',
]).pipe(dest('man/', {overwrite: true}));
}
return log('Unable to find dash-core-components `man` directory.');
}
function copyHtmlManDirectory() {
if (
fs.existsSync(
path.relative(__dirname, 'gulp-assets/dash-html-components/man')
)
) {
return src([
'gulp-assets/dash-html-components/man/**/*',
'!gulp-assets/dash-html-components/man/*-package.Rd',
]).pipe(dest('man/', {overwrite: true}));
}
return log('Unable to find dash-html-components `man` directory.');
}
function copyTableManDirectory() {
if (fs.existsSync(path.relative(__dirname, 'gulp-assets/dash-table/man'))) {
return src([
'gulp-assets/dash-table/man/**/*',
'!gulp-assets/dash-table/man/*-package.Rd',
]).pipe(dest('man/', {overwrite: true}));
}
return log('Unable to find dash-table `man` directory.');
}
function copyBootstrapManDirectory() {
if (
fs.existsSync(
path.relative(
__dirname,
'gulp-assets/dash-bootstrap-components/man'
)
)
) {
return src([
'gulp-assets/dash-bootstrap-components/man/**/*',
'!gulp-assets/dash-bootstrap-components/man/*-package.Rd',
]).pipe(dest('man/', {overwrite: true}));
}
return log('Unable to find dash-bootstrap-components `man` directory.');
}
// Update the R directories for each of the component packages.
function copyCoreRDirectory() {
if (
fs.existsSync(
path.relative(__dirname, 'gulp-assets/dash-core-components/R')
)
) {
return src([
'gulp-assets/dash-core-components/R/**/*',
'!gulp-assets/dash-core-components/R/internal.R',
])
.pipe(print())
.pipe(concat('dashCoreComponents.R'))
.pipe(dest('R/', {overwrite: true}));
}
return log('Unable to find dash-core-components `R` directory.');
}
function copyHtmlRDirectory() {
if (
fs.existsSync(
path.relative(__dirname, 'gulp-assets/dash-html-components/R')
)
) {
return src([
'gulp-assets/dash-html-components/R/**/*',
'!gulp-assets/dash-html-components/R/internal.R',
])
.pipe(print())
.pipe(concat('dashHtmlComponents.R'))
.pipe(replace(/#'\s@export/g, ""))
.pipe(dest('R/', {overwrite: true}));
}
return log('Unable to find dash-html-components `R` directory.');
}
function copyTableRDirectory() {
if (fs.existsSync(path.relative(__dirname, 'gulp-assets/dash-table/R'))) {
return src([
'gulp-assets/dash-table/R/**/*',
'!gulp-assets/dash-table/R/internal.R',
])
.pipe(print())
.pipe(concat('dashTable.R'))
.pipe(dest('R/', {overwrite: true}));
}
return log('Unable to find dash-table `R` directory.');
}
function copyBootstrapRDirectory() {
if (
fs.existsSync(
path.relative(__dirname, 'gulp-assets/dash-bootstrap-components/R')
)
) {
return src([
'gulp-assets/dash-bootstrap-components/R/**/*',
'!gulp-assets/dash-bootstrap-components/R/internal.R',
])
.pipe(print())
.pipe(concat('dashBootstrapComponents.R'))
.pipe(replace(/#'\s@export'/g, "#' @export"))
.pipe(dest('R/', {overwrite: true}));
}
return log('Unable to find dash-bootstrap-components `R` directory.');
}
// Append the internal.R for each of the component packages to the DashR internal.R.
function appendCoreInternal() {
return src('gulp-assets/internal.template')
.pipe(print())
.pipe(
replace(
'{dcc_deps}',
fs.readFileSync('gulp-assets/dash-core-components/R/internal.R')
)
)
.pipe(rename('internal.R'))
.pipe(dest('R/', {overwrite: true}));
}
function appendHtmlInternal() {
return src('R/internal.R')
.pipe(print())
.pipe(
replace(
'{html_deps}',
fs.readFileSync('gulp-assets/dash-html-components/R/internal.R')
)
)
.pipe(dest('R/', {overwrite: true}));
}
function appendTableInternal() {
return src('R/internal.R')
.pipe(print())
.pipe(
replace(
'{table_deps}',
fs.readFileSync('gulp-assets/dash-table/R/internal.R')
)
)
.pipe(dest('R/', {overwrite: true}));
}
function appendBootstrapInternal() {
return src('R/internal.R')
.pipe(print())
.pipe(
replace(
'{dbc_deps}',
fs.readFileSync(
'gulp-assets/dash-bootstrap-components/R/internal.R'
)
)
)
.pipe(dest('R/', {overwrite: true}));
}
// Point dependency sourcing to Dash package.
function replacePackageDependency() {
return src('R/internal.R')
.pipe(print())
.pipe(replace(/package = "dashCoreComponents"/g, 'package = "dash"'))
.pipe(replace(/package = "dashHtmlComponents"/g, 'package = "dash"'))
.pipe(replace(/package = "dashTable"/g, 'package = "dash"'))
.pipe(
replace(/package = "dashBootstrapComponents"/g, 'package = "dash"')
)
.pipe(replace(/name = "dcc\//g, 'name = "'))
.pipe(
replace(
/`dash_core_components.+name\s=\s.+",$/gm,
'`dash_core_components` = structure(list(name = "dash_core_components",'
)
)
.pipe(
replace(
/`dcc\/dash_core_components.+name\s=\s.+",$/gm,
'`dash_core_components` = structure(list(name = "dash_core_components",'
)
)
.pipe(
replace(
/`html\/dash_html_components.+name\s=\s.+",$/gm,
'`dash_html_components` = structure(list(name = "dash_html_components",'
)
)
.pipe(
replace(
/`dash_table.+name\s=\s.+",$/gm,
'`dash_table` = structure(list(name = "dash_table",'
)
)
.pipe(
replace(
/`html\/dash_bootstrap_components.+name\s=\s.+",$/gm,
'`dash_bootstrap_components` = structure(list(name = "dash_bootstrap_components",'
)
)
.pipe(dest('R/'));
}
// Task to clean build artifacts from gulp-assets
const cleanAssets = async () => {
const assetsPath = path.resolve(__dirname, 'gulp-assets');
shell.cd(assetsPath);
shell.exec(
'rm -rfv dash-core-components dash-html-components dash-table dash-bootstrap-components dash'
);
};
// Document package
const document = async () => {
shell.exec('Rscript scripts/generate_tags.R')
shell.exec('Rscript -e "devtools::document()"');
};
exports.unify = series(
parallel(
copyCoreInstDirectory,
copyHtmlInstDirectory,
copyTableInstDirectory,
copyBootstrapInstDirectory
),
parallel(
copyCoreManDirectory,
copyHtmlManDirectory,
copyTableManDirectory,
copyBootstrapManDirectory
),
parallel(
copyCoreRDirectory,
copyHtmlRDirectory,
copyTableRDirectory,
copyBootstrapRDirectory
)
);
exports.update = series(
appendCoreInternal,
appendHtmlInternal,
appendTableInternal,
appendBootstrapInternal,
replacePackageDependency,
document
);
exports.clone = series(retrieveAssets);
exports.test = series(replacePackageDependency);
exports.clean = series(cleanAssets);