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

fix: use ts files when necessary with --bare option#653

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 1 commit intovuejs:mainfromcexbrayat:fix/bare-typescript
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
38 changes: 22 additions & 16 deletionsindex.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +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'
import{trimBoilerplate, removeCSSImport, emptyRouterConfig } from './utils/trimBoilerplate'

import cliPackageJson from './package.json'

Expand DownExpand Up@@ -560,6 +560,24 @@ async function init() {
},
)

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.
Expand DownExpand Up@@ -610,21 +628,9 @@ async function init() {
}

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)
}
}

Expand Down
2 changes: 1 addition & 1 deletiontemplate/base/vite.config.js.data.mjs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ export default function getData() {
id: 'vite-plugin-vue-devtools',
importer: "import vueDevTools from 'vite-plugin-vue-devtools'",
initializer: 'vueDevTools()',
}
},
],
}
}
24 changes: 13 additions & 11 deletionsutils/trimBoilerplate.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,8 +6,7 @@ function replaceContent(filepath: string, replacer: (content: string) => string)
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)) {
Expand All@@ -19,18 +18,21 @@ export default function trimBoilerplate(rootDir: string, features: Record<string
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: [],'),
)
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp