Skip to content

Commit a8fad84

Browse files
committed
chore: add aliasLanguages
1 parent 2330d8a commit a8fad84

File tree

14 files changed

+55
-41
lines changed

14 files changed

+55
-41
lines changed

src/index.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#! /usr/bin/env node
2+
/* eslint-disable curly */
23
import { fileURLToPath } from 'node:url'
34
import process from 'node:process'
45
import { $, argv, chalk, fs, glob, path } from 'zx'
@@ -12,8 +13,9 @@ if (argv._[0] !== 'sg') {
1213
$.verbose = false
1314

1415
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.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

1820
let 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

8082
if (['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
}
102104
else {
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
}

src/rules/define-slots.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: v-define-slots default
2-
language: html
2+
language: vue
33
rule:
44
kind: tag_name
55
regex: ^slot$
@@ -15,7 +15,7 @@ fix:
1515
---
1616

1717
id: v-define-slots name
18-
language: html
18+
language: vue
1919
rule:
2020
kind: tag_name
2121
regex: ^slot$
@@ -36,7 +36,7 @@ fix:
3636
---
3737

3838
id: v-define-slots remove name
39-
language: html
39+
language: vue
4040
rule:
4141
kind: attribute
4242
has:
@@ -51,7 +51,7 @@ fix: |-
5151
---
5252

5353
id: tsx v-define-slots
54-
language: tsx
54+
language: vue
5555
rule:
5656
kind: expression_statement
5757
pattern: $A
@@ -68,7 +68,7 @@ fix: |-
6868
---
6969

7070
id: tsx define-short-slots
71-
language: tsx
71+
language: vue
7272
rule:
7373
kind: type_annotation
7474
has:

src/rules/jsx-directive/v-bind.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: v-bind shorthand
2-
language: html
2+
language: vue
33
rule:
44
kind: attribute
55
has:
@@ -23,7 +23,7 @@ fix: |-
2323
---
2424

2525
id: v-bind transform to {...props}
26-
language: html
26+
language: vue
2727
rule:
2828
kind: attribute
2929
has:

src/rules/jsx-directive/v-directive.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: v-directive
2-
language: html
2+
language: vue
33
rule:
44
kind: attribute
55
has:

src/rules/jsx-directive/v-on.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: v-on shorthand
2-
language: html
2+
language: vue
33
rule:
44
kind: attribute
55
has:
@@ -37,7 +37,7 @@ fix: |-
3737
---
3838

3939
id: v-on transform to on
40-
language: html
40+
language: vue
4141
rule:
4242
kind: attribute_name
4343
regex: ^v-on$
@@ -47,7 +47,7 @@ fix:
4747
---
4848

4949
id: tsx v-on
50-
language: tsx
50+
language: vue
5151
rule:
5252
kind: jsx_expression
5353
not:

src/rules/jsx-directive/v-slot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: v-slot shorthand
2-
language: html
2+
language: vue
33
rule:
44
kind: attribute
55
has:

src/rules/jsx-directive/v-text.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: tsx v-text
2-
language: tsx
2+
language: vue
33
rule:
44
kind: jsx_expression
55
has:

src/rules/render/define-render.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: define-render
2-
language: html
2+
language: vue
33
rule:
44
kind: end_tag
55
regex: </script>
@@ -26,15 +26,15 @@ fix: |-
2626
---
2727

2828
id: define-render remove template
29-
language: html
29+
language: vue
3030
rule:
3131
matches: is-template
3232
fix: |-
3333
3434
---
3535

3636
id: define-render has lang
37-
language: html
37+
language: vue
3838
rule:
3939
kind: attribute_value
4040
inside:
@@ -53,7 +53,7 @@ fix: |-
5353
---
5454

5555
id: define-render no lang
56-
language: html
56+
language: vue
5757
rule:
5858
kind: tag_name
5959
regex: script

src/rules/render/export-render.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: export-render
2-
language: html
2+
language: vue
33
rule:
44
kind: end_tag
55
regex: </script>
@@ -26,15 +26,15 @@ fix: |-
2626
---
2727

2828
id: export-render remove template
29-
language: html
29+
language: vue
3030
rule:
3131
matches: is-template
3232
fix: |-
3333
3434
---
3535

3636
id: export-render has lang
37-
language: html
37+
language: vue
3838
rule:
3939
kind: attribute_value
4040
inside:
@@ -53,7 +53,7 @@ fix: |-
5353
---
5454

5555
id: export-render no lang
56-
language: html
56+
language: vue
5757
rule:
5858
kind: tag_name
5959
regex: script

src/rules/setup-sfc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
id: setup-sfc
2-
language: html
2+
language: vue
33
rule:
44
kind: script_element
55
has:
@@ -8,4 +8,4 @@ rule:
88
inside:
99
kind: fragment
1010
fix: |-
11-
$A
11+
$A

0 commit comments

Comments
 (0)