@sanity/cli-test 0.0.2-alpha.4 → 0.0.2-alpha.6

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 (66) hide show
  1. package/README.md +228 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +3 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/test/constants.d.ts +2 -0
  6. package/dist/test/constants.js +8 -0
  7. package/dist/test/constants.js.map +1 -0
  8. package/dist/test/setupExamples.d.ts +60 -0
  9. package/dist/test/setupExamples.js +129 -0
  10. package/dist/test/setupExamples.js.map +1 -0
  11. package/dist/test/testExample.d.ts +46 -0
  12. package/dist/test/testExample.js +93 -0
  13. package/dist/test/testExample.js.map +1 -0
  14. package/dist/utils/fileExists.d.ts +9 -0
  15. package/dist/utils/fileExists.js +13 -0
  16. package/dist/utils/fileExists.js.map +1 -0
  17. package/dist/utils/paths.d.ts +22 -0
  18. package/dist/utils/paths.js +30 -0
  19. package/dist/utils/paths.js.map +1 -0
  20. package/dist/vitest.d.ts +20 -0
  21. package/dist/vitest.js +21 -0
  22. package/dist/vitest.js.map +1 -0
  23. package/dist/vitestWorker.d.ts +23 -0
  24. package/dist/vitestWorker.js +131 -0
  25. package/dist/vitestWorker.js.map +1 -0
  26. package/examples/basic-app/package.json +27 -0
  27. package/examples/basic-app/sanity.cli.ts +12 -0
  28. package/examples/basic-app/src/App.css +20 -0
  29. package/examples/basic-app/src/App.tsx +26 -0
  30. package/examples/basic-app/src/ExampleComponent.css +84 -0
  31. package/examples/basic-app/src/ExampleComponent.tsx +38 -0
  32. package/examples/basic-app/tsconfig.json +17 -0
  33. package/examples/basic-studio/package.json +29 -0
  34. package/examples/basic-studio/sanity.cli.ts +11 -0
  35. package/examples/basic-studio/sanity.config.ts +18 -0
  36. package/examples/basic-studio/schemaTypes/author.ts +52 -0
  37. package/examples/basic-studio/schemaTypes/blockContent.ts +71 -0
  38. package/examples/basic-studio/schemaTypes/category.ts +20 -0
  39. package/examples/basic-studio/schemaTypes/index.ts +6 -0
  40. package/examples/basic-studio/schemaTypes/post.ts +67 -0
  41. package/examples/basic-studio/tsconfig.json +17 -0
  42. package/examples/multi-workspace-studio/package.json +29 -0
  43. package/examples/multi-workspace-studio/sanity.cli.ts +11 -0
  44. package/examples/multi-workspace-studio/sanity.config.ts +37 -0
  45. package/examples/multi-workspace-studio/schemaTypes/author.ts +52 -0
  46. package/examples/multi-workspace-studio/schemaTypes/blockContent.ts +70 -0
  47. package/examples/multi-workspace-studio/schemaTypes/category.ts +20 -0
  48. package/examples/multi-workspace-studio/schemaTypes/index.ts +6 -0
  49. package/examples/multi-workspace-studio/schemaTypes/post.ts +67 -0
  50. package/examples/multi-workspace-studio/tsconfig.json +17 -0
  51. package/examples/worst-case-studio/README.md +21 -0
  52. package/examples/worst-case-studio/package.json +33 -0
  53. package/examples/worst-case-studio/sanity.cli.ts +16 -0
  54. package/examples/worst-case-studio/sanity.config.tsx +48 -0
  55. package/examples/worst-case-studio/src/defines.ts +8 -0
  56. package/examples/worst-case-studio/src/descriptionIcon.svg +7 -0
  57. package/examples/worst-case-studio/src/descriptionInput.module.css +13 -0
  58. package/examples/worst-case-studio/src/descriptionInput.tsx +55 -0
  59. package/examples/worst-case-studio/src/schemaTypes/author.ts +52 -0
  60. package/examples/worst-case-studio/src/schemaTypes/blockContent.ts +70 -0
  61. package/examples/worst-case-studio/src/schemaTypes/category.ts +20 -0
  62. package/examples/worst-case-studio/src/schemaTypes/index.ts +6 -0
  63. package/examples/worst-case-studio/src/schemaTypes/post.ts +71 -0
  64. package/examples/worst-case-studio/src/typings.d.ts +37 -0
  65. package/examples/worst-case-studio/tsconfig.json +22 -0
  66. package/package.json +31 -14
@@ -0,0 +1,55 @@
1
+ import {useEffect, useState} from 'react'
2
+
3
+ // Look ma, SVG imports in the config 🙈
4
+ import iconPath from './descriptionIcon.svg'
5
+ // Look ma, CSS module imports in the config 🙈
6
+ import styles from './descriptionInput.module.css'
7
+
8
+ // Look ma, process.env variables in the config 🙈
9
+ if (process.env.SANITY_STUDIO_PREFIXED_VAR !== 'yes-this-is-prefixed') {
10
+ throw new Error('`process.env.SANITY_STUDIO_PREFIXED_VAR` is not set to `yes-this-is-prefixed`')
11
+ }
12
+
13
+ // Look ma, import.meta.env variables in the config 🙈
14
+ if (import.meta.env.SANITY_STUDIO_PREFIXED_VAR !== 'yes-this-is-prefixed') {
15
+ throw new Error(
16
+ '`import.meta.env.SANITY_STUDIO_PREFIXED_VAR` is not set to `yes-this-is-prefixed`',
17
+ )
18
+ }
19
+
20
+ export default function DescriptionInput() {
21
+ const [counter, setCounter] = useState(0)
22
+ useEffect(() => {
23
+ const timer = setInterval(() => {
24
+ setCounter((prev) => prev + 1)
25
+ }, 1000)
26
+
27
+ return () => clearInterval(timer)
28
+ }, [])
29
+
30
+ return (
31
+ <div className={styles.input}>
32
+ <img src={iconPath} style={{width: '32px'}} />
33
+ Look ma, gradients, icons & counters
34
+ <div className={styles.counter}>{counter}</div>
35
+ </div>
36
+ )
37
+ }
38
+
39
+ const logCallback = requestIdleCallback(() => {
40
+ console.log('Look ma, requestIdleCallback in the config 🙈')
41
+ })
42
+
43
+ if (document.location.hostname === 'localhost') {
44
+ console.log('Look ma, `document` references in the config 🙈')
45
+ }
46
+
47
+ // Look ma, unchecked `window` references in the config 🙈
48
+ window.addEventListener('beforeunload', () => {
49
+ cancelIdleCallback(logCallback)
50
+ })
51
+
52
+ // Look ma, this will just run forever 🙈
53
+ setInterval(() => {
54
+ console.log('Look ma, setInterval in the config 🙈')
55
+ }, 15_000)
@@ -0,0 +1,52 @@
1
+ import {defineField, defineType} from 'sanity'
2
+
3
+ export default defineType({
4
+ name: 'author',
5
+ title: 'Author',
6
+ type: 'document',
7
+
8
+ fields: [
9
+ defineField({
10
+ name: 'name',
11
+ title: 'Name',
12
+ type: 'string',
13
+ }),
14
+ defineField({
15
+ name: 'slug',
16
+ options: {
17
+ maxLength: 96,
18
+ source: 'name',
19
+ },
20
+ title: 'Slug',
21
+ type: 'slug',
22
+ }),
23
+ defineField({
24
+ name: 'image',
25
+ options: {
26
+ hotspot: true,
27
+ },
28
+ title: 'Image',
29
+ type: 'image',
30
+ }),
31
+ defineField({
32
+ name: 'bio',
33
+ of: [
34
+ {
35
+ lists: [],
36
+ styles: [{title: 'Normal', value: 'normal'}],
37
+ title: 'Block',
38
+ type: 'block',
39
+ },
40
+ ],
41
+ title: 'Bio',
42
+ type: 'array',
43
+ }),
44
+ ],
45
+
46
+ preview: {
47
+ select: {
48
+ media: 'image',
49
+ title: 'name',
50
+ },
51
+ },
52
+ })
@@ -0,0 +1,70 @@
1
+ import {defineArrayMember, defineType} from 'sanity'
2
+
3
+ /**
4
+ * This is the schema definition for the rich text fields used for
5
+ * for this blog studio. When you import it in schemas.js it can be
6
+ * reused in other parts of the studio with:
7
+ * ```ts
8
+ * {
9
+ * name: 'someName',
10
+ * title: 'Some title',
11
+ * type: 'blockContent'
12
+ * }
13
+ * ```
14
+ */
15
+ export default defineType({
16
+ name: 'blockContent',
17
+ title: 'Block Content',
18
+ type: 'array',
19
+
20
+ of: [
21
+ defineArrayMember({
22
+ lists: [{title: 'Bullet', value: 'bullet'}],
23
+ // Marks let you mark up inline text in the block editor.
24
+ marks: {
25
+ // Annotations can be any object structure – e.g. a link or a footnote.
26
+ annotations: [
27
+ {
28
+ fields: [
29
+ {
30
+ name: 'href',
31
+ title: 'URL',
32
+ type: 'url',
33
+ },
34
+ ],
35
+ name: 'link',
36
+ title: 'URL',
37
+ type: 'object',
38
+ },
39
+ ],
40
+ // Decorators usually describe a single property – e.g. a typographic
41
+ // preference or highlighting by editors.
42
+ decorators: [
43
+ {title: 'Strong', value: 'strong'},
44
+ {title: 'Emphasis', value: 'em'},
45
+ ],
46
+ },
47
+ // Styles let you set what your user can mark up blocks with. These
48
+ // correspond with HTML tags, but you can set any title or value
49
+ // you want and decide how you want to deal with it where you want to
50
+ // use your content.
51
+ styles: [
52
+ {title: 'Normal', value: 'normal'},
53
+ {title: 'H1', value: 'h1'},
54
+ {title: 'H2', value: 'h2'},
55
+ {title: 'H3', value: 'h3'},
56
+ {title: 'H4', value: 'h4'},
57
+ {title: 'Quote', value: 'blockquote'},
58
+ ],
59
+ title: 'Block',
60
+ type: 'block',
61
+ }),
62
+ // You can add additional types here. Note that you can't use
63
+ // primitive types such as 'string' and 'number' in the same array
64
+ // as a block type.
65
+ defineArrayMember({
66
+ options: {hotspot: true},
67
+ type: 'image',
68
+ }),
69
+ ],
70
+ })
@@ -0,0 +1,20 @@
1
+ import {defineField, defineType} from 'sanity'
2
+
3
+ export default defineType({
4
+ name: 'category',
5
+ title: 'Category',
6
+ type: 'document',
7
+
8
+ fields: [
9
+ defineField({
10
+ name: 'title',
11
+ title: 'Title',
12
+ type: 'string',
13
+ }),
14
+ defineField({
15
+ name: 'description',
16
+ title: 'Description',
17
+ type: 'text',
18
+ }),
19
+ ],
20
+ })
@@ -0,0 +1,6 @@
1
+ import author from './author'
2
+ import blockContent from './blockContent'
3
+ import category from './category'
4
+ import post from './post'
5
+
6
+ export const schemaTypes = [post, author, category, blockContent]
@@ -0,0 +1,71 @@
1
+ import {defineField, defineType} from 'sanity'
2
+
3
+ export default defineType({
4
+ name: 'post',
5
+ title: 'Post',
6
+ type: 'document',
7
+
8
+ fields: [
9
+ defineField({
10
+ name: 'title',
11
+ title: 'Title',
12
+ type: 'string',
13
+ }),
14
+ defineField({
15
+ name: 'slug',
16
+ options: {
17
+ maxLength: 96,
18
+ source: 'title',
19
+ },
20
+ title: 'Slug',
21
+ type: 'slug',
22
+ }),
23
+ defineField({
24
+ name: 'author',
25
+ title: 'Author',
26
+ to: {type: 'author'},
27
+ type: 'reference',
28
+ }),
29
+ defineField({
30
+ name: 'mainImage',
31
+ options: {
32
+ hotspot: true,
33
+ },
34
+ title: 'Main image',
35
+ type: 'image',
36
+ }),
37
+ defineField({
38
+ name: 'code',
39
+ type: 'code',
40
+ }),
41
+ defineField({
42
+ name: 'categories',
43
+ of: [{to: {type: 'category'}, type: 'reference'}],
44
+ title: 'Categories',
45
+ type: 'array',
46
+ }),
47
+ defineField({
48
+ name: 'publishedAt',
49
+ title: 'Published at',
50
+ type: 'datetime',
51
+ }),
52
+ defineField({
53
+ name: 'body',
54
+ title: 'Body',
55
+ type: 'blockContent',
56
+ }),
57
+ ],
58
+
59
+ preview: {
60
+ select: {
61
+ author: 'author.name',
62
+ media: 'mainImage',
63
+ title: 'title',
64
+ },
65
+
66
+ prepare(selection) {
67
+ const {author} = selection
68
+ return {...selection, subtitle: author && `by ${author}`}
69
+ },
70
+ },
71
+ })
@@ -0,0 +1,37 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ interface ImportMetaEnv {
4
+ readonly SANITY_STUDIO_PREFIXED_VAR: string
5
+ }
6
+
7
+ interface ImportMeta {
8
+ readonly env: ImportMetaEnv
9
+ }
10
+
11
+ declare module 'https://themer.sanity.build/api/hues?*' {
12
+ interface Hue extends Omit<import('@sanity/color').ColorHueConfig, 'midPoint' | 'title'> {
13
+ midPoint: 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950
14
+ }
15
+ interface Hues {
16
+ caution: Hue
17
+ critical: Hue
18
+ default: Hue
19
+ positive: Hue
20
+ primary: Hue
21
+ transparent: Hue
22
+ }
23
+ export const hues: Hues
24
+ type Theme = import('sanity').StudioTheme
25
+ export function createTheme(_hues: Hues): Theme
26
+ export const theme: Theme
27
+ }
28
+
29
+ declare module '*.module.css' {
30
+ const classes: {[key: string]: string}
31
+ export default classes
32
+ }
33
+
34
+ declare module '*.svg' {
35
+ const path: string
36
+ export default path
37
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "target": "ES2017",
5
+ "lib": ["dom", "dom.iterable", "esnext"],
6
+ "allowJs": true,
7
+ "skipLibCheck": true,
8
+ "strict": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "module": "Preserve",
11
+ "moduleDetection": "force",
12
+ "isolatedModules": true,
13
+ "jsx": "preserve",
14
+ "incremental": true,
15
+ "noEmit": true,
16
+ "paths": {
17
+ "@/*": ["./src/*"]
18
+ }
19
+ },
20
+ "include": ["**/*.ts", "**/*.tsx"],
21
+ "exclude": ["node_modules"],
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-test",
3
- "version": "0.0.2-alpha.4",
3
+ "version": "0.0.2-alpha.6",
4
4
  "description": "Sanity CLI test helpers and utilities",
5
5
  "keywords": [
6
6
  "sanity",
@@ -20,6 +20,7 @@
20
20
  },
21
21
  "license": "MIT",
22
22
  "author": "Sanity.io <hello@sanity.io>",
23
+ "sideEffects": false,
23
24
  "type": "module",
24
25
  "exports": {
25
26
  ".": {
@@ -27,36 +28,47 @@
27
28
  "require": "./dist/index.js",
28
29
  "import": "./dist/index.js"
29
30
  },
31
+ "./vitest": {
32
+ "source": "./src/vitest.ts",
33
+ "require": "./dist/vitest.js",
34
+ "import": "./dist/vitest.js"
35
+ },
30
36
  "./package.json": "./package.json"
31
37
  },
32
38
  "main": "dist/index.js",
33
39
  "types": "dist/index.d.ts",
34
40
  "files": [
35
- "./dist"
41
+ "./dist",
42
+ "./examples"
36
43
  ],
37
44
  "dependencies": {
38
- "@oclif/core": "^4.8.0",
45
+ "@swc/core": "^1.15.8",
39
46
  "ansis": "^4.2.0",
40
- "nock": "^14.0.10"
47
+ "esbuild": "^0.27.2",
48
+ "nock": "^14.0.10",
49
+ "ora": "^9.0.0",
50
+ "tinyglobby": "^0.2.15"
41
51
  },
42
52
  "devDependencies": {
43
- "@eslint/compat": "^2.0.0",
53
+ "@eslint/compat": "^2.0.1",
44
54
  "@oclif/core": "^4.8.0",
45
- "@sanity/client": "^7.3.0",
55
+ "@sanity/client": "^7.14.0",
46
56
  "@swc/cli": "^0.7.9",
47
- "@swc/core": "^1.15.8",
48
- "@types/debug": "^4.1.12",
49
- "@types/node": "^20.19.27",
57
+ "@types/node": "^20.19.30",
50
58
  "eslint": "^9.39.2",
59
+ "publint": "^0.3.16",
51
60
  "typescript": "^5.9.3",
52
- "vitest": "^3.2.4",
61
+ "vitest": "^4.0.17",
62
+ "yaml": "^2.8.2",
53
63
  "@repo/tsconfig": "3.70.0",
54
- "@sanity/cli-core": "0.1.0-alpha.5",
55
- "@sanity/eslint-config-cli": "0.0.0-alpha.1"
64
+ "@sanity/eslint-config-cli": "0.0.0-alpha.1",
65
+ "@sanity/cli-core": "0.1.0-alpha.7"
56
66
  },
57
67
  "peerDependencies": {
58
68
  "@oclif/core": "^4.0.0",
59
- "@sanity/cli-core": "0.1.0-alpha.5"
69
+ "@sanity/client": "^7.14.0",
70
+ "vitest": ">=3.0.0 <4.0.0",
71
+ "@sanity/cli-core": "0.1.0-alpha.7"
60
72
  },
61
73
  "engines": {
62
74
  "node": ">=20.19.1 <22 || >=22.12"
@@ -65,10 +77,15 @@
65
77
  "access": "public"
66
78
  },
67
79
  "scripts": {
68
- "build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
80
+ "prebuild": "pnpm run clean",
81
+ "build": "pnpm run build:js && pnpm run copy:examples",
82
+ "build:js": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
69
83
  "build:types": "tsc --project tsconfig.lib.json",
70
84
  "check:types": "tsc --noEmit",
85
+ "clean": "rm -rf dist examples",
86
+ "copy:examples": "node scripts/copy-examples.js",
71
87
  "lint": "eslint .",
88
+ "publint": "publint",
72
89
  "test": "vitest run",
73
90
  "posttest": "pnpm run lint",
74
91
  "test:coverage": "vitest run --coverage",