@sanity/ui-codemod 1.0.0-alpha.1

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.
Files changed (157) hide show
  1. package/bin/run.js +5 -0
  2. package/dist/_chunks-es/addAttribute.js +11 -0
  3. package/dist/_chunks-es/addAttribute.js.map +1 -0
  4. package/dist/_chunks-es/box.mods.js +186 -0
  5. package/dist/_chunks-es/box.mods.js.map +1 -0
  6. package/dist/_chunks-es/flex.mods.js +74 -0
  7. package/dist/_chunks-es/flex.mods.js.map +1 -0
  8. package/dist/_chunks-es/getTransformPath.js +75 -0
  9. package/dist/_chunks-es/getTransformPath.js.map +1 -0
  10. package/dist/_chunks-es/grid.mods.js +110 -0
  11. package/dist/_chunks-es/grid.mods.js.map +1 -0
  12. package/dist/_chunks-es/layout-mods.js +424 -0
  13. package/dist/_chunks-es/layout-mods.js.map +1 -0
  14. package/dist/_chunks-es/transformComponent.js +359 -0
  15. package/dist/_chunks-es/transformComponent.js.map +1 -0
  16. package/dist/commands/latest/box.d.ts +47 -0
  17. package/dist/commands/latest/box.js +17 -0
  18. package/dist/commands/latest/box.js.map +1 -0
  19. package/dist/commands/latest/card.d.ts +47 -0
  20. package/dist/commands/latest/card.js +17 -0
  21. package/dist/commands/latest/card.js.map +1 -0
  22. package/dist/commands/latest/code.d.ts +47 -0
  23. package/dist/commands/latest/code.js +17 -0
  24. package/dist/commands/latest/code.js.map +1 -0
  25. package/dist/commands/latest/container.d.ts +47 -0
  26. package/dist/commands/latest/container.js +17 -0
  27. package/dist/commands/latest/container.js.map +1 -0
  28. package/dist/commands/latest/flex.d.ts +47 -0
  29. package/dist/commands/latest/flex.js +17 -0
  30. package/dist/commands/latest/flex.js.map +1 -0
  31. package/dist/commands/latest/grid.d.ts +47 -0
  32. package/dist/commands/latest/grid.js +17 -0
  33. package/dist/commands/latest/grid.js.map +1 -0
  34. package/dist/commands/latest/heading.d.ts +47 -0
  35. package/dist/commands/latest/heading.js +17 -0
  36. package/dist/commands/latest/heading.js.map +1 -0
  37. package/dist/commands/latest/text.d.ts +47 -0
  38. package/dist/commands/latest/text.js +17 -0
  39. package/dist/commands/latest/text.js.map +1 -0
  40. package/dist/transforms/latest/box/box.d.ts +18 -0
  41. package/dist/transforms/latest/box/box.js +101 -0
  42. package/dist/transforms/latest/box/box.js.map +1 -0
  43. package/dist/transforms/latest/card/card.d.ts +18 -0
  44. package/dist/transforms/latest/card/card.js +618 -0
  45. package/dist/transforms/latest/card/card.js.map +1 -0
  46. package/dist/transforms/latest/code/code.d.ts +18 -0
  47. package/dist/transforms/latest/code/code.js +73 -0
  48. package/dist/transforms/latest/code/code.js.map +1 -0
  49. package/dist/transforms/latest/container/container.d.ts +18 -0
  50. package/dist/transforms/latest/container/container.js +91 -0
  51. package/dist/transforms/latest/container/container.js.map +1 -0
  52. package/dist/transforms/latest/flex/flex.d.ts +18 -0
  53. package/dist/transforms/latest/flex/flex.js +19 -0
  54. package/dist/transforms/latest/flex/flex.js.map +1 -0
  55. package/dist/transforms/latest/grid/grid.d.ts +18 -0
  56. package/dist/transforms/latest/grid/grid.js +19 -0
  57. package/dist/transforms/latest/grid/grid.js.map +1 -0
  58. package/dist/transforms/latest/heading/heading.d.ts +18 -0
  59. package/dist/transforms/latest/heading/heading.js +85 -0
  60. package/dist/transforms/latest/heading/heading.js.map +1 -0
  61. package/dist/transforms/latest/text/text.d.ts +18 -0
  62. package/dist/transforms/latest/text/text.js +88 -0
  63. package/dist/transforms/latest/text/text.js.map +1 -0
  64. package/package.json +68 -0
  65. package/src/baseCommand.ts +74 -0
  66. package/src/commands/latest/box.ts +21 -0
  67. package/src/commands/latest/card.ts +21 -0
  68. package/src/commands/latest/code.ts +21 -0
  69. package/src/commands/latest/container.ts +21 -0
  70. package/src/commands/latest/flex.ts +21 -0
  71. package/src/commands/latest/grid.ts +21 -0
  72. package/src/commands/latest/heading.ts +21 -0
  73. package/src/commands/latest/inline.ts +21 -0
  74. package/src/commands/latest/label.ts +21 -0
  75. package/src/commands/latest/stack.ts +21 -0
  76. package/src/commands/latest/text.ts +21 -0
  77. package/src/constants/latest/layout-mods.ts +422 -0
  78. package/src/transforms/latest/box/box.mods.ts +88 -0
  79. package/src/transforms/latest/box/box.test.ts +204 -0
  80. package/src/transforms/latest/box/box.ts +104 -0
  81. package/src/transforms/latest/card/card.mods.ts +592 -0
  82. package/src/transforms/latest/card/card.test.ts +207 -0
  83. package/src/transforms/latest/card/card.ts +71 -0
  84. package/src/transforms/latest/code/code.mods.ts +57 -0
  85. package/src/transforms/latest/code/code.test.ts +61 -0
  86. package/src/transforms/latest/code/code.ts +53 -0
  87. package/src/transforms/latest/container/container.mods.ts +77 -0
  88. package/src/transforms/latest/container/container.test.ts +105 -0
  89. package/src/transforms/latest/container/container.ts +42 -0
  90. package/src/transforms/latest/flex/flex.mods.ts +73 -0
  91. package/src/transforms/latest/flex/flex.test.ts +80 -0
  92. package/src/transforms/latest/flex/flex.ts +42 -0
  93. package/src/transforms/latest/grid/grid.mods.ts +109 -0
  94. package/src/transforms/latest/grid/grid.test.ts +97 -0
  95. package/src/transforms/latest/grid/grid.ts +42 -0
  96. package/src/transforms/latest/heading/heading.mods.ts +70 -0
  97. package/src/transforms/latest/heading/heading.test.ts +87 -0
  98. package/src/transforms/latest/heading/heading.ts +53 -0
  99. package/src/transforms/latest/inline/inline.mods.ts +65 -0
  100. package/src/transforms/latest/inline/inline.test.ts +57 -0
  101. package/src/transforms/latest/inline/inline.ts +42 -0
  102. package/src/transforms/latest/label/label.mods.ts +72 -0
  103. package/src/transforms/latest/label/label.test.ts +113 -0
  104. package/src/transforms/latest/label/label.ts +67 -0
  105. package/src/transforms/latest/stack/stack.mods.ts +12 -0
  106. package/src/transforms/latest/stack/stack.test.ts +160 -0
  107. package/src/transforms/latest/stack/stack.ts +102 -0
  108. package/src/transforms/latest/text/text.mods.ts +72 -0
  109. package/src/transforms/latest/text/text.test.ts +113 -0
  110. package/src/transforms/latest/text/text.ts +57 -0
  111. package/src/types/AnyExpression.ts +9 -0
  112. package/src/types/AttributeMods.ts +16 -0
  113. package/src/types/BaseOptions.ts +6 -0
  114. package/src/utils/addAttribute.test.ts +43 -0
  115. package/src/utils/addAttribute.ts +26 -0
  116. package/src/utils/addImportSpecifier.test.ts +36 -0
  117. package/src/utils/addImportSpecifier.ts +42 -0
  118. package/src/utils/getAttribute.ts +22 -0
  119. package/src/utils/getAttributeExpression.ts +22 -0
  120. package/src/utils/getAttributeValue.ts +20 -0
  121. package/src/utils/getClonedImportSpecifiers.ts +29 -0
  122. package/src/utils/getComponentJsxNames.ts +17 -0
  123. package/src/utils/getComponentLocalNames.ts +69 -0
  124. package/src/utils/getCompositeAttrValue.ts +39 -0
  125. package/src/utils/getMappingArray.ts +36 -0
  126. package/src/utils/getMappingExpression.ts +22 -0
  127. package/src/utils/getMappingValue.ts +52 -0
  128. package/src/utils/getShorthandAttributes.ts +54 -0
  129. package/src/utils/getSplitImportSpecifiers.ts +40 -0
  130. package/src/utils/getStaticAttributeExpression.ts +35 -0
  131. package/src/utils/getStyleExpression.ts +37 -0
  132. package/src/utils/getStyledComponentAliases.ts +28 -0
  133. package/src/utils/getStyledComponentName.ts +52 -0
  134. package/src/utils/getTransformPath.ts +17 -0
  135. package/src/utils/insertTodoWarning.ts +48 -0
  136. package/src/utils/isImportBindingUsed.ts +53 -0
  137. package/src/utils/isValidStyleType.ts +21 -0
  138. package/src/utils/mergeStyle.ts +64 -0
  139. package/src/utils/removeUnusedImport.test.ts +77 -0
  140. package/src/utils/removeUnusedImport.ts +57 -0
  141. package/src/utils/replaceElement.test.ts +181 -0
  142. package/src/utils/replaceElement.ts +106 -0
  143. package/src/utils/replaceStyledComponent.test.ts +57 -0
  144. package/src/utils/replaceStyledComponent.ts +60 -0
  145. package/src/utils/shouldTransformComponent.test.ts +61 -0
  146. package/src/utils/shouldTransformComponent.ts +40 -0
  147. package/src/utils/testUtils.ts +54 -0
  148. package/src/utils/transformAttributes.test.ts +544 -0
  149. package/src/utils/transformAttributes.ts +248 -0
  150. package/src/utils/transformComponent.test.ts +45 -0
  151. package/src/utils/transformComponent.ts +31 -0
  152. package/src/utils/transformImport.test.ts +175 -0
  153. package/src/utils/transformImport.ts +55 -0
  154. package/src/utils/transformImportAlias.test.ts +40 -0
  155. package/src/utils/transformImportAlias.ts +49 -0
  156. package/src/utils/transformStyledComponents.test.ts +172 -0
  157. package/src/utils/transformStyledComponents.ts +58 -0
@@ -0,0 +1,74 @@
1
+ import {Command, Flags, type Interfaces} from '@oclif/core'
2
+
3
+ export type Flags<T extends typeof Command> = Interfaces.InferredFlags<
4
+ (typeof BaseCommand)['baseFlags'] & T['flags']
5
+ >
6
+ export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>
7
+
8
+ export abstract class BaseCommand<T extends typeof Command> extends Command {
9
+ static override baseFlags = {
10
+ paths: Flags.string({
11
+ description: 'Paths for jscodeshift',
12
+ multiple: true,
13
+ required: true,
14
+ helpValue: '<paths>',
15
+ }),
16
+ fromPackage: Flags.string({
17
+ description: 'Original package name to transform',
18
+ }),
19
+ toPackage: Flags.string({
20
+ description: 'New package name',
21
+ }),
22
+ extensions: Flags.string({
23
+ description: 'File extensions to transform (comma-separated, without dots)',
24
+ default: 'ts,tsx,js,jsx',
25
+ }),
26
+ dry: Flags.boolean({
27
+ description: 'Dry run without changing files',
28
+ default: false,
29
+ allowNo: true,
30
+ }),
31
+ print: Flags.boolean({
32
+ description: 'Print transformed files',
33
+ default: false,
34
+ allowNo: true,
35
+ }),
36
+ verbose: Flags.integer({
37
+ description: 'Log level for jscodeshift errors',
38
+ min: 0,
39
+ max: 2,
40
+ default: 0,
41
+ }),
42
+ }
43
+
44
+ protected flags!: Flags<T>
45
+ protected args!: Args<T>
46
+
47
+ static override examples = [
48
+ '<%= config.bin %> <%= command.id %> --paths <paths>',
49
+ '<%= config.bin %> <%= command.id %> --paths <paths> --dry',
50
+ '<%= config.bin %> <%= command.id %> --paths <paths> --print',
51
+ ]
52
+
53
+ public override async init(): Promise<void> {
54
+ await super.init()
55
+
56
+ const {args, flags} = await this.parse({
57
+ flags: this.ctor.flags,
58
+ baseFlags: (super.ctor as typeof BaseCommand).baseFlags,
59
+ args: this.ctor.args,
60
+ strict: this.ctor.strict,
61
+ })
62
+
63
+ this.flags = flags as Flags<T>
64
+ this.args = args as Args<T>
65
+ }
66
+
67
+ protected override async catch(err: Error & {exitCode?: number}): Promise<unknown> {
68
+ return super.catch(err)
69
+ }
70
+
71
+ protected override async finally(_: Error | undefined): Promise<unknown> {
72
+ return super.finally(_)
73
+ }
74
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Box extends BaseCommand<typeof Box> {
8
+ static override description = 'Transform Box component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Box)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'box')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Card extends BaseCommand<typeof Card> {
8
+ static override description = 'Transform Card component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Card)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'card')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Code extends BaseCommand<typeof Code> {
8
+ static override description = 'Transform Code component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Code)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'code')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Container extends BaseCommand<typeof Container> {
8
+ static override description = 'Transform Container component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Container)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'container')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Flex extends BaseCommand<typeof Flex> {
8
+ static override description = 'Transform Flex component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Flex)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'flex')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Grid extends BaseCommand<typeof Grid> {
8
+ static override description = 'Transform Grid component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Grid)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'grid')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Heading extends BaseCommand<typeof Heading> {
8
+ static override description = 'Transform Heading component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Heading)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'heading')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Inline extends BaseCommand<typeof Inline> {
8
+ static override description = 'Transform Card component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Inline)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'inline')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Label extends BaseCommand<typeof Label> {
8
+ static override description = 'Transform Label component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Label)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'label')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Stack extends BaseCommand<typeof Stack> {
8
+ static override description = 'Transform Card component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Stack)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'stack')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import {run} from 'jscodeshift/src/Runner.js'
2
+
3
+ import {BaseCommand} from '../../baseCommand'
4
+ import {getTransformPath} from '../../utils/getTransformPath'
5
+
6
+ /** @public */
7
+ export default class Text extends BaseCommand<typeof Text> {
8
+ static override description = 'Transform Text component'
9
+
10
+ public async run(): Promise<void> {
11
+ const {flags} = await this.parse(Text)
12
+ const {paths, ...restFlags} = flags
13
+ const transformPath = getTransformPath(this.config.root, 'latest', 'text')
14
+
15
+ await run(transformPath, paths, {
16
+ babel: true,
17
+ parser: 'tsx',
18
+ ...restFlags,
19
+ })
20
+ }
21
+ }