import { PromptModuleAPI } from "../promptModuleAPI"; /** * * 当使用 Babel(useTsWithBabel: true) 时,该插件将会输出 ES2015 并将其它基于浏览器目标的自动的 polyfill 委托给 Babel。 * 仅在 production 模式下 */ export default function(cli: PromptModuleAPI): void { cli.injectFeature({ name: "TypeScript", value: "ts", short: "TS", description: "Add support for the TypeScript language", plugins: ["typescript"], link: "http://www.typescriptlang.org", }); // selected ts and not selected babel will asked this question // this question's answer is default true // both selected ts and babel this question will not asked and also the config `useTsWithBabel` is true cli.injectPrompt({ name: "useTsWithBabel", when: (answers) => { return answers.features.includes("ts") && !answers.features.includes("babel"); }, type: "confirm", message: "Use Babel alongside TypeScript (auto-detected polyfills)?", // description: // "It will output ES2015 and delegate the rest to Babel for auto polyfill based on browser targets.", default: true, }); cli.onPromptComplete((answers, options) => { if (!options.plugins) { return; } if (answers.features.includes("ts")) { options.plugins["cli-plugin-typescript"] = { useTsWithBabel: answers.useTsWithBabel || false }; } }); };