Skip to content

Commit 50d903d

Browse files
committed
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.
1 parent fb5d851 commit 50d903d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async function init() {
7272
const cwd = process.cwd()
7373
// possible options:
7474
// --default
75+
// --minimal
7576
// --typescript / --ts
7677
// --jsx
7778
// --router / --vue-router
@@ -107,6 +108,7 @@ async function init() {
107108
const isFeatureFlagsUsed =
108109
typeof (
109110
argv.default ??
111+
argv.minimal ??
110112
(argv.ts || argv.typescript) ??
111113
argv.jsx ??
112114
(argv.router || argv['vue-router']) ??
@@ -563,6 +565,31 @@ async function init() {
563565
)
564566
}
565567

568+
if (argv.minimal) {
569+
// Only keep `src/App.vue` and `src/main.js` inside the `src` folder
570+
postOrderDirectoryTraverse(
571+
path.resolve(root, 'src'),
572+
(dir) => {
573+
if (path.basename(dir) === 'src') {
574+
return
575+
}
576+
fs.rmdirSync(dir)
577+
},
578+
(filepath) => {
579+
if (!['App.vue', 'main.js'].includes(path.basename(filepath))) fs.unlinkSync(filepath)
580+
},
581+
)
582+
// Replace the content in `src/App.vue` with a minimal template
583+
fs.writeFileSync(
584+
path.resolve(root, 'src/App.vue'),
585+
'<script setup>\n</script>\n\n<template>\n <h1>Hello World</h1>\n</template>\n\n<style scoped>\n</style>\n',
586+
)
587+
// Remove CSS import in `src/main.js`
588+
const srcMainJsPath = path.resolve(root, 'src/main.js')
589+
const srcMainJsContent = fs.readFileSync(srcMainJsPath, 'utf8')
590+
fs.writeFileSync(srcMainJsPath, srcMainJsContent.replace("import './assets/main.css'\n\n", ''))
591+
}
592+
566593
// Instructions:
567594
// Supported package managers: pnpm > yarn > bun > npm
568595
const userAgent = process.env.npm_config_user_agent ?? ''

0 commit comments

Comments
 (0)