diff --git a/README.md b/README.md index ce210bd..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 -```shell -pnpm create vite my-vue-macros --template vue +supported vue macros: -cd my-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) 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/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 ", 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/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)) 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