@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.
- package/LICENSE +1 -1
- package/README.md +53 -38
- package/assets/inject/semver-workflow/lint-staged.template.js +1 -1
- package/bin/plugin-kit.js +2 -0
- package/dist/_chunks/cli-dbe00b65.js +162 -0
- package/dist/_chunks/cli-dbe00b65.js.map +1 -0
- package/dist/_chunks/init-2a3b4528.js +104 -0
- package/dist/_chunks/init-2a3b4528.js.map +1 -0
- package/dist/_chunks/init-7cd30f64.js +952 -0
- package/dist/_chunks/init-7cd30f64.js.map +1 -0
- package/dist/_chunks/inject-f8928379.js +49 -0
- package/dist/_chunks/inject-f8928379.js.map +1 -0
- package/dist/_chunks/link-watch-9e3f1174.js +94 -0
- package/dist/_chunks/link-watch-9e3f1174.js.map +1 -0
- package/dist/_chunks/package-bdb22a22.js +2314 -0
- package/dist/_chunks/package-bdb22a22.js.map +1 -0
- package/dist/_chunks/package-f79f12a7.js +152 -0
- package/dist/_chunks/package-f79f12a7.js.map +1 -0
- package/dist/_chunks/ts-5747e004.js +167 -0
- package/dist/_chunks/ts-5747e004.js.map +1 -0
- package/dist/_chunks/verify-package-73b843df.js +98 -0
- package/dist/_chunks/verify-package-73b843df.js.map +1 -0
- package/dist/_chunks/verify-studio-5e333969.js +75 -0
- package/dist/_chunks/verify-studio-5e333969.js.map +1 -0
- package/dist/_chunks/version-f89917d7.js +58 -0
- package/dist/_chunks/version-f89917d7.js.map +1 -0
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -17
- package/src/actions/init.ts +2 -0
- package/src/actions/inject.ts +66 -87
- package/src/actions/link-watch.ts +8 -5
- package/src/actions/verify/types.ts +0 -23
- package/src/actions/verify/validations.ts +142 -39
- package/src/actions/verify/verify-common.ts +5 -4
- package/src/actions/verify-package.ts +21 -7
- package/src/actions/verify-studio.ts +7 -4
- package/src/cli.ts +1 -3
- package/src/cmds/index.ts +18 -6
- package/src/cmds/inject.ts +5 -2
- package/src/cmds/link-watch.ts +0 -1
- package/src/configs/default-source.ts +10 -14
- package/src/configs/eslint.ts +51 -0
- package/src/configs/forced-package-versions.ts +8 -7
- package/src/configs/git.ts +68 -0
- package/src/configs/pkg-config.ts +31 -0
- package/src/configs/prettier.ts +11 -0
- package/src/configs/tsconfig.ts +79 -0
- package/src/configs/uselessFiles.ts +1 -1
- package/src/constants.ts +2 -0
- package/src/index.ts +1 -4
- package/src/npm/package.ts +62 -26
- package/src/presets/presets.ts +2 -1
- package/src/presets/renovatebot.ts +10 -1
- package/src/presets/semver-workflow.ts +26 -14
- package/src/presets/ui-workshop.ts +28 -12
- package/src/presets/ui.ts +68 -0
- package/src/sanity/manifest.ts +2 -2
- package/src/util/files.ts +8 -8
- package/src/util/readme.ts +17 -15
- package/src/util/ts.ts +13 -0
- package/assets/inject/gitignore +0 -57
- package/assets/inject/package.config.template +0 -16
- package/assets/inject/template-tsconfig.json +0 -24
- package/lib/package.json +0 -129
- package/lib/src/actions/init.d.ts +0 -73
- package/lib/src/actions/init.js +0 -79
- package/lib/src/actions/init.js.map +0 -1
- package/lib/src/actions/inject.d.ts +0 -31
- package/lib/src/actions/inject.js +0 -350
- package/lib/src/actions/inject.js.map +0 -1
- package/lib/src/actions/link-watch.d.ts +0 -3
- package/lib/src/actions/link-watch.js +0 -87
- package/lib/src/actions/link-watch.js.map +0 -1
- package/lib/src/actions/verify/types.d.ts +0 -75
- package/lib/src/actions/verify/types.js +0 -3
- package/lib/src/actions/verify/types.js.map +0 -1
- package/lib/src/actions/verify/validations.d.ts +0 -27
- package/lib/src/actions/verify/validations.js +0 -410
- package/lib/src/actions/verify/validations.js.map +0 -1
- package/lib/src/actions/verify/verify-common.d.ts +0 -44
- package/lib/src/actions/verify/verify-common.js +0 -89
- package/lib/src/actions/verify/verify-common.js.map +0 -1
- package/lib/src/actions/verify-package.d.ts +0 -5
- package/lib/src/actions/verify-package.js +0 -73
- package/lib/src/actions/verify-package.js.map +0 -1
- package/lib/src/actions/verify-studio.d.ts +0 -5
- package/lib/src/actions/verify-studio.js +0 -55
- package/lib/src/actions/verify-studio.js.map +0 -1
- package/lib/src/cli.d.ts +0 -2
- package/lib/src/cli.js +0 -87
- package/lib/src/cli.js.map +0 -1
- package/lib/src/cmds/index.d.ts +0 -9
- package/lib/src/cmds/index.js +0 -11
- package/lib/src/cmds/index.js.map +0 -1
- package/lib/src/cmds/init.d.ts +0 -4
- package/lib/src/cmds/init.js +0 -95
- package/lib/src/cmds/init.js.map +0 -1
- package/lib/src/cmds/inject.d.ts +0 -4
- package/lib/src/cmds/inject.js +0 -76
- package/lib/src/cmds/inject.js.map +0 -1
- package/lib/src/cmds/link-watch.d.ts +0 -4
- package/lib/src/cmds/link-watch.js +0 -49
- package/lib/src/cmds/link-watch.js.map +0 -1
- package/lib/src/cmds/verify-package.d.ts +0 -4
- package/lib/src/cmds/verify-package.js +0 -38
- package/lib/src/cmds/verify-package.js.map +0 -1
- package/lib/src/cmds/verify-studio.d.ts +0 -4
- package/lib/src/cmds/verify-studio.js +0 -38
- package/lib/src/cmds/verify-studio.js.map +0 -1
- package/lib/src/cmds/verify.d.ts +0 -0
- package/lib/src/cmds/verify.js +0 -42
- package/lib/src/cmds/verify.js.map +0 -1
- package/lib/src/cmds/version.d.ts +0 -4
- package/lib/src/cmds/version.js +0 -55
- package/lib/src/cmds/version.js.map +0 -1
- package/lib/src/configs/banned-packages.d.ts +0 -2
- package/lib/src/configs/banned-packages.js +0 -30
- package/lib/src/configs/banned-packages.js.map +0 -1
- package/lib/src/configs/buildExtensions.d.ts +0 -1
- package/lib/src/configs/buildExtensions.js +0 -5
- package/lib/src/configs/buildExtensions.js.map +0 -1
- package/lib/src/configs/default-source.d.ts +0 -3
- package/lib/src/configs/default-source.js +0 -70
- package/lib/src/configs/default-source.js.map +0 -1
- package/lib/src/configs/forced-package-versions.d.ts +0 -16
- package/lib/src/configs/forced-package-versions.js +0 -14
- package/lib/src/configs/forced-package-versions.js.map +0 -1
- package/lib/src/configs/uselessFiles.d.ts +0 -1
- package/lib/src/configs/uselessFiles.js +0 -33
- package/lib/src/configs/uselessFiles.js.map +0 -1
- package/lib/src/constants.d.ts +0 -11
- package/lib/src/constants.js +0 -15
- package/lib/src/constants.js.map +0 -1
- package/lib/src/dependencies/find.d.ts +0 -0
- package/lib/src/dependencies/find.js +0 -195
- package/lib/src/dependencies/find.js.map +0 -1
- package/lib/src/dependencies/import-linter.d.ts +0 -3
- package/lib/src/dependencies/import-linter.js +0 -112
- package/lib/src/dependencies/import-linter.js.map +0 -1
- package/lib/src/index.d.ts +0 -2
- package/lib/src/index.js +0 -6
- package/lib/src/index.js.map +0 -1
- package/lib/src/npm/manager.d.ts +0 -7
- package/lib/src/npm/manager.js +0 -62
- package/lib/src/npm/manager.js.map +0 -1
- package/lib/src/npm/package.d.ts +0 -11
- package/lib/src/npm/package.js +0 -302
- package/lib/src/npm/package.js.map +0 -1
- package/lib/src/npm/publish.d.ts +0 -1
- package/lib/src/npm/publish.js +0 -14
- package/lib/src/npm/publish.js.map +0 -1
- package/lib/src/npm/resolveLatestVersions.d.ts +0 -3
- package/lib/src/npm/resolveLatestVersions.js +0 -37
- package/lib/src/npm/resolveLatestVersions.js.map +0 -1
- package/lib/src/presets/presets.d.ts +0 -8
- package/lib/src/presets/presets.js +0 -53
- package/lib/src/presets/presets.js.map +0 -1
- package/lib/src/presets/renovatebot.d.ts +0 -2
- package/lib/src/presets/renovatebot.js +0 -24
- package/lib/src/presets/renovatebot.js.map +0 -1
- package/lib/src/presets/semver-workflow.d.ts +0 -8
- package/lib/src/presets/semver-workflow.js +0 -166
- package/lib/src/presets/semver-workflow.js.map +0 -1
- package/lib/src/presets/ui-workshop.d.ts +0 -2
- package/lib/src/presets/ui-workshop.js +0 -88
- package/lib/src/presets/ui-workshop.js.map +0 -1
- package/lib/src/sanity/manifest.d.ts +0 -48
- package/lib/src/sanity/manifest.js +0 -263
- package/lib/src/sanity/manifest.js.map +0 -1
- package/lib/src/sharedFlags.d.ts +0 -15
- package/lib/src/sharedFlags.js +0 -17
- package/lib/src/sharedFlags.js.map +0 -1
- package/lib/src/util/command-parser.d.ts +0 -9
- package/lib/src/util/command-parser.js +0 -46
- package/lib/src/util/command-parser.js.map +0 -1
- package/lib/src/util/errorToUndefined.d.ts +0 -1
- package/lib/src/util/errorToUndefined.js +0 -11
- package/lib/src/util/errorToUndefined.js.map +0 -1
- package/lib/src/util/files.d.ts +0 -36
- package/lib/src/util/files.js +0 -264
- package/lib/src/util/files.js.map +0 -1
- package/lib/src/util/log.d.ts +0 -14
- package/lib/src/util/log.js +0 -36
- package/lib/src/util/log.js.map +0 -1
- package/lib/src/util/prompt.d.ts +0 -14
- package/lib/src/util/prompt.js +0 -75
- package/lib/src/util/prompt.js.map +0 -1
- package/lib/src/util/readme.d.ts +0 -8
- package/lib/src/util/readme.js +0 -92
- package/lib/src/util/readme.js.map +0 -1
- package/lib/src/util/request.d.ts +0 -1
- package/lib/src/util/request.js +0 -19
- package/lib/src/util/request.js.map +0 -1
- package/lib/src/util/user.d.ts +0 -13
- package/lib/src/util/user.js +0 -111
- package/lib/src/util/user.js.map +0 -1
- package/lib/test/cli.test.d.ts +0 -1
- package/lib/test/cli.test.js +0 -64
- package/lib/test/cli.test.js.map +0 -1
- package/lib/test/fixture-utils.d.ts +0 -25
- package/lib/test/fixture-utils.js +0 -67
- package/lib/test/fixture-utils.js.map +0 -1
- package/lib/test/init-verify-build.test.d.ts +0 -1
- package/lib/test/init-verify-build.test.js +0 -68
- package/lib/test/init-verify-build.test.js.map +0 -1
- package/lib/test/init.test.d.ts +0 -1
- package/lib/test/init.test.js +0 -169
- package/lib/test/init.test.js.map +0 -1
- package/lib/test/inject.test.d.ts +0 -1
- package/lib/test/inject.test.js +0 -75
- package/lib/test/inject.test.js.map +0 -1
- package/lib/test/run-test-command.d.ts +0 -1
- package/lib/test/run-test-command.js +0 -6
- package/lib/test/run-test-command.js.map +0 -1
- package/lib/test/semver-workflow.test.d.ts +0 -1
- package/lib/test/semver-workflow.test.js +0 -93
- package/lib/test/semver-workflow.test.js.map +0 -1
- package/lib/test/verify-package.test.d.ts +0 -1
- package/lib/test/verify-package.test.js +0 -87
- package/lib/test/verify-package.test.js.map +0 -1
- package/lib/test/version.test.d.ts +0 -1
- package/lib/test/version.test.js +0 -48
- package/lib/test/version.test.js.map +0 -1
- package/src/cmds/verify.ts +0 -40
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
# @sanity/plugin-kit
|
|
2
2
|
|
|
3
|
-
> **NOTE**
|
|
4
|
-
>
|
|
5
|
-
> This is a developer preview package meant for **Sanity Studio v3** plugin development.
|
|
6
|
-
>
|
|
7
|
-
> For a v2 alternative, consider using [Sanipack](https://github.com/rexxars/sanipack).
|
|
8
|
-
|
|
9
3
|
## What is it?
|
|
10
4
|
|
|
11
|
-
`@sanity/plugin-kit` is an opinionated, enhanced [Sanity
|
|
5
|
+
`@sanity/plugin-kit` is an opinionated, enhanced [Sanity](https://www.sanity.io/) plugin development experience.
|
|
6
|
+
|
|
7
|
+
It provides a set of CLI commands for initializing, verifying and testing a Sanity plugin for Sanity Studio.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# Initialize a new Sanity plugin project
|
|
11
|
+
npx @sanity/plugin-kit init my-sanity-plugin
|
|
12
|
+
```
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
```sh
|
|
15
|
+
# Verify your plugin package.
|
|
16
|
+
# This command can also be used when upgrading plugins from Sanity Studio v2 → v3.
|
|
17
|
+
npx @sanity/plugin-kit verify-package
|
|
18
|
+
```
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
```sh
|
|
21
|
+
# Get help upgrading from Sanity Studio v2 → v3.
|
|
22
|
+
npx @sanity/plugin-kit verify-studio
|
|
23
|
+
```
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
`@sanity/plugin-kit` assumes and recommends [`@sanity/pkg-utils`](https://github.com/sanity-io/pkg-utils#sanitypkg-utils) for building,
|
|
19
26
|
and [Yalc](https://github.com/wclr/yalc) with watch for testing the plugin in Sanity Studio.
|
|
20
27
|
Check the [FAQ](#faq) fro more on these.
|
|
21
28
|
|
|
@@ -39,7 +46,7 @@ Check the [FAQ](#faq) fro more on these.
|
|
|
39
46
|
|
|
40
47
|
### Install build tool
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
`@sanity/plugin-kit` assumes the plugin will use [@sanity/pkg-utils](https://github.com/sanity-io/pkg-utils#sanitypkg-utils) for build and watch:
|
|
43
50
|
|
|
44
51
|
> npm install --save-dev @sanity/plugin-kit
|
|
45
52
|
|
|
@@ -57,7 +64,7 @@ npx @sanity/plugin-kit init sanity-plugin-testing-it-out
|
|
|
57
64
|
cd sanity-plugin-testing-it-out
|
|
58
65
|
npm run link-watch
|
|
59
66
|
|
|
60
|
-
# In another shell
|
|
67
|
+
# In another shell
|
|
61
68
|
cd /path/to/my-studio
|
|
62
69
|
# now link the plugin to your Sanity studio using the command indicated by link-watch output (see below)
|
|
63
70
|
```
|
|
@@ -71,23 +78,21 @@ yalc add --link sanity-plugin-testing-it-out && yarn install
|
|
|
71
78
|
```
|
|
72
79
|
|
|
73
80
|
```bash
|
|
74
|
-
# studio uses npm
|
|
81
|
+
# studio uses npm
|
|
75
82
|
cd /path/to/my-studio
|
|
76
83
|
npx yalc add sanity-plugin-testing-it-out && npx yalc link sanity-plugin-testing-it-out && npm install
|
|
77
84
|
```
|
|
78
85
|
|
|
79
|
-
Now, configure the plugin in sanity.config.ts (or .js) in Sanity Studio:
|
|
86
|
+
Now, configure the plugin in `sanity.config.ts` (or .js) in Sanity Studio:
|
|
80
87
|
|
|
81
88
|
```ts
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
import {defineConfig} from 'sanity'
|
|
90
|
+
import {myPlugin} from 'sanity-plugin-testing-it-out'
|
|
84
91
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
]
|
|
90
|
-
})
|
|
92
|
+
export default defineConfig({
|
|
93
|
+
//...
|
|
94
|
+
plugins: [myPlugin({})],
|
|
95
|
+
})
|
|
91
96
|
```
|
|
92
97
|
|
|
93
98
|
Start the Sanity Studio development server:
|
|
@@ -129,7 +134,7 @@ Verify that the plugin package is configured correctly by running:
|
|
|
129
134
|
- Check for sanity imports that has changed in v3, using eslint
|
|
130
135
|
- Check tsconfig.json settings
|
|
131
136
|
- Check for [SPDX](https://spdx.org/licenses/) compatible license definition
|
|
132
|
-
- If the package uses TypeScript, this will also run `tsc --
|
|
137
|
+
- If the package uses TypeScript, this will also run `tsc --build` when all other checks have passed
|
|
133
138
|
|
|
134
139
|
Each check will explain why it is needed, steps to fix it and how it can be individually disabled.
|
|
135
140
|
|
|
@@ -179,13 +184,15 @@ This will only output the first validation that fails. Useful when working throu
|
|
|
179
184
|
## Inject config into existing package
|
|
180
185
|
|
|
181
186
|
```
|
|
182
|
-
npx @sanity/plugin-kit inject
|
|
187
|
+
npx @sanity/plugin-kit inject
|
|
183
188
|
```
|
|
189
|
+
|
|
184
190
|
will inject recommended V3 plugin package boilerplate into an existing plugin.
|
|
185
191
|
Be sure to commit any local changes before running this command, so you can easily revert anything
|
|
186
192
|
you dont want.
|
|
187
193
|
|
|
188
194
|
Consult the inject command CLI help:
|
|
195
|
+
|
|
189
196
|
```
|
|
190
197
|
npx @sanity/plugin-kit inject --help
|
|
191
198
|
```
|
|
@@ -196,9 +203,10 @@ for up-to-date specifics.
|
|
|
196
203
|
|
|
197
204
|
The inject command can do more work by adding presets. Consult the individual preset docs for details:
|
|
198
205
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
- [semver-workflow](./docs/semver-workflow.md) - Add an opinionated Github workflow to automate NPM releases
|
|
207
|
+
- [renovatebot](./docs/renovatebot.md) - Add opinionated Renovatebot config to make dependency management a breeze
|
|
208
|
+
- [ui](./docs/ui.md) - Add [@sanity/ui](https://github.com/sanity-io/ui) to build plugin UIs.
|
|
209
|
+
- [ui-workshop](./docs/ui-workshop.md) - Add [@sanity/ui-workshop](https://github.com/sanity-io/ui-workshop) to make component testing a breeze
|
|
202
210
|
|
|
203
211
|
## Testing a plugin in Sanity Studio
|
|
204
212
|
|
|
@@ -251,16 +259,14 @@ This command can be configured using `sanityPlugin.linkWatch` in package.json:
|
|
|
251
259
|
|
|
252
260
|
```json5
|
|
253
261
|
{
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
// directory to watch
|
|
257
|
-
"folder": "lib",
|
|
262
|
+
sanityPlugin: {
|
|
263
|
+
linkWatch: {
|
|
258
264
|
// command to run when content in linkWatch.folder changes
|
|
259
|
-
|
|
265
|
+
command: 'npm run watch',
|
|
260
266
|
// file extensions to watch for changes in the linkWatch.folder
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
}
|
|
267
|
+
extensions: 'js,png,svg,gif,jpeg,css',
|
|
268
|
+
},
|
|
269
|
+
},
|
|
264
270
|
}
|
|
265
271
|
```
|
|
266
272
|
|
|
@@ -365,6 +371,16 @@ Your plugin may have other needs.
|
|
|
365
371
|
You are also free to not use @sanity/pkg-utils at all; simply change your package.json build script, and disable any verification-steps
|
|
366
372
|
you don't care for with `sanityPlugin.verifyPackage`.
|
|
367
373
|
|
|
374
|
+
#### Q: Why multiple `tsconfig*.json` files?
|
|
375
|
+
|
|
376
|
+
After running `plugin-kit init` you will get these tsconfig files:
|
|
377
|
+
|
|
378
|
+
- `tsconfig.json` used by the IDE (this typically includes test files)
|
|
379
|
+
- `tsconfig.dist.json` used by the build system, and ignores test files
|
|
380
|
+
- `tsconfig.settings.json` with shared settings between tsconfig.json and tsconfig.dist.json
|
|
381
|
+
|
|
382
|
+
This configuration allows for type-checking you scripts and tests, and not only the distribution files. When building the scripts and test files will not be included in the npm package distribution.
|
|
383
|
+
|
|
368
384
|
## CLI Help
|
|
369
385
|
|
|
370
386
|
```sh
|
|
@@ -377,7 +393,7 @@ Usage
|
|
|
377
393
|
|
|
378
394
|
init Create a new Sanity plugin
|
|
379
395
|
verify-package Verify that a Sanity plugin follows plugin-kit conventions
|
|
380
|
-
inject Inject plugin-kit
|
|
396
|
+
inject Inject plugin-kit compatible package config into an existing plugin directory
|
|
381
397
|
link-watch Recompile plugin automatically on changes and push to yalc
|
|
382
398
|
version Show the version of ${cliName} currently installed
|
|
383
399
|
|
|
@@ -404,7 +420,6 @@ Provide a sanityPlugin config in package.json (defaults shown):
|
|
|
404
420
|
{
|
|
405
421
|
"sanityPlugin": {
|
|
406
422
|
"linkWatch": {
|
|
407
|
-
"folder": "lib",
|
|
408
423
|
"command": "npm run watch",
|
|
409
424
|
"extensions": "js,png,svg,gif,jpeg,css"
|
|
410
425
|
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var meow = require('meow');
|
|
4
|
+
var chalk = require('chalk');
|
|
5
|
+
function _interopDefaultCompat(e) {
|
|
6
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
7
|
+
default: e
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
var meow__default = /*#__PURE__*/_interopDefaultCompat(meow);
|
|
11
|
+
var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
12
|
+
let beQuiet = false;
|
|
13
|
+
let beVerbose = false;
|
|
14
|
+
function setVerbosity(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
verbose,
|
|
17
|
+
silent
|
|
18
|
+
} = _ref;
|
|
19
|
+
if (silent) {
|
|
20
|
+
beVerbose = false;
|
|
21
|
+
beQuiet = true;
|
|
22
|
+
} else if (verbose) {
|
|
23
|
+
beVerbose = true;
|
|
24
|
+
beQuiet = false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
var log = {
|
|
28
|
+
setVerbosity,
|
|
29
|
+
msg: function (msg) {
|
|
30
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
31
|
+
args[_key - 1] = arguments[_key];
|
|
32
|
+
}
|
|
33
|
+
return !beQuiet && console.log(msg, ...args);
|
|
34
|
+
},
|
|
35
|
+
debug: function (msg) {
|
|
36
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
37
|
+
args[_key2 - 1] = arguments[_key2];
|
|
38
|
+
}
|
|
39
|
+
return !beQuiet && beVerbose && console.debug("".concat(chalk__default.default.bgBlack.white("[debug]"), " ").concat(msg), ...args);
|
|
40
|
+
},
|
|
41
|
+
success: function (msg) {
|
|
42
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
43
|
+
args[_key3 - 1] = arguments[_key3];
|
|
44
|
+
}
|
|
45
|
+
return !beQuiet && console.info("".concat(chalk__default.default.bgBlack.greenBright("[success]"), " ").concat(msg), ...args);
|
|
46
|
+
},
|
|
47
|
+
info: function (msg) {
|
|
48
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
49
|
+
args[_key4 - 1] = arguments[_key4];
|
|
50
|
+
}
|
|
51
|
+
return !beQuiet && console.info("".concat(chalk__default.default.bgBlack.cyanBright("[info]"), " ").concat(msg), ...args);
|
|
52
|
+
},
|
|
53
|
+
warn: function (msg) {
|
|
54
|
+
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
|
55
|
+
args[_key5 - 1] = arguments[_key5];
|
|
56
|
+
}
|
|
57
|
+
return !beQuiet && console.warn("".concat(chalk__default.default.bgBlack.yellowBright("[warn]"), " ").concat(msg), ...args);
|
|
58
|
+
},
|
|
59
|
+
error: function (msg) {
|
|
60
|
+
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
|
61
|
+
args[_key6 - 1] = arguments[_key6];
|
|
62
|
+
}
|
|
63
|
+
return console.error("".concat(chalk__default.default.bgBlack.redBright("[error]"), " ").concat(msg), ...args);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var commands = {
|
|
67
|
+
init: async options => {
|
|
68
|
+
await (await Promise.resolve().then(function () {
|
|
69
|
+
return require('./init-2a3b4528.js');
|
|
70
|
+
})).default(options);
|
|
71
|
+
},
|
|
72
|
+
inject: async options => {
|
|
73
|
+
await (await Promise.resolve().then(function () {
|
|
74
|
+
return require('./inject-f8928379.js');
|
|
75
|
+
})).default(options);
|
|
76
|
+
},
|
|
77
|
+
"link-watch": async options => {
|
|
78
|
+
await (await Promise.resolve().then(function () {
|
|
79
|
+
return require('./link-watch-9e3f1174.js');
|
|
80
|
+
})).default(options);
|
|
81
|
+
},
|
|
82
|
+
"verify-package": async options => {
|
|
83
|
+
await (await Promise.resolve().then(function () {
|
|
84
|
+
return require('./verify-package-73b843df.js');
|
|
85
|
+
})).default(options);
|
|
86
|
+
},
|
|
87
|
+
"verify-studio": async options => {
|
|
88
|
+
await (await Promise.resolve().then(function () {
|
|
89
|
+
return require('./verify-studio-5e333969.js');
|
|
90
|
+
})).default(options);
|
|
91
|
+
},
|
|
92
|
+
version: async options => {
|
|
93
|
+
await (await Promise.resolve().then(function () {
|
|
94
|
+
return require('./version-f89917d7.js');
|
|
95
|
+
})).default(options);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var sharedFlags = {
|
|
99
|
+
debug: {
|
|
100
|
+
default: false,
|
|
101
|
+
type: "boolean"
|
|
102
|
+
},
|
|
103
|
+
silent: {
|
|
104
|
+
type: "boolean",
|
|
105
|
+
default: false
|
|
106
|
+
},
|
|
107
|
+
verbose: {
|
|
108
|
+
type: "boolean",
|
|
109
|
+
default: false
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const cliName = "@sanity/plugin-kit";
|
|
113
|
+
const urls = {
|
|
114
|
+
refDocs: "https://beta.sanity.io/docs/reference",
|
|
115
|
+
migrationGuideStudio: "https://beta.sanity.io/docs/platform/v2-to-v3",
|
|
116
|
+
migrationGuidePlugin: "https://beta.sanity.io/docs/platform/v2-to-v3/plugins",
|
|
117
|
+
pluginReadme: "https://github.com/sanity-io/plugin-kit",
|
|
118
|
+
incompatiblePlugin: "https://github.com/sanity-io/incompatible-plugin",
|
|
119
|
+
sanityExchange: "https://www.sanity.io/exchange",
|
|
120
|
+
linterPackage: "https://github.com/sanity-io/eslint-config-no-v2-imports"
|
|
121
|
+
};
|
|
122
|
+
const incompatiblePluginPackage = "@sanity/incompatible-plugin";
|
|
123
|
+
const defaultOutDir = "dist";
|
|
124
|
+
async function cliEntry() {
|
|
125
|
+
let argv = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : process.argv;
|
|
126
|
+
let autoExit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
127
|
+
const cli = meow__default.default("\n\tUsage\n\t $ ".concat(cliName, " [--help] [--debug] <command> [<args>]\n\n These are common commands used in various situations:\n\n init Create a new Sanity plugin\n inject Inject config into an existing Sanity v3 plugin\n verify-package Check that a Sanity plugin package follows V3 conventions. Prints upgrade steps.\n verify-studio Check that a Sanity Studio follows V3 conventions. Prints upgrade steps.\n link-watch Recompiles plugin automatically on changes and runs yalc push --publish\n version Show the version of ").concat(cliName, " currently installed\n\n Options\n --silent Do not print info and warning messages\n --verbose Log everything. This option conflicts with --silent\n --debug Print stack trace on errors\n --version Output the version number\n --help Output usage information\n\n Examples\n # Init a new plugin in current directory\n $ ").concat(cliName, " init\n\n # Init a new plugin in my-sanity-plugin directory\n $ ").concat(cliName, " init my-sanity-plugin\n\n # Check that a Sanity plugin package in current directory follows V3 conventions\n $ ").concat(cliName, " verify-package\n\n # Check that a Sanity Studio in current directory follows V3 conventions\n $ ").concat(cliName, " verify-studio\n"), {
|
|
128
|
+
autoHelp: false,
|
|
129
|
+
flags: sharedFlags,
|
|
130
|
+
argv: argv.slice(2)
|
|
131
|
+
});
|
|
132
|
+
const commandName = cli.input[0];
|
|
133
|
+
if (!commandName) {
|
|
134
|
+
cli.showHelp();
|
|
135
|
+
}
|
|
136
|
+
if (!(commandName in commands)) {
|
|
137
|
+
console.error("Unknown command \"".concat(commandName, "\""));
|
|
138
|
+
cli.showHelp();
|
|
139
|
+
}
|
|
140
|
+
if (cli.flags.silent && cli.flags.verbose) {
|
|
141
|
+
log.error("--silent and --verbose are mutually exclusive");
|
|
142
|
+
cli.showHelp();
|
|
143
|
+
}
|
|
144
|
+
const cmd = commands[commandName];
|
|
145
|
+
try {
|
|
146
|
+
log.setVerbosity(cli.flags);
|
|
147
|
+
await cmd({
|
|
148
|
+
argv: argv.slice(3)
|
|
149
|
+
});
|
|
150
|
+
} catch (err) {
|
|
151
|
+
log.error(err instanceof TypeError || cli.flags.debug ? err.stack : err.message);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.cliEntry = cliEntry;
|
|
156
|
+
exports.cliName = cliName;
|
|
157
|
+
exports.defaultOutDir = defaultOutDir;
|
|
158
|
+
exports.incompatiblePluginPackage = incompatiblePluginPackage;
|
|
159
|
+
exports.log = log;
|
|
160
|
+
exports.sharedFlags = sharedFlags;
|
|
161
|
+
exports.urls = urls;
|
|
162
|
+
//# sourceMappingURL=cli-dbe00b65.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-dbe00b65.js","sources":["../../src/util/log.ts","../../src/cmds/index.ts","../../src/sharedFlags.ts","../../src/constants.ts","../../src/cli.ts"],"sourcesContent":["// Note: This is _specifically_ meant for CLI usage,\n// I realize that \"singletons\" are bad.\n\nimport chalk from 'chalk'\n\nlet beQuiet = false\nlet beVerbose = false\n\nfunction setVerbosity({verbose, silent}: {verbose: boolean; silent: boolean}) {\n if (silent) {\n beVerbose = false\n beQuiet = true\n } else if (verbose) {\n beVerbose = true\n beQuiet = false\n }\n}\n\nexport default {\n setVerbosity: setVerbosity,\n\n // Bypasses any checks, prints regardless (only use for things like `cli --version`)\n msg: (msg: any, ...args: any[]) => !beQuiet && console.log(msg, ...args),\n\n // Debug only printed on --verbose\n debug: (msg: any, ...args: any[]) =>\n !beQuiet && beVerbose && console.debug(`${chalk.bgBlack.white('[debug]')} ${msg}`, ...args),\n\n // Success messages only printed if not --silent\n success: (msg: any, ...args: any[]) =>\n !beQuiet && console.info(`${chalk.bgBlack.greenBright('[success]')} ${msg}`, ...args),\n\n // Info only printed if not --silent (\"standard\" level)\n info: (msg: any, ...args: any[]) =>\n !beQuiet && console.info(`${chalk.bgBlack.cyanBright('[info]')} ${msg}`, ...args),\n\n // Warning only printed if not --silent\n warn: (msg: any, ...args: any[]) =>\n !beQuiet && console.warn(`${chalk.bgBlack.yellowBright('[warn]')} ${msg}`, ...args),\n\n // Errors are always printed\n error: (msg: any, ...args: any[]) =>\n console.error(`${chalk.bgBlack.redBright('[error]')} ${msg}`, ...args),\n}\n","export default {\n init: async (options: {argv: string[]}) => {\n await (await import('./init')).default(options)\n },\n inject: async (options: {argv: string[]}) => {\n await (await import('./inject')).default(options)\n },\n 'link-watch': async (options: {argv: string[]}) => {\n await (await import('./link-watch')).default(options)\n },\n 'verify-package': async (options: {argv: string[]}) => {\n await (await import('./verify-package')).default(options)\n },\n 'verify-studio': async (options: {argv: string[]}) => {\n await (await import('./verify-studio')).default(options)\n },\n version: async (options: {argv: string[]}) => {\n await (await import('./version')).default(options)\n },\n}\n","export default {\n debug: {\n default: false,\n type: 'boolean',\n },\n silent: {\n type: 'boolean',\n default: false,\n },\n verbose: {\n type: 'boolean',\n default: false,\n },\n} as const\n","export const cliName = '@sanity/plugin-kit'\n\nexport const urls = {\n refDocs: 'https://beta.sanity.io/docs/reference',\n migrationGuideStudio: 'https://beta.sanity.io/docs/platform/v2-to-v3',\n migrationGuidePlugin: 'https://beta.sanity.io/docs/platform/v2-to-v3/plugins',\n pluginReadme: 'https://github.com/sanity-io/plugin-kit',\n incompatiblePlugin: 'https://github.com/sanity-io/incompatible-plugin',\n sanityExchange: 'https://www.sanity.io/exchange',\n linterPackage: 'https://github.com/sanity-io/eslint-config-no-v2-imports',\n}\n\nexport const incompatiblePluginPackage = '@sanity/incompatible-plugin'\n\nexport const defaultOutDir = 'dist'\n","import meow from 'meow'\nimport log from './util/log'\nimport commands from './cmds'\nimport sharedFlags from './sharedFlags'\nimport {cliName} from './constants'\n\nexport async function cliEntry(argv = process.argv, autoExit = true) {\n const cli = meow(\n `\n\tUsage\n\t $ ${cliName} [--help] [--debug] <command> [<args>]\n\n These are common commands used in various situations:\n\n init Create a new Sanity plugin\n inject Inject config into an existing Sanity v3 plugin\n verify-package Check that a Sanity plugin package follows V3 conventions. Prints upgrade steps.\n verify-studio Check that a Sanity Studio follows V3 conventions. Prints upgrade steps.\n link-watch Recompiles plugin automatically on changes and runs yalc push --publish\n version Show the version of ${cliName} currently installed\n\n Options\n --silent Do not print info and warning messages\n --verbose Log everything. This option conflicts with --silent\n --debug Print stack trace on errors\n --version Output the version number\n --help Output usage information\n\n Examples\n # Init a new plugin in current directory\n $ ${cliName} init\n\n # Init a new plugin in my-sanity-plugin directory\n $ ${cliName} init my-sanity-plugin\n\n # Check that a Sanity plugin package in current directory follows V3 conventions\n $ ${cliName} verify-package\n\n # Check that a Sanity Studio in current directory follows V3 conventions\n $ ${cliName} verify-studio\n`,\n {\n autoHelp: false,\n flags: sharedFlags,\n argv: argv.slice(2),\n }\n )\n\n const commandName = cli.input[0]\n if (!commandName) {\n cli.showHelp() // Exits\n }\n\n if (!(commandName in commands)) {\n console.error(`Unknown command \"${commandName}\"`)\n cli.showHelp() // Exits\n }\n\n if (cli.flags.silent && cli.flags.verbose) {\n log.error(`--silent and --verbose are mutually exclusive`)\n cli.showHelp() // Exits\n }\n\n // Lazy-load command\n const cmd = commands[commandName as keyof typeof commands]\n\n try {\n log.setVerbosity(cli.flags)\n await cmd({argv: argv.slice(3)})\n } catch (err: any) {\n log.error(err instanceof TypeError || cli.flags.debug ? err.stack : err.message)\n\n // eslint-disable-next-line no-process-exit\n process.exit(1)\n }\n}\n"],"names":["beQuiet","beVerbose","setVerbosity","verbose","silent","log","msg","args","console","debug","chalk","bgBlack","white","success","info","default","greenBright","cyanBright","warn","yellowBright","error","redBright","commands","init","options","Promise","resolve","then","require","inject","version","sharedFlags","type","cliName","urls","refDocs","migrationGuideStudio","migrationGuidePlugin","pluginReadme","incompatiblePlugin","sanityExchange","linterPackage","incompatiblePluginPackage","defaultOutDir","cliEntry","argv","process","autoExit","cli","meow","autoHelp","flags","slice","commandName","input","showHelp","cmd","err","TypeError","stack","message","exit"],"mappings":";;;;;;;;;;;AAKA,IAAIA,OAAU,GAAA,KAAA;AACd,IAAIC,SAAY,GAAA,KAAA;AAEhB,SAASC,YAAa,OAAwD;EAAA,IAAxD;IAACC,OAAS;IAAAC;GAA8C;EAC5E,IAAIA,MAAQ,EAAA;IACEH,SAAA,GAAA,KAAA;IACFD,OAAA,GAAA,IAAA;aACDG,OAAS,EAAA;IACNF,SAAA,GAAA,IAAA;IACFD,OAAA,GAAA,KAAA;EACZ;AACF;AAEA,IAAeK,GAAA,GAAA;EACbH,YAAA;EAGAI,GAAA,EAAK,UAACA,GAAA;IAAA,kCAAaC,IAAgB;MAAhBA,IAAgB;IAAA;IAAA,OAAA,CAACP,WAAWQ,OAAQ,CAAAH,GAAA,CAAIC,GAAK,EAAA,GAAGC,IAAI,CAAA;EAAA;EAGvEE,OAAO,UAACH,GAAA;IAAA,mCAAaC,IACnB;MADmBA,IACnB;IAAA;IAAA,OAAA,CAACP,WAAWC,SAAa,IAAAO,OAAA,CAAQC,KAAM,WAAGC,cAAAA,CAAAA,QAAMC,OAAQ,CAAAC,KAAA,CAAM,SAAS,CAAK,c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AAA;IACEhD,GAAA,CAAAH,YAAA,CAAa8C,IAAIG,KAAK,CAAA;IAC1B,MAAMK,IAAI;MAACX,IAAA,EAAMA,KAAKO,KAAM,CAAA,CAAC;KAAE,CAAA;WACxBK,GAAP,EAAA;IACIpD,GAAA,CAAAe,KAAA,CAAMqC,eAAeC,SAAa,IAAAV,GAAA,CAAIG,MAAM1C,KAAQ,GAAAgD,GAAA,CAAIE,KAAQ,GAAAF,GAAA,CAAIG,OAAO,CAAA;IAG/Ed,OAAA,CAAQe,KAAK,CAAC,CAAA;EAChB;AACF;;;;;;;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var meow = require('meow');
|
|
5
|
+
var cli = require('./cli-dbe00b65.js');
|
|
6
|
+
var init = require('./init-7cd30f64.js');
|
|
7
|
+
var _package = require('./package-bdb22a22.js');
|
|
8
|
+
var execa = require('execa');
|
|
9
|
+
function _interopDefaultCompat(e) {
|
|
10
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
11
|
+
default: e
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
15
|
+
var meow__default = /*#__PURE__*/_interopDefaultCompat(meow);
|
|
16
|
+
var execa__default = /*#__PURE__*/_interopDefaultCompat(execa);
|
|
17
|
+
function npmIsAvailable() {
|
|
18
|
+
return execa__default.default("npm", ["-v"]).then(() => true).catch(() => false);
|
|
19
|
+
}
|
|
20
|
+
function yarnIsAvailable() {
|
|
21
|
+
return execa__default.default("yarn", ["-v"]).then(() => true).catch(() => false);
|
|
22
|
+
}
|
|
23
|
+
function pnpmAvailable() {
|
|
24
|
+
return execa__default.default("pnpm", ["-v"]).then(() => true).catch(() => false);
|
|
25
|
+
}
|
|
26
|
+
async function promptForPackageManager() {
|
|
27
|
+
const [npm, yarn, pnpm] = await Promise.all([npmIsAvailable(), yarnIsAvailable(), pnpmAvailable()]);
|
|
28
|
+
const choices = [npm && "npm", yarn && "yarn", pnpm && "pnpm"].filter(Boolean);
|
|
29
|
+
if (choices.length < 2) {
|
|
30
|
+
return choices[0] || "npm";
|
|
31
|
+
}
|
|
32
|
+
return _package.prompt("Which package manager do you prefer?", {
|
|
33
|
+
choices: choices.map(value => ({
|
|
34
|
+
value,
|
|
35
|
+
name: value
|
|
36
|
+
})),
|
|
37
|
+
default: choices[0]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async function installDependencies(pm, _ref) {
|
|
41
|
+
let {
|
|
42
|
+
cwd
|
|
43
|
+
} = _ref;
|
|
44
|
+
const proc = execa__default.default(pm, ["install"], {
|
|
45
|
+
cwd,
|
|
46
|
+
stdio: "inherit"
|
|
47
|
+
});
|
|
48
|
+
const {
|
|
49
|
+
exitCode
|
|
50
|
+
} = await proc;
|
|
51
|
+
return exitCode <= 0;
|
|
52
|
+
}
|
|
53
|
+
const description = "Initialize a new Sanity plugin";
|
|
54
|
+
const help = "\nUsage\n $ ".concat(cli.cliName, " init [dir] [<args>]\n\nOptions\n --no-eslint Disables ESLint config and dependencies from being added\n --no-prettier Disables prettier config and dependencies from being added\n --no-typescript Disables typescript config and dependencies from being added\n --no-license Disables LICENSE + package.json license field from being added\n --no-editorconfig Disables .editorconfig from being added\n --no-gitignore Disables .gitignore from being added\n --no-scripts Disables scripts from being added to package.json\n --no-install Disables automatically running package manager install\n\n --name [package-name] Use the provided package-name\n --author [name] Use the provided author\n --repo [url] Use the provided repo url\n --license [spdx] Use the license with the given SPDX identifier\n --force No promt when overwriting files\n\n --preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.\n The following presets are available:\n").concat(init.presetHelpList(30), "\n\nExamples\n # Initialize a new plugin in the current directory\n $ ").concat(cli.cliName, " init\n\n # Initialize a plugin in the directory ~/my-plugin\n $ ").concat(cli.cliName, " init ~/my-plugin\n\n # Don't add eslint or prettier\n $ ").concat(cli.cliName, " init --no-eslint --no-prettier\n");
|
|
55
|
+
async function run(_ref2) {
|
|
56
|
+
let {
|
|
57
|
+
argv
|
|
58
|
+
} = _ref2;
|
|
59
|
+
const cli$1 = meow__default.default(help, {
|
|
60
|
+
flags: init.initFlags,
|
|
61
|
+
argv,
|
|
62
|
+
description
|
|
63
|
+
});
|
|
64
|
+
const basePath = path__default.default.resolve(cli$1.input[0] || process.cwd());
|
|
65
|
+
const {
|
|
66
|
+
exists,
|
|
67
|
+
isRoot
|
|
68
|
+
} = await _package.hasSanityJson(basePath);
|
|
69
|
+
if (exists && isRoot) {
|
|
70
|
+
throw new Error("sanity.json has a \"root\" property set to true - are you trying to init into a studio instead of a plugin?");
|
|
71
|
+
}
|
|
72
|
+
const {
|
|
73
|
+
v3ConfigFile
|
|
74
|
+
} = await _package.findStudioV3Config(basePath);
|
|
75
|
+
if (v3ConfigFile) {
|
|
76
|
+
throw new Error("".concat(v3ConfigFile, " exsists - are you trying to init into a studio instead of a plugin?"));
|
|
77
|
+
}
|
|
78
|
+
cli.log.info('Initializing new plugin in "%s"', basePath);
|
|
79
|
+
if (!cli$1.flags.force && !(await _package.isEmptyish(basePath)) && !(await _package.prompt("Directory is not empty, proceed?", {
|
|
80
|
+
type: "confirm",
|
|
81
|
+
default: false
|
|
82
|
+
}))) {
|
|
83
|
+
cli.log.error("Directory is not empty. Cancelled.");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
await _package.ensureDir(basePath);
|
|
87
|
+
await init.init({
|
|
88
|
+
basePath,
|
|
89
|
+
flags: cli$1.flags
|
|
90
|
+
});
|
|
91
|
+
if (cli$1.flags.install) {
|
|
92
|
+
if (await installDependencies(await promptForPackageManager(), {
|
|
93
|
+
cwd: basePath
|
|
94
|
+
})) {
|
|
95
|
+
cli.log.info("Done!");
|
|
96
|
+
} else {
|
|
97
|
+
cli.log.error("Failed to install dependencies, try manually running `npm install`");
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
cli.log.info("Dependency installation skipped.");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.default = run;
|
|
104
|
+
//# sourceMappingURL=init-2a3b4528.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-2a3b4528.js","sources":["../../src/npm/manager.ts","../../src/cmds/init.ts"],"sourcesContent":["import execa from 'execa'\nimport {prompt} from '../util/prompt'\n\nexport function npmIsAvailable() {\n return execa('npm', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nexport function yarnIsAvailable() {\n return execa('yarn', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nexport function pnpmAvailable() {\n return execa('pnpm', ['-v'])\n .then(() => true)\n .catch(() => false)\n}\n\nexport async function promptForPackageManager() {\n const [npm, yarn, pnpm] = await Promise.all([\n npmIsAvailable(),\n yarnIsAvailable(),\n pnpmAvailable(),\n ])\n\n const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm'].filter(Boolean)\n if (choices.length < 2) {\n return choices[0] || 'npm'\n }\n\n return prompt('Which package manager do you prefer?', {\n choices: choices.map((value) => ({value, name: value})),\n default: choices[0],\n })\n}\n\nexport async function installDependencies(pm: string, {cwd}: {cwd?: string}) {\n const proc = execa(pm, ['install'], {cwd, stdio: 'inherit'})\n const {exitCode} = await proc\n return exitCode <= 0\n}\n","import path from 'path'\nimport meow from 'meow'\nimport log from '../util/log'\nimport {init, initFlags} from '../actions/init'\nimport {isEmptyish, ensureDir} from '../util/files'\nimport {installDependencies, promptForPackageManager} from '../npm/manager'\nimport {findStudioV3Config, hasSanityJson} from '../sanity/manifest'\nimport {prompt} from '../util/prompt'\nimport {cliName} from '../constants'\nimport {presetHelpList} from '../presets/presets'\n\nconst description = `Initialize a new Sanity plugin`\n\nconst help = `\nUsage\n $ ${cliName} init [dir] [<args>]\n\nOptions\n --no-eslint Disables ESLint config and dependencies from being added\n --no-prettier Disables prettier config and dependencies from being added\n --no-typescript Disables typescript config and dependencies from being added\n --no-license Disables LICENSE + package.json license field from being added\n --no-editorconfig Disables .editorconfig from being added\n --no-gitignore Disables .gitignore from being added\n --no-scripts Disables scripts from being added to package.json\n --no-install Disables automatically running package manager install\n\n --name [package-name] Use the provided package-name\n --author [name] Use the provided author\n --repo [url] Use the provided repo url\n --license [spdx] Use the license with the given SPDX identifier\n --force No promt when overwriting files\n\n --preset [preset-name] Adds config and files from a named preset. --preset can be supplied multiple times.\n The following presets are available:\n${presetHelpList(30)}\n\nExamples\n # Initialize a new plugin in the current directory\n $ ${cliName} init\n\n # Initialize a plugin in the directory ~/my-plugin\n $ ${cliName} init ~/my-plugin\n\n # Don't add eslint or prettier\n $ ${cliName} init --no-eslint --no-prettier\n`\n\nasync function run({argv}: {argv: string[]}) {\n const cli = meow(help, {flags: initFlags, argv, description})\n const basePath = path.resolve(cli.input[0] || process.cwd())\n\n const {exists, isRoot} = await hasSanityJson(basePath)\n if (exists && isRoot) {\n throw new Error(\n `sanity.json has a \"root\" property set to true - are you trying to init into a studio instead of a plugin?`\n )\n }\n\n const {v3ConfigFile} = await findStudioV3Config(basePath)\n if (v3ConfigFile) {\n throw new Error(\n `${v3ConfigFile} exsists - are you trying to init into a studio instead of a plugin?`\n )\n }\n\n log.info('Initializing new plugin in \"%s\"', basePath)\n if (\n !cli.flags.force &&\n !(await isEmptyish(basePath)) &&\n !(await prompt('Directory is not empty, proceed?', {type: 'confirm', default: false}))\n ) {\n log.error('Directory is not empty. Cancelled.')\n return\n }\n\n await ensureDir(basePath)\n await init({basePath, flags: cli.flags})\n if (cli.flags.install) {\n if (await installDependencies(await promptForPackageManager(), {cwd: basePath})) {\n log.info('Done!')\n } else {\n log.error('Failed to install dependencies, try manually running `npm install`')\n }\n } else {\n log.info('Dependency installation skipped.')\n }\n}\n\nexport default run\n"],"names":["npmIsAvailable","execa","then","catch","yarnIsAvailable","pnpmAvailable","promptForPackageManager","npm","yarn","pnpm","Promise","all","choices","filter","Boolean","length","prompt","map","value","name","default","installDependencies","pm","cwd","proc","stdio","exitCode","description","help","cliName","presetHelpList","run","argv","cli","meow","flags","initFlags","basePath","path","resolve","input","process","exists","isRoot","hasSanityJson","Error","v3ConfigFile","findStudioV3Config","log","info","force","isEmptyish","type","error","ensureDir","init","install"],"mappings":";;;;;;;;;;;;;;;;AAGO,SAASA,cAAiB,GAAA;EAC/B,OAAOC,sBAAM,CAAA,KAAA,EAAO,CAAC,IAAI,CAAC,CAAA,CACvBC,IAAK,CAAA,MAAM,IAAI,CAAA,CACfC,KAAM,CAAA,MAAM,KAAK,CAAA;AACtB;AAEO,SAASC,eAAkB,GAAA;EAChC,OAAOH,sBAAM,CAAA,MAAA,EAAQ,CAAC,IAAI,CAAC,CAAA,CACxBC,IAAK,CAAA,MAAM,IAAI,CAAA,CACfC,KAAM,CAAA,MAAM,KAAK,CAAA;AACtB;AAEO,SAASE,aAAgB,GAAA;EAC9B,OAAOJ,sBAAM,CAAA,MAAA,EAAQ,CAAC,IAAI,CAAC,CAAA,CACxBC,IAAK,CAAA,MAAM,IAAI,CAAA,CACfC,KAAM,CAAA,MAAM,KAAK,CAAA;AACtB;AAEA,eAAsBG,uBAA0B,GAAA;EAC9C,MAAM,CAACC,GAAK,EAAAC,IAAA,EAAMC,IAAI,CAAI,GAAA,MAAMC,QAAQC,GAAI,CAAA,CAC1CX,cAAe,EAAA,EACfI,eAAgB,EAAA,EAChBC,aAAc,EAAA,CACf,CAAA;EAEK,MAAAO,OAAA,GAAU,CAACL,GAAA,IAAO,KAAO,EAAAC,IAAA,IAAQ,QAAQC,IAAQ,IAAA,MAAM,CAAE,CAAAI,MAAA,CAAOC,OAAO,CAAA;EACzE,IAAAF,OAAA,CAAQG,SAAS,CAAG,EAAA;IACtB,OAAOH,QAAQ,CAAM,CAAA,IAAA,KAAA;EACvB;EAEA,OAAOI,QAAAA,CAAAA,OAAO,sCAAwC,EAAA;IACpDJ,OAAA,EAASA,QAAQK,GAAI,CAACC,UAAW;MAACA,KAAA;MAAOC,IAAM,EAAAD;IAAA,CAAO,CAAA,CA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