-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use a
--bare
flag to generate a template without too much boi…
- Loading branch information
1 parent
d4999b7
commit b3d661e
Showing
9 changed files
with
128 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script setup></script> | ||
|
||
<template> | ||
<h1>Hello World</h1> | ||
</template> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import App from '../App.vue' | ||
|
||
describe('App', () => { | ||
it('mounts and renders properly', () => { | ||
cy.mount(App) | ||
cy.get('h1').should('contain', 'Hello World') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
describe('App', function () { | ||
before((browser) => { | ||
browser.init() | ||
}) | ||
|
||
it('mounts and renders properly', async function () { | ||
const appComponent = await browser.mountComponent('/src/App.vue'); | ||
|
||
browser.expect.element(appComponent).to.be.present; | ||
browser.expect.element('h1').text.to.contain('Hello World'); | ||
}) | ||
|
||
after((browser) => browser.end()) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script setup lang="ts"></script> | ||
|
||
<template> | ||
<h1>Hello World</h1> | ||
</template> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { describe, it, expect } from 'vitest' | ||
|
||
import { mount } from '@vue/test-utils' | ||
import App from '../App.vue' | ||
|
||
describe('App', () => { | ||
it('mounts renders properly', () => { | ||
const wrapper = mount(App) | ||
expect(wrapper.text()).toContain('Hello World') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as fs from 'node:fs' | ||
import * as path from 'path' | ||
|
||
function replaceContent(filepath: string, replacer: (content: string) => string) { | ||
const content = fs.readFileSync(filepath, 'utf8') | ||
fs.writeFileSync(filepath, replacer(content)) | ||
} | ||
|
||
export default function trimBoilerplate(rootDir: string, features: Record<string, boolean>) { | ||
const isTs = features.needsTypeScript | ||
const srcDir = path.resolve(rootDir, 'src') | ||
|
||
for (const filename of fs.readdirSync(srcDir)) { | ||
// Keep `main.js/ts`, `router`, and `stores` directories | ||
// `App.vue` would be re-rendered in the next step | ||
if (['main.js', 'main.ts', 'router', 'stores'].includes(filename)) { | ||
continue | ||
} | ||
const fullpath = path.resolve(srcDir, filename) | ||
fs.rmSync(fullpath, { recursive: true }) | ||
} | ||
|
||
// Remove CSS import in the entry file | ||
const entryPath = path.resolve(rootDir, isTs ? 'src/main.ts' : 'src/main.js') | ||
replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\n\n", '')) | ||
|
||
// 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: [],'), | ||
) | ||
} | ||
} |