Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
haoqunjiang merged 13 commits intovuejs:mainfromhaoqunjiang:feat-minimal
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from9 commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
50d903d
feat: `--minimal` option
haoqunjiangDec 12, 2024
fce4361
chore: add snapshot for `--minimal` flag
haoqunjiangDec 12, 2024
c4289cd
feat: use a `--bare` flag to generate a template without too much boi…
haoqunjiangDec 12, 2024
e2056bc
chore: remove debugging code
haoqunjiangDec 12, 2024
b813514
chore: remove `minimal` flag from snapshot as it's not implemented an…
haoqunjiangDec 12, 2024
ed03d7c
chore: merge branch 'main' into feat-minimal
haoqunjiangDec 19, 2024
42df7c5
test: remove extraneous flag combinations
haoqunjiangDec 19, 2024
639413f
feat: add snapshots for `--bare` flag
haoqunjiangDec 19, 2024
06e9d46
ci: use single quotes everywhere to avoid different behavior between …
haoqunjiangDec 19, 2024
976ac5e
ci: should also exclude bare templates from e2e tests
haoqunjiangDec 19, 2024
2d77ded
ci: add comments for the reason of excluding bare templates from unit…
haoqunjiangDec 19, 2024
e7603a4
chore: clarify that `--bare` & `--force` are *supplementary* options …
haoqunjiangDec 19, 2024
b56500c
feat: render unit test files even in --bare mode
haoqunjiangDec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions.github/workflows/ci.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,13 +49,13 @@ jobs:
node-version: [18, 20, 22]
os: [ubuntu-latest, windows-latest, macos-latest]
verification-script:
- pnpm --filter"\!*typescript*" build
- pnpm --filter"*typescript*" build
- pnpm --filter"*vitest*" test:unit
- pnpm --filter"*eslint*" lint --no-fix --max-warnings=0
- pnpm --filter"*prettier*" format --write --check
- pnpm --filter'!*typescript*' build
- pnpm --filter'*typescript*' build
- pnpm --filter'*vitest*' --filter '!*bare*' test:unit
- pnpm --filter'*eslint*' lint --no-fix --max-warnings=0
- pnpm --filter'*prettier*' format --write --check
# FIXME: it's failing now
# - pnpm --filter"*with-tests*" test:unit
# - pnpm --filter'*with-tests*' test:unit
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.os == 'windows-latest' }}
env:
Expand DownExpand Up@@ -163,11 +163,11 @@ jobs:

- name: Run build script
working-directory: ./playground
run: pnpm --filter"*${{ matrix.e2e-framework }}*" build
run: pnpm --filter'*${{ matrix.e2e-framework }}*' build

- name: Run e2e test script
working-directory: ./playground
run: pnpm --filter"*${{ matrix.e2e-framework }}*" --workspace-concurrency 1 test:e2e
run: pnpm --filter'*${{ matrix.e2e-framework }}*' --workspace-concurrency 1 test:e2e

- name: Cypress component testing for projects without Vitest
if: ${{ contains(matrix.e2e-framework, 'cypress') }}
Expand Down
10 changes: 8 additions & 2 deletionsindex.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,6 +18,7 @@ import generateReadme from './utils/generateReadme'
import getCommand from './utils/getCommand'
import getLanguage from './utils/getLanguage'
import renderEslint from './utils/renderEslint'
import trimBoilerplate from './utils/trimBoilerplate'

function isValidPackageName(projectName) {
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName)
Expand DownExpand Up@@ -84,6 +85,7 @@ async function init() {
// --eslint
// --eslint-with-prettier (only support prettier through eslint for simplicity)
// --force (for force overwriting)
// --bare (for a barebone template)

const args = process.argv.slice(2)

Expand DownExpand Up@@ -319,8 +321,8 @@ async function init() {
packageName = projectName ?? defaultProjectName,
shouldOverwrite = argv.force,
needsJsx = argv.jsx,
needsTypeScript = argv.ts || argv.typescript,
needsRouter = argv.router || argv['vue-router'],
needsTypeScript =(argv.ts || argv.typescript) as boolean,
needsRouter =(argv.router || argv['vue-router']) as boolean,
needsPinia = argv.pinia,
needsVitest = argv.vitest || argv.tests,
needsPrettier = argv['eslint-with-prettier'],
Expand DownExpand Up@@ -563,6 +565,10 @@ async function init() {
)
}

if (argv.bare) {
trimBoilerplate(root, { needsTypeScript, needsRouter })
}

// Instructions:
// Supported package managers: pnpm > yarn > bun > npm
const userAgent = process.env.npm_config_user_agent ?? ''
Expand Down
20 changes: 10 additions & 10 deletionsscripts/snapshot.mjs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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',
Expand DownExpand Up@@ -54,12 +55,7 @@ function fullCombination(arr) {
}

let flagCombinations = fullCombination(featureFlags)
flagCombinations.push(
['default'],
['router', 'pinia'],
['eslint'],
['eslint-with-prettier'],
)
flagCombinations.push(['default'], ['bare', 'default'], ['eslint'], ['eslint-with-prettier'])

// `--with-tests` are equivalent of `--vitest --cypress`
// Previously it means `--cypress` without `--vitest`.
Expand All@@ -85,10 +81,14 @@ 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))),
)
flagCombinations = flagCombinations
.filter(
(combination) =>
!featureFlagsDenylist.some((denylist) =>
denylist.every((flag) => combination.includes(flag)),
),
)
.filter((combination) => !(combination.length === 1 && combination[0] === 'bare'))

const bin = path.posix.relative('../playground/', '../outfile.cjs')

Expand Down
51 changes: 51 additions & 0 deletionsutils/trimBoilerplate.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
import * as fs from 'node:fs'
import * as path from 'path'

function getBareBoneAppContent(isTs: boolean) {
return `<script setup${isTs ? ' lang="ts"' : ''}>
</script>

<template>
<h1>Hello World</h1>
</template>

<style scoped>
</style>
`
}

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 `App.vue`, `main.js/ts`, `router`, and `stores` directories
if (['App.vue', 'main.js', 'main.ts', 'router', 'stores'].includes(filename)) {
continue
}
const fullpath = path.resolve(srcDir, filename)
fs.rmSync(fullpath, { recursive: true })
}

// Replace the content in `src/App.vue` with a barebone template
replaceContent(path.resolve(rootDir, 'src/App.vue'), () => getBareBoneAppContent(isTs))

// 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: [],'),
)
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp