@sanity/plugin-kit 2.2.0 → 3.1.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.
Files changed (228) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +53 -38
  3. package/assets/inject/semver-workflow/lint-staged.template.js +1 -1
  4. package/bin/plugin-kit.js +2 -0
  5. package/dist/_chunks/cli-dbe00b65.js +162 -0
  6. package/dist/_chunks/cli-dbe00b65.js.map +1 -0
  7. package/dist/_chunks/init-2a3b4528.js +104 -0
  8. package/dist/_chunks/init-2a3b4528.js.map +1 -0
  9. package/dist/_chunks/init-7cd30f64.js +952 -0
  10. package/dist/_chunks/init-7cd30f64.js.map +1 -0
  11. package/dist/_chunks/inject-f8928379.js +49 -0
  12. package/dist/_chunks/inject-f8928379.js.map +1 -0
  13. package/dist/_chunks/link-watch-9e3f1174.js +94 -0
  14. package/dist/_chunks/link-watch-9e3f1174.js.map +1 -0
  15. package/dist/_chunks/package-bdb22a22.js +2314 -0
  16. package/dist/_chunks/package-bdb22a22.js.map +1 -0
  17. package/dist/_chunks/package-f79f12a7.js +152 -0
  18. package/dist/_chunks/package-f79f12a7.js.map +1 -0
  19. package/dist/_chunks/ts-5747e004.js +167 -0
  20. package/dist/_chunks/ts-5747e004.js.map +1 -0
  21. package/dist/_chunks/verify-package-73b843df.js +98 -0
  22. package/dist/_chunks/verify-package-73b843df.js.map +1 -0
  23. package/dist/_chunks/verify-studio-5e333969.js +75 -0
  24. package/dist/_chunks/verify-studio-5e333969.js.map +1 -0
  25. package/dist/_chunks/version-f89917d7.js +58 -0
  26. package/dist/_chunks/version-f89917d7.js.map +1 -0
  27. package/dist/cli.js +9 -0
  28. package/dist/cli.js.map +1 -0
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.js +2 -0
  31. package/dist/index.js.map +1 -0
  32. package/package.json +29 -17
  33. package/src/actions/init.ts +2 -0
  34. package/src/actions/inject.ts +66 -87
  35. package/src/actions/link-watch.ts +8 -5
  36. package/src/actions/verify/types.ts +0 -23
  37. package/src/actions/verify/validations.ts +142 -39
  38. package/src/actions/verify/verify-common.ts +5 -4
  39. package/src/actions/verify-package.ts +21 -7
  40. package/src/actions/verify-studio.ts +7 -4
  41. package/src/cli.ts +1 -3
  42. package/src/cmds/index.ts +18 -6
  43. package/src/cmds/inject.ts +5 -2
  44. package/src/cmds/link-watch.ts +0 -1
  45. package/src/configs/default-source.ts +10 -14
  46. package/src/configs/eslint.ts +51 -0
  47. package/src/configs/forced-package-versions.ts +8 -7
  48. package/src/configs/git.ts +68 -0
  49. package/src/configs/pkg-config.ts +31 -0
  50. package/src/configs/prettier.ts +11 -0
  51. package/src/configs/tsconfig.ts +79 -0
  52. package/src/configs/uselessFiles.ts +1 -1
  53. package/src/constants.ts +2 -0
  54. package/src/index.ts +1 -4
  55. package/src/npm/package.ts +62 -26
  56. package/src/presets/presets.ts +2 -1
  57. package/src/presets/renovatebot.ts +10 -1
  58. package/src/presets/semver-workflow.ts +26 -14
  59. package/src/presets/ui-workshop.ts +28 -12
  60. package/src/presets/ui.ts +68 -0
  61. package/src/sanity/manifest.ts +2 -2
  62. package/src/util/files.ts +8 -8
  63. package/src/util/readme.ts +17 -15
  64. package/src/util/ts.ts +13 -0
  65. package/assets/inject/gitignore +0 -57
  66. package/assets/inject/package.config.template +0 -16
  67. package/assets/inject/template-tsconfig.json +0 -24
  68. package/lib/package.json +0 -129
  69. package/lib/src/actions/init.d.ts +0 -73
  70. package/lib/src/actions/init.js +0 -79
  71. package/lib/src/actions/init.js.map +0 -1
  72. package/lib/src/actions/inject.d.ts +0 -31
  73. package/lib/src/actions/inject.js +0 -350
  74. package/lib/src/actions/inject.js.map +0 -1
  75. package/lib/src/actions/link-watch.d.ts +0 -3
  76. package/lib/src/actions/link-watch.js +0 -87
  77. package/lib/src/actions/link-watch.js.map +0 -1
  78. package/lib/src/actions/verify/types.d.ts +0 -75
  79. package/lib/src/actions/verify/types.js +0 -3
  80. package/lib/src/actions/verify/types.js.map +0 -1
  81. package/lib/src/actions/verify/validations.d.ts +0 -27
  82. package/lib/src/actions/verify/validations.js +0 -410
  83. package/lib/src/actions/verify/validations.js.map +0 -1
  84. package/lib/src/actions/verify/verify-common.d.ts +0 -44
  85. package/lib/src/actions/verify/verify-common.js +0 -89
  86. package/lib/src/actions/verify/verify-common.js.map +0 -1
  87. package/lib/src/actions/verify-package.d.ts +0 -5
  88. package/lib/src/actions/verify-package.js +0 -73
  89. package/lib/src/actions/verify-package.js.map +0 -1
  90. package/lib/src/actions/verify-studio.d.ts +0 -5
  91. package/lib/src/actions/verify-studio.js +0 -55
  92. package/lib/src/actions/verify-studio.js.map +0 -1
  93. package/lib/src/cli.d.ts +0 -2
  94. package/lib/src/cli.js +0 -87
  95. package/lib/src/cli.js.map +0 -1
  96. package/lib/src/cmds/index.d.ts +0 -9
  97. package/lib/src/cmds/index.js +0 -11
  98. package/lib/src/cmds/index.js.map +0 -1
  99. package/lib/src/cmds/init.d.ts +0 -4
  100. package/lib/src/cmds/init.js +0 -95
  101. package/lib/src/cmds/init.js.map +0 -1
  102. package/lib/src/cmds/inject.d.ts +0 -4
  103. package/lib/src/cmds/inject.js +0 -76
  104. package/lib/src/cmds/inject.js.map +0 -1
  105. package/lib/src/cmds/link-watch.d.ts +0 -4
  106. package/lib/src/cmds/link-watch.js +0 -49
  107. package/lib/src/cmds/link-watch.js.map +0 -1
  108. package/lib/src/cmds/verify-package.d.ts +0 -4
  109. package/lib/src/cmds/verify-package.js +0 -38
  110. package/lib/src/cmds/verify-package.js.map +0 -1
  111. package/lib/src/cmds/verify-studio.d.ts +0 -4
  112. package/lib/src/cmds/verify-studio.js +0 -38
  113. package/lib/src/cmds/verify-studio.js.map +0 -1
  114. package/lib/src/cmds/verify.d.ts +0 -0
  115. package/lib/src/cmds/verify.js +0 -42
  116. package/lib/src/cmds/verify.js.map +0 -1
  117. package/lib/src/cmds/version.d.ts +0 -4
  118. package/lib/src/cmds/version.js +0 -55
  119. package/lib/src/cmds/version.js.map +0 -1
  120. package/lib/src/configs/banned-packages.d.ts +0 -2
  121. package/lib/src/configs/banned-packages.js +0 -30
  122. package/lib/src/configs/banned-packages.js.map +0 -1
  123. package/lib/src/configs/buildExtensions.d.ts +0 -1
  124. package/lib/src/configs/buildExtensions.js +0 -5
  125. package/lib/src/configs/buildExtensions.js.map +0 -1
  126. package/lib/src/configs/default-source.d.ts +0 -3
  127. package/lib/src/configs/default-source.js +0 -70
  128. package/lib/src/configs/default-source.js.map +0 -1
  129. package/lib/src/configs/forced-package-versions.d.ts +0 -16
  130. package/lib/src/configs/forced-package-versions.js +0 -14
  131. package/lib/src/configs/forced-package-versions.js.map +0 -1
  132. package/lib/src/configs/uselessFiles.d.ts +0 -1
  133. package/lib/src/configs/uselessFiles.js +0 -33
  134. package/lib/src/configs/uselessFiles.js.map +0 -1
  135. package/lib/src/constants.d.ts +0 -11
  136. package/lib/src/constants.js +0 -15
  137. package/lib/src/constants.js.map +0 -1
  138. package/lib/src/dependencies/find.d.ts +0 -0
  139. package/lib/src/dependencies/find.js +0 -195
  140. package/lib/src/dependencies/find.js.map +0 -1
  141. package/lib/src/dependencies/import-linter.d.ts +0 -3
  142. package/lib/src/dependencies/import-linter.js +0 -112
  143. package/lib/src/dependencies/import-linter.js.map +0 -1
  144. package/lib/src/index.d.ts +0 -2
  145. package/lib/src/index.js +0 -6
  146. package/lib/src/index.js.map +0 -1
  147. package/lib/src/npm/manager.d.ts +0 -7
  148. package/lib/src/npm/manager.js +0 -62
  149. package/lib/src/npm/manager.js.map +0 -1
  150. package/lib/src/npm/package.d.ts +0 -11
  151. package/lib/src/npm/package.js +0 -302
  152. package/lib/src/npm/package.js.map +0 -1
  153. package/lib/src/npm/publish.d.ts +0 -1
  154. package/lib/src/npm/publish.js +0 -14
  155. package/lib/src/npm/publish.js.map +0 -1
  156. package/lib/src/npm/resolveLatestVersions.d.ts +0 -3
  157. package/lib/src/npm/resolveLatestVersions.js +0 -37
  158. package/lib/src/npm/resolveLatestVersions.js.map +0 -1
  159. package/lib/src/presets/presets.d.ts +0 -8
  160. package/lib/src/presets/presets.js +0 -53
  161. package/lib/src/presets/presets.js.map +0 -1
  162. package/lib/src/presets/renovatebot.d.ts +0 -2
  163. package/lib/src/presets/renovatebot.js +0 -24
  164. package/lib/src/presets/renovatebot.js.map +0 -1
  165. package/lib/src/presets/semver-workflow.d.ts +0 -8
  166. package/lib/src/presets/semver-workflow.js +0 -166
  167. package/lib/src/presets/semver-workflow.js.map +0 -1
  168. package/lib/src/presets/ui-workshop.d.ts +0 -2
  169. package/lib/src/presets/ui-workshop.js +0 -88
  170. package/lib/src/presets/ui-workshop.js.map +0 -1
  171. package/lib/src/sanity/manifest.d.ts +0 -48
  172. package/lib/src/sanity/manifest.js +0 -263
  173. package/lib/src/sanity/manifest.js.map +0 -1
  174. package/lib/src/sharedFlags.d.ts +0 -15
  175. package/lib/src/sharedFlags.js +0 -17
  176. package/lib/src/sharedFlags.js.map +0 -1
  177. package/lib/src/util/command-parser.d.ts +0 -9
  178. package/lib/src/util/command-parser.js +0 -46
  179. package/lib/src/util/command-parser.js.map +0 -1
  180. package/lib/src/util/errorToUndefined.d.ts +0 -1
  181. package/lib/src/util/errorToUndefined.js +0 -11
  182. package/lib/src/util/errorToUndefined.js.map +0 -1
  183. package/lib/src/util/files.d.ts +0 -36
  184. package/lib/src/util/files.js +0 -264
  185. package/lib/src/util/files.js.map +0 -1
  186. package/lib/src/util/log.d.ts +0 -14
  187. package/lib/src/util/log.js +0 -36
  188. package/lib/src/util/log.js.map +0 -1
  189. package/lib/src/util/prompt.d.ts +0 -14
  190. package/lib/src/util/prompt.js +0 -75
  191. package/lib/src/util/prompt.js.map +0 -1
  192. package/lib/src/util/readme.d.ts +0 -8
  193. package/lib/src/util/readme.js +0 -92
  194. package/lib/src/util/readme.js.map +0 -1
  195. package/lib/src/util/request.d.ts +0 -1
  196. package/lib/src/util/request.js +0 -19
  197. package/lib/src/util/request.js.map +0 -1
  198. package/lib/src/util/user.d.ts +0 -13
  199. package/lib/src/util/user.js +0 -111
  200. package/lib/src/util/user.js.map +0 -1
  201. package/lib/test/cli.test.d.ts +0 -1
  202. package/lib/test/cli.test.js +0 -64
  203. package/lib/test/cli.test.js.map +0 -1
  204. package/lib/test/fixture-utils.d.ts +0 -25
  205. package/lib/test/fixture-utils.js +0 -67
  206. package/lib/test/fixture-utils.js.map +0 -1
  207. package/lib/test/init-verify-build.test.d.ts +0 -1
  208. package/lib/test/init-verify-build.test.js +0 -68
  209. package/lib/test/init-verify-build.test.js.map +0 -1
  210. package/lib/test/init.test.d.ts +0 -1
  211. package/lib/test/init.test.js +0 -169
  212. package/lib/test/init.test.js.map +0 -1
  213. package/lib/test/inject.test.d.ts +0 -1
  214. package/lib/test/inject.test.js +0 -75
  215. package/lib/test/inject.test.js.map +0 -1
  216. package/lib/test/run-test-command.d.ts +0 -1
  217. package/lib/test/run-test-command.js +0 -6
  218. package/lib/test/run-test-command.js.map +0 -1
  219. package/lib/test/semver-workflow.test.d.ts +0 -1
  220. package/lib/test/semver-workflow.test.js +0 -93
  221. package/lib/test/semver-workflow.test.js.map +0 -1
  222. package/lib/test/verify-package.test.d.ts +0 -1
  223. package/lib/test/verify-package.test.js +0 -87
  224. package/lib/test/verify-package.test.js.map +0 -1
  225. package/lib/test/version.test.d.ts +0 -1
  226. package/lib/test/version.test.js +0 -48
  227. package/lib/test/version.test.js.map +0 -1
  228. package/src/cmds/verify.ts +0 -40
@@ -1,4 +1,4 @@
1
- import {FromTo, InjectOptions, writeAssets} from '../actions/inject'
1
+ import {Injectable, InjectOptions, writeAssets} from '../actions/inject'
2
2
  import {resolveLatestVersions} from '../npm/resolveLatestVersions'
3
3
  import {Preset} from './presets'
4
4
  import {
@@ -148,19 +148,31 @@ function closeEnough(a: string, b: string) {
148
148
  return isCloseEnough
149
149
  }
150
150
 
151
- function semverWorkflowFiles(): FromTo[] {
152
- return [
153
- {from: ['.github', 'workflows', 'main.yml'], to: ['.github', 'workflows', 'main.yml']},
154
- {from: ['.husky', 'commit-msg'], to: ['.husky', 'commit-msg']},
155
- {from: ['.husky', 'pre-commit'], to: ['.husky', 'pre-commit']},
156
- {from: ['.releaserc.json'], to: '.releaserc.json'},
157
- {from: ['npmrc'], to: '.npmrc'},
158
- {from: ['commitlint.template.js'], to: 'commitlint.config.js'},
159
- {from: ['lint-staged.template.js'], to: 'lint-staged.config.js'},
160
- ].map((fromTo) => ({
161
- ...fromTo,
162
- from: ['semver-workflow', ...fromTo.from],
163
- }))
151
+ function semverWorkflowFiles(): Injectable[] {
152
+ const base: Injectable[] = [
153
+ {
154
+ type: 'copy',
155
+ from: ['.github', 'workflows', 'main.yml'],
156
+ to: ['.github', 'workflows', 'main.yml'],
157
+ },
158
+ {type: 'copy', from: ['.husky', 'commit-msg'], to: ['.husky', 'commit-msg']},
159
+ {type: 'copy', from: ['.husky', 'pre-commit'], to: ['.husky', 'pre-commit']},
160
+ {type: 'copy', from: ['.releaserc.json'], to: '.releaserc.json'},
161
+ {type: 'copy', from: ['npmrc'], to: '.npmrc'},
162
+ {type: 'copy', from: ['commitlint.template.js'], to: 'commitlint.config.js'},
163
+ {type: 'copy', from: ['lint-staged.template.js'], to: 'lint-staged.config.js'},
164
+ ]
165
+
166
+ return base.map((fromTo) => {
167
+ if (fromTo.type === 'copy') {
168
+ return {
169
+ ...fromTo,
170
+ from: ['semver-workflow', ...fromTo.from],
171
+ }
172
+ }
173
+
174
+ return fromTo
175
+ })
164
176
  }
165
177
 
166
178
  async function semverWorkflowDependencies(): Promise<Record<string, string>> {
@@ -1,5 +1,5 @@
1
1
  import {Preset} from './presets'
2
- import {FromTo, InjectOptions, writeAssets} from '../actions/inject'
2
+ import {Injectable, InjectOptions, writeAssets} from '../actions/inject'
3
3
  import {getPackage, sortKeys, writePackageJsonDirect} from '../npm/package'
4
4
  import log from '../util/log'
5
5
  import chalk from 'chalk'
@@ -32,16 +32,32 @@ async function applyPreset(options: InjectOptions) {
32
32
  )
33
33
  }
34
34
 
35
- function files(): FromTo[] {
36
- return [
37
- {from: ['workshop.config.ts'], to: ['workshop.config.ts']},
38
- {from: ['src', 'CustomField.tsx'], to: ['src', 'CustomField.tsx']},
39
- {from: ['src', '__workshop__', 'index.tsx'], to: ['src', '__workshop__', 'index.tsx']},
40
- {from: ['src', '__workshop__', 'props.tsx'], to: ['src', '__workshop__', 'props.tsx']},
41
- ].map((fromTo) => ({
42
- ...fromTo,
43
- from: ['ui-workshop', ...fromTo.from],
44
- }))
35
+ function files(): Injectable[] {
36
+ const base: Injectable[] = [
37
+ {type: 'copy', from: ['workshop.config.ts'], to: ['workshop.config.ts']},
38
+ {type: 'copy', from: ['src', 'CustomField.tsx'], to: ['src', 'CustomField.tsx']},
39
+ {
40
+ type: 'copy',
41
+ from: ['src', '__workshop__', 'index.tsx'],
42
+ to: ['src', '__workshop__', 'index.tsx'],
43
+ },
44
+ {
45
+ type: 'copy',
46
+ from: ['src', '__workshop__', 'props.tsx'],
47
+ to: ['src', '__workshop__', 'props.tsx'],
48
+ },
49
+ ]
50
+
51
+ return base.map((fromTo) => {
52
+ if (fromTo.type === 'copy') {
53
+ return {
54
+ ...fromTo,
55
+ from: ['ui-workshop', ...fromTo.from],
56
+ }
57
+ }
58
+
59
+ return fromTo
60
+ })
45
61
  }
46
62
 
47
63
  async function updateGitIgnore(options: InjectOptions) {
@@ -76,6 +92,6 @@ async function devDependencies(): Promise<Record<string, string>> {
76
92
  '@sanity/ui',
77
93
  'react',
78
94
  'react-dom',
79
- 'styled-component',
95
+ 'styled-components',
80
96
  ])
81
97
  }
@@ -0,0 +1,68 @@
1
+ import {Preset} from './presets'
2
+ import {InjectOptions} from '../actions/inject'
3
+ import {forceDependencyVersions, getPackage, sortKeys, writePackageJsonDirect} from '../npm/package'
4
+ import log from '../util/log'
5
+ import chalk from 'chalk'
6
+ import {resolveLatestVersions} from '../npm/resolveLatestVersions'
7
+ import {forcedDevPackageVersions, forcedPackageVersions} from '../configs/forced-package-versions'
8
+
9
+ export const ui: Preset = {
10
+ name: 'ui',
11
+ description: '`@sanity/ui` and dependencies',
12
+ apply: applyPreset,
13
+ }
14
+
15
+ async function applyPreset(options: InjectOptions) {
16
+ await addDependencies(options)
17
+ await addDevDependencies(options)
18
+
19
+ log.info(chalk.green('ui preset injected'))
20
+ }
21
+
22
+ async function addDependencies(options: InjectOptions) {
23
+ const pkg = await getPackage(options)
24
+ const newDeps = sortKeys(
25
+ forceDependencyVersions(
26
+ {
27
+ ...pkg.dependencies,
28
+ ...(await resolveDependencyList()),
29
+ },
30
+ forcedPackageVersions
31
+ )
32
+ )
33
+ const newPkg = {...pkg}
34
+ newPkg.dependencies = newDeps
35
+ await writePackageJsonDirect(newPkg, options)
36
+ log.info('Updated dependencies.')
37
+ }
38
+
39
+ async function addDevDependencies(options: InjectOptions) {
40
+ const pkg = await getPackage(options)
41
+ const newDeps = sortKeys(
42
+ forceDependencyVersions(
43
+ {
44
+ ...pkg.devDependencies,
45
+ ...(await resolveDevDependencyList()),
46
+ },
47
+ forcedDevPackageVersions
48
+ )
49
+ )
50
+ const newPkg = {...pkg}
51
+ newPkg.devDependencies = newDeps
52
+ await writePackageJsonDirect(newPkg, options)
53
+ log.info('Updated devDependencies.')
54
+ }
55
+
56
+ async function resolveDependencyList(): Promise<Record<string, string>> {
57
+ return resolveLatestVersions(['@sanity/icons', '@sanity/ui'])
58
+ }
59
+
60
+ async function resolveDevDependencyList(): Promise<Record<string, string>> {
61
+ return resolveLatestVersions([
62
+ // install the peer dependencies of `@sanity/ui` as dev dependencies
63
+ 'react',
64
+ 'react-dom',
65
+ 'react-is',
66
+ 'styled-components',
67
+ ])
68
+ }
@@ -233,7 +233,7 @@ async function validatePartFiles(
233
233
  return
234
234
  }
235
235
 
236
- const [srcExists, libExists] = await Promise.all([
236
+ const [srcExists, outDirExists] = await Promise.all([
237
237
  hasSourceFile(part.path, paths),
238
238
  verifyCompiledParts && hasCompiledFile(part.path, paths),
239
239
  ])
@@ -246,7 +246,7 @@ async function validatePartFiles(
246
246
  )
247
247
  }
248
248
 
249
- if (verifyCompiledParts && !libExists) {
249
+ if (verifyCompiledParts && !outDirExists) {
250
250
  throw new Error(
251
251
  `Invalid sanity.json: Part path references file ("${part.path}") that does not exist in compiled directory (${paths?.compiled}) (parts[${index}])`
252
252
  )
package/src/util/files.ts CHANGED
@@ -24,10 +24,10 @@ export function hasSourceEquivalent(compiledFile: string, paths: ManifestPaths)
24
24
  )
25
25
  }
26
26
 
27
- // /plugin/lib/MyComponent.js => /plugin/src
27
+ // /plugin/dist/MyComponent.js => /plugin/src
28
28
  const baseDir = path.dirname(compiledFile.replace(paths.compiled as string, paths.source))
29
29
 
30
- // /plugin/lib/MyComponent.js => MyComponent
30
+ // /plugin/dist/MyComponent.js => MyComponent
31
31
  const baseName = path.basename(compiledFile, path.extname(compiledFile))
32
32
 
33
33
  // MyComponent => /plugin/src/MyComponent
@@ -72,14 +72,14 @@ export function hasCompiledFile(filePath: string, paths?: ManifestPaths) {
72
72
  }
73
73
 
74
74
  // filePath: components/SomeInput
75
- // paths: {compiled: '/plugin/lib'}
75
+ // paths: {compiled: '/plugin/dist'}
76
76
 
77
- // components/SomeInput => /plugin/lib/components/SomeInput
77
+ // components/SomeInput => /plugin/dist/components/SomeInput
78
78
  const absPath = path.isAbsolute(filePath) ? filePath : path.resolve(paths.compiled, filePath)
79
79
 
80
- // /plugin/lib/components/SomeInput => /plugin/lib/components/SomeInput.js
81
- // /plugin/lib/components/SomeInput.js => /plugin/lib/components/SomeInput.js
82
- // /plugin/lib/components/SomeInput.css => /plugin/lib/components/SomeInput.css
80
+ // /plugin/dist/components/SomeInput => /plugin/dist/components/SomeInput.js
81
+ // /plugin/dist/components/SomeInput.js => /plugin/dist/components/SomeInput.js
82
+ // /plugin/dist/components/SomeInput.css => /plugin/dist/components/SomeInput.css
83
83
  const fileExt = path.extname(absPath)
84
84
  const withExt = fileExt === '' ? `${absPath}.js` : absPath
85
85
 
@@ -106,7 +106,7 @@ export async function readJsonFile<T>(filePath: string) {
106
106
  }
107
107
 
108
108
  export function writeJsonFile(filePath: string, content: Record<string, unknown>) {
109
- const data = JSON.stringify(content, null, 2)
109
+ const data = JSON.stringify(content, null, 2) + '\n'
110
110
  return writeFile(filePath, data, {encoding: 'utf8'})
111
111
  }
112
112
 
@@ -7,7 +7,8 @@ import {User} from './user'
7
7
  export function generateReadme(data: PackageData) {
8
8
  const {user, pluginName, license, description} = data
9
9
 
10
- return outdent`
10
+ return (
11
+ outdent`
11
12
  # ${pluginName}
12
13
 
13
14
  ${v3BannerNotice()}
@@ -15,22 +16,23 @@ export function generateReadme(data: PackageData) {
15
16
  ${installationSnippet(pluginName ?? 'unknown')}
16
17
 
17
18
  ## Usage
18
- Add it as a plugin in sanity.config.ts (or .js):
19
19
 
20
+ Add it as a plugin in \`sanity.config.ts\` (or .js):
21
+
22
+ \`\`\`ts
23
+ import {defineConfig} from 'sanity'
24
+ import {myPlugin} from '${pluginName}'
25
+
26
+ export default defineConfig({
27
+ //...
28
+ plugins: [myPlugin({})],
29
+ })
20
30
  \`\`\`
21
- import {defineConfig} from 'sanity'
22
- import {myPlugin} from '${pluginName}'
23
-
24
- export const defineConfig({
25
- //...
26
- plugins: [
27
- myPlugin({})
28
- ]
29
- })
30
- \`\`\`
31
+
31
32
  ${getLicenseText(license?.id, user?.name ? (user as User) : undefined)}
32
33
  ${developTestSnippet()}
33
- `
34
+ ` + '\n'
35
+ )
34
36
  }
35
37
 
36
38
  export function v3BannerNotice() {
@@ -41,8 +43,8 @@ export function installationSnippet(packageName: string) {
41
43
  return outdent`
42
44
  ## Installation
43
45
 
44
- \`\`\`
45
- npm install --save ${packageName}@studio-v3
46
+ \`\`\`sh
47
+ npm install ${packageName}
46
48
  \`\`\`
47
49
  `
48
50
  }
package/src/util/ts.ts ADDED
@@ -0,0 +1,13 @@
1
+ import {loadTSConfig} from '@sanity/pkg-utils'
2
+ import path from 'path'
3
+ import {fileExists} from './files'
4
+
5
+ export async function readTSConfig(options: {basePath: string; filename: string}) {
6
+ const {basePath, filename} = options
7
+ const filePath = path.resolve(basePath, filename)
8
+ const exists = await fileExists(filePath)
9
+
10
+ if (!exists) return undefined
11
+
12
+ return await loadTSConfig({cwd: basePath, tsconfigPath: filename})
13
+ }
@@ -1,57 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
- npm-debug.log*
5
-
6
- # Runtime data
7
- pids
8
- *.pid
9
- *.seed
10
-
11
- # Directory for instrumented libs generated by jscoverage/JSCover
12
- lib-cov
13
-
14
- # Coverage directory used by tools like istanbul
15
- coverage
16
-
17
- # nyc test coverage
18
- .nyc_output
19
-
20
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21
- .grunt
22
-
23
- # node-waf configuration
24
- .lock-wscript
25
-
26
- # Compiled binary addons (http://nodejs.org/api/addons.html)
27
- build/Release
28
-
29
- # Dependency directories
30
- node_modules
31
- jspm_packages
32
-
33
- # Optional npm cache directory
34
- .npm
35
-
36
- # Optional REPL history
37
- .node_repl_history
38
-
39
- # macOS finder cache file
40
- .DS_Store
41
-
42
- # VS Code settings
43
- .vscode
44
-
45
- # IntelliJ
46
- .idea
47
- *.iml
48
-
49
- # Cache
50
- .cache
51
-
52
- # Yalc
53
- .yalc
54
- yalc.lock
55
-
56
- ##npm package zips
57
- *.tgz
@@ -1,16 +0,0 @@
1
- import {defineConfig} from '@sanity/pkg-utils'
2
-
3
- export default defineConfig({
4
- dist: 'lib',
5
- minify: true,
6
- legacyExports: true,
7
- // Remove this block to enable strict export validation
8
- extract: {
9
- rules: {
10
- 'ae-forgotten-export': 'off',
11
- 'ae-incompatible-release-tags': 'off',
12
- 'ae-internal-missing-underscore': 'off',
13
- 'ae-missing-release-tag': 'off',
14
- },
15
- },
16
- })
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "jsx": "preserve",
4
- "moduleResolution": "node",
5
- "target": "esnext",
6
- "module": "esnext",
7
- "esModuleInterop": true,
8
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
9
- "strict": true,
10
- "sourceMap": false,
11
- "inlineSourceMap": false,
12
- "downlevelIteration": true,
13
- "declaration": true,
14
- "allowSyntheticDefaultImports": true,
15
- "experimentalDecorators": true,
16
- "emitDecoratorMetadata": true,
17
- "outDir": "lib",
18
- "skipLibCheck": true,
19
- "isolatedModules": true,
20
- "checkJs": false,
21
- "rootDir": "src"
22
- },
23
- "include": ["src/**/*"]
24
- }
package/lib/package.json DELETED
@@ -1,129 +0,0 @@
1
- {
2
- "name": "@sanity/plugin-kit",
3
- "version": "2.2.0",
4
- "description": "Enhanced Sanity.io plugin development experience",
5
- "keywords": [
6
- "sanity-io",
7
- "sanity",
8
- "plugin",
9
- "development",
10
- "babel",
11
- "typescript",
12
- "bootstrap"
13
- ],
14
- "homepage": "https://github.com/sanity-io/plugin-kit#readme",
15
- "bugs": {
16
- "url": "https://github.com/sanity-io/plugin-kit/issues"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+ssh://git@github.com/sanity-io/plugin-kit.git"
21
- },
22
- "license": "MIT",
23
- "author": "Sanity.io <hello@sanity.io>",
24
- "main": "./lib/src/index.js",
25
- "source": "./src/index.ts",
26
- "types": "./lib/src/index.d.ts",
27
- "bin": "lib/src/index.js",
28
- "files": [
29
- "v2-incompatible.js",
30
- "src",
31
- "lib",
32
- "assets"
33
- ],
34
- "scripts": {
35
- "prebuild": "npm run clean",
36
- "build": "tsc",
37
- "postbuild": "node executable-index.js",
38
- "clean": "rimraf lib",
39
- "commit": "git-cz",
40
- "compile": "tsc --noEmit",
41
- "format": "prettier src -w",
42
- "lint": "eslint .",
43
- "prepare": "husky install",
44
- "prepublishOnly": "npm run build",
45
- "test": "tap",
46
- "watch": "tsc --watch"
47
- },
48
- "tap": {
49
- "browser": false,
50
- "check-coverage": false,
51
- "coverage-report": [
52
- "html"
53
- ],
54
- "jobs": 2,
55
- "reporter": "spec",
56
- "test-ignore": "^lib/.*|.*ignore.*|.*run-test-command.*|.*fixture.utils.*",
57
- "timeout": 120,
58
- "ts": true
59
- },
60
- "dependencies": {
61
- "@rexxars/choosealicense-list": "^1.1.2",
62
- "chalk": "^4.1.2",
63
- "concurrently": "^7.5.0",
64
- "discover-path": "^1.0.0",
65
- "email-validator": "^2.0.4",
66
- "execa": "^5.1.1",
67
- "find-babel-config": "^1.2.0",
68
- "get-it": "^7.0.2",
69
- "get-latest-version": "^4.0.0",
70
- "git-remote-origin-url": "^3.1.0",
71
- "git-user-info": "^2.0.3",
72
- "github-url-to-object": "^4.0.6",
73
- "inquirer": "^8.2.5",
74
- "meow": "^9.0.0",
75
- "nodemon": "^2.0.20",
76
- "npm-packlist": "^7.0.2",
77
- "npm-run-path": "^4.0.1",
78
- "outdent": "^0.8.0",
79
- "p-any": "^3.0.0",
80
- "p-props": "^4.0.0",
81
- "postcss": "^8.4.19",
82
- "rimraf": "^3.0.2",
83
- "semver": "^7.3.8",
84
- "spdx-license-ids": "^3.0.12",
85
- "validate-npm-package-name": "^5.0.0",
86
- "xdg-basedir": "^4.0.0",
87
- "yalc": "^1.0.0-pre.53"
88
- },
89
- "devDependencies": {
90
- "@commitlint/cli": "^17.2.0",
91
- "@commitlint/config-conventional": "^17.2.0",
92
- "@sanity/pkg-utils": "^1.20.1",
93
- "@sanity/semantic-release-preset": "^2.0.2",
94
- "@sanity/ui-workshop": "^1.0.1",
95
- "@types/eslint": "^8.4.10",
96
- "@types/fs-extra": "^9.0.13",
97
- "@types/inquirer": "^9.0.3",
98
- "@types/node": "^18.11.9",
99
- "@types/nodemon": "^1.19.2",
100
- "@types/tap": "^15.0.7",
101
- "@typescript-eslint/eslint-plugin": "^5.43.0",
102
- "@typescript-eslint/parser": "^5.43.0",
103
- "eslint": "^8.27.0",
104
- "eslint-config-prettier": "^8.5.0",
105
- "eslint-config-sanity": "^6.0.0",
106
- "eslint-plugin-prettier": "^4.2.1",
107
- "eslint-plugin-react-hooks": "^4.6.0",
108
- "fs-extra": "^10.1.0",
109
- "husky": "^8.0.2",
110
- "json5": "^2.2.1",
111
- "lint-staged": "^13.0.3",
112
- "prettier": "^2.7.1",
113
- "prettier-plugin-packagejson": "^2.3.0",
114
- "readdirp": "^3.6.0",
115
- "rimraf": "^3.0.2",
116
- "sanity": "^3.0.0",
117
- "sinon": "^14.0.2",
118
- "tap": "^16.3.1",
119
- "ts-node": "^10.9.1",
120
- "typescript": "^4.8.4"
121
- },
122
- "peerDependencies": {
123
- "eslint": ">=8.0.0"
124
- },
125
- "engines": {
126
- "node": ">=14"
127
- },
128
- "binname": "sanity-plugin"
129
- }
@@ -1,73 +0,0 @@
1
- import { TypedFlags } from 'meow';
2
- export declare const initFlags: {
3
- readonly scripts: {
4
- readonly type: "boolean";
5
- readonly default: true;
6
- };
7
- readonly eslint: {
8
- readonly type: "boolean";
9
- readonly default: true;
10
- };
11
- readonly typescript: {
12
- readonly type: "boolean";
13
- readonly default: true;
14
- };
15
- readonly prettier: {
16
- readonly type: "boolean";
17
- readonly default: true;
18
- };
19
- readonly license: {
20
- readonly type: "string";
21
- };
22
- readonly editorconfig: {
23
- readonly type: "boolean";
24
- readonly default: true;
25
- };
26
- readonly gitignore: {
27
- readonly type: "boolean";
28
- readonly default: true;
29
- };
30
- readonly force: {
31
- readonly type: "boolean";
32
- readonly default: false;
33
- };
34
- readonly install: {
35
- readonly type: "boolean";
36
- readonly default: true;
37
- };
38
- readonly name: {
39
- readonly type: "string";
40
- };
41
- readonly author: {
42
- readonly type: "string";
43
- };
44
- readonly repo: {
45
- readonly type: "string";
46
- };
47
- readonly presetOnly: {
48
- readonly type: "boolean";
49
- readonly default: false;
50
- };
51
- readonly preset: {
52
- readonly type: "string";
53
- readonly isMultiple: true;
54
- };
55
- readonly debug: {
56
- readonly default: false;
57
- readonly type: "boolean";
58
- };
59
- readonly silent: {
60
- readonly type: "boolean";
61
- readonly default: false;
62
- };
63
- readonly verbose: {
64
- readonly type: "boolean";
65
- readonly default: false;
66
- };
67
- };
68
- export declare type InitFlags = TypedFlags<typeof initFlags>;
69
- export interface InitOptions {
70
- basePath: string;
71
- flags: InitFlags;
72
- }
73
- export declare function init(options: InitOptions): Promise<void>;