From d6fea9f6076549219848473d913810f3dc163b61 Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Fri, 1 Dec 2023 15:47:40 +0800 Subject: [PATCH 1/3] feat(sg): add v-slot no value support --- src/rules/jsx-directive/v-slot.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/rules/jsx-directive/v-slot.yml b/src/rules/jsx-directive/v-slot.yml index 9159d5c..1928160 100644 --- a/src/rules/jsx-directive/v-slot.yml +++ b/src/rules/jsx-directive/v-slot.yml @@ -19,3 +19,21 @@ transform: startChar: 1 fix: v-slot:$K={$V} + +--- + +id: v-slot shorthand no value +language: html +rule: + kind: attribute + has: + kind: attribute_name + regex: ^# + pattern: $NAME +transform: + K: + substring: + source: $NAME + startChar: 1 +fix: + v-slot:$K From 9c307e2cad979ca5e9b8185046f21f47c5a01d13 Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Fri, 1 Dec 2023 16:36:33 +0800 Subject: [PATCH 2/3] fix(setup-sfc): only process vue file --- package.json | 1 + pnpm-lock.yaml | 9 +++------ src/index.ts | 17 +++++++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 9fbbf70..8cb0b62 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "dependencies": { "@ast-grep/cli": "^0.14.1", "@inquirer/prompts": "^3.3.0", + "pkg-types": "^1.0.3", "zx": "^7.2.3" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9672446..3a16603 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ dependencies: '@inquirer/prompts': specifier: ^3.3.0 version: 3.3.0 + pkg-types: + specifier: ^1.0.3 + version: 1.0.3 zx: specifier: ^7.2.3 version: 7.2.3 @@ -1757,7 +1760,6 @@ packages: resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==} engines: {node: '>=0.4.0'} hasBin: true - dev: true /agent-base@7.1.0: resolution: {integrity: sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==} @@ -3407,7 +3409,6 @@ packages: /jsonc-parser@3.2.0: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} - dev: true /jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} @@ -3676,7 +3677,6 @@ packages: pathe: 1.1.1 pkg-types: 1.0.3 ufo: 1.3.2 - dev: true /mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} @@ -3940,7 +3940,6 @@ packages: /pathe@1.1.1: resolution: {integrity: sha512-d+RQGp0MAYTIaDBIMmOfMwz3E+LOZnxx1HZd5R18mmCZY0QBlK0LDZfPc8FW8Ed2DlvsuE6PRjroDY+wg4+j/Q==} - dev: true /pathval@1.1.1: resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==} @@ -3970,7 +3969,6 @@ packages: jsonc-parser: 3.2.0 mlly: 1.4.2 pathe: 1.1.1 - dev: true /pluralize@8.0.0: resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==} @@ -4785,7 +4783,6 @@ packages: /ufo@1.3.2: resolution: {integrity: sha512-o+ORpgGwaYQXgqGDwd+hkS4PuZ3QnmqMMxRuajK/a38L6fTpcE5GPIfrf+L/KemFzfUpeUQc1rRS1iDBozvnFA==} - dev: true /unbuild@2.0.0(typescript@5.3.2): resolution: {integrity: sha512-JWCUYx3Oxdzvw2J9kTAp+DKE8df/BnH/JTSj6JyA4SH40ECdFu7FoJJcrm8G92B7TjofQ6GZGjJs50TRxoH6Wg==} diff --git a/src/index.ts b/src/index.ts index 6b69aaf..d43496b 100755 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url' import process from 'node:process' import { $, argv, chalk, fs, glob, path } from 'zx' import { select } from '@inquirer/prompts' +import { readPackageJSON } from 'pkg-types' if (argv._[0] !== 'sg') { console.log(chalk.red('Do you want to use `sg` cmd?')) @@ -11,10 +12,6 @@ if (argv._[0] !== 'sg') { $.verbose = false -const __filename = fileURLToPath(import.meta.url) -const sg = path.resolve(path.dirname(__filename), '../node_modules/.bin/ast-grep') -const config = `${path.dirname(__filename)}/sgconfig` - let macro = await select({ message: chalk.green( `Which vue macro do you want to use?`, @@ -53,10 +50,16 @@ if (macro === 'short-v-model') { }) } +const dirname = path.dirname(fileURLToPath(import.meta.url)) +if (argv.v || argv.version) { + const localPackageJson = await readPackageJSON(dirname) + console.log(`${localPackageJson.name} ${localPackageJson.version}`) +} + const target = path.resolve(argv._.at(1) || './src') async function toSetupSFC() { - const filename = path.basename(target) - const files = await glob(`${target}${filename ? '' : '/**/*.vue'}`, { + const extname = path.extname(target) + const files = await glob(`${target}${extname ? '' : '/**/*.vue'}`, { ignore: [ '**/node_modules/**', ], @@ -65,6 +68,8 @@ async function toSetupSFC() { await Promise.all(files.map(async file => fs.move(file, `${file.slice(0, -3)}setup.tsx`))) } +const config = `${dirname}/sgconfig` +const sg = path.resolve(dirname, '../node_modules/.bin/ast-grep') async function useTsx(cb = () => {}, action = 'clean') { await $`${sg} scan -c ${config}.yml -U --filter '^setup-sfc start' ${target}` await $`${sg} scan -c ${config}.yml -U --filter '^setup-sfc end' ${target}` From 13c010ce150af3206e4b79059d96cfd15e362451 Mon Sep 17 00:00:00 2001 From: gaokefei <260480378@qq.com> Date: Fri, 1 Dec 2023 16:36:53 +0800 Subject: [PATCH 3/3] chore: release v1.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8cb0b62..6da7013 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@vue-macros/cli", "type": "module", - "version": "1.0.4", + "version": "1.0.5", "packageManager": "pnpm@8.10.5", "description": "Rewriting at vue macros powered by ast-grep.", "author": "zhiyuanzmj ",