11#! /usr/bin/env node
2+ /* eslint-disable curly */
23import { fileURLToPath } from 'node:url'
34import process from 'node:process'
45import { $ , argv , chalk , fs , glob , path } from 'zx'
@@ -12,8 +13,9 @@ if (argv._[0] !== 'sg') {
1213$ . verbose = false
1314
1415const __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.yml`
16+ // const sg = path.resolve(path.dirname(__filename), '../node_modules/.bin/ast-grep')
17+ const sg = 'sg'
18+ const config = `${ path . dirname ( __filename ) } /sgconfig`
1719
1820let macro = await select ( {
1921 message : chalk . green (
@@ -75,31 +77,31 @@ const files = await glob(`${targetDirectory}/**/*.vue`, {
7577 ] . filter ( Boolean ) ,
7678} )
7779
78- await Promise . all ( files . map ( async file => fs . move ( file , `${ file } .sg.html` ) ) )
80+ // await Promise.all(files.map(async file => fs.move(file, `${file}.sg.html`)))
7981
8082if ( [ 'jsx-directive' , 'setup-sfc' ] . includes ( macro ) ) {
81- await $ `${ sg } scan -c ${ config } -U --filter '^v-' ${ targetDirectory } `
83+ await $ `${ sg } scan -c ${ config } .yml -U --filter '^v-(on|directive) ' ${ targetDirectory } `
8284
83- await $ `${ sg } scan -c ${ config } -U --filter '^${ macro === 'setup-sfc' ? render : 'export-render' } ' ${ targetDirectory } `
85+ await $ `${ sg } scan -c ${ config } .yml -U --filter '^${ macro === 'setup-sfc' ? render : 'export-render' } ' ${ targetDirectory } `
8486
85- await $ `${ sg } scan -c ${ config } -U --filter '^setup-sfc' ${ targetDirectory } `
87+ await $ `${ sg } scan -c ${ config } .yml -U --filter '^setup-sfc' ${ targetDirectory } `
8688
87- await Promise . all ( files . map ( async file => fs . move ( `${ file } .sg.html` , `${ file } .sg.tsx` ) ) )
89+ // await Promise.all(files.map(async file => fs.move(`${file}.sg.html`, `${file}.sg.tsx`)))
8890
89- await $ `${ sg } scan -c ${ config } -U --filter '^tsx v-' ${ targetDirectory } `
91+ await $ `${ sg } scan -c ${ config } -tsx.yml -U --filter '^tsx v-' ${ targetDirectory } `
9092
9193 if ( defineSlots === 'define-short-slots' )
92- await $ `${ sg } scan -c ${ config } -U --filter 'tsx define-short-slots' ${ targetDirectory } `
94+ await $ `${ sg } scan -c ${ config } .yml -U --filter 'tsx define-short-slots' ${ targetDirectory } `
9395
9496 if ( macro === 'setup-sfc' ) {
95- await Promise . all ( files . map ( async file => fs . move ( ` ${ file } .sg.tsx` , `${ file . slice ( 0 , - 3 ) } setup.tsx` ) ) )
97+ await Promise . all ( files . map ( async file => fs . move ( file , `${ file . slice ( 0 , - 3 ) } setup.tsx` ) ) )
9698 }
9799 else {
98- await $ `${ sg } scan -c ${ config } -U --filter '^tsx sfc$' ${ targetDirectory } `
99- await Promise . all ( files . map ( async file => fs . move ( `${ file } .sg.tsx` , file ) ) )
100+ await $ `${ sg } scan -c ${ config } -tsx.yml -U --filter '^tsx sfc$' ${ targetDirectory } `
101+ // await Promise.all(files.map(async file => fs.move(`${file}.sg.tsx`, file)))
100102 }
101103}
102104else {
103- await $ `${ sg } scan -c ${ config } -U --filter ^${ macro } ${ targetDirectory } `
104- await Promise . all ( files . map ( async file => fs . move ( `${ file } .sg.html` , file ) ) )
105+ await $ `${ sg } scan -c ${ config } .yml -U --filter ^${ macro } ${ targetDirectory } `
106+ // await Promise.all(files.map(async file => fs.move(`${file}.sg.html`, file)))
105107}
0 commit comments