@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url'
33import process from 'node:process'
44import { $ , argv , chalk , fs , glob , path } from 'zx'
55import { select } from '@inquirer/prompts'
6+ import { readPackageJSON } from 'pkg-types'
67
78if ( 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-
1815let 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+
5659const target = path . resolve ( argv . _ . at ( 1 ) || './src' )
5760async 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' )
6873async 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