From 4e5dd2bf728afbed0e0182ca177f85a2392c261c Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Wed, 6 Dec 2023 00:06:42 +0800 Subject: [PATCH 1/5] fix: typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce210bd..dacd8ac 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ vue-macros sg ### Init ```shell -pnpm create vite my-vue-macros --template vue +pnpm create vite my-vue-macros --template vue-ts cd my-vue-macros From 7c51557981c322fae0435b8ed85e35bf4b4c22ce Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Wed, 6 Dec 2023 14:21:31 +0800 Subject: [PATCH 2/5] feat(setup-sfc): convert to setup.tsx suffix --- eslint.config.js | 1 + playground/src/App.vue | 2 +- src/init/package.ts | 2 +- src/sg/rules/setup-sfc.yml | 56 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 556284b..44c1011 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -12,6 +12,7 @@ export default antfu( }, typescript: { 'no-console': 'off', + 'prefer-const': 'off', }, yaml: { 'yaml/indent': 'off', diff --git a/playground/src/App.vue b/playground/src/App.vue index dbb5afc..cbf5637 100644 --- a/playground/src/App.vue +++ b/playground/src/App.vue @@ -5,7 +5,7 @@ import Comp from './components/Comp.vue' const list = [{ id: 1 }] const bind = { } const on = { submit: () => {} } -const select = $ref<{ id: number }>(list[0]) +let select = $ref<{ id: number }>(list[0]) const compRef = shallowRef() diff --git a/src/init/package.ts b/src/init/package.ts index 9f17883..0c0d428 100644 --- a/src/init/package.ts +++ b/src/init/package.ts @@ -21,7 +21,7 @@ export async function rewritePackage(macros: VueMacros, target: string) { && !packageJson.optionalDependencies?.[dep], ) - if (devDeps) + if (devDeps.length) return $`${ni} ${devDeps} -D` } diff --git a/src/sg/rules/setup-sfc.yml b/src/sg/rules/setup-sfc.yml index b077830..7b4b551 100644 --- a/src/sg/rules/setup-sfc.yml +++ b/src/sg/rules/setup-sfc.yml @@ -80,3 +80,59 @@ rule: inside: kind: program fix: '' + +--- + +id: setup-sfc delete .vue suffix in ts +language: ts +rule: + kind: string_fragment + regex: \.vue$ + pattern: $A + any: + - inside: + kind: string + inside: + kind: import_statement + - inside: + kind: string + inside: + kind: arguments + follows: + kind: import + stopBy: end +transform: + B: + replace: + replace: vue$ + by: setup.tsx + source: $A +fix: $B + +--- + +id: setup-sfc delete .vue suffix in tsx +language: tsx +rule: + kind: string_fragment + regex: \.vue$ + pattern: $A + any: + - inside: + kind: string + inside: + kind: import_statement + - inside: + kind: string + inside: + kind: arguments + follows: + kind: import + stopBy: end +transform: + B: + replace: + replace: vue$ + by: setup.tsx + source: $A +fix: $B From a2559c1167891faf0a87df805e19da609566b9a8 Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Wed, 6 Dec 2023 17:33:23 +0800 Subject: [PATCH 3/5] feat(sg): support single file --- src/init/tsconfig.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/init/tsconfig.ts b/src/init/tsconfig.ts index 1c2cacf..deb3b2e 100644 --- a/src/init/tsconfig.ts +++ b/src/init/tsconfig.ts @@ -1,13 +1,16 @@ import type { TSConfig } from 'pkg-types' import { readTSConfig, writeTSConfig } from 'pkg-types' +import { fs } from 'zx' import type { VueMacros } from '../common' import { vueMacros } from '../common' export async function rewriteTsConfig(selectedMacros: VueMacros, target: string) { - const tsconfig = await readTSConfig(target) as TSConfig & { vueCompilerOptions?: any } - if (!tsconfig) + const filename = `${target}/nuxt.config.ts` + if (!await fs.pathExists(filename)) return + const tsconfig = await readTSConfig(target) as TSConfig & { vueCompilerOptions?: any } + const macros = vueMacros.reduce((result, macro) => { if (macro.volar) { if (['stable', 'official'].includes(macro.status)) From c1cacf6839b17092319f584289276c4cf51e85f5 Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Wed, 6 Dec 2023 21:27:21 +0800 Subject: [PATCH 4/5] docs: up readme --- README.md | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index dacd8ac..82c0aab 100644 --- a/README.md +++ b/README.md @@ -2,37 +2,39 @@ @vue-macros/cli is a CLI for rewriting at Vue Macros powered by [ast-grep](https://github.com/ast-grep/ast-grep). -## Support vue macros - -- [x] jsx-directive -- [x] define-render -- [x] export-render -- [x] define-slots -- [x] short-vmodel -- [x] setup-sfc - - -## Usage - +## Installation ```shell # install pnpm add -g @vue-macros/cli ``` +## Usage + ### SG + +Rewriting at Vue Macros. + ```shell vue-macros sg ``` -### Init +supported vue macros: + +- [x] jsx-directive +- [x] define-render +- [x] export-render +- [x] define-slots +- [x] short-vmodel +- [x] setup-sfc + +### Initialization + ```shell pnpm create vite my-vue-macros --template vue-ts - cd my-vue-macros - vue-macros init ``` -## Licenase +## License MIT License © 2023-PRESENT [zhiyuanzmj](https://github.com/zhiyuanzmj) From 8fb12776b639deda1b8fbf128e1598102e860e62 Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Wed, 6 Dec 2023 21:27:40 +0800 Subject: [PATCH 5/5] chore: release v1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83300b4..ea6db2c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@vue-macros/cli", "type": "module", - "version": "1.1.0", + "version": "1.1.1", "packageManager": "pnpm@8.10.5", "description": "Rewriting at vue macros powered by ast-grep.", "author": "zhiyuanzmj ",