Skip to content

Commit 9c307e2

Browse files
committed
fix(setup-sfc): only process vue file
1 parent d6fea9f commit 9c307e2

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"dependencies": {
4545
"@ast-grep/cli": "^0.14.1",
4646
"@inquirer/prompts": "^3.3.0",
47+
"pkg-types": "^1.0.3",
4748
"zx": "^7.2.3"
4849
},
4950
"devDependencies": {

pnpm-lock.yaml

+3-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'
33
import process from 'node:process'
44
import { $, argv, chalk, fs, glob, path } from 'zx'
55
import { select } from '@inquirer/prompts'
6+
import { readPackageJSON } from 'pkg-types'
67

78
if (argv._[0] !== 'sg') {
89
console.log(chalk.red('Do you want to use `sg` cmd?'))
@@ -11,10 +12,6 @@ if (argv._[0] !== 'sg') {
1112

1213
$.verbose = false
1314

14-
const __filename = fileURLToPath(import.meta.url)
15-
const sg = path.resolve(path.dirname(__filename), '../node_modules/.bin/ast-grep')
16-
const config = `${path.dirname(__filename)}/sgconfig`
17-
1815
let macro = await select({
1916
message: chalk.green(
2017
`Which vue macro do you want to use?`,
@@ -53,10 +50,16 @@ if (macro === 'short-v-model') {
5350
})
5451
}
5552

53+
const dirname = path.dirname(fileURLToPath(import.meta.url))
54+
if (argv.v || argv.version) {
55+
const localPackageJson = await readPackageJSON(dirname)
56+
console.log(`${localPackageJson.name} ${localPackageJson.version}`)
57+
}
58+
5659
const target = path.resolve(argv._.at(1) || './src')
5760
async function toSetupSFC() {
58-
const filename = path.basename(target)
59-
const files = await glob(`${target}${filename ? '' : '/**/*.vue'}`, {
61+
const extname = path.extname(target)
62+
const files = await glob(`${target}${extname ? '' : '/**/*.vue'}`, {
6063
ignore: [
6164
'**/node_modules/**',
6265
],
@@ -65,6 +68,8 @@ async function toSetupSFC() {
6568
await Promise.all(files.map(async file => fs.move(file, `${file.slice(0, -3)}setup.tsx`)))
6669
}
6770

71+
const config = `${dirname}/sgconfig`
72+
const sg = path.resolve(dirname, '../node_modules/.bin/ast-grep')
6873
async function useTsx(cb = () => {}, action = 'clean') {
6974
await $`${sg} scan -c ${config}.yml -U --filter '^setup-sfc start' ${target}`
7075
await $`${sg} scan -c ${config}.yml -U --filter '^setup-sfc end' ${target}`

0 commit comments

Comments
 (0)