@sanity/cli-test 0.0.0-20260410130107
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 +21 -0
- package/README.md +260 -0
- package/dist/index.d.ts +531 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/test/captureOutput.js +83 -0
- package/dist/test/captureOutput.js.map +1 -0
- package/dist/test/constants.js +24 -0
- package/dist/test/constants.js.map +1 -0
- package/dist/test/createTestClient.js +53 -0
- package/dist/test/createTestClient.js.map +1 -0
- package/dist/test/createTestToken.js +13 -0
- package/dist/test/createTestToken.js.map +1 -0
- package/dist/test/mockApi.js +16 -0
- package/dist/test/mockApi.js.map +1 -0
- package/dist/test/mockSanityCommand.js +71 -0
- package/dist/test/mockSanityCommand.js.map +1 -0
- package/dist/test/mockTelemetry.js +24 -0
- package/dist/test/mockTelemetry.js.map +1 -0
- package/dist/test/setupFixtures.js +140 -0
- package/dist/test/setupFixtures.js.map +1 -0
- package/dist/test/snapshotSerializer.js +12 -0
- package/dist/test/snapshotSerializer.js.map +1 -0
- package/dist/test/testCommand.js +19 -0
- package/dist/test/testCommand.js.map +1 -0
- package/dist/test/testFixture.js +112 -0
- package/dist/test/testFixture.js.map +1 -0
- package/dist/test/testHook.js +43 -0
- package/dist/test/testHook.js.map +1 -0
- package/dist/utils/fileExists.js +13 -0
- package/dist/utils/fileExists.js.map +1 -0
- package/dist/utils/paths.js +66 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/vitest.d.ts +121 -0
- package/dist/vitest.js +22 -0
- package/dist/vitest.js.map +1 -0
- package/dist/vitestWorker.js +135 -0
- package/dist/vitestWorker.js.map +1 -0
- package/fixtures/basic-app/package.json +25 -0
- package/fixtures/basic-app/sanity.cli.ts +12 -0
- package/fixtures/basic-app/src/App.css +20 -0
- package/fixtures/basic-app/src/App.tsx +26 -0
- package/fixtures/basic-app/src/ExampleComponent.css +84 -0
- package/fixtures/basic-app/src/ExampleComponent.tsx +38 -0
- package/fixtures/basic-app/tsconfig.json +17 -0
- package/fixtures/basic-functions/functions/test-function/index.ts +7 -0
- package/fixtures/basic-functions/package.json +14 -0
- package/fixtures/basic-functions/sanity.blueprint.ts +5 -0
- package/fixtures/basic-studio/package.json +28 -0
- package/fixtures/basic-studio/sanity.cli.ts +11 -0
- package/fixtures/basic-studio/sanity.config.ts +18 -0
- package/fixtures/basic-studio/schemaTypes/author.ts +52 -0
- package/fixtures/basic-studio/schemaTypes/blockContent.ts +71 -0
- package/fixtures/basic-studio/schemaTypes/category.ts +20 -0
- package/fixtures/basic-studio/schemaTypes/index.ts +6 -0
- package/fixtures/basic-studio/schemaTypes/post.ts +67 -0
- package/fixtures/basic-studio/tsconfig.json +17 -0
- package/fixtures/federated-studio/package.json +24 -0
- package/fixtures/federated-studio/sanity.cli.ts +14 -0
- package/fixtures/federated-studio/sanity.config.ts +17 -0
- package/fixtures/federated-studio/schemaTypes/index.ts +1 -0
- package/fixtures/federated-studio/tsconfig.json +17 -0
- package/fixtures/graphql-studio/package.json +25 -0
- package/fixtures/graphql-studio/sanity.cli.ts +20 -0
- package/fixtures/graphql-studio/sanity.config.ts +37 -0
- package/fixtures/graphql-studio/schemaTypes/author.ts +52 -0
- package/fixtures/graphql-studio/schemaTypes/blockContent.ts +71 -0
- package/fixtures/graphql-studio/schemaTypes/category.ts +20 -0
- package/fixtures/graphql-studio/schemaTypes/event.ts +25 -0
- package/fixtures/graphql-studio/schemaTypes/index.ts +10 -0
- package/fixtures/graphql-studio/schemaTypes/post.ts +67 -0
- package/fixtures/graphql-studio/tsconfig.json +17 -0
- package/fixtures/multi-workspace-studio/package.json +28 -0
- package/fixtures/multi-workspace-studio/sanity.cli.ts +11 -0
- package/fixtures/multi-workspace-studio/sanity.config.ts +37 -0
- package/fixtures/multi-workspace-studio/schemaTypes/author.ts +52 -0
- package/fixtures/multi-workspace-studio/schemaTypes/blockContent.ts +70 -0
- package/fixtures/multi-workspace-studio/schemaTypes/category.ts +20 -0
- package/fixtures/multi-workspace-studio/schemaTypes/index.ts +6 -0
- package/fixtures/multi-workspace-studio/schemaTypes/post.ts +67 -0
- package/fixtures/multi-workspace-studio/tsconfig.json +17 -0
- package/fixtures/prebuilt-app/README.md +3 -0
- package/fixtures/prebuilt-app/dist/favicon.ico +0 -0
- package/fixtures/prebuilt-app/dist/index.html +102 -0
- package/fixtures/prebuilt-app/dist/static/sanity-CtOxKsdo.css +24 -0
- package/fixtures/prebuilt-app/dist/static/sanity-D4a4eOYZ.js +17 -0
- package/fixtures/prebuilt-app/package.json +25 -0
- package/fixtures/prebuilt-app/sanity.cli.ts +12 -0
- package/fixtures/prebuilt-app/src/App.css +20 -0
- package/fixtures/prebuilt-app/src/App.tsx +24 -0
- package/fixtures/prebuilt-app/tsconfig.json +17 -0
- package/fixtures/prebuilt-studio/README.md +3 -0
- package/fixtures/prebuilt-studio/dist/favicon.ico +0 -0
- package/fixtures/prebuilt-studio/dist/index.html +113 -0
- package/fixtures/prebuilt-studio/dist/static/sanity-DxH-rpFr.js +9 -0
- package/fixtures/prebuilt-studio/package.json +25 -0
- package/fixtures/prebuilt-studio/sanity.cli.ts +11 -0
- package/fixtures/prebuilt-studio/sanity.config.ts +11 -0
- package/fixtures/prebuilt-studio/tsconfig.json +17 -0
- package/fixtures/worst-case-studio/.env +1 -0
- package/fixtures/worst-case-studio/README.md +22 -0
- package/fixtures/worst-case-studio/fieldComponentsTest.tsx +80 -0
- package/fixtures/worst-case-studio/package.json +33 -0
- package/fixtures/worst-case-studio/sanity.cli.ts +16 -0
- package/fixtures/worst-case-studio/sanity.config.tsx +55 -0
- package/fixtures/worst-case-studio/src/browserGlobalsCheck.ts +14 -0
- package/fixtures/worst-case-studio/src/defines.ts +8 -0
- package/fixtures/worst-case-studio/src/descriptionIcon.svg +7 -0
- package/fixtures/worst-case-studio/src/descriptionInput.module.css +13 -0
- package/fixtures/worst-case-studio/src/descriptionInput.tsx +55 -0
- package/fixtures/worst-case-studio/src/schemaTypes/author.ts +52 -0
- package/fixtures/worst-case-studio/src/schemaTypes/blockContent.ts +70 -0
- package/fixtures/worst-case-studio/src/schemaTypes/category.ts +20 -0
- package/fixtures/worst-case-studio/src/schemaTypes/index.ts +6 -0
- package/fixtures/worst-case-studio/src/schemaTypes/post.ts +71 -0
- package/fixtures/worst-case-studio/src/typings.d.ts +37 -0
- package/fixtures/worst-case-studio/tsconfig.json +22 -0
- package/package.json +97 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
// Capture the initial working directory before any tests change it
|
|
3
|
+
const INITIAL_CWD = process.cwd();
|
|
4
|
+
/**
|
|
5
|
+
* Gets the path to the fixtures directory bundled with this package.
|
|
6
|
+
*
|
|
7
|
+
* The fixtures are copied during build and bundled with the published package.
|
|
8
|
+
* This function works the same whether the package is used in a monorepo
|
|
9
|
+
* or installed from npm.
|
|
10
|
+
*
|
|
11
|
+
* @returns Absolute path to the fixtures directory
|
|
12
|
+
* @internal
|
|
13
|
+
*/ export function getFixturesPath() {
|
|
14
|
+
// From dist/utils/paths.js -> ../../fixtures
|
|
15
|
+
return resolve(import.meta.dirname, '../../fixtures');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets the path to the temporary directory for test fixtures.
|
|
19
|
+
*
|
|
20
|
+
* Uses the initial working directory captured when this module was first loaded,
|
|
21
|
+
* not process.cwd() which may change during test execution.
|
|
22
|
+
*
|
|
23
|
+
* @param customTempDir - Optional custom temp directory path
|
|
24
|
+
* @returns Absolute path to temp directory (default: initial cwd/tmp)
|
|
25
|
+
* @internal
|
|
26
|
+
*/ export function getTempPath(customTempDir) {
|
|
27
|
+
return customTempDir || resolve(INITIAL_CWD, 'tmp');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets the current Windows drive letter from process.cwd().
|
|
31
|
+
* Falls back to 'C:\\' if detection fails.
|
|
32
|
+
*
|
|
33
|
+
* @returns Drive letter with backslash (e.g., 'C:\\', 'D:\\') or empty string on Unix
|
|
34
|
+
* @internal
|
|
35
|
+
*/ export function getCurrentDrive() {
|
|
36
|
+
if (process.platform !== 'win32') {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
const cwd = process.cwd();
|
|
40
|
+
const match = cwd.match(/^([A-Z]:)[\\/]/);
|
|
41
|
+
return match ? match[1] + '\\' : 'C:\\';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts Unix-style paths to platform-appropriate paths.
|
|
45
|
+
* On Windows:
|
|
46
|
+
* - Absolute paths starting with '/': adds drive letter and converts to backslashes
|
|
47
|
+
* - Relative/partial paths: converts forward slashes to backslashes
|
|
48
|
+
* On Unix: keeps paths as-is.
|
|
49
|
+
*
|
|
50
|
+
* @param pathStr - Unix-style path (e.g., '/test/path' or '.config/file.json')
|
|
51
|
+
* @returns Platform-appropriate path
|
|
52
|
+
* @internal
|
|
53
|
+
*/ export function convertToSystemPath(pathStr) {
|
|
54
|
+
if (process.platform === 'win32') {
|
|
55
|
+
if (pathStr.startsWith('/')) {
|
|
56
|
+
// Absolute Unix path - add drive letter
|
|
57
|
+
const drive = getCurrentDrive();
|
|
58
|
+
return `${drive}${pathStr.slice(1).replaceAll('/', '\\')}`;
|
|
59
|
+
}
|
|
60
|
+
// Relative/partial path - just convert separators
|
|
61
|
+
return pathStr.replaceAll('/', '\\');
|
|
62
|
+
}
|
|
63
|
+
return pathStr;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/paths.ts"],"sourcesContent":["import {resolve} from 'node:path'\n\n// Capture the initial working directory before any tests change it\nconst INITIAL_CWD = process.cwd()\n\n/**\n * Gets the path to the fixtures directory bundled with this package.\n *\n * The fixtures are copied during build and bundled with the published package.\n * This function works the same whether the package is used in a monorepo\n * or installed from npm.\n *\n * @returns Absolute path to the fixtures directory\n * @internal\n */\nexport function getFixturesPath(): string {\n // From dist/utils/paths.js -> ../../fixtures\n return resolve(import.meta.dirname, '../../fixtures')\n}\n\n/**\n * Gets the path to the temporary directory for test fixtures.\n *\n * Uses the initial working directory captured when this module was first loaded,\n * not process.cwd() which may change during test execution.\n *\n * @param customTempDir - Optional custom temp directory path\n * @returns Absolute path to temp directory (default: initial cwd/tmp)\n * @internal\n */\nexport function getTempPath(customTempDir?: string): string {\n return customTempDir || resolve(INITIAL_CWD, 'tmp')\n}\n\n/**\n * Gets the current Windows drive letter from process.cwd().\n * Falls back to 'C:\\\\' if detection fails.\n *\n * @returns Drive letter with backslash (e.g., 'C:\\\\', 'D:\\\\') or empty string on Unix\n * @internal\n */\nexport function getCurrentDrive(): string {\n if (process.platform !== 'win32') {\n return ''\n }\n const cwd = process.cwd()\n const match = cwd.match(/^([A-Z]:)[\\\\/]/)\n return match ? match[1] + '\\\\' : 'C:\\\\'\n}\n\n/**\n * Converts Unix-style paths to platform-appropriate paths.\n * On Windows:\n * - Absolute paths starting with '/': adds drive letter and converts to backslashes\n * - Relative/partial paths: converts forward slashes to backslashes\n * On Unix: keeps paths as-is.\n *\n * @param pathStr - Unix-style path (e.g., '/test/path' or '.config/file.json')\n * @returns Platform-appropriate path\n * @internal\n */\nexport function convertToSystemPath(pathStr: string): string {\n if (process.platform === 'win32') {\n if (pathStr.startsWith('/')) {\n // Absolute Unix path - add drive letter\n const drive = getCurrentDrive()\n return `${drive}${pathStr.slice(1).replaceAll('/', '\\\\')}`\n }\n // Relative/partial path - just convert separators\n return pathStr.replaceAll('/', '\\\\')\n }\n return pathStr\n}\n"],"names":["resolve","INITIAL_CWD","process","cwd","getFixturesPath","dirname","getTempPath","customTempDir","getCurrentDrive","platform","match","convertToSystemPath","pathStr","startsWith","drive","slice","replaceAll"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AAEjC,mEAAmE;AACnE,MAAMC,cAAcC,QAAQC,GAAG;AAE/B;;;;;;;;;CASC,GACD,OAAO,SAASC;IACd,6CAA6C;IAC7C,OAAOJ,QAAQ,YAAYK,OAAO,EAAE;AACtC;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASC,YAAYC,aAAsB;IAChD,OAAOA,iBAAiBP,QAAQC,aAAa;AAC/C;AAEA;;;;;;CAMC,GACD,OAAO,SAASO;IACd,IAAIN,QAAQO,QAAQ,KAAK,SAAS;QAChC,OAAO;IACT;IACA,MAAMN,MAAMD,QAAQC,GAAG;IACvB,MAAMO,QAAQP,IAAIO,KAAK,CAAC;IACxB,OAAOA,QAAQA,KAAK,CAAC,EAAE,GAAG,OAAO;AACnC;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,oBAAoBC,OAAe;IACjD,IAAIV,QAAQO,QAAQ,KAAK,SAAS;QAChC,IAAIG,QAAQC,UAAU,CAAC,MAAM;YAC3B,wCAAwC;YACxC,MAAMC,QAAQN;YACd,OAAO,GAAGM,QAAQF,QAAQG,KAAK,CAAC,GAAGC,UAAU,CAAC,KAAK,OAAO;QAC5D;QACA,kDAAkD;QAClD,OAAOJ,QAAQI,UAAU,CAAC,KAAK;IACjC;IACA,OAAOJ;AACT"}
|
package/dist/vitest.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { TestProject } from "vitest/node";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Global setup function for initializing test fixtures.
|
|
5
|
+
*
|
|
6
|
+
* Copies fixtures from the bundled location to a temp directory
|
|
7
|
+
* and installs dependencies.
|
|
8
|
+
*
|
|
9
|
+
* Note: Fixtures are NOT built during setup. Tests that need built
|
|
10
|
+
* fixtures should build them as part of the test.
|
|
11
|
+
*
|
|
12
|
+
* This function is designed to be used with vitest globalSetup.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*
|
|
16
|
+
* @param options - Configuration options
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // In vitest.config.ts
|
|
20
|
+
* export default defineConfig({
|
|
21
|
+
* test: {
|
|
22
|
+
* globalSetup: ['@sanity/cli-test/vitest']
|
|
23
|
+
* }
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function setup(
|
|
28
|
+
_: TestProject,
|
|
29
|
+
options?: SetupTestFixturesOptions,
|
|
30
|
+
): Promise<void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Options for setupTestFixtures
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
declare interface SetupTestFixturesOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Glob patterns for additional fixture directories to set up.
|
|
40
|
+
*
|
|
41
|
+
* Each pattern is matched against directories in the current working directory.
|
|
42
|
+
* Only directories containing a `package.json` file are included.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* ['fixtures/*', 'dev/*']
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
additionalFixtures?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Custom temp directory path. Defaults to process.cwd()/tmp
|
|
52
|
+
*/
|
|
53
|
+
tempDir?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Setup function to build the worker files with esbuild.
|
|
58
|
+
*
|
|
59
|
+
* Bundles the worker files with esbuild and sets up watch mode if in watch mode.
|
|
60
|
+
* All npm packages are automatically marked as external (loaded from node_modules at runtime).
|
|
61
|
+
* Only internal project code is bundled inline.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*
|
|
65
|
+
* @param filePaths - The paths to the worker files to build
|
|
66
|
+
* @returns A promise that resolves when the worker build is setup
|
|
67
|
+
* @throws If the worker files cannot be bundled
|
|
68
|
+
* @throws If the watcher cannot be set up
|
|
69
|
+
*/
|
|
70
|
+
export declare function setupWorkerBuild(filePaths: string[]): Promise<void>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Serializer for snapshot tests to normalize line endings and Windows ^ to Unix `\`
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export declare const snapshotSerializer: {
|
|
77
|
+
serialize: (val: string) => string;
|
|
78
|
+
test: (val: unknown) => val is string;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Teardown function to clean up test fixtures.
|
|
83
|
+
*
|
|
84
|
+
* Removes the temp directory created by setupTestFixtures.
|
|
85
|
+
*
|
|
86
|
+
* This function is designed to be used with vitest globalSetup.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*
|
|
90
|
+
* @param options - Configuration options
|
|
91
|
+
*/
|
|
92
|
+
export declare function teardown(
|
|
93
|
+
options?: TeardownTestFixturesOptions,
|
|
94
|
+
): Promise<void>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Options for teardownTestFixtures
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
declare interface TeardownTestFixturesOptions {
|
|
102
|
+
/**
|
|
103
|
+
* Custom temp directory path. Defaults to process.cwd()/tmp
|
|
104
|
+
*/
|
|
105
|
+
tempDir?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Teardown function to clean up the worker build.
|
|
110
|
+
*
|
|
111
|
+
* Closes all build contexts and deletes the compiled JavaScript files.
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*
|
|
115
|
+
* @returns A promise that resolves when the worker build is teared down
|
|
116
|
+
* @throws If the build contexts cannot be disposed
|
|
117
|
+
* @throws If the compiled JavaScript files cannot be deleted
|
|
118
|
+
*/
|
|
119
|
+
export declare function teardownWorkerBuild(): Promise<void>;
|
|
120
|
+
|
|
121
|
+
export {};
|
package/dist/vitest.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest global setup entry point.
|
|
3
|
+
*
|
|
4
|
+
* Import this in your vitest.config.ts globalSetup array for automatic
|
|
5
|
+
* test fixture setup and teardown.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // vitest.config.ts
|
|
10
|
+
* import {defineConfig} from 'vitest/config'
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* test: {
|
|
14
|
+
* globalSetup: ['@sanity/cli-test/vitest']
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/ export { setup, teardown } from './test/setupFixtures.js';
|
|
19
|
+
export { snapshotSerializer } from './test/snapshotSerializer.js';
|
|
20
|
+
export { setupWorkerBuild, teardownWorkerBuild } from './vitestWorker.js';
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=vitest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vitest.ts"],"sourcesContent":["/**\n * Vitest global setup entry point.\n *\n * Import this in your vitest.config.ts globalSetup array for automatic\n * test fixture setup and teardown.\n *\n * @example\n * ```typescript\n * // vitest.config.ts\n * import {defineConfig} from 'vitest/config'\n *\n * export default defineConfig({\n * test: {\n * globalSetup: ['@sanity/cli-test/vitest']\n * }\n * })\n * ```\n */\nexport {setup, teardown} from './test/setupFixtures.js'\nexport {snapshotSerializer} from './test/snapshotSerializer.js'\n\nexport {setupWorkerBuild, teardownWorkerBuild} from './vitestWorker.js'\n"],"names":["setup","teardown","snapshotSerializer","setupWorkerBuild","teardownWorkerBuild"],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GACD,SAAQA,KAAK,EAAEC,QAAQ,QAAO,0BAAyB;AACvD,SAAQC,kBAAkB,QAAO,+BAA8B;AAE/D,SAAQC,gBAAgB,EAAEC,mBAAmB,QAAO,oBAAmB"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest worker setup for the Sanity CLI.
|
|
3
|
+
*
|
|
4
|
+
* This builds the worker TS files into JS files using esbuild bundling.
|
|
5
|
+
* All internal dependencies are bundled inline, while npm packages remain external.
|
|
6
|
+
*/ import { unlink } from 'node:fs/promises';
|
|
7
|
+
import { build, context } from 'esbuild';
|
|
8
|
+
const compiledFiles = new Set();
|
|
9
|
+
let buildContexts = [];
|
|
10
|
+
/**
|
|
11
|
+
* Generate esbuild configuration for bundling worker files.
|
|
12
|
+
*
|
|
13
|
+
* @param filePath - The worker file path to bundle
|
|
14
|
+
* @param outputFile - The output file path for the bundled worker
|
|
15
|
+
* @returns esbuild configuration object
|
|
16
|
+
*/ function esbuildOptions(filePath, outputFile) {
|
|
17
|
+
return {
|
|
18
|
+
bundle: true,
|
|
19
|
+
conditions: [
|
|
20
|
+
'node',
|
|
21
|
+
'import'
|
|
22
|
+
],
|
|
23
|
+
entryPoints: [
|
|
24
|
+
filePath
|
|
25
|
+
],
|
|
26
|
+
// Marks cli-core as external to avoid bundling it inline
|
|
27
|
+
// this is mostly necessary for the monorepo.
|
|
28
|
+
external: [
|
|
29
|
+
'@sanity/cli-core'
|
|
30
|
+
],
|
|
31
|
+
format: 'esm',
|
|
32
|
+
loader: {
|
|
33
|
+
'.json': 'json'
|
|
34
|
+
},
|
|
35
|
+
logLevel: 'warning',
|
|
36
|
+
mainFields: [
|
|
37
|
+
'module',
|
|
38
|
+
'main'
|
|
39
|
+
],
|
|
40
|
+
outfile: outputFile,
|
|
41
|
+
packages: 'external',
|
|
42
|
+
platform: 'node',
|
|
43
|
+
sourcemap: false,
|
|
44
|
+
target: 'node20'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Bundle a single worker file with esbuild.
|
|
49
|
+
*
|
|
50
|
+
* @param filePath - The worker file path to bundle
|
|
51
|
+
* @param external - Array of package names to keep external
|
|
52
|
+
* @returns The output file path
|
|
53
|
+
*/ async function bundleWorkerFile(filePath) {
|
|
54
|
+
const outputFile = filePath.replace(/\.ts$/, '.js');
|
|
55
|
+
await build(esbuildOptions(filePath, outputFile));
|
|
56
|
+
compiledFiles.add(outputFile);
|
|
57
|
+
return outputFile;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Bundle all worker files with esbuild (non-watch mode).
|
|
61
|
+
*
|
|
62
|
+
* @param filePaths - Array of worker file paths to bundle
|
|
63
|
+
*/ async function setupBundling(filePaths) {
|
|
64
|
+
console.log(`Found ${filePaths.length} worker files to bundle`);
|
|
65
|
+
for (const workerFile of filePaths){
|
|
66
|
+
try {
|
|
67
|
+
await bundleWorkerFile(workerFile);
|
|
68
|
+
console.log(`✓ Bundled ${workerFile}`);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(`✗ Failed to bundle ${workerFile}:`, error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set up watch mode for worker files using esbuild's native watch API.
|
|
77
|
+
*
|
|
78
|
+
* @param files - Array of worker file paths to watch
|
|
79
|
+
*/ async function setupWatchMode(files) {
|
|
80
|
+
for (const filePath of files){
|
|
81
|
+
const outputFile = filePath.replace(/\.ts$/, '.js');
|
|
82
|
+
const ctx = await context(esbuildOptions(filePath, outputFile));
|
|
83
|
+
await ctx.watch();
|
|
84
|
+
buildContexts.push(ctx);
|
|
85
|
+
compiledFiles.add(outputFile);
|
|
86
|
+
console.log(`👀 Watching ${filePath}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Setup function to build the worker files with esbuild.
|
|
91
|
+
*
|
|
92
|
+
* Bundles the worker files with esbuild and sets up watch mode if in watch mode.
|
|
93
|
+
* All npm packages are automatically marked as external (loaded from node_modules at runtime).
|
|
94
|
+
* Only internal project code is bundled inline.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*
|
|
98
|
+
* @param filePaths - The paths to the worker files to build
|
|
99
|
+
* @returns A promise that resolves when the worker build is setup
|
|
100
|
+
* @throws If the worker files cannot be bundled
|
|
101
|
+
* @throws If the watcher cannot be set up
|
|
102
|
+
*/ export async function setupWorkerBuild(filePaths) {
|
|
103
|
+
const isWatchMode = (process.env.VITEST_WATCH === 'true' || !process.argv.includes('run')) && process.env.CI !== 'true';
|
|
104
|
+
await (isWatchMode ? setupWatchMode(filePaths) : setupBundling(filePaths));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Teardown function to clean up the worker build.
|
|
108
|
+
*
|
|
109
|
+
* Closes all build contexts and deletes the compiled JavaScript files.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*
|
|
113
|
+
* @returns A promise that resolves when the worker build is teared down
|
|
114
|
+
* @throws If the build contexts cannot be disposed
|
|
115
|
+
* @throws If the compiled JavaScript files cannot be deleted
|
|
116
|
+
*/ export async function teardownWorkerBuild() {
|
|
117
|
+
// Dispose all build contexts (for watch mode)
|
|
118
|
+
for (const ctx of buildContexts){
|
|
119
|
+
await ctx.dispose();
|
|
120
|
+
}
|
|
121
|
+
buildContexts = [];
|
|
122
|
+
// Clean up compiled JavaScript files
|
|
123
|
+
console.log('Cleaning up compiled JavaScript files...');
|
|
124
|
+
for (const filePath of compiledFiles){
|
|
125
|
+
try {
|
|
126
|
+
await unlink(filePath);
|
|
127
|
+
console.log(`✓ Deleted ${filePath}`);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error(`Failed to delete ${filePath}:`, error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
compiledFiles.clear();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=vitestWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vitestWorker.ts"],"sourcesContent":["/**\n * Vitest worker setup for the Sanity CLI.\n *\n * This builds the worker TS files into JS files using esbuild bundling.\n * All internal dependencies are bundled inline, while npm packages remain external.\n */\nimport {unlink} from 'node:fs/promises'\n\nimport {build, type BuildContext, type BuildOptions, context} from 'esbuild'\n\nconst compiledFiles: Set<string> = new Set()\nlet buildContexts: BuildContext[] = []\n\n/**\n * Generate esbuild configuration for bundling worker files.\n *\n * @param filePath - The worker file path to bundle\n * @param outputFile - The output file path for the bundled worker\n * @returns esbuild configuration object\n */\nfunction esbuildOptions(filePath: string, outputFile: string): BuildOptions {\n return {\n bundle: true,\n conditions: ['node', 'import'],\n entryPoints: [filePath],\n // Marks cli-core as external to avoid bundling it inline\n // this is mostly necessary for the monorepo.\n external: ['@sanity/cli-core'],\n format: 'esm',\n loader: {'.json': 'json'},\n logLevel: 'warning',\n mainFields: ['module', 'main'],\n outfile: outputFile,\n packages: 'external',\n platform: 'node',\n sourcemap: false,\n target: 'node20',\n }\n}\n\n/**\n * Bundle a single worker file with esbuild.\n *\n * @param filePath - The worker file path to bundle\n * @param external - Array of package names to keep external\n * @returns The output file path\n */\nasync function bundleWorkerFile(filePath: string): Promise<string> {\n const outputFile = filePath.replace(/\\.ts$/, '.js')\n\n await build(esbuildOptions(filePath, outputFile))\n\n compiledFiles.add(outputFile)\n return outputFile\n}\n\n/**\n * Bundle all worker files with esbuild (non-watch mode).\n *\n * @param filePaths - Array of worker file paths to bundle\n */\nasync function setupBundling(filePaths: string[]) {\n console.log(`Found ${filePaths.length} worker files to bundle`)\n\n for (const workerFile of filePaths) {\n try {\n await bundleWorkerFile(workerFile)\n console.log(`✓ Bundled ${workerFile}`)\n } catch (error) {\n console.error(`✗ Failed to bundle ${workerFile}:`, error)\n throw error\n }\n }\n}\n\n/**\n * Set up watch mode for worker files using esbuild's native watch API.\n *\n * @param files - Array of worker file paths to watch\n */\nasync function setupWatchMode(files: string[]) {\n for (const filePath of files) {\n const outputFile = filePath.replace(/\\.ts$/, '.js')\n\n const ctx = await context(esbuildOptions(filePath, outputFile))\n\n await ctx.watch()\n buildContexts.push(ctx)\n compiledFiles.add(outputFile)\n\n console.log(`👀 Watching ${filePath}`)\n }\n}\n\n/**\n * Setup function to build the worker files with esbuild.\n *\n * Bundles the worker files with esbuild and sets up watch mode if in watch mode.\n * All npm packages are automatically marked as external (loaded from node_modules at runtime).\n * Only internal project code is bundled inline.\n *\n * @public\n *\n * @param filePaths - The paths to the worker files to build\n * @returns A promise that resolves when the worker build is setup\n * @throws If the worker files cannot be bundled\n * @throws If the watcher cannot be set up\n */\nexport async function setupWorkerBuild(filePaths: string[]) {\n const isWatchMode =\n (process.env.VITEST_WATCH === 'true' || !process.argv.includes('run')) &&\n process.env.CI !== 'true'\n\n await (isWatchMode ? setupWatchMode(filePaths) : setupBundling(filePaths))\n}\n\n/**\n * Teardown function to clean up the worker build.\n *\n * Closes all build contexts and deletes the compiled JavaScript files.\n *\n * @public\n *\n * @returns A promise that resolves when the worker build is teared down\n * @throws If the build contexts cannot be disposed\n * @throws If the compiled JavaScript files cannot be deleted\n */\nexport async function teardownWorkerBuild(): Promise<void> {\n // Dispose all build contexts (for watch mode)\n for (const ctx of buildContexts) {\n await ctx.dispose()\n }\n buildContexts = []\n\n // Clean up compiled JavaScript files\n console.log('Cleaning up compiled JavaScript files...')\n for (const filePath of compiledFiles) {\n try {\n await unlink(filePath)\n console.log(`✓ Deleted ${filePath}`)\n } catch (error) {\n console.error(`Failed to delete ${filePath}:`, error)\n }\n }\n compiledFiles.clear()\n}\n"],"names":["unlink","build","context","compiledFiles","Set","buildContexts","esbuildOptions","filePath","outputFile","bundle","conditions","entryPoints","external","format","loader","logLevel","mainFields","outfile","packages","platform","sourcemap","target","bundleWorkerFile","replace","add","setupBundling","filePaths","console","log","length","workerFile","error","setupWatchMode","files","ctx","watch","push","setupWorkerBuild","isWatchMode","process","env","VITEST_WATCH","argv","includes","CI","teardownWorkerBuild","dispose","clear"],"mappings":"AAAA;;;;;CAKC,GACD,SAAQA,MAAM,QAAO,mBAAkB;AAEvC,SAAQC,KAAK,EAAwCC,OAAO,QAAO,UAAS;AAE5E,MAAMC,gBAA6B,IAAIC;AACvC,IAAIC,gBAAgC,EAAE;AAEtC;;;;;;CAMC,GACD,SAASC,eAAeC,QAAgB,EAAEC,UAAkB;IAC1D,OAAO;QACLC,QAAQ;QACRC,YAAY;YAAC;YAAQ;SAAS;QAC9BC,aAAa;YAACJ;SAAS;QACvB,yDAAyD;QACzD,6CAA6C;QAC7CK,UAAU;YAAC;SAAmB;QAC9BC,QAAQ;QACRC,QAAQ;YAAC,SAAS;QAAM;QACxBC,UAAU;QACVC,YAAY;YAAC;YAAU;SAAO;QAC9BC,SAAST;QACTU,UAAU;QACVC,UAAU;QACVC,WAAW;QACXC,QAAQ;IACV;AACF;AAEA;;;;;;CAMC,GACD,eAAeC,iBAAiBf,QAAgB;IAC9C,MAAMC,aAAaD,SAASgB,OAAO,CAAC,SAAS;IAE7C,MAAMtB,MAAMK,eAAeC,UAAUC;IAErCL,cAAcqB,GAAG,CAAChB;IAClB,OAAOA;AACT;AAEA;;;;CAIC,GACD,eAAeiB,cAAcC,SAAmB;IAC9CC,QAAQC,GAAG,CAAC,CAAC,MAAM,EAAEF,UAAUG,MAAM,CAAC,uBAAuB,CAAC;IAE9D,KAAK,MAAMC,cAAcJ,UAAW;QAClC,IAAI;YACF,MAAMJ,iBAAiBQ;YACvBH,QAAQC,GAAG,CAAC,CAAC,UAAU,EAAEE,YAAY;QACvC,EAAE,OAAOC,OAAO;YACdJ,QAAQI,KAAK,CAAC,CAAC,mBAAmB,EAAED,WAAW,CAAC,CAAC,EAAEC;YACnD,MAAMA;QACR;IACF;AACF;AAEA;;;;CAIC,GACD,eAAeC,eAAeC,KAAe;IAC3C,KAAK,MAAM1B,YAAY0B,MAAO;QAC5B,MAAMzB,aAAaD,SAASgB,OAAO,CAAC,SAAS;QAE7C,MAAMW,MAAM,MAAMhC,QAAQI,eAAeC,UAAUC;QAEnD,MAAM0B,IAAIC,KAAK;QACf9B,cAAc+B,IAAI,CAACF;QACnB/B,cAAcqB,GAAG,CAAChB;QAElBmB,QAAQC,GAAG,CAAC,CAAC,YAAY,EAAErB,UAAU;IACvC;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,eAAe8B,iBAAiBX,SAAmB;IACxD,MAAMY,cACJ,AAACC,CAAAA,QAAQC,GAAG,CAACC,YAAY,KAAK,UAAU,CAACF,QAAQG,IAAI,CAACC,QAAQ,CAAC,MAAK,KACpEJ,QAAQC,GAAG,CAACI,EAAE,KAAK;IAErB,MAAON,CAAAA,cAAcN,eAAeN,aAAaD,cAAcC,UAAS;AAC1E;AAEA;;;;;;;;;;CAUC,GACD,OAAO,eAAemB;IACpB,8CAA8C;IAC9C,KAAK,MAAMX,OAAO7B,cAAe;QAC/B,MAAM6B,IAAIY,OAAO;IACnB;IACAzC,gBAAgB,EAAE;IAElB,qCAAqC;IACrCsB,QAAQC,GAAG,CAAC;IACZ,KAAK,MAAMrB,YAAYJ,cAAe;QACpC,IAAI;YACF,MAAMH,OAAOO;YACboB,QAAQC,GAAG,CAAC,CAAC,UAAU,EAAErB,UAAU;QACrC,EAAE,OAAOwB,OAAO;YACdJ,QAAQI,KAAK,CAAC,CAAC,iBAAiB,EAAExB,SAAS,CAAC,CAAC,EAAEwB;QACjD;IACF;IACA5B,cAAc4C,KAAK;AACrB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "basic-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sanity"
|
|
7
|
+
],
|
|
8
|
+
"license": "UNLICENSED",
|
|
9
|
+
"main": "package.json",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "sanity dev",
|
|
12
|
+
"start": "sanity start"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@sanity/sdk": "^2.6.0",
|
|
16
|
+
"@sanity/sdk-react": "^2.6.0",
|
|
17
|
+
"react": "^19.2.3",
|
|
18
|
+
"react-dom": "^19.2.3",
|
|
19
|
+
"sanity": "^5.18.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "^19.2.9",
|
|
23
|
+
"typescript": "^5.9.3"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* Container styling for the app */
|
|
2
|
+
.app-container {
|
|
3
|
+
max-width: 1200px;
|
|
4
|
+
margin: 0 auto;
|
|
5
|
+
padding: 2rem;
|
|
6
|
+
font-family:
|
|
7
|
+
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
|
|
8
|
+
'Helvetica Neue', sans-serif;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* Basic reset */
|
|
12
|
+
* {
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
body {
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 0;
|
|
19
|
+
background-color: #f9f9f9;
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {type SanityConfig} from '@sanity/sdk'
|
|
2
|
+
import {SanityApp} from '@sanity/sdk-react'
|
|
3
|
+
|
|
4
|
+
import {ExampleComponent} from './ExampleComponent'
|
|
5
|
+
import './App.css'
|
|
6
|
+
|
|
7
|
+
function App() {
|
|
8
|
+
// apps can access many different projects or other sources of data
|
|
9
|
+
const sanityConfigs: SanityConfig[] = [
|
|
10
|
+
{
|
|
11
|
+
dataset: 'dataset-name',
|
|
12
|
+
projectId: 'project-id',
|
|
13
|
+
},
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div className="app-container">
|
|
18
|
+
<SanityApp config={sanityConfigs} fallback={<div>Loading...</div>}>
|
|
19
|
+
{/* add your own components here! */}
|
|
20
|
+
<ExampleComponent />
|
|
21
|
+
</SanityApp>
|
|
22
|
+
</div>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default App
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
.example-container {
|
|
2
|
+
background-color: white;
|
|
3
|
+
border-radius: 8px;
|
|
4
|
+
padding: 2rem;
|
|
5
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.example-avatar-container {
|
|
9
|
+
position: relative;
|
|
10
|
+
margin-block-end: 1rem;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@keyframes wave {
|
|
14
|
+
0% {
|
|
15
|
+
rotate: 0deg;
|
|
16
|
+
}
|
|
17
|
+
2% {
|
|
18
|
+
rotate: 20deg;
|
|
19
|
+
filter: blur(1px);
|
|
20
|
+
}
|
|
21
|
+
4% {
|
|
22
|
+
rotate: 0deg;
|
|
23
|
+
}
|
|
24
|
+
6% {
|
|
25
|
+
rotate: -20deg;
|
|
26
|
+
}
|
|
27
|
+
8% {
|
|
28
|
+
rotate: 0deg;
|
|
29
|
+
}
|
|
30
|
+
10% {
|
|
31
|
+
rotate: 20deg;
|
|
32
|
+
}
|
|
33
|
+
12% {
|
|
34
|
+
rotate: 0deg;
|
|
35
|
+
}
|
|
36
|
+
14% {
|
|
37
|
+
rotate: -20deg;
|
|
38
|
+
}
|
|
39
|
+
16% {
|
|
40
|
+
rotate: 0deg;
|
|
41
|
+
filter: blur(0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.example-avatar-container:after {
|
|
46
|
+
content: '👋';
|
|
47
|
+
position: absolute;
|
|
48
|
+
font-size: 1.5rem;
|
|
49
|
+
display: flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
justify-container: center;
|
|
52
|
+
inset-inline-start: 0;
|
|
53
|
+
inset-block-start: 0;
|
|
54
|
+
translate: -25% -25%;
|
|
55
|
+
transform-origin: 100% 100%;
|
|
56
|
+
animation: wave 4s infinite linear;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.example-avatar {
|
|
60
|
+
inline-size: 4rem;
|
|
61
|
+
aspect-ratio: 1;
|
|
62
|
+
border-radius: 50%;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.example-heading {
|
|
66
|
+
color: #333;
|
|
67
|
+
margin-top: 0;
|
|
68
|
+
font-size: 2rem;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
p {
|
|
72
|
+
color: #666;
|
|
73
|
+
line-height: 1.6;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.code-hint {
|
|
77
|
+
background-color: #f5f5f5;
|
|
78
|
+
padding: 1rem;
|
|
79
|
+
border-radius: 4px;
|
|
80
|
+
font-family: monospace;
|
|
81
|
+
margin-top: 1.5rem;
|
|
82
|
+
border-left: 3px solid #e0e0e0;
|
|
83
|
+
line-height: 1.5;
|
|
84
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {type CurrentUser, useCurrentUser} from '@sanity/sdk-react'
|
|
2
|
+
|
|
3
|
+
import './ExampleComponent.css'
|
|
4
|
+
|
|
5
|
+
export function ExampleComponent() {
|
|
6
|
+
const user: CurrentUser | null = useCurrentUser()
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<div className="example-container">
|
|
10
|
+
{user?.profileImage ? (
|
|
11
|
+
<div className="example-avatar-container">
|
|
12
|
+
<img alt="" className="example-avatar" src={user.profileImage} />
|
|
13
|
+
</div>
|
|
14
|
+
) : (
|
|
15
|
+
''
|
|
16
|
+
)}
|
|
17
|
+
<h1 className="example-heading">
|
|
18
|
+
Welcome to your Sanity App{user?.name ? `, ${user.name}` : ''}!
|
|
19
|
+
</h1>
|
|
20
|
+
<p className="example-text">
|
|
21
|
+
This is an example component. You can replace this with your own content by creating a new
|
|
22
|
+
component and importing it in App.tsx.
|
|
23
|
+
</p>
|
|
24
|
+
<div className="code-hint">
|
|
25
|
+
<p>
|
|
26
|
+
Quick tip: Create new components in separate files and import them like this in App.tsx /
|
|
27
|
+
App.jsx:
|
|
28
|
+
</p>
|
|
29
|
+
<pre>{`import {YourComponent} from './YourComponent'
|
|
30
|
+
|
|
31
|
+
// Then use it in your JSX
|
|
32
|
+
<SanityApp config={sanityConfigs}>
|
|
33
|
+
<YourComponent />
|
|
34
|
+
</SanityApp>`}</pre>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2017",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"module": "Preserve",
|
|
10
|
+
"moduleDetection": "force",
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"jsx": "preserve",
|
|
13
|
+
"incremental": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["**/*.ts", "**/*.tsx"],
|
|
16
|
+
"exclude": ["node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {documentEventHandler} from '@sanity/functions'
|
|
2
|
+
|
|
3
|
+
export const handler = documentEventHandler(async () => {
|
|
4
|
+
const time = new Date().toLocaleTimeString()
|
|
5
|
+
// eslint-disable-next-line no-console
|
|
6
|
+
console.log(`👋 Your Sanity Function was called at ${time}`)
|
|
7
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "basic-functions",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@sanity/blueprints": "^0.12.2",
|
|
9
|
+
"@sanity/functions": "^1.2.0"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"sanity": "^5.18.0"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "basic-studio",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sanity"
|
|
7
|
+
],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "package.json",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"deploy": "sanity deploy",
|
|
13
|
+
"deploy-graphql": "sanity graphql deploy",
|
|
14
|
+
"dev": "sanity dev",
|
|
15
|
+
"start": "sanity start"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@sanity/vision": "^5.18.0",
|
|
19
|
+
"react": "^19.2.3",
|
|
20
|
+
"react-dom": "^19.2.3",
|
|
21
|
+
"sanity": "^5.18.0",
|
|
22
|
+
"styled-components": "^6.3.8"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "^19.2.9",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
}
|
|
28
|
+
}
|