- Notifications
You must be signed in to change notification settings - Fork479
feat: new--bare
CLI option to generate a barebone project without example code#636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
13 commits Select commitHold shift + click to select a range
50d903d
feat: `--minimal` option
haoqunjiangfce4361
chore: add snapshot for `--minimal` flag
haoqunjiangc4289cd
feat: use a `--bare` flag to generate a template without too much boi…
haoqunjiange2056bc
chore: remove debugging code
haoqunjiangb813514
chore: remove `minimal` flag from snapshot as it's not implemented an…
haoqunjianged03d7c
chore: merge branch 'main' into feat-minimal
haoqunjiang42df7c5
test: remove extraneous flag combinations
haoqunjiang639413f
feat: add snapshots for `--bare` flag
haoqunjiang06e9d46
ci: use single quotes everywhere to avoid different behavior between …
haoqunjiang976ac5e
ci: should also exclude bare templates from e2e tests
haoqunjiang2d77ded
ci: add comments for the reason of excluding bare templates from unit…
haoqunjiange7603a4
chore: clarify that `--bare` & `--force` are *supplementary* options …
haoqunjiangb56500c
feat: render unit test files even in --bare mode
haoqunjiangFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
17 changes: 9 additions & 8 deletions.github/workflows/ci.yml
This file contains hidden or 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
28 changes: 25 additions & 3 deletionsindex.ts
This file contains hidden or 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
21 changes: 11 additions & 10 deletionsscripts/snapshot.mjs
This file contains hidden or 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 |
---|---|---|
@@ -8,6 +8,7 @@ if (!/pnpm/.test(process.env.npm_config_user_agent ?? '')) | ||
throw new Error("Please use pnpm ('pnpm run snapshot') to generate snapshots!") | ||
const featureFlags = [ | ||
'bare', | ||
'typescript', | ||
'jsx', | ||
'router', | ||
@@ -54,12 +55,7 @@ function fullCombination(arr) { | ||
} | ||
let flagCombinations = fullCombination(featureFlags) | ||
flagCombinations.push(['default'], ['bare', 'default'], ['eslint'], ['eslint-with-prettier']) | ||
// `--with-tests` are equivalent of `--vitest --cypress` | ||
// Previously it means `--cypress` without `--vitest`. | ||
@@ -85,10 +81,15 @@ for (const flags of flagCombinations) { | ||
} | ||
// Filter out combinations that are not allowed | ||
flagCombinations = flagCombinations | ||
.filter( | ||
(combination) => | ||
!featureFlagsDenylist.some((denylist) => | ||
denylist.every((flag) => combination.includes(flag)), | ||
), | ||
) | ||
// `--bare` is a supplementary flag and should not be used alone | ||
.filter((combination) => !(combination.length === 1 && combination[0] === 'bare')) | ||
haoqunjiang marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
const bin = path.posix.relative('../playground/', '../outfile.cjs') | ||
7 changes: 7 additions & 0 deletionstemplate/bare/base/src/App.vue
This file contains hidden or 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> |
8 changes: 8 additions & 0 deletionstemplate/bare/cypress-ct/src/__tests__/App.cy.js
This file contains hidden or 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') | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletionstemplate/bare/nightwatch-ct/src/__tests__/App.spec.js
This file contains hidden or 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()) | ||
}) |
7 changes: 7 additions & 0 deletionstemplate/bare/typescript/src/App.vue
This file contains hidden or 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> |
11 changes: 11 additions & 0 deletionstemplate/bare/vitest/src/__tests__/App.spec.js
This file contains hidden or 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') | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletionsutils/trimBoilerplate.ts
This file contains hidden or 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: [],'), | ||
) | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.