@sanity/cli 6.0.0-alpha.3 → 6.0.0-alpha.4

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 (110) hide show
  1. package/dist/actions/auth/login/{index.js → login.js} +1 -1
  2. package/dist/actions/auth/login/{index.js.map → login.js.map} +1 -1
  3. package/dist/actions/organizations/getOrganizationChoices.d.ts +6 -0
  4. package/dist/actions/organizations/getOrganizationChoices.js +23 -0
  5. package/dist/actions/organizations/getOrganizationChoices.js.map +1 -0
  6. package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.d.ts +2 -0
  7. package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.js +9 -0
  8. package/dist/actions/organizations/getOrganizationsWithAttachGrantInfo.js.map +1 -0
  9. package/dist/actions/organizations/hasProjectAttachGrant.d.ts +1 -0
  10. package/dist/actions/organizations/hasProjectAttachGrant.js +24 -0
  11. package/dist/actions/organizations/hasProjectAttachGrant.js.map +1 -0
  12. package/dist/actions/schema/utils/schemaStoreValidation.js +2 -2
  13. package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
  14. package/dist/commands/__tests__/init/init.authentication.test.js +60 -0
  15. package/dist/commands/__tests__/init/init.authentication.test.js.map +1 -0
  16. package/dist/commands/__tests__/init/init.create-new-project.test.js +196 -0
  17. package/dist/commands/__tests__/init/init.create-new-project.test.js.map +1 -0
  18. package/dist/commands/__tests__/init/init.plan.test.js +220 -0
  19. package/dist/commands/__tests__/init/init.plan.test.js.map +1 -0
  20. package/dist/commands/__tests__/init/init.setup.test.js +279 -0
  21. package/dist/commands/__tests__/init/init.setup.test.js.map +1 -0
  22. package/dist/commands/__tests__/migration.test.js +119 -0
  23. package/dist/commands/__tests__/migration.test.js.map +1 -0
  24. package/dist/commands/backup/__tests__/download.test.js +3 -3
  25. package/dist/commands/backup/__tests__/download.test.js.map +1 -1
  26. package/dist/commands/dataset/__tests__/import.test.js +2 -2
  27. package/dist/commands/dataset/__tests__/import.test.js.map +1 -1
  28. package/dist/commands/documents/__tests__/query.test.js +3 -3
  29. package/dist/commands/documents/__tests__/query.test.js.map +1 -1
  30. package/dist/commands/init.d.ts +4 -0
  31. package/dist/commands/init.js +151 -18
  32. package/dist/commands/init.js.map +1 -1
  33. package/dist/commands/login.js +1 -1
  34. package/dist/commands/login.js.map +1 -1
  35. package/dist/services/organizations.d.ts +40 -0
  36. package/dist/services/organizations.js +41 -0
  37. package/dist/services/organizations.js.map +1 -0
  38. package/dist/services/projects.d.ts +20 -0
  39. package/dist/services/projects.js +30 -1
  40. package/dist/services/projects.js.map +1 -1
  41. package/dist/services/user.d.ts +2 -0
  42. package/dist/services/user.js +11 -0
  43. package/dist/services/user.js.map +1 -0
  44. package/oclif.config.js +6 -1
  45. package/oclif.manifest.json +33 -184
  46. package/package.json +7 -7
  47. package/dist/actions/migration/getMigrationRootDirectory.d.ts +0 -2
  48. package/dist/actions/migration/getMigrationRootDirectory.js +0 -14
  49. package/dist/actions/migration/getMigrationRootDirectory.js.map +0 -1
  50. package/dist/actions/migration/resolveMigrations.d.ts +0 -19
  51. package/dist/actions/migration/resolveMigrations.js +0 -43
  52. package/dist/actions/migration/resolveMigrations.js.map +0 -1
  53. package/dist/actions/migration/templates/__tests__/minimalAdvanced.test.js +0 -65
  54. package/dist/actions/migration/templates/__tests__/minimalAdvanced.test.js.map +0 -1
  55. package/dist/actions/migration/templates/__tests__/minimalSimple.test.js +0 -145
  56. package/dist/actions/migration/templates/__tests__/minimalSimple.test.js.map +0 -1
  57. package/dist/actions/migration/templates/__tests__/renameField.test.js +0 -63
  58. package/dist/actions/migration/templates/__tests__/renameField.test.js.map +0 -1
  59. package/dist/actions/migration/templates/__tests__/renameType.test.js +0 -61
  60. package/dist/actions/migration/templates/__tests__/renameType.test.js.map +0 -1
  61. package/dist/actions/migration/templates/__tests__/stringToPTE.test.js +0 -87
  62. package/dist/actions/migration/templates/__tests__/stringToPTE.test.js.map +0 -1
  63. package/dist/actions/migration/templates/index.d.ts +0 -5
  64. package/dist/actions/migration/templates/index.js +0 -7
  65. package/dist/actions/migration/templates/index.js.map +0 -1
  66. package/dist/actions/migration/templates/minimalAdvanced.d.ts +0 -4
  67. package/dist/actions/migration/templates/minimalAdvanced.js +0 -21
  68. package/dist/actions/migration/templates/minimalAdvanced.js.map +0 -1
  69. package/dist/actions/migration/templates/minimalSimple.d.ts +0 -4
  70. package/dist/actions/migration/templates/minimalSimple.js +0 -61
  71. package/dist/actions/migration/templates/minimalSimple.js.map +0 -1
  72. package/dist/actions/migration/templates/renameField.d.ts +0 -4
  73. package/dist/actions/migration/templates/renameField.js +0 -20
  74. package/dist/actions/migration/templates/renameField.js.map +0 -1
  75. package/dist/actions/migration/templates/renameType.d.ts +0 -4
  76. package/dist/actions/migration/templates/renameType.js +0 -19
  77. package/dist/actions/migration/templates/renameType.js.map +0 -1
  78. package/dist/actions/migration/templates/stringToPTE.d.ts +0 -4
  79. package/dist/actions/migration/templates/stringToPTE.js +0 -32
  80. package/dist/actions/migration/templates/stringToPTE.js.map +0 -1
  81. package/dist/commands/__tests__/init.test.js +0 -411
  82. package/dist/commands/__tests__/init.test.js.map +0 -1
  83. package/dist/commands/migration/__tests__/create.test.js +0 -296
  84. package/dist/commands/migration/__tests__/create.test.js.map +0 -1
  85. package/dist/commands/migration/__tests__/list.test.js +0 -166
  86. package/dist/commands/migration/__tests__/list.test.js.map +0 -1
  87. package/dist/commands/migration/__tests__/run.test.js +0 -481
  88. package/dist/commands/migration/__tests__/run.test.js.map +0 -1
  89. package/dist/commands/migration/create.d.ts +0 -17
  90. package/dist/commands/migration/create.js +0 -143
  91. package/dist/commands/migration/create.js.map +0 -1
  92. package/dist/commands/migration/list.d.ts +0 -9
  93. package/dist/commands/migration/list.js +0 -61
  94. package/dist/commands/migration/list.js.map +0 -1
  95. package/dist/commands/migration/run.d.ts +0 -26
  96. package/dist/commands/migration/run.js +0 -271
  97. package/dist/commands/migration/run.js.map +0 -1
  98. package/dist/util/migration/constants.d.ts +0 -3
  99. package/dist/util/migration/constants.js +0 -10
  100. package/dist/util/migration/constants.js.map +0 -1
  101. package/dist/util/migration/ensureApiVersionFormat.d.ts +0 -9
  102. package/dist/util/migration/ensureApiVersionFormat.js +0 -16
  103. package/dist/util/migration/ensureApiVersionFormat.js.map +0 -1
  104. package/dist/util/migration/prettyMutationFormatter.d.ts +0 -8
  105. package/dist/util/migration/prettyMutationFormatter.js +0 -141
  106. package/dist/util/migration/prettyMutationFormatter.js.map +0 -1
  107. package/dist/utils/migration/resolveMigrationScript.d.ts +0 -44
  108. package/dist/utils/migration/resolveMigrationScript.js +0 -74
  109. package/dist/utils/migration/resolveMigrationScript.js.map +0 -1
  110. /package/dist/actions/auth/login/{index.d.ts → login.d.ts} +0 -0
@@ -534,7 +534,13 @@
534
534
  "type": "option"
535
535
  },
536
536
  "project": {
537
+ "aliases": [
538
+ "project-id"
539
+ ],
537
540
  "description": "Project ID to use for the studio",
541
+ "exclusive": [
542
+ "create-project"
543
+ ],
538
544
  "name": "project",
539
545
  "hasDynamicHelp": false,
540
546
  "helpValue": "<id>",
@@ -2460,6 +2466,32 @@
2460
2466
  "logs.js"
2461
2467
  ]
2462
2468
  },
2469
+ "mcp:configure": {
2470
+ "aliases": [],
2471
+ "args": {},
2472
+ "description": "Configure Sanity MCP server for AI editors (Cursor, VS Code, Claude Code)",
2473
+ "examples": [
2474
+ {
2475
+ "command": "<%= config.bin %> <%= command.id %>",
2476
+ "description": "Configure Sanity MCP server for detected AI editors"
2477
+ }
2478
+ ],
2479
+ "flags": {},
2480
+ "hasDynamicHelp": false,
2481
+ "hiddenAliases": [],
2482
+ "id": "mcp:configure",
2483
+ "pluginAlias": "@sanity/cli",
2484
+ "pluginName": "@sanity/cli",
2485
+ "pluginType": "core",
2486
+ "strict": true,
2487
+ "isESM": true,
2488
+ "relativePath": [
2489
+ "dist",
2490
+ "commands",
2491
+ "mcp",
2492
+ "configure.js"
2493
+ ]
2494
+ },
2463
2495
  "manifest:extract": {
2464
2496
  "aliases": [],
2465
2497
  "args": {},
@@ -2499,32 +2531,6 @@
2499
2531
  "extract.js"
2500
2532
  ]
2501
2533
  },
2502
- "mcp:configure": {
2503
- "aliases": [],
2504
- "args": {},
2505
- "description": "Configure Sanity MCP server for AI editors (Cursor, VS Code, Claude Code)",
2506
- "examples": [
2507
- {
2508
- "command": "<%= config.bin %> <%= command.id %>",
2509
- "description": "Configure Sanity MCP server for detected AI editors"
2510
- }
2511
- ],
2512
- "flags": {},
2513
- "hasDynamicHelp": false,
2514
- "hiddenAliases": [],
2515
- "id": "mcp:configure",
2516
- "pluginAlias": "@sanity/cli",
2517
- "pluginName": "@sanity/cli",
2518
- "pluginType": "core",
2519
- "strict": true,
2520
- "isESM": true,
2521
- "relativePath": [
2522
- "dist",
2523
- "commands",
2524
- "mcp",
2525
- "configure.js"
2526
- ]
2527
- },
2528
2534
  "media:create-aspect": {
2529
2535
  "aliases": [],
2530
2536
  "args": {},
@@ -2775,163 +2781,6 @@
2775
2781
  "import.js"
2776
2782
  ]
2777
2783
  },
2778
- "migration:create": {
2779
- "aliases": [],
2780
- "args": {
2781
- "title": {
2782
- "description": "Title of migration",
2783
- "name": "title",
2784
- "required": false
2785
- }
2786
- },
2787
- "description": "Create a new migration within your project",
2788
- "examples": [
2789
- {
2790
- "command": "<%= config.bin %> <%= command.id %>",
2791
- "description": "Create a new migration, prompting for title and options"
2792
- },
2793
- {
2794
- "command": "<%= config.bin %> <%= command.id %> \"Rename field from location to address\"",
2795
- "description": "Create a new migration with the provided title, prompting for options"
2796
- }
2797
- ],
2798
- "flags": {},
2799
- "hasDynamicHelp": false,
2800
- "hiddenAliases": [],
2801
- "id": "migration:create",
2802
- "pluginAlias": "@sanity/cli",
2803
- "pluginName": "@sanity/cli",
2804
- "pluginType": "core",
2805
- "strict": true,
2806
- "isESM": true,
2807
- "relativePath": [
2808
- "dist",
2809
- "commands",
2810
- "migration",
2811
- "create.js"
2812
- ]
2813
- },
2814
- "migration:list": {
2815
- "aliases": [],
2816
- "args": {},
2817
- "description": "List available migrations",
2818
- "examples": [
2819
- {
2820
- "command": "<%= config.bin %> <%= command.id %>",
2821
- "description": "List all available migrations in the project"
2822
- }
2823
- ],
2824
- "flags": {},
2825
- "hasDynamicHelp": false,
2826
- "hiddenAliases": [],
2827
- "id": "migration:list",
2828
- "pluginAlias": "@sanity/cli",
2829
- "pluginName": "@sanity/cli",
2830
- "pluginType": "core",
2831
- "strict": true,
2832
- "isESM": true,
2833
- "relativePath": [
2834
- "dist",
2835
- "commands",
2836
- "migration",
2837
- "list.js"
2838
- ]
2839
- },
2840
- "migration:run": {
2841
- "aliases": [],
2842
- "args": {
2843
- "id": {
2844
- "description": "ID",
2845
- "name": "id",
2846
- "required": false
2847
- }
2848
- },
2849
- "description": "Run a migration against a dataset",
2850
- "examples": [
2851
- {
2852
- "command": "<%= config.bin %> <%= command.id %> <id>",
2853
- "description": "dry run the migration"
2854
- },
2855
- {
2856
- "command": "<%= config.bin %> <%= command.id %> <id> --no-dry-run --project xyz --dataset staging",
2857
- "description": "execute the migration against a dataset"
2858
- },
2859
- {
2860
- "command": "<%= config.bin %> <%= command.id %> <id> --from-export=production.tar.gz --no-dry-run --project xyz --dataset staging",
2861
- "description": "execute the migration using a dataset export as the source"
2862
- }
2863
- ],
2864
- "flags": {
2865
- "api-version": {
2866
- "description": "API version to use when migrating. Defaults to v2024-01-29.",
2867
- "name": "api-version",
2868
- "hasDynamicHelp": false,
2869
- "multiple": false,
2870
- "type": "option"
2871
- },
2872
- "concurrency": {
2873
- "description": "How many mutation requests to run in parallel. Must be between 1 and 10. Default: 6.",
2874
- "name": "concurrency",
2875
- "default": 6,
2876
- "hasDynamicHelp": false,
2877
- "multiple": false,
2878
- "type": "option"
2879
- },
2880
- "confirm": {
2881
- "description": "Prompt for confirmation before running the migration (default: true). Use --no-confirm to skip.",
2882
- "name": "confirm",
2883
- "allowNo": true,
2884
- "type": "boolean"
2885
- },
2886
- "dataset": {
2887
- "description": "Dataset to migrate. Defaults to the dataset configured in your Sanity CLI config.",
2888
- "name": "dataset",
2889
- "hasDynamicHelp": false,
2890
- "multiple": false,
2891
- "type": "option"
2892
- },
2893
- "dry-run": {
2894
- "description": "By default the migration runs in dry mode. Use --no-dry-run to migrate dataset.",
2895
- "name": "dry-run",
2896
- "allowNo": true,
2897
- "type": "boolean"
2898
- },
2899
- "from-export": {
2900
- "description": "Use a local dataset export as source for migration instead of calling the Sanity API. Note: this is only supported for dry runs.",
2901
- "name": "from-export",
2902
- "hasDynamicHelp": false,
2903
- "multiple": false,
2904
- "type": "option"
2905
- },
2906
- "progress": {
2907
- "description": "Display progress during migration (default: true). Use --no-progress to hide output.",
2908
- "name": "progress",
2909
- "allowNo": true,
2910
- "type": "boolean"
2911
- },
2912
- "project": {
2913
- "description": "Project ID of the dataset to migrate. Defaults to the projectId configured in your Sanity CLI config.",
2914
- "name": "project",
2915
- "hasDynamicHelp": false,
2916
- "multiple": false,
2917
- "type": "option"
2918
- }
2919
- },
2920
- "hasDynamicHelp": false,
2921
- "hiddenAliases": [],
2922
- "id": "migration:run",
2923
- "pluginAlias": "@sanity/cli",
2924
- "pluginName": "@sanity/cli",
2925
- "pluginType": "core",
2926
- "strict": true,
2927
- "isESM": true,
2928
- "relativePath": [
2929
- "dist",
2930
- "commands",
2931
- "migration",
2932
- "run.js"
2933
- ]
2934
- },
2935
2784
  "openapi:get": {
2936
2785
  "aliases": [],
2937
2786
  "args": {
@@ -3953,5 +3802,5 @@
3953
3802
  ]
3954
3803
  }
3955
3804
  },
3956
- "version": "6.0.0-alpha.3"
3805
+ "version": "6.0.0-alpha.4"
3957
3806
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli",
3
- "version": "6.0.0-alpha.3",
3
+ "version": "6.0.0-alpha.4",
4
4
  "description": "Sanity CLI tool for managing Sanity projects and organizations",
5
5
  "keywords": [
6
6
  "sanity",
@@ -46,7 +46,7 @@
46
46
  "@sanity/export": "^6.0.0",
47
47
  "@sanity/id-utils": "^1.0.0",
48
48
  "@sanity/import": "^4.0.0",
49
- "@sanity/migrate": "^5.1.0",
49
+ "@sanity/migrate": "^5.2.0",
50
50
  "@sanity/runtime-cli": "^12.1.0",
51
51
  "@sanity/schema": "^5.1.0",
52
52
  "@sanity/telemetry": "^0.8.1",
@@ -61,7 +61,7 @@
61
61
  "console-table-printer": "^2.14.6",
62
62
  "date-fns": "^4.1.0",
63
63
  "debug": "^4.4.3",
64
- "eventsource": "^4.0.0",
64
+ "eventsource": "^4.1.0",
65
65
  "execa": "^9.6.0",
66
66
  "form-data": "^4.0.5",
67
67
  "get-it": "^8.7.0",
@@ -102,7 +102,7 @@
102
102
  "vite": "^7.1.6",
103
103
  "which": "^5.0.0",
104
104
  "zod": "^3.24.2",
105
- "@sanity/cli-core": "0.1.0-alpha.3"
105
+ "@sanity/cli-core": "0.1.0-alpha.4"
106
106
  },
107
107
  "devDependencies": {
108
108
  "@eslint/compat": "^2.0.0",
@@ -125,7 +125,7 @@
125
125
  "@vitest/coverage-istanbul": "^3.2.4",
126
126
  "babel-plugin-react-compiler": "^1.0.0",
127
127
  "chokidar": "^4.0.3",
128
- "eslint": "^9.39.1",
128
+ "eslint": "^9.39.2",
129
129
  "glob": "^11.0.3",
130
130
  "nock": "^14.0.10",
131
131
  "oclif": "^4.22.57",
@@ -134,8 +134,8 @@
134
134
  "vite-tsconfig-paths": "^6.0.1",
135
135
  "vitest": "^3.2.4",
136
136
  "@repo/tsconfig": "3.70.0",
137
- "@repo/eslint-config": "0.0.0",
138
- "@sanity/cli-test": "0.0.2-alpha.2"
137
+ "@sanity/cli-test": "0.0.2-alpha.3",
138
+ "@sanity/eslint-config-cli": "0.0.0-alpha.1"
139
139
  },
140
140
  "engines": {
141
141
  "node": ">=20.19.1 <22 || >=22.12"
@@ -1,2 +0,0 @@
1
- import { Output } from '@sanity/cli-core';
2
- export declare function getMigrationRootDirectory(output: Output): Promise<string>;
@@ -1,14 +0,0 @@
1
- import { findProjectRoot } from '@sanity/cli-core';
2
- export async function getMigrationRootDirectory(output) {
3
- try {
4
- const projectRoot = await findProjectRoot(process.cwd());
5
- return projectRoot.directory;
6
- } catch (error) {
7
- const message = error instanceof Error ? error.message : 'Could not find Sanity project root';
8
- output.error(message, {
9
- exit: 1
10
- });
11
- }
12
- }
13
-
14
- //# sourceMappingURL=getMigrationRootDirectory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/actions/migration/getMigrationRootDirectory.ts"],"sourcesContent":["import {findProjectRoot, Output} from '@sanity/cli-core'\n\nexport async function getMigrationRootDirectory(output: Output): Promise<string> {\n try {\n const projectRoot = await findProjectRoot(process.cwd())\n return projectRoot.directory\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Could not find Sanity project root'\n output.error(message, {exit: 1})\n }\n}\n"],"names":["findProjectRoot","getMigrationRootDirectory","output","projectRoot","process","cwd","directory","error","message","Error","exit"],"mappings":"AAAA,SAAQA,eAAe,QAAe,mBAAkB;AAExD,OAAO,eAAeC,0BAA0BC,MAAc;IAC5D,IAAI;QACF,MAAMC,cAAc,MAAMH,gBAAgBI,QAAQC,GAAG;QACrD,OAAOF,YAAYG,SAAS;IAC9B,EAAE,OAAOC,OAAO;QACd,MAAMC,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAG;QACzDN,OAAOK,KAAK,CAACC,SAAS;YAACE,MAAM;QAAC;IAChC;AACF"}
@@ -1,19 +0,0 @@
1
- import { type Migration } from '@sanity/migrate';
2
- /**
3
- * A resolved migration, where you are guaranteed that the migration file exists
4
- *
5
- * @internal
6
- */
7
- interface ResolvedMigration {
8
- id: string;
9
- migration: Migration;
10
- }
11
- /**
12
- * Resolves all migrations in the studio working directory
13
- *
14
- * @param workDir - The studio working directory
15
- * @returns Array of migrations and their respective paths
16
- * @internal
17
- */
18
- export declare function resolveMigrations(workDir: string): Promise<ResolvedMigration[]>;
19
- export {};
@@ -1,43 +0,0 @@
1
- import { readdir } from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY } from '../../util/migration/constants.js';
4
- import { isLoadableMigrationScript, resolveMigrationScript } from '../../utils/migration/resolveMigrationScript.js';
5
- /**
6
- * Removes migration script extensions from a filename
7
- *
8
- * @param fileName - The filename to process
9
- * @returns The filename without the extension
10
- * @internal
11
- */ function removeMigrationScriptExtension(fileName) {
12
- // Remove `.ts`, `.js` etc from the end of a filename
13
- const ext = MIGRATION_SCRIPT_EXTENSIONS.find((e)=>fileName.endsWith(`.${e}`));
14
- return ext ? path.basename(fileName, `.${ext}`) : fileName;
15
- }
16
- /**
17
- * Resolves all migrations in the studio working directory
18
- *
19
- * @param workDir - The studio working directory
20
- * @returns Array of migrations and their respective paths
21
- * @internal
22
- */ export async function resolveMigrations(workDir) {
23
- const migrationsDir = path.join(workDir, MIGRATIONS_DIRECTORY);
24
- const migrationEntries = await readdir(migrationsDir, {
25
- withFileTypes: true
26
- });
27
- const migrations = [];
28
- for (const entry of migrationEntries){
29
- const entryName = entry.isDirectory() ? entry.name : removeMigrationScriptExtension(entry.name);
30
- const candidates = await resolveMigrationScript(workDir, entryName);
31
- for (const candidate of candidates){
32
- if (isLoadableMigrationScript(candidate)) {
33
- migrations.push({
34
- id: entryName,
35
- migration: candidate.mod.default
36
- });
37
- }
38
- }
39
- }
40
- return migrations;
41
- }
42
-
43
- //# sourceMappingURL=resolveMigrations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/actions/migration/resolveMigrations.ts"],"sourcesContent":["import {readdir} from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {type Migration} from '@sanity/migrate'\n\nimport {MIGRATION_SCRIPT_EXTENSIONS, MIGRATIONS_DIRECTORY} from '../../util/migration/constants.js'\nimport {\n isLoadableMigrationScript,\n resolveMigrationScript,\n} from '../../utils/migration/resolveMigrationScript.js'\n\n/**\n * A resolved migration, where you are guaranteed that the migration file exists\n *\n * @internal\n */\ninterface ResolvedMigration {\n id: string\n migration: Migration\n}\n\n/**\n * Removes migration script extensions from a filename\n *\n * @param fileName - The filename to process\n * @returns The filename without the extension\n * @internal\n */\nfunction removeMigrationScriptExtension(fileName: string): string {\n // Remove `.ts`, `.js` etc from the end of a filename\n const ext = MIGRATION_SCRIPT_EXTENSIONS.find((e) => fileName.endsWith(`.${e}`))\n return ext ? path.basename(fileName, `.${ext}`) : fileName\n}\n\n/**\n * Resolves all migrations in the studio working directory\n *\n * @param workDir - The studio working directory\n * @returns Array of migrations and their respective paths\n * @internal\n */\nexport async function resolveMigrations(workDir: string): Promise<ResolvedMigration[]> {\n const migrationsDir = path.join(workDir, MIGRATIONS_DIRECTORY)\n const migrationEntries = await readdir(migrationsDir, {withFileTypes: true})\n\n const migrations: ResolvedMigration[] = []\n for (const entry of migrationEntries) {\n const entryName = entry.isDirectory() ? entry.name : removeMigrationScriptExtension(entry.name)\n const candidates = await resolveMigrationScript(workDir, entryName)\n for (const candidate of candidates) {\n if (isLoadableMigrationScript(candidate)) {\n migrations.push({\n id: entryName,\n migration: candidate.mod.default,\n })\n }\n }\n }\n\n return migrations\n}\n"],"names":["readdir","path","MIGRATION_SCRIPT_EXTENSIONS","MIGRATIONS_DIRECTORY","isLoadableMigrationScript","resolveMigrationScript","removeMigrationScriptExtension","fileName","ext","find","e","endsWith","basename","resolveMigrations","workDir","migrationsDir","join","migrationEntries","withFileTypes","migrations","entry","entryName","isDirectory","name","candidates","candidate","push","id","migration","mod","default"],"mappings":"AAAA,SAAQA,OAAO,QAAO,mBAAkB;AACxC,OAAOC,UAAU,YAAW;AAI5B,SAAQC,2BAA2B,EAAEC,oBAAoB,QAAO,oCAAmC;AACnG,SACEC,yBAAyB,EACzBC,sBAAsB,QACjB,kDAAiD;AAYxD;;;;;;CAMC,GACD,SAASC,+BAA+BC,QAAgB;IACtD,qDAAqD;IACrD,MAAMC,MAAMN,4BAA4BO,IAAI,CAAC,CAACC,IAAMH,SAASI,QAAQ,CAAC,CAAC,CAAC,EAAED,GAAG;IAC7E,OAAOF,MAAMP,KAAKW,QAAQ,CAACL,UAAU,CAAC,CAAC,EAAEC,KAAK,IAAID;AACpD;AAEA;;;;;;CAMC,GACD,OAAO,eAAeM,kBAAkBC,OAAe;IACrD,MAAMC,gBAAgBd,KAAKe,IAAI,CAACF,SAASX;IACzC,MAAMc,mBAAmB,MAAMjB,QAAQe,eAAe;QAACG,eAAe;IAAI;IAE1E,MAAMC,aAAkC,EAAE;IAC1C,KAAK,MAAMC,SAASH,iBAAkB;QACpC,MAAMI,YAAYD,MAAME,WAAW,KAAKF,MAAMG,IAAI,GAAGjB,+BAA+Bc,MAAMG,IAAI;QAC9F,MAAMC,aAAa,MAAMnB,uBAAuBS,SAASO;QACzD,KAAK,MAAMI,aAAaD,WAAY;YAClC,IAAIpB,0BAA0BqB,YAAY;gBACxCN,WAAWO,IAAI,CAAC;oBACdC,IAAIN;oBACJO,WAAWH,UAAUI,GAAG,CAACC,OAAO;gBAClC;YACF;QACF;IACF;IAEA,OAAOX;AACT"}
@@ -1,65 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { minimalAdvanced } from '../minimalAdvanced';
3
- describe('#minimalAdvanced', ()=>{
4
- test('creates template with no doc types', ()=>{
5
- const minimalAdvancedTemplate = minimalAdvanced({
6
- documentTypes: [],
7
- migrationName: 'My Migration'
8
- });
9
- expect(minimalAdvancedTemplate).toMatchInlineSnapshot(`
10
- "import {defineMigration, patch, at, setIfMissing} from '@sanity/migrate'
11
-
12
- /**
13
- * this migration will set \`Default title\` on all documents that are missing a title
14
- * and make \`true\` the default value for the \`enabled\` field
15
- */
16
- export default defineMigration({
17
- title: "My Migration",
18
-
19
- async *migrate(documents, context) {
20
- for await (const document of documents()) {
21
- yield patch(document._id, [
22
- at('title', setIfMissing('Default title')),
23
- at('enabled', setIfMissing(true)),
24
- ])
25
- }
26
- }
27
- })
28
- "
29
- `);
30
- });
31
- test('creates template with doc types', ()=>{
32
- const minimalAdvancedTemplate = minimalAdvanced({
33
- documentTypes: [
34
- 'document-1',
35
- 'document-2',
36
- 'document-3'
37
- ],
38
- migrationName: 'My Migration'
39
- });
40
- expect(minimalAdvancedTemplate).toMatchInlineSnapshot(`
41
- "import {defineMigration, patch, at, setIfMissing} from '@sanity/migrate'
42
-
43
- /**
44
- * this migration will set \`Default title\` on all documents that are missing a title
45
- * and make \`true\` the default value for the \`enabled\` field
46
- */
47
- export default defineMigration({
48
- title: "My Migration",
49
- documentTypes: ["document-1", "document-2", "document-3"],
50
-
51
- async *migrate(documents, context) {
52
- for await (const document of documents()) {
53
- yield patch(document._id, [
54
- at('title', setIfMissing('Default title')),
55
- at('enabled', setIfMissing(true)),
56
- ])
57
- }
58
- }
59
- })
60
- "
61
- `);
62
- });
63
- });
64
-
65
- //# sourceMappingURL=minimalAdvanced.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/actions/migration/templates/__tests__/minimalAdvanced.test.ts"],"sourcesContent":["import {describe, expect, test} from 'vitest'\n\nimport {minimalAdvanced} from '../minimalAdvanced'\n\ndescribe('#minimalAdvanced', () => {\n test('creates template with no doc types', () => {\n const minimalAdvancedTemplate = minimalAdvanced({\n documentTypes: [],\n migrationName: 'My Migration',\n })\n\n expect(minimalAdvancedTemplate).toMatchInlineSnapshot(`\n \"import {defineMigration, patch, at, setIfMissing} from '@sanity/migrate'\n\n /**\n * this migration will set \\`Default title\\` on all documents that are missing a title\n * and make \\`true\\` the default value for the \\`enabled\\` field\n */\n export default defineMigration({\n title: \"My Migration\",\n\n async *migrate(documents, context) {\n for await (const document of documents()) {\n yield patch(document._id, [\n at('title', setIfMissing('Default title')),\n at('enabled', setIfMissing(true)),\n ])\n }\n }\n })\n \"\n `)\n })\n\n test('creates template with doc types', () => {\n const minimalAdvancedTemplate = minimalAdvanced({\n documentTypes: ['document-1', 'document-2', 'document-3'],\n migrationName: 'My Migration',\n })\n\n expect(minimalAdvancedTemplate).toMatchInlineSnapshot(`\n \"import {defineMigration, patch, at, setIfMissing} from '@sanity/migrate'\n\n /**\n * this migration will set \\`Default title\\` on all documents that are missing a title\n * and make \\`true\\` the default value for the \\`enabled\\` field\n */\n export default defineMigration({\n title: \"My Migration\",\n documentTypes: [\"document-1\", \"document-2\", \"document-3\"],\n\n async *migrate(documents, context) {\n for await (const document of documents()) {\n yield patch(document._id, [\n at('title', setIfMissing('Default title')),\n at('enabled', setIfMissing(true)),\n ])\n }\n }\n })\n \"\n `)\n })\n})\n"],"names":["describe","expect","test","minimalAdvanced","minimalAdvancedTemplate","documentTypes","migrationName","toMatchInlineSnapshot"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAO,SAAQ;AAE7C,SAAQC,eAAe,QAAO,qBAAoB;AAElDH,SAAS,oBAAoB;IAC3BE,KAAK,sCAAsC;QACzC,MAAME,0BAA0BD,gBAAgB;YAC9CE,eAAe,EAAE;YACjBC,eAAe;QACjB;QAEAL,OAAOG,yBAAyBG,qBAAqB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;IAoBvD,CAAC;IACH;IAEAL,KAAK,mCAAmC;QACtC,MAAME,0BAA0BD,gBAAgB;YAC9CE,eAAe;gBAAC;gBAAc;gBAAc;aAAa;YACzDC,eAAe;QACjB;QAEAL,OAAOG,yBAAyBG,qBAAqB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;IAqBvD,CAAC;IACH;AACF"}
@@ -1,145 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { minimalSimple } from '../minimalSimple';
3
- describe('#minimalSimple', ()=>{
4
- test('creates template with no doc types', ()=>{
5
- const minimalSimpleTemplate = minimalSimple({
6
- documentTypes: [],
7
- migrationName: 'My Migration'
8
- });
9
- expect(minimalSimpleTemplate).toMatchInlineSnapshot(`
10
- "import {at, defineMigration, setIfMissing, unset} from '@sanity/migrate'
11
-
12
- export default defineMigration({
13
- title: "My Migration",
14
-
15
- migrate: {
16
- document(doc, context) {
17
- // this will be called for every document of the matching type
18
- // any patch returned will be applied to the document
19
- // you can also return mutations that touches other documents
20
-
21
- return at('title', setIfMissing('Default title'))
22
- },
23
- node(node, path, context) {
24
- // this will be called for every node in every document of the matching type
25
- // any patch returned will be applied to the document
26
- // you can also return mutations that touches other documents
27
-
28
- if (typeof node === 'string' && node === 'deleteme') {
29
- return unset()
30
- }
31
- },
32
- object(node, path, context) {
33
- // this will be called for every object node in every document of the matching type
34
- // any patch returned will be applied to the document
35
- // you can also return mutations that touches other documents
36
- if (node._type === 'author') {
37
- // make sure all authors objects have a books array
38
- return at('books', setIfMissing([]))
39
- }
40
- },
41
- array(node, path, context) {
42
- // this will be called for every array node in every document of the matching type
43
- // any patch returned will be applied to the document
44
- // you can also return mutations that touches other documents
45
- },
46
- string(node, path, context) {
47
- // this will be called for every string node in every document of the matching type
48
- // any patch returned will be applied to the document
49
- // you can also return mutations that touches other documents
50
- },
51
- number(node, path, context) {
52
- // this will be called for every number node in every document of the matching type
53
- // any patch returned will be applied to the document
54
- // you can also return mutations that touches other documents
55
- },
56
- boolean(node, path, context) {
57
- // this will be called for every boolean node in every document of the matching type
58
- // any patch returned will be applied to the document
59
- // you can also return mutations that touches other documents
60
- },
61
- null(node, path, context) {
62
- // this will be called for every null node in every document of the matching type
63
- // any patch returned will be applied to the document
64
- // you can also return mutations that touches other documents
65
- },
66
- },
67
- })
68
- "
69
- `);
70
- });
71
- test('creates template with doc types', ()=>{
72
- const minimalSimpleTemplate = minimalSimple({
73
- documentTypes: [
74
- 'document-1',
75
- 'document-2',
76
- 'document-3'
77
- ],
78
- migrationName: 'My Migration'
79
- });
80
- expect(minimalSimpleTemplate).toMatchInlineSnapshot(`
81
- "import {at, defineMigration, setIfMissing, unset} from '@sanity/migrate'
82
-
83
- export default defineMigration({
84
- title: "My Migration",
85
- documentTypes: ["document-1", "document-2", "document-3"],
86
-
87
- migrate: {
88
- document(doc, context) {
89
- // this will be called for every document of the matching type
90
- // any patch returned will be applied to the document
91
- // you can also return mutations that touches other documents
92
-
93
- return at('title', setIfMissing('Default title'))
94
- },
95
- node(node, path, context) {
96
- // this will be called for every node in every document of the matching type
97
- // any patch returned will be applied to the document
98
- // you can also return mutations that touches other documents
99
-
100
- if (typeof node === 'string' && node === 'deleteme') {
101
- return unset()
102
- }
103
- },
104
- object(node, path, context) {
105
- // this will be called for every object node in every document of the matching type
106
- // any patch returned will be applied to the document
107
- // you can also return mutations that touches other documents
108
- if (node._type === 'author') {
109
- // make sure all authors objects have a books array
110
- return at('books', setIfMissing([]))
111
- }
112
- },
113
- array(node, path, context) {
114
- // this will be called for every array node in every document of the matching type
115
- // any patch returned will be applied to the document
116
- // you can also return mutations that touches other documents
117
- },
118
- string(node, path, context) {
119
- // this will be called for every string node in every document of the matching type
120
- // any patch returned will be applied to the document
121
- // you can also return mutations that touches other documents
122
- },
123
- number(node, path, context) {
124
- // this will be called for every number node in every document of the matching type
125
- // any patch returned will be applied to the document
126
- // you can also return mutations that touches other documents
127
- },
128
- boolean(node, path, context) {
129
- // this will be called for every boolean node in every document of the matching type
130
- // any patch returned will be applied to the document
131
- // you can also return mutations that touches other documents
132
- },
133
- null(node, path, context) {
134
- // this will be called for every null node in every document of the matching type
135
- // any patch returned will be applied to the document
136
- // you can also return mutations that touches other documents
137
- },
138
- },
139
- })
140
- "
141
- `);
142
- });
143
- });
144
-
145
- //# sourceMappingURL=minimalSimple.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/actions/migration/templates/__tests__/minimalSimple.test.ts"],"sourcesContent":["import {describe, expect, test} from 'vitest'\n\nimport {minimalSimple} from '../minimalSimple'\n\ndescribe('#minimalSimple', () => {\n test('creates template with no doc types', () => {\n const minimalSimpleTemplate = minimalSimple({\n documentTypes: [],\n migrationName: 'My Migration',\n })\n\n expect(minimalSimpleTemplate).toMatchInlineSnapshot(`\n \"import {at, defineMigration, setIfMissing, unset} from '@sanity/migrate'\n\n export default defineMigration({\n title: \"My Migration\",\n\n migrate: {\n document(doc, context) {\n // this will be called for every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n\n return at('title', setIfMissing('Default title'))\n },\n node(node, path, context) {\n // this will be called for every node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n\n if (typeof node === 'string' && node === 'deleteme') {\n return unset()\n }\n },\n object(node, path, context) {\n // this will be called for every object node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n if (node._type === 'author') {\n // make sure all authors objects have a books array\n return at('books', setIfMissing([]))\n }\n },\n array(node, path, context) {\n // this will be called for every array node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n string(node, path, context) {\n // this will be called for every string node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n number(node, path, context) {\n // this will be called for every number node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n boolean(node, path, context) {\n // this will be called for every boolean node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n null(node, path, context) {\n // this will be called for every null node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n },\n })\n \"\n `)\n })\n\n test('creates template with doc types', () => {\n const minimalSimpleTemplate = minimalSimple({\n documentTypes: ['document-1', 'document-2', 'document-3'],\n migrationName: 'My Migration',\n })\n\n expect(minimalSimpleTemplate).toMatchInlineSnapshot(`\n \"import {at, defineMigration, setIfMissing, unset} from '@sanity/migrate'\n\n export default defineMigration({\n title: \"My Migration\",\n documentTypes: [\"document-1\", \"document-2\", \"document-3\"],\n\n migrate: {\n document(doc, context) {\n // this will be called for every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n\n return at('title', setIfMissing('Default title'))\n },\n node(node, path, context) {\n // this will be called for every node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n\n if (typeof node === 'string' && node === 'deleteme') {\n return unset()\n }\n },\n object(node, path, context) {\n // this will be called for every object node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n if (node._type === 'author') {\n // make sure all authors objects have a books array\n return at('books', setIfMissing([]))\n }\n },\n array(node, path, context) {\n // this will be called for every array node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n string(node, path, context) {\n // this will be called for every string node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n number(node, path, context) {\n // this will be called for every number node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n boolean(node, path, context) {\n // this will be called for every boolean node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n null(node, path, context) {\n // this will be called for every null node in every document of the matching type\n // any patch returned will be applied to the document\n // you can also return mutations that touches other documents\n },\n },\n })\n \"\n `)\n })\n})\n"],"names":["describe","expect","test","minimalSimple","minimalSimpleTemplate","documentTypes","migrationName","toMatchInlineSnapshot"],"mappings":"AAAA,SAAQA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAO,SAAQ;AAE7C,SAAQC,aAAa,QAAO,mBAAkB;AAE9CH,SAAS,kBAAkB;IACzBE,KAAK,sCAAsC;QACzC,MAAME,wBAAwBD,cAAc;YAC1CE,eAAe,EAAE;YACjBC,eAAe;QACjB;QAEAL,OAAOG,uBAAuBG,qBAAqB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4DrD,CAAC;IACH;IAEAL,KAAK,mCAAmC;QACtC,MAAME,wBAAwBD,cAAc;YAC1CE,eAAe;gBAAC;gBAAc;gBAAc;aAAa;YACzDC,eAAe;QACjB;QAEAL,OAAOG,uBAAuBG,qBAAqB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6DrD,CAAC;IACH;AACF"}