Skip to content

Commit 94481fd

Browse files
committed
chore: change to cli
1 parent 7333bbb commit 94481fd

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# vue-macros-sg
1+
# vue-macros-cli
22

3-
vue-macros-sg is a cli for rewriting at vue macros powered by ast-grep.
3+
vue-macros-cli is a cli for rewriting at vue macros powered by ast-grep.
44

55
## Support vue macros
66

@@ -14,7 +14,11 @@ vue-macros-sg is a cli for rewriting at vue macros powered by ast-grep.
1414
## Usage
1515

1616
```shell
17-
npx vue-macros-sg ./src
17+
# install
18+
pnpm add -g vue-macros-cli
19+
20+
# run
21+
vue-macros-cli sg ./src
1822
```
1923

2024
## License

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"name": "vue-macros-sg",
2+
"name": "vue-macros-cli",
33
"type": "module",
44
"version": "0.0.3",
5-
"description": "Transform to vue-macros's syntax powered by ast-grep.",
5+
"description": "Rewriting at vue macros powered by ast-grep.",
66
"author": "zhiyuanzmj <zhiyuanzmj@gmail.com>",
77
"license": "MIT",
8-
"homepage": "https://github.com/zhiyuanzmj/vue-macros-sg/tree/main#readme",
8+
"homepage": "https://github.com/zhiyuanzmj/vue-macros-cli/tree/main#readme",
99
"repository": {
1010
"type": "git",
11-
"url": "https://github.com/zhiyuanzmj/vue-macros-sg"
11+
"url": "https://github.com/zhiyuanzmj/vue-macros-cli"
1212
},
1313
"bugs": {
14-
"url": "https://github.com/zhiyuanzmj/vue-macros-sg/issues"
14+
"url": "https://github.com/zhiyuanzmj/vue-macros-cli/issues"
1515
},
1616
"keywords": [
1717
"vue-macros",

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "module",
33
"scripts": {
4-
"sg": "../dist/index.mjs",
4+
"sg": "../dist/index.mjs sg",
55
"dev": "vite",
66
"build": "vite build"
77
},

playground/src/app.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script setup>
2+
import { ref } from 'vue'
23
import Comp from './components/Comp.vue'
34
45
const list = [{ id: 1 }]
56
const bind = { }
67
const on = { submit: () => {} }
8+
const select = ref()
79
</script>
810

911
<template>
@@ -14,8 +16,9 @@ const on = { submit: () => {} }
1416
v-bind="bind"
1517
v-model:id="i.id"
1618
v-loading.fullscreen.lock="true"
19+
v-memo="[select.id === i.id]"
1720
v-on="on"
18-
@click.once="alert(1)"
21+
@click.once="select = i"
1922
@submit="alert"
2023
>
2124
<template v-slot:default="{ id }">

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#! /usr/bin/env node
22
import { fileURLToPath } from 'node:url'
3+
import process from 'node:process'
34
import { $, argv, chalk, fs, glob, path } from 'zx'
45
import { select } from '@inquirer/prompts'
56

7+
if (argv._[0] !== 'sg') {
8+
console.log(chalk.red('Do you want to use `sg` cmd?'))
9+
process.exit()
10+
}
11+
612
$.verbose = false
713

814
const __filename = fileURLToPath(import.meta.url)
@@ -34,9 +40,9 @@ if (macro === 'jsx-directive') {
3440
})
3541
}
3642

37-
const defineShortSlots = 'define-slots'
43+
let defineSlots = 'define-slots'
3844
if (['jsx-directive', 'setup-sfc'].includes(macro)) {
39-
render = await select({
45+
defineSlots = await select({
4046
message: chalk.green(
4147
`Which define-slots macro do you want to use?`,
4248
),
@@ -60,7 +66,7 @@ if (macro === 'short-v-model') {
6066
})
6167
}
6268

63-
const targetDirectory = path.resolve(argv._[0] || '.')
69+
const targetDirectory = path.resolve(argv._.at(-1) || '.')
6470

6571
const files = await glob(`${targetDirectory}/**/*.vue`, {
6672
ignore: [
@@ -82,7 +88,7 @@ if (['jsx-directive', 'setup-sfc'].includes(macro)) {
8288

8389
await $`${sg} scan -c ${config} -U --filter '^tsx v-' ${targetDirectory}`
8490

85-
if (defineShortSlots)
91+
if (defineSlots === 'define-short-slots')
8692
await $`${sg} scan -c ${config} -U --filter 'tsx define-short-slots' ${targetDirectory}`
8793

8894
if (macro === 'setup-sfc') {

0 commit comments

Comments
 (0)