vuetify-codemods 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/LICENSE +557 -0
- package/README.md +17 -0
- package/dist/main.js +96181 -0
- package/eslint.config.js +9 -0
- package/package.json +36 -0
- package/patches/vue-metamorph.patch +38 -0
- package/pnpm-workspace.yaml +5 -0
- package/src/helpers.ts +259 -0
- package/src/main.ts +83 -0
- package/src/plugins/v4/combobox-item-slot.spec.ts +103 -0
- package/src/plugins/v4/combobox-item-slot.ts +100 -0
- package/src/plugins/v4/elevation.spec.ts +23 -0
- package/src/plugins/v4/elevation.ts +97 -0
- package/src/plugins/v4/form-slot-refs.spec.ts +51 -0
- package/src/plugins/v4/form-slot-refs.ts +22 -0
- package/src/plugins/v4/grid.spec.ts +282 -0
- package/src/plugins/v4/grid.ts +103 -0
- package/src/plugins/v4/index.ts +16 -0
- package/src/plugins/v4/snackbar-multiline.spec.ts +19 -0
- package/src/plugins/v4/snackbar-multiline.ts +40 -0
- package/src/plugins/v4/snackbar-queue-slot.spec.ts +53 -0
- package/src/plugins/v4/snackbar-queue-slot.ts +25 -0
- package/src/plugins/v4/typography.spec.ts +31 -0
- package/src/plugins/v4/typography.ts +40 -0
- package/tsconfig.eslint.json +8 -0
- package/tsconfig.json +23 -0
- package/vite.config.ts +25 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CodemodPlugin } from 'vue-metamorph'
|
|
2
|
+
import { findSlotNodes } from '../../helpers'
|
|
3
|
+
|
|
4
|
+
export const v4SnackbarQueueSlotPlugin: CodemodPlugin = {
|
|
5
|
+
type: 'codemod',
|
|
6
|
+
name: 'vuetify-4-snackbar-queue-slot',
|
|
7
|
+
transform ({ sfcAST, utils: { builders } }) {
|
|
8
|
+
if (!sfcAST) return 0
|
|
9
|
+
let count = 0
|
|
10
|
+
const slotNodes = findSlotNodes(sfcAST, ['VSnackbarQueue'], ['default'])
|
|
11
|
+
for (const node of slotNodes) {
|
|
12
|
+
if (node.key.type === 'VDirectiveKey') {
|
|
13
|
+
if (!node.key.argument) {
|
|
14
|
+
node.key.name.rawName = '#'
|
|
15
|
+
node.key.argument = builders.vIdentifier('item')
|
|
16
|
+
count++
|
|
17
|
+
} else if (node.key.argument.type === 'VIdentifier') {
|
|
18
|
+
node.key.argument.rawName = 'item'
|
|
19
|
+
count++
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return count
|
|
24
|
+
},
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { expect, it } from 'vitest'
|
|
2
|
+
import { transform } from 'vue-metamorph'
|
|
3
|
+
import { v4TypographyPlugin } from './typography'
|
|
4
|
+
|
|
5
|
+
it('replaces classes', () => {
|
|
6
|
+
const input = `
|
|
7
|
+
<template>
|
|
8
|
+
<div class="text-h1" />
|
|
9
|
+
<div :class="'text-h1'" />
|
|
10
|
+
<div :class="a ? 'text-h1' : 'bar'" />
|
|
11
|
+
<div :class="a && 'text-h1'" />
|
|
12
|
+
<div :class="['text-h1']" />
|
|
13
|
+
<div :class="{ ['text-h1']: true }" />
|
|
14
|
+
<div :class="{ 'text-h1': true }" />
|
|
15
|
+
</template>
|
|
16
|
+
`
|
|
17
|
+
|
|
18
|
+
expect(transform(input, 'file.vue', [v4TypographyPlugin]).code).toMatchInlineSnapshot(`
|
|
19
|
+
"
|
|
20
|
+
<template>
|
|
21
|
+
<div class="text-display-large" />
|
|
22
|
+
<div :class="'text-display-large'" />
|
|
23
|
+
<div :class="a ? 'text-display-large' : 'bar'" />
|
|
24
|
+
<div :class="a && 'text-display-large'" />
|
|
25
|
+
<div :class="['text-display-large']" />
|
|
26
|
+
<div :class="{ ['text-display-large']: true }" />
|
|
27
|
+
<div :class="{ 'text-display-large': true }" />
|
|
28
|
+
</template>
|
|
29
|
+
"
|
|
30
|
+
`)
|
|
31
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CodemodPlugin } from 'vue-metamorph'
|
|
2
|
+
import { findClassNodes } from '../../helpers'
|
|
3
|
+
|
|
4
|
+
const replacements: Record<string, string> = {
|
|
5
|
+
'text-h1': 'text-display-large',
|
|
6
|
+
'text-h2': 'text-display-medium',
|
|
7
|
+
'text-h3': 'text-display-small',
|
|
8
|
+
'text-h4': 'text-headline-large',
|
|
9
|
+
'text-h5': 'text-headline-medium',
|
|
10
|
+
'text-h6': 'text-headline-small',
|
|
11
|
+
'text-subtitle-1': 'text-body-large',
|
|
12
|
+
'text-subtitle-2': 'text-label-large',
|
|
13
|
+
'text-body-1': 'text-body-large',
|
|
14
|
+
'text-body-2': 'text-body-medium',
|
|
15
|
+
'text-caption': 'text-body-small',
|
|
16
|
+
'text-button': 'text-label-large',
|
|
17
|
+
'text-overline': 'text-label-small',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const matchingRegexp = new RegExp(String.raw`(^|\s)(${Object.keys(replacements).join('|')})(?=$|\s)`, 'g')
|
|
21
|
+
|
|
22
|
+
export const v4TypographyPlugin: CodemodPlugin = {
|
|
23
|
+
type: 'codemod',
|
|
24
|
+
name: 'vuetify-4-typography',
|
|
25
|
+
transform ({ sfcAST, utils }) {
|
|
26
|
+
if (!sfcAST) return 0
|
|
27
|
+
let count = 0
|
|
28
|
+
const found = findClassNodes(sfcAST, utils, Object.keys(replacements))
|
|
29
|
+
for (const node of found) {
|
|
30
|
+
if (node.type === 'Identifier') {
|
|
31
|
+
node.name = node.name.replaceAll(matchingRegexp, (_, s, m) => `${s}${replacements[m]}`)
|
|
32
|
+
count++
|
|
33
|
+
} else if (typeof node.value === 'string') {
|
|
34
|
+
node.value = node.value.replaceAll(matchingRegexp, (_, s, m) => `${s}${replacements[m]}`)
|
|
35
|
+
count++
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return count
|
|
39
|
+
},
|
|
40
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"isolatedModules": true,
|
|
5
|
+
"lib": [
|
|
6
|
+
"ESNext",
|
|
7
|
+
],
|
|
8
|
+
"module": "ESNext",
|
|
9
|
+
"moduleResolution": "Bundler",
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"noImplicitReturns": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"strict": true,
|
|
18
|
+
"target": "ESNext",
|
|
19
|
+
"useDefineForClassFields": true,
|
|
20
|
+
"types": ["node"]
|
|
21
|
+
},
|
|
22
|
+
"include": ["src"]
|
|
23
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
build: {
|
|
5
|
+
ssr: true,
|
|
6
|
+
target: 'node22',
|
|
7
|
+
minify: false,
|
|
8
|
+
|
|
9
|
+
lib: {
|
|
10
|
+
entry: 'src/main.ts',
|
|
11
|
+
formats: ['es'],
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
rollupOptions: {
|
|
15
|
+
output: {
|
|
16
|
+
banner: '#!/usr/bin/env node',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
ssr: {
|
|
21
|
+
noExternal: [
|
|
22
|
+
'vue-metamorph',
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
})
|