]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/js/gulpfile.js
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / js / gulpfile.js
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 const del = require('del');
19 const gulp = require('gulp');
20 const { targets } = require('./gulp/argv');
21 const {
22 from: ObservableFrom,
23 bindNodeCallback: ObservableBindNodeCallback
24 } = require('rxjs');
25 const { flatMap } = require('rxjs/operators');
26 const cleanTask = require('./gulp/clean-task');
27 const compileTask = require('./gulp/compile-task');
28 const packageTask = require('./gulp/package-task');
29 const { testTask, createTestData, cleanTestData } = require('./gulp/test-task');
30 const {
31 taskName, combinations,
32 targetDir, knownTargets,
33 npmPkgName, tasksToSkipPerTargetOrFormat,
34 targetAndModuleCombinations
35 } = require('./gulp/util');
36
37 for (const [target, format] of combinations([`all`], [`all`])) {
38 const task = taskName(target, format);
39 gulp.task(`clean:${task}`, cleanTask(target, format));
40 gulp.task(`test:${task}`, testTask(target, format));
41 gulp.task(`compile:${task}`, compileTask(target, format));
42 gulp.task(`package:${task}`, packageTask(target, format));
43 gulp.task(`build:${task}`, gulp.series(
44 `clean:${task}`, `compile:${task}`, `package:${task}`
45 ));
46 }
47
48 // The UMD bundles build temporary es5/6/next targets via TS,
49 // then run the TS source through either closure-compiler or
50 // a minifier, so we special case that here.
51 knownTargets.forEach((target) => {
52 const umd = taskName(target, `umd`);
53 const cls = taskName(target, `cls`);
54 gulp.task(`build:${umd}`, gulp.series(
55 `build:${cls}`,
56 `clean:${umd}`, `compile:${umd}`, `package:${umd}`,
57 function remove_closure_tmp_files() {
58 return del(targetDir(target, `cls`))
59 }
60 ));
61 });
62
63 // The main "apache-arrow" module builds the es2015/umd, es2015/cjs,
64 // es2015/esm, and esnext/umd targets, then copies and renames the
65 // compiled output into the apache-arrow folder
66 gulp.task(`build:${npmPkgName}`,
67 gulp.series(
68 gulp.parallel(
69 `build:${taskName(`es2015`, `umd`)}`,
70 `build:${taskName(`es2015`, `cjs`)}`,
71 `build:${taskName(`es2015`, `esm`)}`,
72 `build:${taskName(`esnext`, `umd`)}`
73 ),
74 `clean:${npmPkgName}`,
75 `compile:${npmPkgName}`,
76 `package:${npmPkgName}`
77 )
78 );
79
80 // And finally the global composite tasks
81 gulp.task(`clean:testdata`, cleanTestData);
82 gulp.task(`create:testdata`, createTestData);
83 gulp.task(`test`, gulpConcurrent(getTasks(`test`)));
84 gulp.task(`clean`, gulp.parallel(getTasks(`clean`)));
85 gulp.task(`build`, gulpConcurrent(getTasks(`build`)));
86 gulp.task(`compile`, gulpConcurrent(getTasks(`compile`)));
87 gulp.task(`package`, gulpConcurrent(getTasks(`package`)));
88 gulp.task(`default`, gulp.series(`clean`, `build`, `test`));
89
90 function gulpConcurrent(tasks, numCPUs = Math.max(1, require('os').cpus().length * 0.5) | 0) {
91 return () => ObservableFrom(tasks.map((task) => gulp.series(task)))
92 .pipe(flatMap((task) => ObservableBindNodeCallback(task)(), numCPUs || 1));
93 }
94
95 function getTasks(name) {
96 const tasks = [];
97 if (targets.includes(`ts`)) tasks.push(`${name}:ts`);
98 if (targets.includes(npmPkgName)) tasks.push(`${name}:${npmPkgName}`);
99 for (const [target, format] of targetAndModuleCombinations) {
100 if (tasksToSkipPerTargetOrFormat[target] && tasksToSkipPerTargetOrFormat[target][name]) continue;
101 if (tasksToSkipPerTargetOrFormat[format] && tasksToSkipPerTargetOrFormat[format][name]) continue;
102 tasks.push(`${name}:${taskName(target, format)}`);
103 }
104 return tasks.length && tasks || [(done) => done()];
105 }