2020-06-04 19:54:12 -04:00
|
|
|
#!/bin/env node
|
2021-10-28 06:27:35 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2020-12-21 00:03:47 -05:00
|
|
|
/* eslint-disable no-console */
|
2020-04-01 21:53:41 -04:00
|
|
|
/**
|
2020-12-21 00:03:47 -05:00
|
|
|
* Build packages/plugins filtered by globs
|
2020-04-01 21:53:41 -04:00
|
|
|
*/
|
2020-09-03 15:02:23 -04:00
|
|
|
process.env.PATH = `./node_modules/.bin:${process.env.PATH}`;
|
|
|
|
|
2020-06-12 15:24:26 -04:00
|
|
|
const rimraf = require('rimraf');
|
2020-04-01 21:53:41 -04:00
|
|
|
const { spawnSync } = require('child_process');
|
2020-09-03 15:02:23 -04:00
|
|
|
const fastGlob = require('fast-glob');
|
|
|
|
const { argv } = require('yargs')
|
|
|
|
.option('lint', {
|
|
|
|
describe: 'whether to run ESLint',
|
|
|
|
type: 'boolean',
|
|
|
|
// lint is slow, so not turning it on by default
|
|
|
|
default: false,
|
|
|
|
})
|
|
|
|
.option('babel', {
|
|
|
|
describe: 'Whether to run Babel',
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
})
|
|
|
|
.option('clean', {
|
|
|
|
describe: 'Whether to clean cache',
|
|
|
|
type: 'boolean',
|
2020-09-08 16:30:23 -04:00
|
|
|
default: false,
|
2020-09-03 15:02:23 -04:00
|
|
|
})
|
|
|
|
.option('type', {
|
|
|
|
describe: 'Whether to run tsc',
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
});
|
2020-04-01 21:53:41 -04:00
|
|
|
|
2020-09-03 15:02:23 -04:00
|
|
|
const {
|
|
|
|
_: globs,
|
|
|
|
lint: shouldLint,
|
|
|
|
babel: shouldRunBabel,
|
|
|
|
clean: shouldCleanup,
|
|
|
|
type: shouldRunTyping,
|
|
|
|
} = argv;
|
|
|
|
const glob = globs.length > 1 ? `{${globs.join(',')}}` : globs[0] || '*';
|
2020-04-01 21:53:41 -04:00
|
|
|
|
2020-09-03 15:02:23 -04:00
|
|
|
const BABEL_CONFIG = '--config-file=../../babel.config.js';
|
|
|
|
|
|
|
|
// packages that do not need tsc
|
|
|
|
const META_PACKAGES = new Set(['demo', 'generator-superset']);
|
2020-04-01 21:53:41 -04:00
|
|
|
|
2020-09-03 15:02:23 -04:00
|
|
|
function run(cmd, options) {
|
|
|
|
console.log(`\n>> ${cmd}\n`);
|
2020-04-01 21:53:41 -04:00
|
|
|
const [p, ...args] = cmd.split(' ');
|
|
|
|
const runner = spawnSync;
|
2020-09-03 15:02:23 -04:00
|
|
|
const { status } = runner(p, args, { stdio: 'inherit', ...options });
|
2020-04-01 21:53:41 -04:00
|
|
|
if (status !== 0) {
|
|
|
|
process.exit(status);
|
|
|
|
}
|
2020-09-03 15:02:23 -04:00
|
|
|
}
|
2020-06-04 19:54:12 -04:00
|
|
|
|
2021-01-26 06:00:59 -05:00
|
|
|
function getPackages(packagePattern, tsOnly = false) {
|
|
|
|
let pattern = packagePattern;
|
2020-09-03 15:02:23 -04:00
|
|
|
if (pattern === '*' && !tsOnly) {
|
|
|
|
return `@superset-ui/!(${[...META_PACKAGES].join('|')})`;
|
2020-04-01 21:53:41 -04:00
|
|
|
}
|
2021-01-26 06:00:59 -05:00
|
|
|
if (!pattern.includes('*')) {
|
|
|
|
pattern = `*${pattern}`;
|
|
|
|
}
|
2020-09-03 15:02:23 -04:00
|
|
|
const packages = [
|
|
|
|
...new Set(
|
|
|
|
fastGlob
|
|
|
|
.sync([
|
|
|
|
`./node_modules/@superset-ui/${pattern}/src/**/*.${
|
|
|
|
tsOnly ? '{ts,tsx}' : '{ts,tsx,js,jsx}'
|
|
|
|
}`,
|
|
|
|
])
|
|
|
|
.map(x => x.split('/')[3])
|
|
|
|
.filter(x => !META_PACKAGES.has(x)),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
if (packages.length === 0) {
|
|
|
|
throw new Error('No matching packages');
|
|
|
|
}
|
2021-11-09 07:42:28 -05:00
|
|
|
return `@superset-ui/${
|
|
|
|
packages.length > 1 ? `{${packages.join(',')}}` : packages[0]
|
|
|
|
}`;
|
2020-09-03 15:02:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let scope = getPackages(glob);
|
|
|
|
|
|
|
|
if (shouldLint) {
|
2021-10-21 22:35:46 -04:00
|
|
|
run(`npm run lint --fix {packages,plugins}/${scope}/{src,test}`);
|
2020-09-03 15:02:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldCleanup) {
|
2020-12-21 00:03:47 -05:00
|
|
|
// these modules will be installed by `npm link` but not useful for actual build
|
|
|
|
const dirtyModules = 'node_modules/@types/react,node_modules/@superset-ui';
|
2021-04-01 13:58:39 -04:00
|
|
|
const cachePath = `./node_modules/${scope}/{lib,esm,tsconfig.tsbuildinfo,${dirtyModules}}`;
|
2020-09-03 15:02:23 -04:00
|
|
|
console.log(`\n>> Cleaning up ${cachePath}`);
|
|
|
|
rimraf.sync(cachePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldRunBabel) {
|
|
|
|
console.log('--- Run babel --------');
|
|
|
|
const babelCommand = `lerna exec --stream --concurrency 10 --scope ${scope}
|
|
|
|
-- babel ${BABEL_CONFIG} src --extensions ".ts,.tsx,.js,.jsx" --copy-files`;
|
|
|
|
run(`${babelCommand} --out-dir lib`);
|
|
|
|
|
|
|
|
console.log('--- Run babel esm ---');
|
|
|
|
// run again with
|
2021-11-09 07:42:28 -05:00
|
|
|
run(`${babelCommand} --out-dir esm`, {
|
|
|
|
env: { ...process.env, BABEL_OUTPUT: 'esm' },
|
|
|
|
});
|
2020-09-03 15:02:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldRunTyping) {
|
2021-11-03 01:02:48 -04:00
|
|
|
console.log('--- Run tsc ---');
|
2020-09-03 15:02:23 -04:00
|
|
|
// only run tsc for packages with ts files
|
|
|
|
scope = getPackages(glob, true);
|
|
|
|
run(`lerna exec --stream --concurrency 3 --scope ${scope} \
|
|
|
|
-- ../../scripts/tsc.sh --build`);
|
2020-04-01 21:53:41 -04:00
|
|
|
}
|