@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'
3
3
import process from 'node:process'
4
4
import { $ , argv , chalk , fs , glob , path } from 'zx'
5
5
import { select } from '@inquirer/prompts'
6
+ import { readPackageJSON } from 'pkg-types'
6
7
7
8
if ( argv . _ [ 0 ] !== 'sg' ) {
8
9
console . log ( chalk . red ( 'Do you want to use `sg` cmd?' ) )
@@ -11,10 +12,6 @@ if (argv._[0] !== 'sg') {
11
12
12
13
$ . verbose = false
13
14
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
-
18
15
let macro = await select ( {
19
16
message : chalk . green (
20
17
`Which vue macro do you want to use?` ,
@@ -53,10 +50,16 @@ if (macro === 'short-v-model') {
53
50
} )
54
51
}
55
52
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
+
56
59
const target = path . resolve ( argv . _ . at ( 1 ) || './src' )
57
60
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' } ` , {
60
63
ignore : [
61
64
'**/node_modules/**' ,
62
65
] ,
@@ -65,6 +68,8 @@ async function toSetupSFC() {
65
68
await Promise . all ( files . map ( async file => fs . move ( file , `${ file . slice ( 0 , - 3 ) } setup.tsx` ) ) )
66
69
}
67
70
71
+ const config = `${ dirname } /sgconfig`
72
+ const sg = path . resolve ( dirname , '../node_modules/.bin/ast-grep' )
68
73
async function useTsx ( cb = ( ) => { } , action = 'clean' ) {
69
74
await $ `${ sg } scan -c ${ config } .yml -U --filter '^setup-sfc start' ${ target } `
70
75
await $ `${ sg } scan -c ${ config } .yml -U --filter '^setup-sfc end' ${ target } `
0 commit comments