import { PromptModule, QuestionMap, ChoiceOptions, QuestionCollection, Answers } from "inquirer"; import { ExecaChildProcess } from "execa"; import { GeneratorAPI } from "../lib/generatorAPI"; export type PLUGIN_ID = keyof RawPlugin; /** * @type 工具配置文件的文件名后缀 * @example babel.config.js .babel.yaml .babelrc */ export type CONFIG_FILE_TYPE = "js" | "json" | "yaml" | "lines"; /** * @type 支持的 npm 客户端 */ export type SUPPORTED_PACKAGE_MANAGER = "npm" | "yarn"; export type PACKAGE_MANAGER_CONFIG = { [K in SUPPORTED_PACKAGE_MANAGER]: { install: string[]; add: string[]; remove: string[]; upgrade: string[]; }; }; export type StringDictionary = { [index: string]: T; }; export type NumericDictionary = { [index: number]: T; }; export type AnyKindOfDictionary = StringDictionary | NumericDictionary; export type Callback = () => void; export type CliOptions = Partial<{ // 跳过对话 直接使用默认的模板来创建项目 // @unsupported // default: boolean; // 指定安装依赖时的 npm 客户端 // packageManager: SUPPORTED_PACKAGE_MANAGER; // 指定安装依赖时的 npm 源,仅限于 npm registry: string; // 使用 git clone 的方式来下载模板,创建的项目中将会包含 .git 文件夹,将会跳过 git init // @unsupported // clone: true; // 跳过 git init,当指定 git 选项时,此项无效 skipGit: boolean; // 指定生成项目时首次的 git commit message git: string; // 当指定首次的 git commit message 时,此项为 TRUE forceGit: boolean; // 如果指定项目名称与磁盘上的目录相同,force 为 TRUE 时将重写目标目录 force: boolean; }>; /** * @deprecated */ export type DownloadTemplateAnswers = { template: string; description?: string; author?: string; }; export type RootOptions = { projectName?: string; preset?: Preset }; export type RawPlugin = { "cli-plugin-babel"?: {}; "cli-plugin-typescript"?: { useTsWithBabel: boolean; }; "cli-plugin-eslint"?: { config: "base" | "airbnb" | "standard"; }; "cli-plugin-stylelint"?: {}; "cli-plugin-service": RootOptions; }; interface ApplyFn { (api: GeneratorAPI, rootOptions: RootOptions): void; hooks?: (api: GeneratorAPI, rootOptions: RootOptions, pluginIds: string[]) => void; } export type ResolvedPlugin = { id: keyof RawPlugin; apply: ApplyFn; options: RawPlugin[keyof RawPlugin] & StringDictionary; }; /** * @description 创建项目时的预设选项和插件的配置选项 */ export type Preset = { // @deprecated useConfigFiles: boolean; cssPreprocessor?: "less" | "styled-components"; plugins: RawPlugin; configs?: StringDictionary; }; /** * @ignore unused */ export type FinallyAnswers = { cssPreprocessor?: "less" | "styled-components"; eslintConfig?: "base" | "airbnb" | "standard"; features: string[]; useConfigFiles: string; useTsWithBabel?: boolean; }; // 本地缓存的配置项 export type LocalConfig = Partial<{ latestVersion: string; lastChecked: string; packageManager: SUPPORTED_PACKAGE_MANAGER; useTaobaoRegistry: boolean; presets: { default: Preset; }; }>; export type PromptCompleteCallback = (answer: Answers, options: Preset) => void; export type InquirerQuestionType = keyof QuestionMap; /** * @type package.json fields, name and version must required * * @see https://docs.npmjs.com/creating-a-package-json-file */ export type BasePkgFields = { name: string; description?: ""; version: string; main?: string; scripts?: StringDictionary; repository?: StringDictionary; devDependencies?: StringDictionary; dependencies?: StringDictionary; keywords?: string[]; author?: string; browserslist?: string[]; ["__luban_config__"]?: Preset; } & StringDictionary;