@sanity/cli 6.3.1 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +311 -452
- package/dist/actions/build/decorateIndexWithStagingScript.js +16 -0
- package/dist/actions/build/decorateIndexWithStagingScript.js.map +1 -0
- package/dist/actions/build/writeSanityRuntime.js +3 -2
- package/dist/actions/build/writeSanityRuntime.js.map +1 -1
- package/dist/actions/dataset/create.js +4 -0
- package/dist/actions/dataset/create.js.map +1 -1
- package/dist/actions/deploy/findUserApplicationForApp.js +1 -0
- package/dist/actions/deploy/findUserApplicationForApp.js.map +1 -1
- package/dist/actions/deploy/types.js +1 -1
- package/dist/actions/deploy/types.js.map +1 -1
- package/dist/actions/init/bootstrapLocalTemplate.js +16 -1
- package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -1
- package/dist/actions/init/initApp.js +72 -0
- package/dist/actions/init/initApp.js.map +1 -0
- package/dist/actions/init/initHelpers.js +37 -0
- package/dist/actions/init/initHelpers.js.map +1 -0
- package/dist/actions/init/initNextJs.js +246 -0
- package/dist/actions/init/initNextJs.js.map +1 -0
- package/dist/actions/init/initStudio.js +127 -0
- package/dist/actions/init/initStudio.js.map +1 -0
- package/dist/actions/init/scaffoldTemplate.js +114 -0
- package/dist/actions/init/scaffoldTemplate.js.map +1 -0
- package/dist/actions/init/templates/appQuickstart.js +2 -1
- package/dist/actions/init/templates/appQuickstart.js.map +1 -1
- package/dist/actions/init/templates/appSanityUi.js +2 -1
- package/dist/actions/init/templates/appSanityUi.js.map +1 -1
- package/dist/actions/init/templates/nextjs/index.js +1 -2
- package/dist/actions/init/templates/nextjs/index.js.map +1 -1
- package/dist/actions/init/templates/shopify.js +6 -6
- package/dist/actions/init/templates/shopify.js.map +1 -1
- package/dist/actions/init/templates/shopifyOnline.js +2 -2
- package/dist/actions/init/templates/shopifyOnline.js.map +1 -1
- package/dist/actions/manifest/types.js +1 -1
- package/dist/actions/manifest/types.js.map +1 -1
- package/dist/actions/mcp/detectAvailableEditors.js +16 -3
- package/dist/actions/mcp/detectAvailableEditors.js.map +1 -1
- package/dist/actions/mcp/editorConfigs.js +192 -132
- package/dist/actions/mcp/editorConfigs.js.map +1 -1
- package/dist/actions/mcp/setupMCP.js +4 -1
- package/dist/actions/mcp/setupMCP.js.map +1 -1
- package/dist/actions/mcp/writeMCPConfig.js +2 -2
- package/dist/actions/mcp/writeMCPConfig.js.map +1 -1
- package/dist/actions/schema/extractSchema.js +5 -7
- package/dist/actions/schema/extractSchema.js.map +1 -1
- package/dist/actions/schema/types.js +3 -3
- package/dist/actions/schema/types.js.map +1 -1
- package/dist/actions/users/validateEmail.js +2 -2
- package/dist/actions/users/validateEmail.js.map +1 -1
- package/dist/commands/backups/disable.js +1 -1
- package/dist/commands/backups/disable.js.map +1 -1
- package/dist/commands/backups/download.js +1 -1
- package/dist/commands/backups/download.js.map +1 -1
- package/dist/commands/backups/enable.js +1 -1
- package/dist/commands/backups/enable.js.map +1 -1
- package/dist/commands/backups/list.js +1 -1
- package/dist/commands/backups/list.js.map +1 -1
- package/dist/commands/build.js +1 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/cors/add.js +1 -1
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/cors/delete.js +1 -1
- package/dist/commands/cors/delete.js.map +1 -1
- package/dist/commands/cors/list.js +2 -2
- package/dist/commands/cors/list.js.map +1 -1
- package/dist/commands/datasets/alias/create.js +1 -1
- package/dist/commands/datasets/alias/create.js.map +1 -1
- package/dist/commands/datasets/alias/delete.js +1 -1
- package/dist/commands/datasets/alias/delete.js.map +1 -1
- package/dist/commands/datasets/alias/link.js +1 -1
- package/dist/commands/datasets/alias/link.js.map +1 -1
- package/dist/commands/datasets/alias/unlink.js +1 -1
- package/dist/commands/datasets/alias/unlink.js.map +1 -1
- package/dist/commands/datasets/copy.js +15 -1
- package/dist/commands/datasets/copy.js.map +1 -1
- package/dist/commands/datasets/create.js +1 -1
- package/dist/commands/datasets/create.js.map +1 -1
- package/dist/commands/datasets/delete.js +1 -1
- package/dist/commands/datasets/delete.js.map +1 -1
- package/dist/commands/datasets/embeddings/enable.js +11 -0
- package/dist/commands/datasets/embeddings/enable.js.map +1 -1
- package/dist/commands/datasets/export.js +2 -2
- package/dist/commands/datasets/export.js.map +1 -1
- package/dist/commands/datasets/list.js +2 -2
- package/dist/commands/datasets/list.js.map +1 -1
- package/dist/commands/debug.js +1 -1
- package/dist/commands/debug.js.map +1 -1
- package/dist/commands/deploy.js +3 -3
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +5 -5
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/docs/browse.js +1 -1
- package/dist/commands/docs/browse.js.map +1 -1
- package/dist/commands/documents/delete.js +1 -1
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/exec.js +2 -2
- package/dist/commands/exec.js.map +1 -1
- package/dist/commands/graphql/deploy.js +2 -2
- package/dist/commands/graphql/deploy.js.map +1 -1
- package/dist/commands/graphql/list.js +2 -2
- package/dist/commands/graphql/list.js.map +1 -1
- package/dist/commands/hooks/create.js +2 -2
- package/dist/commands/hooks/create.js.map +1 -1
- package/dist/commands/hooks/delete.js +5 -5
- package/dist/commands/hooks/delete.js.map +1 -1
- package/dist/commands/hooks/list.js +3 -3
- package/dist/commands/hooks/list.js.map +1 -1
- package/dist/commands/hooks/logs.js +5 -5
- package/dist/commands/hooks/logs.js.map +1 -1
- package/dist/commands/init.js +175 -490
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/install.js +1 -1
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/learn.js +1 -1
- package/dist/commands/learn.js.map +1 -1
- package/dist/commands/login.js +1 -1
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/manage.js +1 -1
- package/dist/commands/manage.js.map +1 -1
- package/dist/commands/manifest/extract.js +2 -2
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/commands/mcp/configure.js +1 -1
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/media/delete-aspect.js +1 -1
- package/dist/commands/media/delete-aspect.js.map +1 -1
- package/dist/commands/media/export.js +1 -1
- package/dist/commands/media/export.js.map +1 -1
- package/dist/commands/preview.js +3 -3
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/projects/list.js +4 -2
- package/dist/commands/projects/list.js.map +1 -1
- package/dist/commands/schemas/deploy.js +3 -4
- package/dist/commands/schemas/deploy.js.map +1 -1
- package/dist/commands/schemas/extract.js +3 -3
- package/dist/commands/schemas/extract.js.map +1 -1
- package/dist/commands/schemas/list.js +4 -5
- package/dist/commands/schemas/list.js.map +1 -1
- package/dist/commands/telemetry/disable.js +2 -2
- package/dist/commands/telemetry/disable.js.map +1 -1
- package/dist/commands/telemetry/enable.js +2 -2
- package/dist/commands/telemetry/enable.js.map +1 -1
- package/dist/commands/telemetry/status.js +2 -2
- package/dist/commands/telemetry/status.js.map +1 -1
- package/dist/commands/tokens/add.js +1 -1
- package/dist/commands/tokens/add.js.map +1 -1
- package/dist/commands/tokens/delete.js +1 -1
- package/dist/commands/tokens/delete.js.map +1 -1
- package/dist/commands/tokens/list.js +2 -2
- package/dist/commands/tokens/list.js.map +1 -1
- package/dist/commands/users/list.js +1 -1
- package/dist/commands/users/list.js.map +1 -1
- package/dist/commands/versions.js +1 -1
- package/dist/commands/versions.js.map +1 -1
- package/dist/hooks/prerun/injectEnvVariables.js +3 -5
- package/dist/hooks/prerun/injectEnvVariables.js.map +1 -1
- package/dist/server/vite/plugin-sanity-build-entries.js +3 -2
- package/dist/server/vite/plugin-sanity-build-entries.js.map +1 -1
- package/dist/services/datasets.js +2 -1
- package/dist/services/datasets.js.map +1 -1
- package/dist/telemetry/init.telemetry.js.map +1 -1
- package/dist/util/packageManager/installationInfo/detectPackages.js +13 -7
- package/dist/util/packageManager/installationInfo/detectPackages.js.map +1 -1
- package/dist/util/telemetry/createTelemetryStore.js +27 -12
- package/dist/util/telemetry/createTelemetryStore.js.map +1 -1
- package/dist/util/update/fetchUpdateInfo.js +40 -0
- package/dist/util/update/fetchUpdateInfo.js.map +1 -0
- package/dist/util/update/fetchUpdateInfo.worker.js +19 -0
- package/dist/util/update/fetchUpdateInfo.worker.js.map +1 -0
- package/dist/util/update/getRunnerUpdateCommand.js +33 -0
- package/dist/util/update/getRunnerUpdateCommand.js.map +1 -0
- package/dist/util/update/getUpdateCommand.js +6 -7
- package/dist/util/update/getUpdateCommand.js.map +1 -1
- package/dist/util/update/packageRunner.js +10 -0
- package/dist/util/update/packageRunner.js.map +1 -0
- package/dist/util/update/resolveRunnerPackage.js +45 -0
- package/dist/util/update/resolveRunnerPackage.js.map +1 -0
- package/dist/util/update/resolveUpdateTarget.js +31 -0
- package/dist/util/update/resolveUpdateTarget.js.map +1 -0
- package/dist/util/update/showNotificationUpdate.js +8 -6
- package/dist/util/update/showNotificationUpdate.js.map +1 -1
- package/dist/util/update/updateChecker.js +73 -38
- package/dist/util/update/updateChecker.js.map +1 -1
- package/dist/util/validateProjection.js +121 -0
- package/dist/util/validateProjection.js.map +1 -0
- package/oclif.manifest.json +698 -681
- package/package.json +24 -23
- package/templates/app-quickstart/src/App.tsx +2 -2
- package/templates/app-sanity-ui/src/App.tsx +2 -2
- package/templates/shopify/schemaTypes/objects/hotspot/imageWithProductHotspotsType.ts +1 -1
- package/dist/util/update/fetchLatestVersion.js +0 -21
- package/dist/util/update/fetchLatestVersion.js.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isStaging } from '@sanity/cli-core';
|
|
2
|
+
/**
|
|
3
|
+
* Decorates the given HTML template with a script tag that sets
|
|
4
|
+
* `globalThis.__SANITY_STAGING__` to `true` when building in a
|
|
5
|
+
* staging environment. The script is injected as the first child
|
|
6
|
+
* of `<head>` so it runs before any module scripts.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/ export function decorateIndexWithStagingScript(template) {
|
|
10
|
+
if (!isStaging()) {
|
|
11
|
+
return template;
|
|
12
|
+
}
|
|
13
|
+
return template.replace(/<head([^>]*)>/, '<head$1>\n<script>globalThis.__SANITY_STAGING__ = true</script>');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=decorateIndexWithStagingScript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/decorateIndexWithStagingScript.ts"],"sourcesContent":["import {isStaging} from '@sanity/cli-core'\n\n/**\n * Decorates the given HTML template with a script tag that sets\n * `globalThis.__SANITY_STAGING__` to `true` when building in a\n * staging environment. The script is injected as the first child\n * of `<head>` so it runs before any module scripts.\n *\n * @internal\n */\nexport function decorateIndexWithStagingScript(template: string): string {\n if (!isStaging()) {\n return template\n }\n\n return template.replace(\n /<head([^>]*)>/,\n '<head$1>\\n<script>globalThis.__SANITY_STAGING__ = true</script>',\n )\n}\n"],"names":["isStaging","decorateIndexWithStagingScript","template","replace"],"mappings":"AAAA,SAAQA,SAAS,QAAO,mBAAkB;AAE1C;;;;;;;CAOC,GACD,OAAO,SAASC,+BAA+BC,QAAgB;IAC7D,IAAI,CAACF,aAAa;QAChB,OAAOE;IACT;IAEA,OAAOA,SAASC,OAAO,CACrB,iBACA;AAEJ"}
|
|
@@ -6,6 +6,7 @@ import { toForwardSlashes } from '../../util/toForwardSlashes.js';
|
|
|
6
6
|
import { buildDebug } from './buildDebug.js';
|
|
7
7
|
import { decorateIndexWithAutoGeneratedWarning } from './decorateIndexWithAutoGeneratedWarning.js';
|
|
8
8
|
import { decorateIndexWithBridgeScript } from './decorateIndexWithBridgeScript.js';
|
|
9
|
+
import { decorateIndexWithStagingScript } from './decorateIndexWithStagingScript.js';
|
|
9
10
|
import { getEntryModule } from './getEntryModule.js';
|
|
10
11
|
import { getPossibleDocumentComponentLocations } from './getPossibleDocumentComponentLocations.js';
|
|
11
12
|
import { renderDocument } from './renderDocument.js';
|
|
@@ -25,7 +26,7 @@ import { renderDocument } from './renderDocument.js';
|
|
|
25
26
|
});
|
|
26
27
|
async function renderAndWriteDocument() {
|
|
27
28
|
buildDebug('Rendering document template');
|
|
28
|
-
const indexHtml = decorateIndexWithBridgeScript(decorateIndexWithAutoGeneratedWarning(await renderDocument({
|
|
29
|
+
const indexHtml = decorateIndexWithStagingScript(decorateIndexWithBridgeScript(decorateIndexWithAutoGeneratedWarning(await renderDocument({
|
|
29
30
|
isApp,
|
|
30
31
|
props: {
|
|
31
32
|
basePath: basePath || '/',
|
|
@@ -33,7 +34,7 @@ import { renderDocument } from './renderDocument.js';
|
|
|
33
34
|
title: appTitle
|
|
34
35
|
},
|
|
35
36
|
studioRootPath: cwd
|
|
36
|
-
})));
|
|
37
|
+
}))));
|
|
37
38
|
buildDebug('Writing index.html to runtime directory');
|
|
38
39
|
await fs.writeFile(path.join(runtimeDir, 'index.html'), indexHtml);
|
|
39
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {tryFindStudioConfigPath} from '@sanity/cli-core'\nimport {watch as chokidarWatch, type FSWatcher} from 'chokidar'\n\nimport {toForwardSlashes} from '../../util/toForwardSlashes.js'\nimport {buildDebug} from './buildDebug.js'\nimport {decorateIndexWithAutoGeneratedWarning} from './decorateIndexWithAutoGeneratedWarning.js'\nimport {decorateIndexWithBridgeScript} from './decorateIndexWithBridgeScript.js'\nimport {getEntryModule} from './getEntryModule.js'\nimport {getPossibleDocumentComponentLocations} from './getPossibleDocumentComponentLocations.js'\nimport {renderDocument} from './renderDocument.js'\n\ninterface RuntimeOptions {\n cwd: string\n reactStrictMode: boolean\n watch: boolean\n\n appTitle?: string\n basePath?: string\n entry?: string\n isApp?: boolean\n}\n\n/**\n * Generates the `.sanity/runtime` directory, and optionally watches for custom\n * document files, rebuilding when they change\n *\n * @param options - Current working directory (Sanity root dir), and whether or not to watch\n * @returns A watcher instance if watch is enabled, undefined otherwise\n * @internal\n */\nexport async function writeSanityRuntime(options: RuntimeOptions): Promise<FSWatcher | undefined> {\n const {appTitle, basePath, cwd, entry, isApp, reactStrictMode, watch} = options\n const runtimeDir = path.join(cwd, '.sanity', 'runtime')\n\n buildDebug('Making runtime directory')\n await fs.mkdir(runtimeDir, {recursive: true})\n\n async function renderAndWriteDocument() {\n buildDebug('Rendering document template')\n const indexHtml = decorateIndexWithBridgeScript(\n
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/build/writeSanityRuntime.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {tryFindStudioConfigPath} from '@sanity/cli-core'\nimport {watch as chokidarWatch, type FSWatcher} from 'chokidar'\n\nimport {toForwardSlashes} from '../../util/toForwardSlashes.js'\nimport {buildDebug} from './buildDebug.js'\nimport {decorateIndexWithAutoGeneratedWarning} from './decorateIndexWithAutoGeneratedWarning.js'\nimport {decorateIndexWithBridgeScript} from './decorateIndexWithBridgeScript.js'\nimport {decorateIndexWithStagingScript} from './decorateIndexWithStagingScript.js'\nimport {getEntryModule} from './getEntryModule.js'\nimport {getPossibleDocumentComponentLocations} from './getPossibleDocumentComponentLocations.js'\nimport {renderDocument} from './renderDocument.js'\n\ninterface RuntimeOptions {\n cwd: string\n reactStrictMode: boolean\n watch: boolean\n\n appTitle?: string\n basePath?: string\n entry?: string\n isApp?: boolean\n}\n\n/**\n * Generates the `.sanity/runtime` directory, and optionally watches for custom\n * document files, rebuilding when they change\n *\n * @param options - Current working directory (Sanity root dir), and whether or not to watch\n * @returns A watcher instance if watch is enabled, undefined otherwise\n * @internal\n */\nexport async function writeSanityRuntime(options: RuntimeOptions): Promise<FSWatcher | undefined> {\n const {appTitle, basePath, cwd, entry, isApp, reactStrictMode, watch} = options\n const runtimeDir = path.join(cwd, '.sanity', 'runtime')\n\n buildDebug('Making runtime directory')\n await fs.mkdir(runtimeDir, {recursive: true})\n\n async function renderAndWriteDocument() {\n buildDebug('Rendering document template')\n const indexHtml = decorateIndexWithStagingScript(\n decorateIndexWithBridgeScript(\n decorateIndexWithAutoGeneratedWarning(\n await renderDocument({\n isApp,\n props: {\n basePath: basePath || '/',\n entryPath: `/${toForwardSlashes(path.relative(cwd, path.join(runtimeDir, 'app.js')))}`,\n title: appTitle,\n },\n studioRootPath: cwd,\n }),\n ),\n ),\n )\n\n buildDebug('Writing index.html to runtime directory')\n await fs.writeFile(path.join(runtimeDir, 'index.html'), indexHtml)\n }\n\n let watcher: FSWatcher | undefined\n\n if (watch) {\n watcher = chokidarWatch(getPossibleDocumentComponentLocations(cwd)).on('all', () =>\n renderAndWriteDocument(),\n )\n }\n\n await renderAndWriteDocument()\n\n buildDebug('Writing app.js to runtime directory')\n let relativeConfigLocation: string | null = null\n if (!isApp) {\n const studioConfigPath = await tryFindStudioConfigPath(cwd)\n relativeConfigLocation = studioConfigPath\n ? toForwardSlashes(path.relative(runtimeDir, studioConfigPath))\n : null\n }\n\n const relativeEntry = toForwardSlashes(\n path.relative(runtimeDir, path.resolve(cwd, entry || './src/App')),\n )\n const appJsContent = getEntryModule({\n basePath,\n entry: relativeEntry,\n isApp,\n reactStrictMode,\n relativeConfigLocation,\n })\n await fs.writeFile(path.join(runtimeDir, 'app.js'), appJsContent)\n\n return watcher\n}\n"],"names":["fs","path","tryFindStudioConfigPath","watch","chokidarWatch","toForwardSlashes","buildDebug","decorateIndexWithAutoGeneratedWarning","decorateIndexWithBridgeScript","decorateIndexWithStagingScript","getEntryModule","getPossibleDocumentComponentLocations","renderDocument","writeSanityRuntime","options","appTitle","basePath","cwd","entry","isApp","reactStrictMode","runtimeDir","join","mkdir","recursive","renderAndWriteDocument","indexHtml","props","entryPath","relative","title","studioRootPath","writeFile","watcher","on","relativeConfigLocation","studioConfigPath","relativeEntry","resolve","appJsContent"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC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wBe;QACvDkB,yBAAyBC,mBACrB/B,iBAAiBJ,KAAK4B,QAAQ,CAACR,YAAYe,qBAC3C;IACN;IAEA,MAAMC,gBAAgBhC,iBACpBJ,KAAK4B,QAAQ,CAACR,YAAYpB,KAAKqC,OAAO,CAACrB,KAAKC,SAAS;IAEvD,MAAMqB,eAAe7B,eAAe;QAClCM;QACAE,OAAOmB;QACPlB;QACAC;QACAe;IACF;IACA,MAAMnC,GAAGgC,SAAS,CAAC/B,KAAKqB,IAAI,CAACD,YAAY,WAAWkB;IAEpD,OAAON;AACT"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { subdebug } from '@sanity/cli-core';
|
|
2
2
|
import { spinner } from '@sanity/cli-core/ux';
|
|
3
3
|
import { createDataset as createDatasetService } from '../../services/datasets.js';
|
|
4
|
+
import { validateProjection } from '../../util/validateProjection.js';
|
|
4
5
|
import { determineDatasetAclMode } from './determineDatasetAclMode.js';
|
|
5
6
|
const debug = subdebug('dataset:create');
|
|
6
7
|
/**
|
|
@@ -24,6 +25,9 @@ const debug = subdebug('dataset:create');
|
|
|
24
25
|
output,
|
|
25
26
|
visibility
|
|
26
27
|
});
|
|
28
|
+
if (embeddingsProjection) {
|
|
29
|
+
validateProjection(embeddingsProjection);
|
|
30
|
+
}
|
|
27
31
|
try {
|
|
28
32
|
const spin = spinner('Creating dataset').start();
|
|
29
33
|
const newDataset = await createDatasetService({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/dataset/create.ts"],"sourcesContent":["import {type Output, subdebug} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {type DatasetAclMode, DatasetResponse} from '@sanity/client'\n\nimport {createDataset as createDatasetService} from '../../services/datasets.js'\nimport {determineDatasetAclMode} from './determineDatasetAclMode.js'\n\nconst debug = subdebug('dataset:create')\n\n/**\n * Options for creating a dataset\n */\ninterface CreateDatasetOptions {\n /**\n * Name of the dataset to create\n */\n datasetName: string\n\n /**\n * Output instance for logging\n */\n output: Output\n\n /**\n * Array of project features to determine capabilities\n * Used to check if private datasets are available\n */\n projectFeatures: string[]\n\n /**\n * Project ID where the dataset will be created\n */\n projectId: string\n\n /**\n * Whether to enable embeddings for the new dataset\n */\n embeddings?: boolean\n\n /**\n * GROQ projection for embeddings indexing (e.g. \"\\{ title, body \\}\")\n * Only used when embeddings is true\n */\n embeddingsProjection?: string\n\n /**\n * Whether to force disable private dataset creation\n * Used when default config is selected (which forces public datasets)\n */\n forcePublic?: boolean\n\n /**\n * Whether to run in unattended mode (no prompts)\n */\n isUnattended?: boolean\n\n /**\n * Requested visibility mode from flags/options\n */\n visibility?: string\n}\n\n/**\n * Creates a new dataset with the appropriate ACL mode.\n *\n * This action handles the business logic for:\n * - Determining the appropriate ACL mode based on project capabilities\n * - Creating the dataset via the service layer\n * - Handling errors and providing user feedback\n *\n * @param options - Configuration options\n * @returns Promise resolving when dataset is created\n * @throws Error if dataset creation fails\n */\nexport async function createDataset(options: CreateDatasetOptions): Promise<DatasetResponse> {\n const {\n datasetName,\n embeddings,\n embeddingsProjection,\n forcePublic = false,\n isUnattended = false,\n output,\n projectFeatures,\n projectId,\n visibility,\n } = options\n\n const canCreatePrivate = projectFeatures.includes('privateDataset') && !forcePublic\n\n // Determine the appropriate ACL mode\n const aclMode: DatasetAclMode = await determineDatasetAclMode({\n canCreatePrivate,\n isUnattended,\n output,\n visibility,\n })\n\n try {\n const spin = spinner('Creating dataset').start()\n const newDataset = await createDatasetService({\n aclMode,\n datasetName,\n embeddings: embeddings\n ? {enabled: true, ...(embeddingsProjection ? {projection: embeddingsProjection} : {})}\n : undefined,\n projectId,\n })\n spin.succeed()\n output.log(`Dataset created successfully`)\n return newDataset\n } catch (error) {\n debug('Error creating dataset', {datasetName, error})\n throw error\n }\n}\n"],"names":["subdebug","spinner","createDataset","createDatasetService","determineDatasetAclMode","debug","options","datasetName","embeddings","embeddingsProjection","forcePublic","isUnattended","output","projectFeatures","projectId","visibility","canCreatePrivate","includes","aclMode","spin","start","newDataset","enabled","projection","undefined","succeed","log","error"],"mappings":"AAAA,SAAqBA,QAAQ,QAAO,mBAAkB;AACtD,SAAQC,OAAO,QAAO,sBAAqB;AAG3C,SAAQC,iBAAiBC,oBAAoB,QAAO,6BAA4B;AAChF,SAAQC,uBAAuB,QAAO,+BAA8B;AAEpE,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/dataset/create.ts"],"sourcesContent":["import {type Output, subdebug} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {type DatasetAclMode, DatasetResponse} from '@sanity/client'\n\nimport {createDataset as createDatasetService} from '../../services/datasets.js'\nimport {validateProjection} from '../../util/validateProjection.js'\nimport {determineDatasetAclMode} from './determineDatasetAclMode.js'\n\nconst debug = subdebug('dataset:create')\n\n/**\n * Options for creating a dataset\n */\ninterface CreateDatasetOptions {\n /**\n * Name of the dataset to create\n */\n datasetName: string\n\n /**\n * Output instance for logging\n */\n output: Output\n\n /**\n * Array of project features to determine capabilities\n * Used to check if private datasets are available\n */\n projectFeatures: string[]\n\n /**\n * Project ID where the dataset will be created\n */\n projectId: string\n\n /**\n * Whether to enable embeddings for the new dataset\n */\n embeddings?: boolean\n\n /**\n * GROQ projection for embeddings indexing (e.g. \"\\{ title, body \\}\")\n * Only used when embeddings is true\n */\n embeddingsProjection?: string\n\n /**\n * Whether to force disable private dataset creation\n * Used when default config is selected (which forces public datasets)\n */\n forcePublic?: boolean\n\n /**\n * Whether to run in unattended mode (no prompts)\n */\n isUnattended?: boolean\n\n /**\n * Requested visibility mode from flags/options\n */\n visibility?: string\n}\n\n/**\n * Creates a new dataset with the appropriate ACL mode.\n *\n * This action handles the business logic for:\n * - Determining the appropriate ACL mode based on project capabilities\n * - Creating the dataset via the service layer\n * - Handling errors and providing user feedback\n *\n * @param options - Configuration options\n * @returns Promise resolving when dataset is created\n * @throws Error if dataset creation fails\n */\nexport async function createDataset(options: CreateDatasetOptions): Promise<DatasetResponse> {\n const {\n datasetName,\n embeddings,\n embeddingsProjection,\n forcePublic = false,\n isUnattended = false,\n output,\n projectFeatures,\n projectId,\n visibility,\n } = options\n\n const canCreatePrivate = projectFeatures.includes('privateDataset') && !forcePublic\n\n // Determine the appropriate ACL mode\n const aclMode: DatasetAclMode = await determineDatasetAclMode({\n canCreatePrivate,\n isUnattended,\n output,\n visibility,\n })\n\n if (embeddingsProjection) {\n validateProjection(embeddingsProjection)\n }\n\n try {\n const spin = spinner('Creating dataset').start()\n const newDataset = await createDatasetService({\n aclMode,\n datasetName,\n embeddings: embeddings\n ? {enabled: true, ...(embeddingsProjection ? {projection: embeddingsProjection} : {})}\n : undefined,\n projectId,\n })\n spin.succeed()\n output.log(`Dataset created successfully`)\n return newDataset\n } catch (error) {\n debug('Error creating dataset', {datasetName, error})\n throw error\n }\n}\n"],"names":["subdebug","spinner","createDataset","createDatasetService","validateProjection","determineDatasetAclMode","debug","options","datasetName","embeddings","embeddingsProjection","forcePublic","isUnattended","output","projectFeatures","projectId","visibility","canCreatePrivate","includes","aclMode","spin","start","newDataset","enabled","projection","undefined","succeed","log","error"],"mappings":"AAAA,SAAqBA,QAAQ,QAAO,mBAAkB;AACtD,SAAQC,OAAO,QAAO,sBAAqB;AAG3C,SAAQC,iBAAiBC,oBAAoB,QAAO,6BAA4B;AAChF,SAAQC,kBAAkB,QAAO,mCAAkC;AACnE,SAAQC,uBAAuB,QAAO,+BAA8B;AAEpE,MAAMC,QAAQN,SAAS;AAuDvB;;;;;;;;;;;CAWC,GACD,OAAO,eAAeE,cAAcK,OAA6B;IAC/D,MAAM,EACJC,WAAW,EACXC,UAAU,EACVC,oBAAoB,EACpBC,cAAc,KAAK,EACnBC,eAAe,KAAK,EACpBC,MAAM,EACNC,eAAe,EACfC,SAAS,EACTC,UAAU,EACX,GAAGT;IAEJ,MAAMU,mBAAmBH,gBAAgBI,QAAQ,CAAC,qBAAqB,CAACP;IAExE,qCAAqC;IACrC,MAAMQ,UAA0B,MAAMd,wBAAwB;QAC5DY;QACAL;QACAC;QACAG;IACF;IAEA,IAAIN,sBAAsB;QACxBN,mBAAmBM;IACrB;IAEA,IAAI;QACF,MAAMU,OAAOnB,QAAQ,oBAAoBoB,KAAK;QAC9C,MAAMC,aAAa,MAAMnB,qBAAqB;YAC5CgB;YACAX;YACAC,YAAYA,aACR;gBAACc,SAAS;gBAAM,GAAIb,uBAAuB;oBAACc,YAAYd;gBAAoB,IAAI,CAAC,CAAC;YAAC,IACnFe;YACJV;QACF;QACAK,KAAKM,OAAO;QACZb,OAAOc,GAAG,CAAC,CAAC,4BAA4B,CAAC;QACzC,OAAOL;IACT,EAAE,OAAOM,OAAO;QACdtB,MAAM,0BAA0B;YAACE;YAAaoB;QAAK;QACnD,MAAMA;IACR;AACF"}
|
|
@@ -45,6 +45,7 @@ import { deployDebug } from './deployDebug.js';
|
|
|
45
45
|
});
|
|
46
46
|
// If no applications are found, return null
|
|
47
47
|
if (!userApplications?.length) {
|
|
48
|
+
spin.info('No application ID configured');
|
|
48
49
|
return null;
|
|
49
50
|
}
|
|
50
51
|
// No app ID configured, done checking for existing applications;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/findUserApplicationForApp.ts"],"sourcesContent":["/**\n * Helper functions to find a user application for a Sanity application.\n */\n\nimport {type CliConfig, type Output} from '@sanity/cli-core'\nimport {select, Separator, spinner} from '@sanity/cli-core/ux'\n\nimport {\n getUserApplication,\n getUserApplications,\n type UserApplication,\n} from '../../services/userApplications.js'\nimport {checkForDeprecatedAppId, getAppId} from '../../util/appId.js'\nimport {deployDebug} from './deployDebug.js'\n\ninterface FindUserApplicationForAppOptions {\n cliConfig: CliConfig\n organizationId: string\n output: Output\n}\n\n/**\n * Find a user application for a Sanity application.\n */\nexport async function findUserApplicationForApp(\n options: FindUserApplicationForAppOptions,\n): Promise<UserApplication | null> {\n const {cliConfig, organizationId, output} = options\n\n const spin = spinner('Checking application info...').start()\n\n try {\n checkForDeprecatedAppId({cliConfig, output})\n\n deployDebug('Checking for a user application as specified in the local app config')\n const userApplication = await findUserApplication(options)\n\n if (userApplication) {\n deployDebug('Found a user application as configured')\n spin.succeed()\n return userApplication\n }\n\n const appId = getAppId(cliConfig)\n\n // If there's an appId in the application config but there's no userApplication,\n // then the provided application ID doesn’t exist in the org\n if (appId) {\n spin.clear()\n output.error(\n 'The `appId` provided in your configuration’s `deployment` object cannot be found in your organization',\n {\n exit: 1,\n suggestions: ['Verify the appId in your configuration matches an existing application'],\n },\n )\n return null\n }\n\n // Done checking local application info\n // Update the spinner text to indicate the next operation\n spin.text = 'No application ID configured; checking for existing applications...'\n\n // Get a list of existing applications to select from.\n // This will fail if the org ID is malformed or the user doesn’t have access to the org ID\n const userApplications = await getUserApplications({\n appType: 'coreApp',\n organizationId,\n })\n\n // If no applications are found, return null\n if (!userApplications?.length) {\n return null\n }\n\n // No app ID configured, done checking for existing applications;\n // retain this spinner text for clarity\n spin.info('No application ID configured')\n\n // Enumerate the available applications\n const choices = userApplications.map((app) => ({\n name: app.title ?? app.appHost,\n value: app.appHost,\n }))\n\n // Ask the user to select an existing app or create a new one\n const selected = await select({\n choices: [\n {name: 'New application deployment', value: 'NEW_APP'},\n new Separator(' ════ Existing applications: ════ '),\n ...choices,\n ],\n loop: false,\n message:\n 'Would you like to create a new application deployment, or deploy to an existing one?',\n pageSize: 10,\n })\n\n // If the user wants to create a new deployed application, return null\n if (selected === 'NEW_APP') {\n return null\n }\n\n return userApplications.find((app) => app.appHost === selected)!\n } catch (error) {\n // User can't access applications for the org\n if (error?.statusCode === 403) {\n spin.clear()\n deployDebug(\n 'User does not have permission to get applications for the org, or the org ID is malformed/doesn’t exist',\n error,\n )\n output.error(\n `You don’t have permission to view applications for the configured organization ID (\"${organizationId}\")`,\n {\n exit: 1,\n suggestions: [\n 'Verify that you’ve entered the correct organization ID',\n 'Ask your Sanity organization’s admin to provide you with the proper permissions',\n ],\n },\n )\n return null\n }\n\n // We've failed for some other reason\n spin.clear()\n deployDebug('Error finding user application for app', error)\n output.error(error)\n return null\n }\n}\n\nfunction findUserApplication(\n options: FindUserApplicationForAppOptions,\n): Promise<UserApplication | null> | null {\n const {cliConfig} = options\n\n const appId = getAppId(cliConfig)\n\n if (!appId) {\n return null\n }\n\n return getUserApplication({appId, isSdkApp: true})\n}\n"],"names":["select","Separator","spinner","getUserApplication","getUserApplications","checkForDeprecatedAppId","getAppId","deployDebug","findUserApplicationForApp","options","cliConfig","organizationId","output","spin","start","userApplication","findUserApplication","succeed","appId","clear","error","exit","suggestions","text","userApplications","appType","length","info","choices","map","app","name","title","appHost","value","selected","loop","message","pageSize","find","statusCode","isSdkApp"],"mappings":"AAAA;;CAEC,GAGD,SAAQA,MAAM,EAAEC,SAAS,EAAEC,OAAO,QAAO,sBAAqB;AAE9D,SACEC,kBAAkB,EAClBC,mBAAmB,QAEd,qCAAoC;AAC3C,SAAQC,uBAAuB,EAAEC,QAAQ,QAAO,sBAAqB;AACrE,SAAQC,WAAW,QAAO,mBAAkB;AAQ5C;;CAEC,GACD,OAAO,eAAeC,0BACpBC,OAAyC;IAEzC,MAAM,EAACC,SAAS,EAAEC,cAAc,EAAEC,MAAM,EAAC,GAAGH;IAE5C,MAAMI,OAAOX,QAAQ,gCAAgCY,KAAK;IAE1D,IAAI;QACFT,wBAAwB;YAACK;YAAWE;QAAM;QAE1CL,YAAY;QACZ,MAAMQ,kBAAkB,MAAMC,oBAAoBP;QAElD,IAAIM,iBAAiB;YACnBR,YAAY;YACZM,KAAKI,OAAO;YACZ,OAAOF;QACT;QAEA,MAAMG,QAAQZ,SAASI;QAEvB,gFAAgF;QAChF,4DAA4D;QAC5D,IAAIQ,OAAO;YACTL,KAAKM,KAAK;YACVP,OAAOQ,KAAK,CACV,yGACA;gBACEC,MAAM;gBACNC,aAAa;oBAAC;iBAAyE;YACzF;YAEF,OAAO;QACT;QAEA,uCAAuC;QACvC,yDAAyD;QACzDT,KAAKU,IAAI,GAAG;QAEZ,sDAAsD;QACtD,0FAA0F;QAC1F,MAAMC,mBAAmB,MAAMpB,oBAAoB;YACjDqB,SAAS;YACTd;QACF;QAEA,4CAA4C;QAC5C,IAAI,CAACa,kBAAkBE,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/findUserApplicationForApp.ts"],"sourcesContent":["/**\n * Helper functions to find a user application for a Sanity application.\n */\n\nimport {type CliConfig, type Output} from '@sanity/cli-core'\nimport {select, Separator, spinner} from '@sanity/cli-core/ux'\n\nimport {\n getUserApplication,\n getUserApplications,\n type UserApplication,\n} from '../../services/userApplications.js'\nimport {checkForDeprecatedAppId, getAppId} from '../../util/appId.js'\nimport {deployDebug} from './deployDebug.js'\n\ninterface FindUserApplicationForAppOptions {\n cliConfig: CliConfig\n organizationId: string\n output: Output\n}\n\n/**\n * Find a user application for a Sanity application.\n */\nexport async function findUserApplicationForApp(\n options: FindUserApplicationForAppOptions,\n): Promise<UserApplication | null> {\n const {cliConfig, organizationId, output} = options\n\n const spin = spinner('Checking application info...').start()\n\n try {\n checkForDeprecatedAppId({cliConfig, output})\n\n deployDebug('Checking for a user application as specified in the local app config')\n const userApplication = await findUserApplication(options)\n\n if (userApplication) {\n deployDebug('Found a user application as configured')\n spin.succeed()\n return userApplication\n }\n\n const appId = getAppId(cliConfig)\n\n // If there's an appId in the application config but there's no userApplication,\n // then the provided application ID doesn’t exist in the org\n if (appId) {\n spin.clear()\n output.error(\n 'The `appId` provided in your configuration’s `deployment` object cannot be found in your organization',\n {\n exit: 1,\n suggestions: ['Verify the appId in your configuration matches an existing application'],\n },\n )\n return null\n }\n\n // Done checking local application info\n // Update the spinner text to indicate the next operation\n spin.text = 'No application ID configured; checking for existing applications...'\n\n // Get a list of existing applications to select from.\n // This will fail if the org ID is malformed or the user doesn’t have access to the org ID\n const userApplications = await getUserApplications({\n appType: 'coreApp',\n organizationId,\n })\n\n // If no applications are found, return null\n if (!userApplications?.length) {\n spin.info('No application ID configured')\n return null\n }\n\n // No app ID configured, done checking for existing applications;\n // retain this spinner text for clarity\n spin.info('No application ID configured')\n\n // Enumerate the available applications\n const choices = userApplications.map((app) => ({\n name: app.title ?? app.appHost,\n value: app.appHost,\n }))\n\n // Ask the user to select an existing app or create a new one\n const selected = await select({\n choices: [\n {name: 'New application deployment', value: 'NEW_APP'},\n new Separator(' ════ Existing applications: ════ '),\n ...choices,\n ],\n loop: false,\n message:\n 'Would you like to create a new application deployment, or deploy to an existing one?',\n pageSize: 10,\n })\n\n // If the user wants to create a new deployed application, return null\n if (selected === 'NEW_APP') {\n return null\n }\n\n return userApplications.find((app) => app.appHost === selected)!\n } catch (error) {\n // User can't access applications for the org\n if (error?.statusCode === 403) {\n spin.clear()\n deployDebug(\n 'User does not have permission to get applications for the org, or the org ID is malformed/doesn’t exist',\n error,\n )\n output.error(\n `You don’t have permission to view applications for the configured organization ID (\"${organizationId}\")`,\n {\n exit: 1,\n suggestions: [\n 'Verify that you’ve entered the correct organization ID',\n 'Ask your Sanity organization’s admin to provide you with the proper permissions',\n ],\n },\n )\n return null\n }\n\n // We've failed for some other reason\n spin.clear()\n deployDebug('Error finding user application for app', error)\n output.error(error)\n return null\n }\n}\n\nfunction findUserApplication(\n options: FindUserApplicationForAppOptions,\n): Promise<UserApplication | null> | null {\n const {cliConfig} = options\n\n const appId = getAppId(cliConfig)\n\n if (!appId) {\n return null\n }\n\n return getUserApplication({appId, isSdkApp: true})\n}\n"],"names":["select","Separator","spinner","getUserApplication","getUserApplications","checkForDeprecatedAppId","getAppId","deployDebug","findUserApplicationForApp","options","cliConfig","organizationId","output","spin","start","userApplication","findUserApplication","succeed","appId","clear","error","exit","suggestions","text","userApplications","appType","length","info","choices","map","app","name","title","appHost","value","selected","loop","message","pageSize","find","statusCode","isSdkApp"],"mappings":"AAAA;;CAEC,GAGD,SAAQA,MAAM,EAAEC,SAAS,EAAEC,OAAO,QAAO,sBAAqB;AAE9D,SACEC,kBAAkB,EAClBC,mBAAmB,QAEd,qCAAoC;AAC3C,SAAQC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ACE;YACFC,UAAU;QACZ;QAEA,sEAAsE;QACtE,IAAIH,aAAa,WAAW;YAC1B,OAAO;QACT;QAEA,OAAOX,iBAAiBe,IAAI,CAAC,CAACT,MAAQA,IAAIG,OAAO,KAAKE;IACxD,EAAE,OAAOf,OAAO;QACd,6CAA6C;QAC7C,IAAIA,OAAOoB,eAAe,KAAK;YAC7B3B,KAAKM,KAAK;YACVZ,YACE,2GACAa;YAEFR,OAAOQ,KAAK,CACV,CAAC,oFAAoF,EAAET,eAAe,EAAE,CAAC,EACzG;gBACEU,MAAM;gBACNC,aAAa;oBACX;oBACA;iBACD;YACH;YAEF,OAAO;QACT;QAEA,qCAAqC;QACrCT,KAAKM,KAAK;QACVZ,YAAY,0CAA0Ca;QACtDR,OAAOQ,KAAK,CAACA;QACb,OAAO;IACT;AACF;AAEA,SAASJ,oBACPP,OAAyC;IAEzC,MAAM,EAACC,SAAS,EAAC,GAAGD;IAEpB,MAAMS,QAAQZ,SAASI;IAEvB,IAAI,CAACQ,OAAO;QACV,OAAO;IACT;IAEA,OAAOf,mBAAmB;QAACe;QAAOuB,UAAU;IAAI;AAClD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/deploy/types.ts"],"sourcesContent":["import {type CliConfig, type Output, type ProjectRootResult} from '@sanity/cli-core'\nimport {z} from 'zod'\n\nimport {DeployCommand} from '../../commands/deploy.js'\n\nexport type DeployFlags = DeployCommand['flags']\n\nexport interface DeployAppOptions {\n cliConfig: CliConfig\n flags: DeployFlags\n output: Output\n projectRoot: ProjectRootResult\n sourceDir: string\n}\n\nexport const deployStudioSchemasAndManifestsWorkerData = z.object({\n configPath: z.string(),\n isExternal: z.boolean(),\n outPath: z.string(),\n projectId: z.string(),\n schemaRequired: z.boolean(),\n verbose: z.boolean(),\n workDir: z.string(),\n})\n\nexport type DeployStudioSchemasAndManifestsWorkerData = z.infer<\n typeof deployStudioSchemasAndManifestsWorkerData\n>\n"],"names":["z","deployStudioSchemasAndManifestsWorkerData","object","configPath","string","isExternal","boolean","outPath","projectId","schemaRequired","verbose","workDir"],"mappings":"AACA,SAAQA,CAAC,QAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deploy/types.ts"],"sourcesContent":["import {type CliConfig, type Output, type ProjectRootResult} from '@sanity/cli-core'\nimport {z} from 'zod/mini'\n\nimport {DeployCommand} from '../../commands/deploy.js'\n\nexport type DeployFlags = DeployCommand['flags']\n\nexport interface DeployAppOptions {\n cliConfig: CliConfig\n flags: DeployFlags\n output: Output\n projectRoot: ProjectRootResult\n sourceDir: string\n}\n\nexport const deployStudioSchemasAndManifestsWorkerData = z.object({\n configPath: z.string(),\n isExternal: z.boolean(),\n outPath: z.string(),\n projectId: z.string(),\n schemaRequired: z.boolean(),\n verbose: z.boolean(),\n workDir: z.string(),\n})\n\nexport type DeployStudioSchemasAndManifestsWorkerData = z.infer<\n typeof deployStudioSchemasAndManifestsWorkerData\n>\n"],"names":["z","deployStudioSchemasAndManifestsWorkerData","object","configPath","string","isExternal","boolean","outPath","projectId","schemaRequired","verbose","workDir"],"mappings":"AACA,SAAQA,CAAC,QAAO,WAAU;AAc1B,OAAO,MAAMC,4CAA4CD,EAAEE,MAAM,CAAC;IAChEC,YAAYH,EAAEI,MAAM;IACpBC,YAAYL,EAAEM,OAAO;IACrBC,SAASP,EAAEI,MAAM;IACjBI,WAAWR,EAAEI,MAAM;IACnBK,gBAAgBT,EAAEM,OAAO;IACzBI,SAASV,EAAEM,OAAO;IAClBK,SAASX,EAAEI,MAAM;AACnB,GAAE"}
|
|
@@ -11,6 +11,7 @@ import { createCliConfig } from './createCliConfig.js';
|
|
|
11
11
|
import { createPackageManifest } from './createPackageManifest.js';
|
|
12
12
|
import { createStudioConfig } from './createStudioConfig.js';
|
|
13
13
|
import { determineAppTemplate } from './determineAppTemplate.js';
|
|
14
|
+
import { processTemplate } from './processTemplate.js';
|
|
14
15
|
import { sdkAppDependencies } from './sdkAppDependencies.js';
|
|
15
16
|
import { studioDependencies } from './studioDependencies.js';
|
|
16
17
|
import templates from './templates/index.js';
|
|
@@ -44,6 +45,18 @@ export async function bootstrapLocalTemplate(opts) {
|
|
|
44
45
|
await fs.copyFile(path.join(sharedDir, 'tsconfig.json'), path.join(outputPath, 'tsconfig.json'));
|
|
45
46
|
}
|
|
46
47
|
spin.succeed();
|
|
48
|
+
if (isAppTemplate) {
|
|
49
|
+
const appEntryPath = path.join(outputPath, 'src', 'App.tsx');
|
|
50
|
+
const raw = await fs.readFile(appEntryPath, 'utf8');
|
|
51
|
+
const rendered = processTemplate({
|
|
52
|
+
template: raw,
|
|
53
|
+
variables: {
|
|
54
|
+
dataset: variables.dataset ?? '',
|
|
55
|
+
projectId: variables.projectId ?? ''
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
await fs.writeFile(appEntryPath, rendered);
|
|
59
|
+
}
|
|
47
60
|
// Merge global and template-specific plugins and dependencies
|
|
48
61
|
// Resolve latest versions of Sanity-dependencies
|
|
49
62
|
spin = spinner('Resolving latest module versions').start();
|
|
@@ -108,7 +121,9 @@ export async function bootstrapLocalTemplate(opts) {
|
|
|
108
121
|
writeFileIfNotExists('eslint.config.mjs', `import studio from '@sanity/eslint-config-studio'\n\nexport default [...studio]\n`)
|
|
109
122
|
].filter(Boolean));
|
|
110
123
|
debug('Updating initial template metadata');
|
|
111
|
-
|
|
124
|
+
if (variables.projectId) {
|
|
125
|
+
await updateInitialTemplateMetadata(variables.projectId, `cli-${templateName}`);
|
|
126
|
+
}
|
|
112
127
|
// Finish up by providing init process with template-specific info
|
|
113
128
|
spin.succeed();
|
|
114
129
|
return template;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/init/bootstrapLocalTemplate.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Output, subdebug} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport deburr from 'lodash-es/deburr.js'\n\nimport {copy} from '../../util/copy.js'\nimport {resolveLatestVersions} from '../../util/resolveLatestVersions.js'\nimport {createAppCliConfig} from './createAppCliConfig.js'\nimport {createCliConfig} from './createCliConfig.js'\nimport {createPackageManifest} from './createPackageManifest.js'\nimport {createStudioConfig, type GenerateConfigOptions} from './createStudioConfig.js'\nimport {determineAppTemplate} from './determineAppTemplate.js'\nimport {sdkAppDependencies} from './sdkAppDependencies.js'\nimport {studioDependencies} from './studioDependencies.js'\nimport templates from './templates/index.js'\nimport {type ProjectTemplate} from './types.js'\nimport {updateInitialTemplateMetadata} from './updateInitialTemplateMetadata.js'\n\nconst debug = subdebug('init:bootstrapRemoteTemplate')\n\ninterface BootstrapLocalOptions {\n output: Output\n outputPath: string\n packageName: string\n templateName: string\n useTypeScript: boolean\n variables: GenerateConfigOptions['variables']\n\n overwriteFiles?: boolean\n}\n\nexport async function bootstrapLocalTemplate(\n opts: BootstrapLocalOptions,\n): Promise<ProjectTemplate> {\n const {output, outputPath, packageName, templateName, useTypeScript, variables} = opts\n // packages/@sanity/cli/src/actions/init/ -> packages/@sanity/cli/src/action -> packages/@sanity/cli/src/\n const cliRoot = path.resolve(import.meta.dirname, '../../..')\n const templatesDir = path.join(cliRoot, 'templates')\n const sourceDir = path.join(templatesDir, templateName)\n const sharedDir = path.join(templatesDir, 'shared')\n const isAppTemplate = determineAppTemplate(templateName)\n\n // Check that we have a template info file (dependencies, plugins etc)\n const template = templates[templateName]\n if (!template) {\n throw new Error(`Template \"${templateName}\" not defined`)\n }\n\n // Copy template files\n debug('Copying files from template \"%s\" to \"%s\"', templateName, outputPath)\n let spin = spinner('Bootstrapping files from template').start()\n\n debug(`Copying template from : ${sourceDir}`)\n await copy(sourceDir, outputPath, {\n rename: useTypeScript ? toTypeScriptPath : undefined,\n })\n debug(`Copying shared template code from : ${sharedDir}`)\n await copy(path.join(sharedDir, 'gitignore.txt'), outputPath, {rename: () => '.gitignore'})\n\n if (useTypeScript) {\n await fs.copyFile(path.join(sharedDir, 'tsconfig.json'), path.join(outputPath, 'tsconfig.json'))\n }\n\n spin.succeed()\n\n // Merge global and template-specific plugins and dependencies\n\n // Resolve latest versions of Sanity-dependencies\n spin = spinner('Resolving latest module versions').start()\n const dependencyVersions = await resolveLatestVersions({\n ...(isAppTemplate ? sdkAppDependencies.dependencies : studioDependencies.dependencies),\n ...(isAppTemplate ? sdkAppDependencies.devDependencies : studioDependencies.devDependencies),\n ...template.dependencies,\n ...template.devDependencies,\n })\n spin.succeed()\n\n // Use the resolved version for the given dependency\n const dependencies: Record<string, string> = {}\n for (const dependency of Object.keys({\n ...(isAppTemplate ? sdkAppDependencies.dependencies : studioDependencies.dependencies),\n ...template.dependencies,\n })) {\n dependencies[dependency] = dependencyVersions[dependency]\n }\n\n const devDependencies: Record<string, string> = {}\n for (const dependency of Object.keys({\n ...(isAppTemplate ? sdkAppDependencies.devDependencies : studioDependencies.devDependencies),\n ...template.devDependencies,\n })) {\n devDependencies[dependency] = dependencyVersions[dependency]\n }\n\n let packageJsonName: string = packageName\n\n /**\n * Currently app init doesn't ask for a name, so we use the last part of the path\n */\n if (isAppTemplate) {\n packageJsonName = deburr(path.basename(outputPath).toLowerCase())\n .replaceAll(/\\s+/g, '-')\n .replaceAll(/[^a-z0-9-]/g, '')\n }\n\n // Now create a package manifest (`package.json`) with the merged dependencies\n spin = spinner('Creating default project files').start()\n const packageManifest = createPackageManifest({\n dependencies,\n devDependencies,\n isAppTemplate,\n name: packageJsonName,\n scripts: template.scripts,\n type: template.type,\n })\n\n // ...and a studio config (`sanity.config.[ts|js]`)\n const studioConfig = createStudioConfig({\n template: template.configTemplate,\n variables,\n })\n\n // ...and a CLI config (`sanity.cli.[ts|js]`)\n const cliConfig = isAppTemplate\n ? createAppCliConfig({\n entry: template.entry!,\n organizationId: variables.organizationId,\n })\n : createCliConfig({\n autoUpdates: variables.autoUpdates,\n dataset: variables.dataset,\n projectId: variables.projectId,\n })\n\n // Write non-template files to disc\n const codeExt = useTypeScript ? 'ts' : 'js'\n await Promise.all(\n [\n isAppTemplate\n ? Promise.resolve(null)\n : writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig),\n writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig),\n writeFileIfNotExists('package.json', packageManifest),\n\n writeFileIfNotExists(\n 'eslint.config.mjs',\n `import studio from '@sanity/eslint-config-studio'\\n\\nexport default [...studio]\\n`,\n ),\n ].filter(Boolean),\n )\n\n debug('Updating initial template metadata')\n await updateInitialTemplateMetadata(variables.projectId, `cli-${templateName}`)\n\n // Finish up by providing init process with template-specific info\n spin.succeed()\n return template\n\n async function writeFileIfNotExists(fileName: string, content: string): Promise<void> {\n const filePath = path.join(outputPath, fileName)\n\n if (opts.overwriteFiles) {\n // If overwrite is enabled, just write the file\n await fs.writeFile(filePath, content)\n return\n }\n\n try {\n await fs.writeFile(filePath, content, {flag: 'wx'})\n } catch (err) {\n if (err.code === 'EEXIST') {\n output.warn(`\\n${styleText('yellow', '⚠')} File \"${filePath}\" already exists, skipping`)\n } else {\n throw err\n }\n }\n }\n}\n\nfunction toTypeScriptPath(originalPath: string): string {\n return originalPath.replace(/\\.js$/, '.ts')\n}\n"],"names":["fs","path","styleText","subdebug","spinner","deburr","copy","resolveLatestVersions","createAppCliConfig","createCliConfig","createPackageManifest","createStudioConfig","determineAppTemplate","sdkAppDependencies","studioDependencies","templates","updateInitialTemplateMetadata","debug","bootstrapLocalTemplate","opts","output","outputPath","packageName","templateName","useTypeScript","variables","cliRoot","resolve","dirname","templatesDir","join","sourceDir","sharedDir","isAppTemplate","template","Error","spin","start","rename","toTypeScriptPath","undefined","copyFile","succeed","dependencyVersions","dependencies","devDependencies","dependency","Object","keys","packageJsonName","basename","toLowerCase","replaceAll","packageManifest","name","scripts","type","studioConfig","configTemplate","cliConfig","entry","organizationId","autoUpdates","dataset","projectId","codeExt","Promise","all","writeFileIfNotExists","filter","Boolean","fileName","content","filePath","overwriteFiles","writeFile","flag","err","code","warn","originalPath","repl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IAAIpD,KAAKuD,cAAc,EAAE;YACvB,+CAA+C;YAC/C,MAAM1E,GAAG2E,SAAS,CAACF,UAAUD;YAC7B;QACF;QAEA,IAAI;YACF,MAAMxE,GAAG2E,SAAS,CAACF,UAAUD,SAAS;gBAACI,MAAM;YAAI;QACnD,EAAE,OAAOC,KAAK;YACZ,IAAIA,IAAIC,IAAI,KAAK,UAAU;gBACzB1D,OAAO2D,IAAI,CAAC,CAAC,EAAE,EAAE7E,UAAU,UAAU,KAAK,OAAO,EAAEuE,SAAS,0BAA0B,CAAC;YACzF,OAAO;gBACL,MAAMI;YACR;QACF;IACF;AACF;AAEA,SAAStC,iBAAiByC,YAAoB;IAC5C,OAAOA,aAAaC,OAAO,CAAC,SAAS;AACvC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/bootstrapLocalTemplate.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\nimport {styleText} from 'node:util'\n\nimport {Output, subdebug} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport deburr from 'lodash-es/deburr.js'\n\nimport {copy} from '../../util/copy.js'\nimport {resolveLatestVersions} from '../../util/resolveLatestVersions.js'\nimport {createAppCliConfig} from './createAppCliConfig.js'\nimport {createCliConfig} from './createCliConfig.js'\nimport {createPackageManifest} from './createPackageManifest.js'\nimport {createStudioConfig, type GenerateConfigOptions} from './createStudioConfig.js'\nimport {determineAppTemplate} from './determineAppTemplate.js'\nimport {processTemplate} from './processTemplate.js'\nimport {sdkAppDependencies} from './sdkAppDependencies.js'\nimport {studioDependencies} from './studioDependencies.js'\nimport templates from './templates/index.js'\nimport {type ProjectTemplate} from './types.js'\nimport {updateInitialTemplateMetadata} from './updateInitialTemplateMetadata.js'\n\nconst debug = subdebug('init:bootstrapRemoteTemplate')\n\ninterface BootstrapLocalOptions {\n output: Output\n outputPath: string\n packageName: string\n templateName: string\n useTypeScript: boolean\n variables: GenerateConfigOptions['variables']\n\n overwriteFiles?: boolean\n}\n\nexport async function bootstrapLocalTemplate(\n opts: BootstrapLocalOptions,\n): Promise<ProjectTemplate> {\n const {output, outputPath, packageName, templateName, useTypeScript, variables} = opts\n // packages/@sanity/cli/src/actions/init/ -> packages/@sanity/cli/src/action -> packages/@sanity/cli/src/\n const cliRoot = path.resolve(import.meta.dirname, '../../..')\n const templatesDir = path.join(cliRoot, 'templates')\n const sourceDir = path.join(templatesDir, templateName)\n const sharedDir = path.join(templatesDir, 'shared')\n const isAppTemplate = determineAppTemplate(templateName)\n\n // Check that we have a template info file (dependencies, plugins etc)\n const template = templates[templateName]\n if (!template) {\n throw new Error(`Template \"${templateName}\" not defined`)\n }\n\n // Copy template files\n debug('Copying files from template \"%s\" to \"%s\"', templateName, outputPath)\n let spin = spinner('Bootstrapping files from template').start()\n\n debug(`Copying template from : ${sourceDir}`)\n await copy(sourceDir, outputPath, {\n rename: useTypeScript ? toTypeScriptPath : undefined,\n })\n debug(`Copying shared template code from : ${sharedDir}`)\n await copy(path.join(sharedDir, 'gitignore.txt'), outputPath, {rename: () => '.gitignore'})\n\n if (useTypeScript) {\n await fs.copyFile(path.join(sharedDir, 'tsconfig.json'), path.join(outputPath, 'tsconfig.json'))\n }\n\n spin.succeed()\n\n if (isAppTemplate) {\n const appEntryPath = path.join(outputPath, 'src', 'App.tsx')\n const raw = await fs.readFile(appEntryPath, 'utf8')\n const rendered = processTemplate({\n template: raw,\n variables: {\n dataset: variables.dataset ?? '',\n projectId: variables.projectId ?? '',\n },\n })\n await fs.writeFile(appEntryPath, rendered)\n }\n\n // Merge global and template-specific plugins and dependencies\n\n // Resolve latest versions of Sanity-dependencies\n spin = spinner('Resolving latest module versions').start()\n const dependencyVersions = await resolveLatestVersions({\n ...(isAppTemplate ? sdkAppDependencies.dependencies : studioDependencies.dependencies),\n ...(isAppTemplate ? sdkAppDependencies.devDependencies : studioDependencies.devDependencies),\n ...template.dependencies,\n ...template.devDependencies,\n })\n spin.succeed()\n\n // Use the resolved version for the given dependency\n const dependencies: Record<string, string> = {}\n for (const dependency of Object.keys({\n ...(isAppTemplate ? sdkAppDependencies.dependencies : studioDependencies.dependencies),\n ...template.dependencies,\n })) {\n dependencies[dependency] = dependencyVersions[dependency]\n }\n\n const devDependencies: Record<string, string> = {}\n for (const dependency of Object.keys({\n ...(isAppTemplate ? sdkAppDependencies.devDependencies : studioDependencies.devDependencies),\n ...template.devDependencies,\n })) {\n devDependencies[dependency] = dependencyVersions[dependency]\n }\n\n let packageJsonName: string = packageName\n\n /**\n * Currently app init doesn't ask for a name, so we use the last part of the path\n */\n if (isAppTemplate) {\n packageJsonName = deburr(path.basename(outputPath).toLowerCase())\n .replaceAll(/\\s+/g, '-')\n .replaceAll(/[^a-z0-9-]/g, '')\n }\n\n // Now create a package manifest (`package.json`) with the merged dependencies\n spin = spinner('Creating default project files').start()\n const packageManifest = createPackageManifest({\n dependencies,\n devDependencies,\n isAppTemplate,\n name: packageJsonName,\n scripts: template.scripts,\n type: template.type,\n })\n\n // ...and a studio config (`sanity.config.[ts|js]`)\n const studioConfig = createStudioConfig({\n template: template.configTemplate,\n variables,\n })\n\n // ...and a CLI config (`sanity.cli.[ts|js]`)\n const cliConfig = isAppTemplate\n ? createAppCliConfig({\n entry: template.entry!,\n organizationId: variables.organizationId,\n })\n : createCliConfig({\n autoUpdates: variables.autoUpdates,\n dataset: variables.dataset,\n projectId: variables.projectId,\n })\n\n // Write non-template files to disc\n const codeExt = useTypeScript ? 'ts' : 'js'\n await Promise.all(\n [\n isAppTemplate\n ? Promise.resolve(null)\n : writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig),\n writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig),\n writeFileIfNotExists('package.json', packageManifest),\n\n writeFileIfNotExists(\n 'eslint.config.mjs',\n `import studio from '@sanity/eslint-config-studio'\\n\\nexport default [...studio]\\n`,\n ),\n ].filter(Boolean),\n )\n\n debug('Updating initial template metadata')\n if (variables.projectId) {\n await updateInitialTemplateMetadata(variables.projectId, `cli-${templateName}`)\n }\n\n // Finish up by providing init process with template-specific info\n spin.succeed()\n return template\n\n async function writeFileIfNotExists(fileName: string, content: string): Promise<void> {\n const filePath = path.join(outputPath, fileName)\n\n if (opts.overwriteFiles) {\n // If overwrite is enabled, just write the file\n await fs.writeFile(filePath, content)\n return\n }\n\n try {\n await fs.writeFile(filePath, content, {flag: 'wx'})\n } catch (err) {\n if (err.code === 'EEXIST') {\n output.warn(`\\n${styleText('yellow', '⚠')} File \"${filePath}\" already exists, skipping`)\n } else {\n throw err\n }\n }\n }\n}\n\nfunction toTypeScriptPath(originalPath: string): string {\n return originalPath.replace(/\\.js$/, '.ts')\n}\n"],"names":["fs","path","styleText","subdebug","spinner","deburr","copy","resolveLatestVersions","createAppCliConfig","createCliConfig","createPackageManifest","createStudioConfig","determineAppTemplate","processTemplate","sdkAppDependencies","studioDependencies","templates","updateInitialTemplateMetadata","debug","bootstrapLocalTemplate","opts","output","outputPath","packageName","templateName","useTypeScript","variables","cliRoot","resolve","dirname","templatesDir","join","sourceDir","sharedDir","isAppTemplate","template","Error","spin","start","rename","toTypeScriptPath","undefined","copyFile","succeed","appEntryPath","raw","readFile","rendered","dataset","projectId","writeFile","dependencyVersions","dependencies","devDependencies","dependency","Object","keys","packageJsonName","basename","toLowerCase","replaceAll","packageManifest","name","scripts","type","studioConfig","configTemplate","cliConfig","entry","organizationId","autoUpdates","codeExt","Promise","all","writeFileIfNotExists","filter","Boolean","fileName","content","filePath","overwriteFiles","flag","err","code","warn","originalPath","replace"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAC5B,SAAQC,SAAS,QAAO,YAAW;AAEnC,SAAgBC,QAAQ,QAAO,mBAAkB;AACjD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,OAAOC,YAAY,sBAAqB;AAExC,SAAQC,IAAI,QAAO,qBAAoB;AACvC,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,kBAAkB,QAAO,0B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KAAKM,OAAO;IACZ,OAAOR;IAEP,eAAeuC,qBAAqBG,QAAgB,EAAEC,OAAe;QACnE,MAAMC,WAAW9E,KAAK8B,IAAI,CAACT,YAAYuD;QAEvC,IAAIzD,KAAK4D,cAAc,EAAE;YACvB,+CAA+C;YAC/C,MAAMhF,GAAGkD,SAAS,CAAC6B,UAAUD;YAC7B;QACF;QAEA,IAAI;YACF,MAAM9E,GAAGkD,SAAS,CAAC6B,UAAUD,SAAS;gBAACG,MAAM;YAAI;QACnD,EAAE,OAAOC,KAAK;YACZ,IAAIA,IAAIC,IAAI,KAAK,UAAU;gBACzB9D,OAAO+D,IAAI,CAAC,CAAC,EAAE,EAAElF,UAAU,UAAU,KAAK,OAAO,EAAE6E,SAAS,0BAA0B,CAAC;YACzF,OAAO;gBACL,MAAMG;YACR;QACF;IACF;AACF;AAEA,SAAS1C,iBAAiB6C,YAAoB;IAC5C,OAAOA,aAAaC,OAAO,CAAC,SAAS;AACvC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { logSymbols } from '@sanity/cli-core/ux';
|
|
3
|
+
import { getPostInitMCPPrompt } from './initHelpers.js';
|
|
4
|
+
import { scaffoldAndInstall, selectTemplate } from './scaffoldTemplate.js';
|
|
5
|
+
export async function initApp({ autoUpdates, datasetName, defaults, error, git, mcpConfigured, noGit, organizationId, output, outputPath, overwriteFiles, packageManager, projectId, remoteTemplateInfo, sluggedName, template, templateToken, trace, typescript, unattended, workDir }) {
|
|
6
|
+
const { template: resolvedTemplate, templateName, useTypeScript } = await selectTemplate({
|
|
7
|
+
remoteTemplateInfo,
|
|
8
|
+
template,
|
|
9
|
+
trace,
|
|
10
|
+
typescript,
|
|
11
|
+
unattended
|
|
12
|
+
});
|
|
13
|
+
if (!remoteTemplateInfo && !resolvedTemplate) {
|
|
14
|
+
error(`Template "${templateName}" not found`, {
|
|
15
|
+
exit: 1
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
await scaffoldAndInstall({
|
|
19
|
+
autoUpdates,
|
|
20
|
+
datasetName,
|
|
21
|
+
defaults,
|
|
22
|
+
displayName: '',
|
|
23
|
+
git,
|
|
24
|
+
noGit,
|
|
25
|
+
organizationId,
|
|
26
|
+
output,
|
|
27
|
+
outputPath,
|
|
28
|
+
overwriteFiles,
|
|
29
|
+
packageManager,
|
|
30
|
+
projectId,
|
|
31
|
+
remoteTemplateInfo,
|
|
32
|
+
sluggedName,
|
|
33
|
+
templateName,
|
|
34
|
+
templateToken,
|
|
35
|
+
trace,
|
|
36
|
+
unattended,
|
|
37
|
+
useTypeScript,
|
|
38
|
+
workDir
|
|
39
|
+
});
|
|
40
|
+
const isCurrentDir = outputPath === process.cwd();
|
|
41
|
+
const goToProjectDir = `\n(${styleText('cyan', `cd ${outputPath}`)} to navigate to your new project directory)`;
|
|
42
|
+
//output for custom apps here
|
|
43
|
+
output.log(`${logSymbols.success} ${styleText([
|
|
44
|
+
'green',
|
|
45
|
+
'bold'
|
|
46
|
+
], 'Success!')} Your custom app has been scaffolded.`);
|
|
47
|
+
if (!isCurrentDir) output.log(goToProjectDir);
|
|
48
|
+
if (projectId && datasetName) {
|
|
49
|
+
output.log(`\nConfigured with project ${styleText('cyan', projectId)} and dataset ${styleText('cyan', datasetName)}.`);
|
|
50
|
+
output.log('Edit `src/App.tsx` to change these values or add more project / dataset pairs to your config.');
|
|
51
|
+
} else {
|
|
52
|
+
output.log(`\n${styleText('bold', 'Next')}, configure the project(s) and dataset(s) your app should work with in \`src/App.tsx\`.`);
|
|
53
|
+
}
|
|
54
|
+
output.log('\nRefer to our documentation for a walkthrough:');
|
|
55
|
+
output.log(styleText([
|
|
56
|
+
'blue',
|
|
57
|
+
'underline'
|
|
58
|
+
], 'https://www.sanity.io/docs/app-sdk/sdk-configuration'));
|
|
59
|
+
if (mcpConfigured && mcpConfigured.length > 0) {
|
|
60
|
+
const message = await getPostInitMCPPrompt(mcpConfigured);
|
|
61
|
+
output.log(`\n${message}`);
|
|
62
|
+
output.log(`\nLearn more: ${styleText('cyan', 'https://mcp.sanity.io')}`);
|
|
63
|
+
output.log(`\nHave feedback? Tell us in the community: ${styleText('cyan', 'https://www.sanity.io/community/join')}`);
|
|
64
|
+
}
|
|
65
|
+
output.log('\n');
|
|
66
|
+
output.log(`Other helpful commands:`);
|
|
67
|
+
output.log(`npx sanity docs browse to open the documentation in a browser`);
|
|
68
|
+
output.log(`npx sanity dev to start the development server for your app`);
|
|
69
|
+
output.log(`npx sanity deploy to deploy your app`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=initApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/initApp.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type Output, type TelemetryUserProperties} from '@sanity/cli-core'\nimport {logSymbols} from '@sanity/cli-core/ux'\nimport {type TelemetryTrace} from '@sanity/telemetry'\n\nimport {type InitStepResult} from '../../telemetry/init.telemetry.js'\nimport {type EditorName} from '../mcp/editorConfigs.js'\nimport {getPostInitMCPPrompt} from './initHelpers.js'\nimport {type RepoInfo} from './remoteTemplate.js'\nimport {scaffoldAndInstall, selectTemplate} from './scaffoldTemplate.js'\n\nexport async function initApp({\n autoUpdates,\n datasetName,\n defaults,\n error,\n git,\n mcpConfigured,\n noGit,\n organizationId,\n output,\n outputPath,\n overwriteFiles,\n packageManager,\n projectId,\n remoteTemplateInfo,\n sluggedName,\n template,\n templateToken,\n trace,\n typescript,\n unattended,\n workDir,\n}: {\n autoUpdates: boolean\n datasetName: string\n defaults: {projectName: string}\n error: Output['error']\n git?: boolean | string\n mcpConfigured: EditorName[]\n noGit?: boolean\n organizationId: string | undefined\n output: Output\n outputPath: string\n overwriteFiles?: boolean\n packageManager?: string\n projectId: string\n remoteTemplateInfo: RepoInfo | undefined\n sluggedName: string\n template?: string\n templateToken?: string\n trace: TelemetryTrace<TelemetryUserProperties, InitStepResult>\n typescript?: boolean\n unattended: boolean\n workDir: string\n}): Promise<void> {\n const {\n template: resolvedTemplate,\n templateName,\n useTypeScript,\n } = await selectTemplate({\n remoteTemplateInfo,\n template,\n trace,\n typescript,\n unattended,\n })\n\n if (!remoteTemplateInfo && !resolvedTemplate) {\n error(`Template \"${templateName}\" not found`, {exit: 1})\n }\n\n await scaffoldAndInstall({\n autoUpdates,\n datasetName,\n defaults,\n displayName: '',\n git,\n noGit,\n organizationId,\n output,\n outputPath,\n overwriteFiles,\n packageManager,\n projectId,\n remoteTemplateInfo,\n sluggedName,\n templateName,\n templateToken,\n trace,\n unattended,\n useTypeScript,\n workDir,\n })\n\n const isCurrentDir = outputPath === process.cwd()\n const goToProjectDir = `\\n(${styleText('cyan', `cd ${outputPath}`)} to navigate to your new project directory)`\n\n //output for custom apps here\n output.log(\n `${logSymbols.success} ${styleText(['green', 'bold'], 'Success!')} Your custom app has been scaffolded.`,\n )\n if (!isCurrentDir) output.log(goToProjectDir)\n\n if (projectId && datasetName) {\n output.log(\n `\\nConfigured with project ${styleText('cyan', projectId)} and dataset ${styleText('cyan', datasetName)}.`,\n )\n output.log(\n 'Edit `src/App.tsx` to change these values or add more project / dataset pairs to your config.',\n )\n } else {\n output.log(\n `\\n${styleText('bold', 'Next')}, configure the project(s) and dataset(s) your app should work with in \\`src/App.tsx\\`.`,\n )\n }\n output.log('\\nRefer to our documentation for a walkthrough:')\n output.log(\n styleText(['blue', 'underline'], 'https://www.sanity.io/docs/app-sdk/sdk-configuration'),\n )\n if (mcpConfigured && mcpConfigured.length > 0) {\n const message = await getPostInitMCPPrompt(mcpConfigured)\n output.log(`\\n${message}`)\n output.log(`\\nLearn more: ${styleText('cyan', 'https://mcp.sanity.io')}`)\n output.log(\n `\\nHave feedback? Tell us in the community: ${styleText('cyan', 'https://www.sanity.io/community/join')}`,\n )\n }\n output.log('\\n')\n output.log(`Other helpful commands:`)\n output.log(`npx sanity docs browse to open the documentation in a browser`)\n output.log(`npx sanity dev to start the development server for your app`)\n output.log(`npx sanity deploy to deploy your app`)\n}\n"],"names":["styleText","logSymbols","getPostInitMCPPrompt","scaffoldAndInstall","selectTemplate","initApp","autoUpdates","datasetName","defaults","error","git","mcpConfigured","noGit","organizationId","output","outputPath","overwriteFiles","packageManager","projectId","remoteTemplateInfo","sluggedName","template","templateToken","trace","typescript","unattended","workDir","resolvedTemplate","templateName","useTypeScript","exit","displayName","isCurrentDir","process","cwd","goToProjectDir","log","success","length","message"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAGnC,SAAQC,UAAU,QAAO,sBAAqB;AAK9C,SAAQC,oBAAoB,QAAO,mBAAkB;AAErD,SAAQC,kBAAkB,EAAEC,cAAc,QAAO,wBAAuB;AAExE,OAAO,eAAeC,QAAQ,EAC5BC,WAAW,EACXC,WAAW,EACXC,QAAQ,EACRC,KAAK,EACLC,GAAG,EACHC,aAAa,EACbC,KAAK,EACLC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,cAAc,EACdC,cAAc,EACdC,SAAS,EACTC,kBAAkB,EAClBC,WAAW,EACXC,QAAQ,EACRC,aAAa,EACbC,KAAK,EACLC,UAAU,EACVC,UAAU,EACVC,OAAO,EAuBR;IACC,MAAM,EACJL,UAAUM,gBAAgB,EAC1BC,YAAY,EACZC,aAAa,EACd,GAAG,MAAMzB,eAAe;QACvBe;QACAE;QACAE;QACAC;QACAC;IACF;IAEA,IAAI,CAACN,sBAAsB,CAACQ,kBAAkB;QAC5ClB,MAAM,CAAC,UAAU,EAAEmB,aAAa,WAAW,CAAC,EAAE;YAACE,MAAM;QAAC;IACxD;IAEA,MAAM3B,mBAAmB;QACvBG;QACAC;QACAC;QACAuB,aAAa;QACbrB;QACAE;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAN;QACAC;QACAE;QACAI;QACAH;IACF;IAEA,MAAMM,eAAejB,eAAekB,QAAQC,GAAG;IAC/C,MAAMC,iBAAiB,CAAC,GAAG,EAAEnC,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env/createOrAppendEnvVars.js';
|
|
3
|
+
import { fetchPostInitPrompt } from './fetchPostInitPrompt.js';
|
|
4
|
+
/**
|
|
5
|
+
* Returns `true` when the user should be prompted for a flag value:
|
|
6
|
+
* i.e. we are NOT in unattended mode AND the flag was not explicitly provided.
|
|
7
|
+
*/ export function shouldPrompt(unattended, flagValue) {
|
|
8
|
+
return !unattended && flagValue === undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns the flag value if it is a boolean, otherwise returns the default.
|
|
12
|
+
*/ export function flagOrDefault(flagValue, defaultValue) {
|
|
13
|
+
return typeof flagValue === 'boolean' ? flagValue : defaultValue;
|
|
14
|
+
}
|
|
15
|
+
export async function getPostInitMCPPrompt(editorsNames) {
|
|
16
|
+
return fetchPostInitPrompt(new Intl.ListFormat('en').format(editorsNames));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* When running in a non-production Sanity environment (e.g. staging), write the
|
|
20
|
+
* `SANITY_INTERNAL_ENV` variable to a `.env` file in the output directory so that
|
|
21
|
+
* the bootstrapped project continues to target the same environment.
|
|
22
|
+
*/ export async function writeStagingEnvIfNeeded(output, outputPath) {
|
|
23
|
+
const sanityEnv = getSanityEnv();
|
|
24
|
+
if (sanityEnv === 'production') return;
|
|
25
|
+
await createOrAppendEnvVars({
|
|
26
|
+
envVars: {
|
|
27
|
+
INTERNAL_ENV: sanityEnv
|
|
28
|
+
},
|
|
29
|
+
filename: '.env',
|
|
30
|
+
framework: null,
|
|
31
|
+
log: false,
|
|
32
|
+
output,
|
|
33
|
+
outputPath
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=initHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/initHelpers.ts"],"sourcesContent":["import {type Output} from '@sanity/cli-core'\n\nimport {getSanityEnv} from '../../util/getSanityEnv.js'\nimport {type EditorName} from '../mcp/editorConfigs.js'\nimport {createOrAppendEnvVars} from './env/createOrAppendEnvVars.js'\nimport {fetchPostInitPrompt} from './fetchPostInitPrompt.js'\n\n/**\n * Returns `true` when the user should be prompted for a flag value:\n * i.e. we are NOT in unattended mode AND the flag was not explicitly provided.\n */\nexport function shouldPrompt(unattended: boolean, flagValue: unknown): boolean {\n return !unattended && flagValue === undefined\n}\n\n/**\n * Returns the flag value if it is a boolean, otherwise returns the default.\n */\nexport function flagOrDefault(flagValue: boolean | undefined, defaultValue: boolean): boolean {\n return typeof flagValue === 'boolean' ? flagValue : defaultValue\n}\n\nexport async function getPostInitMCPPrompt(editorsNames: EditorName[]): Promise<string> {\n return fetchPostInitPrompt(new Intl.ListFormat('en').format(editorsNames))\n}\n\n/**\n * When running in a non-production Sanity environment (e.g. staging), write the\n * `SANITY_INTERNAL_ENV` variable to a `.env` file in the output directory so that\n * the bootstrapped project continues to target the same environment.\n */\nexport async function writeStagingEnvIfNeeded(output: Output, outputPath: string): Promise<void> {\n const sanityEnv = getSanityEnv()\n if (sanityEnv === 'production') return\n\n await createOrAppendEnvVars({\n envVars: {INTERNAL_ENV: sanityEnv},\n filename: '.env',\n framework: null,\n log: false,\n output,\n outputPath,\n })\n}\n"],"names":["getSanityEnv","createOrAppendEnvVars","fetchPostInitPrompt","shouldPrompt","unattended","flagValue","undefined","flagOrDefault","defaultValue","getPostInitMCPPrompt","editorsNames","Intl","ListFormat","format","writeStagingEnvIfNeeded","output","outputPath","sanityEnv","envVars","INTERNAL_ENV","filename","framework","log"],"mappings":"AAEA,SAAQA,YAAY,QAAO,6BAA4B;AAEvD,SAAQC,qBAAqB,QAAO,iCAAgC;AACpE,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D;;;CAGC,GACD,OAAO,SAASC,aAAaC,UAAmB,EAAEC,SAAkB;IAClE,OAAO,CAACD,cAAcC,cAAcC;AACtC;AAEA;;CAEC,GACD,OAAO,SAASC,cAAcF,SAA8B,EAAEG,YAAqB;IACjF,OAAO,OAAOH,cAAc,YAAYA,YAAYG;AACtD;AAEA,OAAO,eAAeC,qBAAqBC,YAA0B;IACnE,OAAOR,oBAAoB,IAAIS,KAAKC,UAAU,CAAC,MAAMC,MAAM,CAACH;AAC9D;AAEA;;;;CAIC,GACD,OAAO,eAAeI,wBAAwBC,MAAc,EAAEC,UAAkB;IAC9E,MAAMC,YAAYjB;IAClB,IAAIiB,cAAc,cAAc;IAEhC,MAAMhB,sBAAsB;QAC1BiB,SAAS;YAACC,cAAcF;QAAS;QACjCG,UAAU;QACVC,WAAW;QACXC,KAAK;QACLP;QACAC;IACF;AACF"}
|