From 50d903d11fd3160005929afc29995c4cc5a3c1da Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 12 Dec 2024 21:08:28 +0800 Subject: [PATCH] feat: `--minimal` option Closes #112 Closes #300 The minimal template is a cut-down version of the default template; therefore, the `--minimal` flag is mutually exclusive with all other flags. I chose not to include it in the prompts because it's a very specific use case, and it's not a good idea to clutter the CLI with too many options that are not commonly used. I didn't design it as an add-on because the logic would be too complex, and the use case would be even more niche. --- index.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/index.ts b/index.ts index 40f70304..9fff1638 100755 --- a/index.ts +++ b/index.ts @@ -72,6 +72,7 @@ async function init() { const cwd = process.cwd() // possible options: // --default + // --minimal // --typescript / --ts // --jsx // --router / --vue-router @@ -107,6 +108,7 @@ async function init() { const isFeatureFlagsUsed = typeof ( argv.default ?? + argv.minimal ?? (argv.ts || argv.typescript) ?? argv.jsx ?? (argv.router || argv['vue-router']) ?? @@ -563,6 +565,31 @@ async function init() { ) } + if (argv.minimal) { + // Only keep `src/App.vue` and `src/main.js` inside the `src` folder + postOrderDirectoryTraverse( + path.resolve(root, 'src'), + (dir) => { + if (path.basename(dir) === 'src') { + return + } + fs.rmdirSync(dir) + }, + (filepath) => { + if (!['App.vue', 'main.js'].includes(path.basename(filepath))) fs.unlinkSync(filepath) + }, + ) + // Replace the content in `src/App.vue` with a minimal template + fs.writeFileSync( + path.resolve(root, 'src/App.vue'), + '\n\n\n\n\n', + ) + // Remove CSS import in `src/main.js` + const srcMainJsPath = path.resolve(root, 'src/main.js') + const srcMainJsContent = fs.readFileSync(srcMainJsPath, 'utf8') + fs.writeFileSync(srcMainJsPath, srcMainJsContent.replace("import './assets/main.css'\n\n", '')) + } + // Instructions: // Supported package managers: pnpm > yarn > bun > npm const userAgent = process.env.npm_config_user_agent ?? ''