babel/packages/babel-cli/src/babel-external-helpers.ts
2021-08-14 16:57:06 +02:00

35 lines
833 B
TypeScript
Executable File

import commander from "commander";
import { buildExternalHelpers } from "@babel/core";
function collect(
value: string | any,
previousValue: Array<string>,
): Array<string> {
// If the user passed the option with no value, like "babel-external-helpers --whitelist", do nothing.
if (typeof value !== "string") return previousValue;
const values = value.split(",");
if (previousValue) {
previousValue.push(...values);
return previousValue;
}
return values;
}
commander.option(
"-l, --whitelist [whitelist]",
"Whitelist of helpers to ONLY include",
collect,
);
commander.option(
"-t, --output-type [type]",
"Type of output (global|umd|var)",
"global",
);
commander.usage("[options]");
commander.parse(process.argv);
console.log(buildExternalHelpers(commander.whitelist, commander.outputType));