@sanity/plugin-kit 0.0.1-studio-v3.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 (194) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +398 -0
  3. package/assets/splat/LICENSE +21 -0
  4. package/assets/splat/editorconfig +13 -0
  5. package/assets/splat/eslint.config.js +5 -0
  6. package/assets/splat/gitignore +55 -0
  7. package/assets/splat/npmignore +9 -0
  8. package/assets/splat/prettierrc.js +6 -0
  9. package/assets/splat/sanity.json +8 -0
  10. package/assets/splat/template-tsconfig.json +23 -0
  11. package/assets/splat/v2-incompatible.js.template +11 -0
  12. package/lib/package.json +127 -0
  13. package/lib/src/actions/init.d.ts +65 -0
  14. package/lib/src/actions/init.js +83 -0
  15. package/lib/src/actions/init.js.map +1 -0
  16. package/lib/src/actions/link-watch.d.ts +3 -0
  17. package/lib/src/actions/link-watch.js +69 -0
  18. package/lib/src/actions/link-watch.js.map +1 -0
  19. package/lib/src/actions/splat.d.ts +26 -0
  20. package/lib/src/actions/splat.js +296 -0
  21. package/lib/src/actions/splat.js.map +1 -0
  22. package/lib/src/actions/verify/types.d.ts +77 -0
  23. package/lib/src/actions/verify/types.js +3 -0
  24. package/lib/src/actions/verify/types.js.map +1 -0
  25. package/lib/src/actions/verify/validations.d.ts +28 -0
  26. package/lib/src/actions/verify/validations.js +379 -0
  27. package/lib/src/actions/verify/validations.js.map +1 -0
  28. package/lib/src/actions/verify/verify-common.d.ts +43 -0
  29. package/lib/src/actions/verify/verify-common.js +88 -0
  30. package/lib/src/actions/verify/verify-common.js.map +1 -0
  31. package/lib/src/actions/verify-package.d.ts +5 -0
  32. package/lib/src/actions/verify-package.js +72 -0
  33. package/lib/src/actions/verify-package.js.map +1 -0
  34. package/lib/src/actions/verify-studio.d.ts +5 -0
  35. package/lib/src/actions/verify-studio.js +55 -0
  36. package/lib/src/actions/verify-studio.js.map +1 -0
  37. package/lib/src/actions/verify.d.ts +0 -0
  38. package/lib/src/actions/verify.js +330 -0
  39. package/lib/src/actions/verify.js.map +1 -0
  40. package/lib/src/cli.d.ts +2 -0
  41. package/lib/src/cli.js +86 -0
  42. package/lib/src/cli.js.map +1 -0
  43. package/lib/src/cmds/index.d.ts +8 -0
  44. package/lib/src/cmds/index.js +12 -0
  45. package/lib/src/cmds/index.js.map +1 -0
  46. package/lib/src/cmds/init.d.ts +4 -0
  47. package/lib/src/cmds/init.js +90 -0
  48. package/lib/src/cmds/init.js.map +1 -0
  49. package/lib/src/cmds/link-watch.d.ts +4 -0
  50. package/lib/src/cmds/link-watch.js +49 -0
  51. package/lib/src/cmds/link-watch.js.map +1 -0
  52. package/lib/src/cmds/splat.d.ts +4 -0
  53. package/lib/src/cmds/splat.js +63 -0
  54. package/lib/src/cmds/splat.js.map +1 -0
  55. package/lib/src/cmds/verify-package.d.ts +4 -0
  56. package/lib/src/cmds/verify-package.js +38 -0
  57. package/lib/src/cmds/verify-package.js.map +1 -0
  58. package/lib/src/cmds/verify-studio.d.ts +4 -0
  59. package/lib/src/cmds/verify-studio.js +38 -0
  60. package/lib/src/cmds/verify-studio.js.map +1 -0
  61. package/lib/src/cmds/verify.d.ts +0 -0
  62. package/lib/src/cmds/verify.js +42 -0
  63. package/lib/src/cmds/verify.js.map +1 -0
  64. package/lib/src/cmds/version.d.ts +4 -0
  65. package/lib/src/cmds/version.js +55 -0
  66. package/lib/src/cmds/version.js.map +1 -0
  67. package/lib/src/configs/buildExtensions.d.ts +1 -0
  68. package/lib/src/configs/buildExtensions.js +5 -0
  69. package/lib/src/configs/buildExtensions.js.map +1 -0
  70. package/lib/src/configs/default-source.d.ts +3 -0
  71. package/lib/src/configs/default-source.js +70 -0
  72. package/lib/src/configs/default-source.js.map +1 -0
  73. package/lib/src/configs/merged-packages.d.ts +1 -0
  74. package/lib/src/configs/merged-packages.js +24 -0
  75. package/lib/src/configs/merged-packages.js.map +1 -0
  76. package/lib/src/configs/uselessFiles.d.ts +1 -0
  77. package/lib/src/configs/uselessFiles.js +33 -0
  78. package/lib/src/configs/uselessFiles.js.map +1 -0
  79. package/lib/src/constants.d.ts +11 -0
  80. package/lib/src/constants.js +15 -0
  81. package/lib/src/constants.js.map +1 -0
  82. package/lib/src/dependencies/find.d.ts +0 -0
  83. package/lib/src/dependencies/find.js +195 -0
  84. package/lib/src/dependencies/find.js.map +1 -0
  85. package/lib/src/dependencies/import-linter.d.ts +3 -0
  86. package/lib/src/dependencies/import-linter.js +112 -0
  87. package/lib/src/dependencies/import-linter.js.map +1 -0
  88. package/lib/src/index.d.ts +2 -0
  89. package/lib/src/index.js +6 -0
  90. package/lib/src/index.js.map +1 -0
  91. package/lib/src/npm/manager.d.ts +7 -0
  92. package/lib/src/npm/manager.js +62 -0
  93. package/lib/src/npm/manager.js.map +1 -0
  94. package/lib/src/npm/package.d.ts +8 -0
  95. package/lib/src/npm/package.js +288 -0
  96. package/lib/src/npm/package.js.map +1 -0
  97. package/lib/src/npm/publish.d.ts +1 -0
  98. package/lib/src/npm/publish.js +14 -0
  99. package/lib/src/npm/publish.js.map +1 -0
  100. package/lib/src/npm/resolveLatestVersions.d.ts +3 -0
  101. package/lib/src/npm/resolveLatestVersions.js +35 -0
  102. package/lib/src/npm/resolveLatestVersions.js.map +1 -0
  103. package/lib/src/sanity/manifest.d.ts +48 -0
  104. package/lib/src/sanity/manifest.js +263 -0
  105. package/lib/src/sanity/manifest.js.map +1 -0
  106. package/lib/src/sharedFlags.d.ts +15 -0
  107. package/lib/src/sharedFlags.js +17 -0
  108. package/lib/src/sharedFlags.js.map +1 -0
  109. package/lib/src/util/command-parser.d.ts +9 -0
  110. package/lib/src/util/command-parser.js +41 -0
  111. package/lib/src/util/command-parser.js.map +1 -0
  112. package/lib/src/util/errorToUndefined.d.ts +1 -0
  113. package/lib/src/util/errorToUndefined.js +11 -0
  114. package/lib/src/util/errorToUndefined.js.map +1 -0
  115. package/lib/src/util/files.d.ts +36 -0
  116. package/lib/src/util/files.js +253 -0
  117. package/lib/src/util/files.js.map +1 -0
  118. package/lib/src/util/log.d.ts +14 -0
  119. package/lib/src/util/log.js +36 -0
  120. package/lib/src/util/log.js.map +1 -0
  121. package/lib/src/util/prompt.d.ts +13 -0
  122. package/lib/src/util/prompt.js +75 -0
  123. package/lib/src/util/prompt.js.map +1 -0
  124. package/lib/src/util/readme.d.ts +5 -0
  125. package/lib/src/util/readme.js +73 -0
  126. package/lib/src/util/readme.js.map +1 -0
  127. package/lib/src/util/request.d.ts +1 -0
  128. package/lib/src/util/request.js +19 -0
  129. package/lib/src/util/request.js.map +1 -0
  130. package/lib/src/util/user.d.ts +10 -0
  131. package/lib/src/util/user.js +106 -0
  132. package/lib/src/util/user.js.map +1 -0
  133. package/lib/test/cli.test.d.ts +1 -0
  134. package/lib/test/cli.test.js +64 -0
  135. package/lib/test/cli.test.js.map +1 -0
  136. package/lib/test/fixture-utils.d.ts +25 -0
  137. package/lib/test/fixture-utils.js +67 -0
  138. package/lib/test/fixture-utils.js.map +1 -0
  139. package/lib/test/init-verify-build.test.d.ts +1 -0
  140. package/lib/test/init-verify-build.test.js +75 -0
  141. package/lib/test/init-verify-build.test.js.map +1 -0
  142. package/lib/test/init.test.d.ts +1 -0
  143. package/lib/test/init.test.js +137 -0
  144. package/lib/test/init.test.js.map +1 -0
  145. package/lib/test/run-test-command.d.ts +1 -0
  146. package/lib/test/run-test-command.js +6 -0
  147. package/lib/test/run-test-command.js.map +1 -0
  148. package/lib/test/verify-package.test.d.ts +1 -0
  149. package/lib/test/verify-package.test.js +81 -0
  150. package/lib/test/verify-package.test.js.map +1 -0
  151. package/lib/test/version.test.d.ts +1 -0
  152. package/lib/test/version.test.js +48 -0
  153. package/lib/test/version.test.js.map +1 -0
  154. package/package.json +127 -0
  155. package/src/actions/init.ts +104 -0
  156. package/src/actions/link-watch.ts +74 -0
  157. package/src/actions/splat.ts +366 -0
  158. package/src/actions/verify/types.ts +84 -0
  159. package/src/actions/verify/validations.ts +401 -0
  160. package/src/actions/verify/verify-common.ts +92 -0
  161. package/src/actions/verify-package.ts +87 -0
  162. package/src/actions/verify-studio.ts +55 -0
  163. package/src/actions/verify.ts +328 -0
  164. package/src/cli.ts +77 -0
  165. package/src/cmds/index.ts +9 -0
  166. package/src/cmds/init.ts +85 -0
  167. package/src/cmds/link-watch.ts +51 -0
  168. package/src/cmds/splat.ts +59 -0
  169. package/src/cmds/verify-package.ts +36 -0
  170. package/src/cmds/verify-studio.ts +36 -0
  171. package/src/cmds/verify.ts +40 -0
  172. package/src/cmds/version.ts +67 -0
  173. package/src/configs/buildExtensions.ts +1 -0
  174. package/src/configs/default-source.ts +68 -0
  175. package/src/configs/merged-packages.ts +20 -0
  176. package/src/configs/uselessFiles.ts +29 -0
  177. package/src/constants.ts +13 -0
  178. package/src/dependencies/find.ts +193 -0
  179. package/src/dependencies/import-linter.ts +103 -0
  180. package/src/index.ts +4 -0
  181. package/src/npm/manager.ts +44 -0
  182. package/src/npm/package.ts +370 -0
  183. package/src/npm/publish.ts +9 -0
  184. package/src/npm/resolveLatestVersions.ts +26 -0
  185. package/src/sanity/manifest.ts +340 -0
  186. package/src/sharedFlags.ts +14 -0
  187. package/src/util/command-parser.ts +31 -0
  188. package/src/util/errorToUndefined.ts +7 -0
  189. package/src/util/files.ts +249 -0
  190. package/src/util/log.ts +44 -0
  191. package/src/util/prompt.ts +70 -0
  192. package/src/util/readme.ts +72 -0
  193. package/src/util/request.ts +13 -0
  194. package/src/util/user.ts +110 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Espen Hovlandsdal
4
+ Copyright (c) 2022 Sanity.io
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,398 @@
1
+ # @sanity/plugin-kit
2
+
3
+ > **NOTE**
4
+ >
5
+ > This is a developer preview package is meant for **Sanity Studio v3** plugin development.
6
+ >
7
+ > For a v2 alternative, consider using [Sanipack](https://github.com/rexxars/sanipack).
8
+
9
+ ## What is it?
10
+
11
+ `@sanity/plugin-kit` is an opinionated, enhanced [Sanity.io](https://www.sanity.io/) v3 plugin development experience.
12
+
13
+ It provides a set of CLI commands for initializing, verifying and testing a Sanity plugin for Sanity Studio v3.
14
+ The verify-package command can be used when upgrading V2 plugins to Studio V3 versions.
15
+
16
+ @sanity/plugin-kit also comes with a verify-studio command that can be used to recommend upgrade steps in existing Sanity Studio v2 studio.
17
+
18
+ This package assumes and recommends [Parcel](https://parceljs.org/) for building,
19
+ and [Yalc](https://github.com/wclr/yalc) with watch for testing the plugin in Sanity Studio.
20
+ Check the [FAQ](#faq) fro more on these.
21
+
22
+ ## Table of contents
23
+
24
+ * [Installation](#installation)
25
+ * [Initialize a new plugin](#initialize-a-new-plugin)
26
+ * [Verify plugin package](#verify-plugin-package)
27
+ * [Upgrading a v2 plugin](#upgrading-a-v2-plugin)
28
+ * [Upgrade help in v2 Studio](#upgrade-help-in-v2-studio)
29
+ * [Testing a plugin in Sanity Studio](#testing-a-plugin-in-sanity-studio)
30
+ * [FAQ](#faq) aka "Do I _have_ to use this plugin-kit?" aka No
31
+ * [Configuration reference](#configuration-reference)
32
+
33
+ ## Installation
34
+
35
+ > npm install --save-dev @sanity/plugin-kit
36
+
37
+ ### Install build tool
38
+
39
+ @sanity/plugin-kit assumes the plugin will use [Parcel](https://parceljs.org/) for build and watch:
40
+
41
+ > npm install --save-dev parcel
42
+
43
+ Parcel uses a build cache, you probably want to put `.parcel-cache` into `.gitignore`.
44
+
45
+ ## Initialize a new plugin
46
+
47
+ ### Quickstart
48
+
49
+ First, run the init command:
50
+ ```bash
51
+ # Initialize a new plugin (outside of your Sanity studio folder)
52
+ npx @sanity/plugin-kit@latest init sanity-plugin-testing-it-out
53
+
54
+ # Make your plugin linkable, and compile an initial version
55
+ cd sanity-plugin-testing-it-out
56
+ npm run link-watch
57
+
58
+ # In another shell, link the plugin to your Sanity studio
59
+ cd /path/to/my-studio
60
+ yalc add --link sanity-plugin-testing-it-out && yarn install
61
+ ```
62
+
63
+ Now, configure the plugin in sanity.config.ts (or .js) in Sanity Studio:
64
+ ```ts
65
+ import {createConfig} from 'sanity'
66
+ import {myPlugin} from 'sanity-plugin-testing-it-out'
67
+
68
+ export const createConfig({
69
+ //...
70
+ plugins: [
71
+ myPlugin({})
72
+ ]
73
+ })
74
+ ```
75
+
76
+ Start the studio:
77
+
78
+ ```bash
79
+ sanity start
80
+ ```
81
+
82
+ Check browser console: the plugin should have logged `"hello from my-sanity-plugin"`.
83
+ Since the plugin is running in watch mode, any changes you make to the plugin code will be reloaded in the studio.
84
+
85
+ ## Verify plugin package
86
+
87
+ Verify that the plugin package is configured correctly by running:
88
+
89
+ > npx @sanity/plugin-kit@latest verify-package
90
+
91
+ ### What does it do?
92
+
93
+ * Check package.json for:
94
+ * recommended script commands
95
+ * recommended cjs and esm configuration
96
+ * sanity dependency compatibility
97
+ * parcel devDependency
98
+ * recommended usage of devDependencies/peerDependencies/dependencies for certain packages
99
+ * Check for redundant v2 config:
100
+ * babel
101
+ * rollup
102
+ * sanity.json
103
+ * Check for sanity imports that has changed in v3, using eslint
104
+ * Check tsconfig.json settings
105
+ * Check for [SPDX](https://spdx.org/licenses/) compatible license definition
106
+ * If the package uses TypeScript, this will also run `tsc --noEmit` when all other checks have passed
107
+
108
+ Each check will explain why it is needed, steps to fix it and how it can be individually disabled.
109
+
110
+ ### What it is *not*
111
+ `verify-package` is *not* a codemod tool (yet). It will only check files and recommended settings: it will not change any files.
112
+
113
+ ### Upgrading a v2 plugin
114
+
115
+ Simply use the `verify-package` command in a v2 plugin package, and it will notify you about steps you need to take to upgrade the
116
+ plugin to v3.
117
+
118
+ ```sh
119
+ npx @sanity/plugin-kit@latest verify-package
120
+ ```
121
+
122
+ ## Upgrade help in V2 Studio
123
+
124
+ You can use the `verify-studio` command in a v2 Sanity Studio to get some of the same validation there, to help in the upgrade from v2
125
+ to v3.
126
+
127
+ ```sh
128
+ npx @sanity/plugin-kit@latest verify-studio
129
+ ```
130
+
131
+ This will:
132
+
133
+ * Check for `sanity.json,` `sanity.config.(ts|js)` and `sanity.cli.(ts|js)` and advice on how to convert the former to the latter two.
134
+ * Check for sanity dependencies that has changed in v3
135
+ * Check for sanity imports that has changed in v3, using ESlint
136
+
137
+ ### Fail fast mode
138
+
139
+ ```sh
140
+ ## for plugins
141
+ npx @sanity/plugin-kit@latest verify-package --single
142
+
143
+ ## for studio
144
+ npx @sanity/plugin-kit@latest verify-package --studio --single
145
+ ```
146
+
147
+ This will only output the first validation that fails. Useful when working through the list of issues by fixing and rerunning the command.
148
+
149
+ ## Testing a plugin in Sanity Studio
150
+
151
+ Ensure you have the following script setup in package.json:
152
+ ```json
153
+ {
154
+ "scripts": {
155
+ "link-watch": "plugin-kit link-watch"
156
+ }
157
+ }
158
+ ```
159
+
160
+ Then, in a shell, run:
161
+
162
+ ```sh
163
+ npm run link-watch
164
+ ```
165
+
166
+ This will publish the plugin to a local [yalc](https://github.com/wclr/yalc) registry.
167
+
168
+ In another shell, in your test Sanity Studio directory, run:
169
+
170
+ ```sh
171
+ npx yalc add <your-plugin-package> --link && yarn install
172
+ ```
173
+
174
+ You can now change your plugin code, which will:
175
+
176
+ 1. Trigger a rebuild using your watch task
177
+ 2. Update the files in the plugin output directory
178
+ 3. Trigger a `yalc publish --push`
179
+ 4. Update the files in your Sanity Studio
180
+ 5. Trigger hot-reload; you should see changes in the Studio
181
+
182
+ **Note:** Yalc will modify your studio package.json when linking; remember to revert it when you are done testing.
183
+ You should also put `.yalc` and `yalc.lock` into `.gitignore`.
184
+
185
+ When you are done testing, you can run
186
+ ```
187
+ npx yalc remove <your-plugin-package> && yarn install
188
+ ```
189
+ to restore the version in `package.json`.
190
+
191
+ ### Link-watch configuration
192
+ This command can be configured using `sanityPlugin.linkWatch` in package.json:
193
+
194
+ ```json5
195
+ {
196
+ "sanityPlugin": {
197
+ "linkWatch": {
198
+ // directory to watch
199
+ "folder": "lib",
200
+ // command to run when content in linkWatch.folder changes
201
+ "command": "npm run watch",
202
+ // file extensions to watch for changes in the linkWatch.folder
203
+ "extensions": "js,png,svg,gif,jpeg,css"
204
+ }
205
+ }
206
+ }
207
+ ```
208
+
209
+ ### Why use yalc?
210
+
211
+ See the [FAQ](#faq).
212
+
213
+ ## Publishing a plugin
214
+
215
+ **Note:** If you're writing a plugin that is only useful for yourself or your company,
216
+ you might want to develop the plugin directly in the Studio (saves you from having to publish at all, and has improved hot-reload dev experience).
217
+
218
+ If the plugin is shared across multiple "private" studios: register an organization on npm and make sure your module is
219
+ [prefixed with the organization scope](https://docs.npmjs.com/creating-and-publishing-private-packages), eg `@your-company/plugin-name`.
220
+
221
+ Also; you cannot easily remove modules/versions from npm once published.
222
+ Take a good look at your `package.json` to see that the fields in there makes sense to you,
223
+ and make sure there are no "secrets" (authorization tokens, API keys or similar) in the plugin directory -
224
+ anything not listed in `.npmignore` will be part of the published module.
225
+
226
+ When you're ready to publish, run `npm publish` (or `yarn publish` if you prefer).
227
+ The `prepublishOnly` task should kick in and compile the source files, then verify the built output to ensure it looks good.
228
+
229
+ If you have not published any modules to npm before, you will be asked to create a user first.
230
+
231
+ ## FAQ
232
+
233
+ #### Q: Do I _have_ to use this for developing Sanity plugins?
234
+
235
+ **A:** Absolutely not! Make sure your Sanity plugin is ES6-compatible.
236
+ This package was created to make it easier to set up the build toolchain and prevent common mistakes.
237
+
238
+ If you know what you're doing and don't like any magic, roll your own thing! :)
239
+
240
+ #### Q: Why use yalc?
241
+
242
+ npm link & yarn link unfortunately can easily break the [rules of hooks](https://reactjs.org/docs/hooks-rules.html) due
243
+ to the way packages are resolved using symlinks.
244
+
245
+ Yalc bypass this problem as it more closely resembles installing a dependency as normal.
246
+
247
+ #### Q: Do I have to use yalc?
248
+
249
+ **A:** No!
250
+
251
+ Feel free to use any variation of `npm link` or `yarn link` alongside `npm run watch` for testing,
252
+ but beware that if you get errors from React along the lines of
253
+
254
+ ```
255
+ Error: Invalid hook call. Hooks can only be called inside of the body of a function component.
256
+ This could happen for one of the following reasons:
257
+ - You might have mismatching versions of React and the renderer (such as React DOM)
258
+ - You might be breaking the Rules of Hooks
259
+ - You might have more than one copy of React in the same app
260
+ See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
261
+ ```
262
+
263
+ you probably have to revert to using yalc, or use `npm pack` + and install the resulting tzg-file.
264
+
265
+ #### Q: Why use Parcel?
266
+
267
+ Parcel is recommended for building plugins as it provides sensible defaults for building a React library that
268
+ output CommonJS and ESM files.
269
+
270
+ Parcel can in most cases be configured through `package.json` alone, and can often simply be dropped in to existing
271
+ packages without further customization .
272
+ `@sanity/plugin-kit verify-package` ensures Sanity Studio 3 compliant configs exist.
273
+
274
+ Parcel also has very speedy production builds, which is a big plus when testing plugins using watch-mode.
275
+
276
+ **A:** Sanity Studio V3 uses [Vite](https://vitejs.dev/) as the default bundler,
277
+
278
+ #### Q: Can I use another build tool or change parcel configuration?
279
+
280
+ **A:** Yes!
281
+
282
+ Feel free to make any changes to [parcel library configuration](https://parceljs.org/getting-started/library/) as is needed.
283
+ `@sanity/plugin-sdk verify` output is only recommendations for defaults that has been tested to work in Sanity Studio.
284
+ Your plugin may have other needs.
285
+
286
+ You are also free to not use parcel at all; simply change your package.json build script, and disable any verification-steps
287
+ you don't care for with `sanityPlugin.verifyPackage`.
288
+
289
+ ## CLI Help
290
+
291
+ ```sh
292
+ $ npx @sanity/plugin-kit --help
293
+
294
+ Usage
295
+ $ plugin-kit [--help] [--debug] <command> [<args>]
296
+
297
+ These are common commands used in various situations:
298
+
299
+ init Create a new Sanity plugin
300
+ verify-package Verify that a Sanity plugin follows plugin-kit conventions
301
+ splat Inject plugin-kit complatible package config into an existing plugin directory
302
+ link-watch Recompile plugin automatically on changes and push to yalc
303
+ version Show the version of ${cliName} currently installed
304
+
305
+ Options
306
+ --silent Do not print info and warning messages
307
+ --verbose Log everything. This option conflicts with --silent
308
+ --debug Print stack trace on errors
309
+ --version Output the version number
310
+ --help Output usage information
311
+
312
+ Examples
313
+ # Init a new plugin
314
+ $ plugin-kit init
315
+
316
+ # Verify that a Sanity plugin follows plugin-kit conventions
317
+ $ plugin-kit verify-package
318
+ ```
319
+
320
+ ## Configuration reference
321
+
322
+ Provide a sanityPlugin config in package.json (defaults shown):
323
+
324
+ ```json
325
+ {
326
+ "sanityPlugin": {
327
+ "linkWatch": {
328
+ "folder": "lib",
329
+ "command": "npm run watch",
330
+ "extensions": "js,png,svg,gif,jpeg,css"
331
+ }
332
+ },
333
+ "verifyPackage": {
334
+ "packageName": true,
335
+ "module": true,
336
+ "tsconfig": true,
337
+ "tsc": true,
338
+ "dependencies": true,
339
+ "rollupConfig": true,
340
+ "babelConfig": true,
341
+ "sanityV2Json": true,
342
+ "eslintImports": true,
343
+ "scripts": true,
344
+ "parcel": true,
345
+ "nodeEngine": true
346
+ }
347
+ }
348
+ ```
349
+
350
+ ## License
351
+
352
+ MIT © [Espen Hovlandsdal](https://espen.codes/) and [Sanity.io](https://www.sanity.io/)
353
+
354
+ ## Development
355
+
356
+ ### Test in another package
357
+
358
+ In one shell, run
359
+ ```sh
360
+ npm link
361
+ npm run watch
362
+ ```
363
+
364
+ In the package where you want to test plugin kit, run:
365
+
366
+ ```sh
367
+ npm link @sanity/plugin-kit
368
+ ```
369
+
370
+ Now you can run commands:
371
+
372
+ ```
373
+ npx @sanity/plugin-kit verify-package
374
+ ```
375
+
376
+ or use them in package.json scripts:
377
+
378
+ ```
379
+ "verify": "plugin-kit verify-package"
380
+ ```
381
+
382
+ ### Integration tests
383
+
384
+ ```sh
385
+ npm run test
386
+ ```
387
+
388
+ ### Run a single test-file
389
+
390
+ ```sh
391
+ npm run test -- test/verify-package.test.ts
392
+ ```
393
+
394
+ ### Update snapshots for a test
395
+
396
+ ```sh
397
+ npm run test -- test/verify-package.test.ts --snapshot
398
+ ```
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Espen Hovlandsdal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ ; editorconfig.org
2
+ root = true
3
+ charset= utf8
4
+
5
+ [*]
6
+ end_of_line = lf
7
+ insert_final_newline = true
8
+ trim_trailing_whitespace = true
9
+ indent_style = space
10
+ indent_size = 2
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
@@ -0,0 +1,5 @@
1
+ export default {
2
+ parser: 'sanipack/babel/eslint-parser',
3
+ extends: ['sanity', 'sanity/react', 'prettier'],
4
+ ignorePatterns: ['lib/**/'],
5
+ }
@@ -0,0 +1,55 @@
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
+ # Parcel
53
+ .parcel-cache
54
+
55
+ test/fixtures/init/empty
@@ -0,0 +1,9 @@
1
+ /test
2
+ /coverage
3
+ .editorconfig
4
+ .eslintrc
5
+ .gitignore
6
+ .github
7
+ .prettierrc
8
+ .travis.yml
9
+ .nyc_output
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ semi: false,
3
+ printWidth: 100,
4
+ bracketSpacing: false,
5
+ singleQuote: true,
6
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "parts": [
3
+ {
4
+ "implements": "part:@sanity/base/sanity-root",
5
+ "path": "./v2-incompatible.js"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "jsx": "preserve",
4
+ "moduleResolution": "node",
5
+ "target": "esnext",
6
+ "module": "esnext",
7
+ "esModuleInterop": true,
8
+ "lib": ["es2015", "es2016", "es2017", "dom"],
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
+ },
22
+ "include": ["src/**/*"]
23
+ }
@@ -0,0 +1,11 @@
1
+ const {showIncompatiblePluginDialog} = require('@sanity/incompatible-plugin')
2
+ const {name, version, sanityExchangeUrl} = require('./package.json')
3
+
4
+ export default showIncompatiblePluginDialog({
5
+ name: name,
6
+ versions: {
7
+ v3: version,
8
+ v2: undefined,
9
+ },
10
+ sanityExchangeUrl,
11
+ })