import getCommand from './utils/getCommand'
import getLanguage from './utils/getLanguage'
import renderEslint from './utils/renderEslint'
-import trimBoilerplate from './utils/trimBoilerplate'
+import { trimBoilerplate, removeCSSImport, emptyRouterConfig } from './utils/trimBoilerplate'
import cliPackageJson from './package.json'
},
)
+ if (argv.bare) {
+ trimBoilerplate(root)
+ render('bare/base')
+ // TODO: refactor the `render` utility to avoid this kind of manual mapping?
+ if (needsTypeScript) {
+ render('bare/typescript')
+ }
+ if (needsVitest) {
+ render('bare/vitest')
+ }
+ if (needsCypressCT) {
+ render('bare/cypress-ct')
+ }
+ if (needsNightwatchCT) {
+ render('bare/nightwatch-ct')
+ }
+ }
+
// Cleanup.
// We try to share as many files between TypeScript and JavaScript as possible.
}
if (argv.bare) {
- trimBoilerplate(root, { needsTypeScript, needsRouter })
- render('bare/base')
-
- // TODO: refactor the `render` utility to avoid this kind of manual mapping?
- if (needsTypeScript) {
- render('bare/typescript')
- }
- if (needsVitest) {
- render('bare/vitest')
- }
- if (needsCypressCT) {
- render('bare/cypress-ct')
- }
- if (needsNightwatchCT) {
- render('bare/nightwatch-ct')
+ removeCSSImport(root, needsTypeScript)
+ if (needsRouter) {
+ emptyRouterConfig(root, needsTypeScript)
}
}
fs.writeFileSync(filepath, replacer(content))
}
-export default function trimBoilerplate(rootDir: string, features: Record<string, boolean>) {
- const isTs = features.needsTypeScript
+export function trimBoilerplate(rootDir: string) {
const srcDir = path.resolve(rootDir, 'src')
for (const filename of fs.readdirSync(srcDir)) {
const fullpath = path.resolve(srcDir, filename)
fs.rmSync(fullpath, { recursive: true })
}
+}
+export function removeCSSImport(rootDir: string, needsTypeScript: boolean) {
// Remove CSS import in the entry file
- const entryPath = path.resolve(rootDir, isTs ? 'src/main.ts' : 'src/main.js')
+ const entryPath = path.resolve(rootDir, needsTypeScript ? 'src/main.ts' : 'src/main.js')
replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\n\n", ''))
+}
+export function emptyRouterConfig(rootDir: string, needsTypeScript: boolean) {
+ const srcDir = path.resolve(rootDir, 'src')
// If `router` feature is selected, use an empty router configuration
- if (features.needsRouter) {
- const routerEntry = path.resolve(srcDir, isTs ? 'router/index.ts' : 'router/index.js')
- replaceContent(routerEntry, (content) =>
- content
- .replace(`import HomeView from '../views/HomeView.vue'\n`, '')
- .replace(/routes:\s*\[[\s\S]*?\],/, 'routes: [],'),
- )
- }
+ const routerEntry = path.resolve(srcDir, needsTypeScript ? 'router/index.ts' : 'router/index.js')
+ replaceContent(routerEntry, (content) =>
+ content
+ .replace(`import HomeView from '../views/HomeView.vue'\n`, '')
+ .replace(/routes:\s*\[[\s\S]*?\],/, 'routes: [],'),
+ )
}