import chalk from 'chalk' import fs from 'fs-extra' import paths from './config/paths' const getTmpPath = (...args: string[]) => paths.resolveOwn('asset', 'template', ...args) async function generatorOverride() { if (fs.existsSync(paths.override)) { console.log(chalk.red(`文件已存在 ${paths.override}`)) process.exit(0) } fs.copySync(getTmpPath('edu-scripts.override.js.tpl'), paths.override) console.log(chalk.green(`成功生成 ${paths.override}`)) } async function generatorTsconfig() { if (fs.existsSync(paths.tsconfig)) { console.log(chalk.red(`文件已存在 ${paths.tsconfig}`)) process.exit(0) } fs.copySync(getTmpPath('tsconfig.json.tpl'), paths.tsconfig) fs.copySync(getTmpPath('edu-app-env.d.ts.tpl'), paths.eduAppEnv) console.log(chalk.green(`成功生成 ${paths.tsconfig}`)) } async function generatorTailwind() { if (fs.existsSync(paths.tailwind)) { console.log(chalk.red(`文件已存在 ${paths.tailwind}`)) process.exit(0) } fs.copySync(getTmpPath('tailwind.config.js.tpl'), paths.tailwind) const code = ['@tailwind base;', '@tailwind components;', '@tailwind utilities;'].join('\n') const globalLessFile = paths.resolveApp('src', 'index.less') if (fs.existsSync(globalLessFile)) { const content = fs.readFileSync(globalLessFile, 'utf-8') if (!content.includes('@tailwind base')) { fs.writeFileSync(globalLessFile, [code, content].join('\n')) } console.log(chalk.green(`成功生成 ${paths.tailwind}`)) return } console.log( chalk.green( [`成功生成 ${paths.tailwind}`, '', '添加以下代码到入口处的 index.less 中', code].join('\n') ) ) } export { generatorOverride as override, generatorTailwind as tailwind, generatorTsconfig as ts }