@sanity/runtime-cli 17.6.0-blueprinit.g77b7a64 → 17.6.1

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 (33) hide show
  1. package/README.md +19 -19
  2. package/dist/actions/blueprints/pre-deploy.js +11 -18
  3. package/oclif.manifest.json +1 -130
  4. package/package.json +2 -2
  5. package/dist/actions/blueprinit/manifest.d.ts +0 -15
  6. package/dist/actions/blueprinit/manifest.js +0 -82
  7. package/dist/actions/blueprinit/studio.d.ts +0 -6
  8. package/dist/actions/blueprinit/studio.js +0 -43
  9. package/dist/actions/blueprinit/templates.d.ts +0 -34
  10. package/dist/actions/blueprinit/templates.js +0 -83
  11. package/dist/actions/blueprinit/workspace.d.ts +0 -16
  12. package/dist/actions/blueprinit/workspace.js +0 -143
  13. package/dist/actions/sanity/datasets.d.ts +0 -15
  14. package/dist/actions/sanity/datasets.js +0 -26
  15. package/dist/commands/init.d.ts +0 -17
  16. package/dist/commands/init.js +0 -59
  17. package/dist/cores/blueprinit/adopt.d.ts +0 -6
  18. package/dist/cores/blueprinit/adopt.js +0 -119
  19. package/dist/cores/blueprinit/finish.d.ts +0 -14
  20. package/dist/cores/blueprinit/finish.js +0 -64
  21. package/dist/cores/blueprinit/fresh.d.ts +0 -3
  22. package/dist/cores/blueprinit/fresh.js +0 -120
  23. package/dist/cores/blueprinit/preview.d.ts +0 -15
  24. package/dist/cores/blueprinit/preview.js +0 -14
  25. package/dist/cores/blueprinit/prompts.d.ts +0 -5
  26. package/dist/cores/blueprinit/prompts.js +0 -22
  27. package/dist/cores/blueprinit/selection.d.ts +0 -15
  28. package/dist/cores/blueprinit/selection.js +0 -90
  29. package/dist/cores/blueprinit/types.d.ts +0 -16
  30. package/dist/cores/blueprinit/types.js +0 -1
  31. package/dist/cores/blueprinit.d.ts +0 -7
  32. package/dist/cores/blueprinit.js +0 -48
  33. package/skills/init.md +0 -155
@@ -1,143 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
- import { dirname, join, posix } from 'node:path';
3
- import { renderBlueprint, STARTER_FUNCTION_NAME } from './manifest.js';
4
- import { FUNCTION_SET_SLUG, functionPackageJson, renderStudioConfig, STUDIO_POST_TYPE, STUDIO_SCHEMA_TYPES, studioPackageJson, } from './templates.js';
5
- const GITIGNORE_ENTRY = '# Sanity Blueprints\n.sanity/';
6
- const DEFAULT_GITIGNORE = `node_modules
7
- .env
8
-
9
- ${GITIGNORE_ENTRY}
10
- `;
11
- export function scaffoldWorkspace(options) {
12
- const { dir, studioName } = options;
13
- assertTargetsAvailable(dir, [
14
- posix.join('studios', studioName),
15
- posix.join('functions', STARTER_FUNCTION_NAME),
16
- ]);
17
- const packageJson = preparePackageJson(options, ['studios/*', 'functions/*']);
18
- const files = [];
19
- const write = createWriter(dir, files);
20
- const blueprintFilePath = write('sanity.blueprint.ts', renderBlueprint({
21
- ...manifestOptions(options),
22
- studioSrc: `./studios/${studioName}`,
23
- withFunction: true,
24
- }));
25
- write(posix.join('studios', studioName, 'package.json'), formatJson(studioPackageJson(studioName)));
26
- write(posix.join('studios', studioName, 'sanity.config.ts'), renderStudioConfig(options));
27
- write(posix.join('studios', studioName, 'schemaTypes', 'index.ts'), STUDIO_SCHEMA_TYPES);
28
- write(posix.join('studios', studioName, 'schemaTypes', 'post.ts'), STUDIO_POST_TYPE);
29
- write(posix.join('studios', studioName, 'static', '.gitkeep'), '');
30
- write(posix.join('functions', STARTER_FUNCTION_NAME, 'package.json'), formatJson(functionPackageJson(STARTER_FUNCTION_NAME)));
31
- write(posix.join('functions', STARTER_FUNCTION_NAME, 'index.ts'), FUNCTION_SET_SLUG);
32
- writePreparedRootFiles(dir, packageJson, files);
33
- return { blueprintFilePath, files };
34
- }
35
- export function adoptWorkspace(options) {
36
- const { dir } = options;
37
- const packageJson = preparePackageJson(options, []);
38
- const files = [];
39
- const write = createWriter(dir, files);
40
- const blueprintFilePath = write('sanity.blueprint.ts', renderBlueprint({ ...manifestOptions(options), studioSrc: '.', withFunction: false }));
41
- writePreparedRootFiles(dir, packageJson, files);
42
- return { blueprintFilePath, files };
43
- }
44
- function manifestOptions(options) {
45
- return {
46
- projectName: options.stackName,
47
- displayName: options.displayName,
48
- projectId: options.projectId,
49
- datasetName: options.datasetName,
50
- studioName: options.studioName,
51
- studioOrigin: options.studioOrigin,
52
- };
53
- }
54
- function assertTargetsAvailable(dir, paths) {
55
- const conflicts = paths.filter((path) => existsSync(join(dir, path)));
56
- if (conflicts.length > 0) {
57
- throw new Error(`Refusing to overwrite existing paths: ${conflicts.join(', ')}`);
58
- }
59
- }
60
- function createWriter(dir, files) {
61
- return (relativePath, content) => {
62
- const filePath = join(dir, relativePath);
63
- mkdirSync(dirname(filePath), { recursive: true });
64
- writeFileSync(filePath, content);
65
- files.push(relativePath);
66
- return filePath;
67
- };
68
- }
69
- function writePreparedRootFiles(dir, packageJson, files) {
70
- if (writeGitignore(dir))
71
- files.push('.gitignore');
72
- writeFileSync(join(dir, 'package.json'), formatJson(packageJson));
73
- files.push('package.json');
74
- }
75
- function writeGitignore(dir) {
76
- const filePath = join(dir, '.gitignore');
77
- if (!existsSync(filePath)) {
78
- writeFileSync(filePath, DEFAULT_GITIGNORE);
79
- return true;
80
- }
81
- const existing = readFileSync(filePath, 'utf8');
82
- if (existing.split(/\r?\n/).some((line) => line.trim() === '.sanity/'))
83
- return false;
84
- writeFileSync(filePath, `${existing.trimEnd()}\n\n${GITIGNORE_ENTRY}\n`);
85
- return true;
86
- }
87
- function preparePackageJson(options, requiredWorkspaces) {
88
- const filePath = join(options.dir, 'package.json');
89
- const parsed = existsSync(filePath)
90
- ? JSON.parse(readFileSync(filePath, 'utf8'))
91
- : {
92
- name: options.stackName,
93
- version: '0.1.0',
94
- private: true,
95
- type: 'module',
96
- };
97
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
98
- throw new Error('The existing package.json must contain a JSON object.');
99
- }
100
- const packageJson = parsed;
101
- addWorkspaces(packageJson, requiredWorkspaces);
102
- addBlueprintsDependency(packageJson, options.blueprintsVersion);
103
- return packageJson;
104
- }
105
- function addWorkspaces(packageJson, required) {
106
- if (required.length === 0)
107
- return;
108
- if (!packageJson.workspaces) {
109
- packageJson.workspaces = required;
110
- return;
111
- }
112
- if (Array.isArray(packageJson.workspaces)) {
113
- packageJson.workspaces = [...new Set([...packageJson.workspaces, ...required])];
114
- return;
115
- }
116
- if (!packageJson.workspaces || typeof packageJson.workspaces !== 'object') {
117
- throw new Error('Cannot add generated packages to the existing package.json workspaces.');
118
- }
119
- const workspaces = packageJson.workspaces;
120
- if (Array.isArray(workspaces.packages)) {
121
- workspaces.packages = [...new Set([...workspaces.packages, ...required])];
122
- return;
123
- }
124
- throw new Error('Cannot add generated packages to the existing package.json workspaces.');
125
- }
126
- function addBlueprintsDependency(packageJson, blueprintsVersion) {
127
- const dependencies = recordOrEmpty(packageJson.dependencies);
128
- const devDependencies = recordOrEmpty(packageJson.devDependencies);
129
- if (dependencies['@sanity/blueprints'] || devDependencies['@sanity/blueprints'])
130
- return;
131
- packageJson.devDependencies = {
132
- ...devDependencies,
133
- '@sanity/blueprints': blueprintsVersion,
134
- };
135
- }
136
- function recordOrEmpty(value) {
137
- return value && typeof value === 'object' && !Array.isArray(value)
138
- ? value
139
- : {};
140
- }
141
- function formatJson(value) {
142
- return `${JSON.stringify(value, null, 2)}\n`;
143
- }
@@ -1,15 +0,0 @@
1
- import type { Logger } from '../../utils/logger.js';
2
- import type { ActionResponse } from '../../utils/types.js';
3
- export interface Dataset {
4
- name: string;
5
- aclMode: string;
6
- }
7
- interface ListDatasetsResponse extends ActionResponse {
8
- datasets: Dataset[];
9
- }
10
- export declare function listDatasets({ token, projectId, logger, }: {
11
- token: string;
12
- projectId: string;
13
- logger: Logger;
14
- }): Promise<ListDatasetsResponse>;
15
- export {};
@@ -1,26 +0,0 @@
1
- import { createTracedFetch } from '../../utils/traced-fetch.js';
2
- import { projectsApiPath } from './projects.js';
3
- export async function listDatasets({ token, projectId, logger, }) {
4
- const fetchFn = createTracedFetch(logger);
5
- const url = `${projectsApiPath}/${encodeURIComponent(projectId)}/datasets`;
6
- const response = await fetchFn(url, {
7
- method: 'GET',
8
- headers: {
9
- Authorization: `Bearer ${token}`,
10
- 'Content-Type': 'application/json',
11
- },
12
- });
13
- const body = await response.json();
14
- if (!response.ok) {
15
- return {
16
- ok: false,
17
- error: body.error?.message ?? response.statusText,
18
- datasets: [],
19
- };
20
- }
21
- return {
22
- ok: true,
23
- error: null,
24
- datasets: body,
25
- };
26
- }
@@ -1,17 +0,0 @@
1
- import { RuntimeCommand } from '../baseCommands.js';
2
- export default class InitCommand extends RuntimeCommand<typeof InitCommand> {
3
- static hidden: boolean;
4
- static summary: string;
5
- static description: string;
6
- static examples: string[];
7
- static flags: {
8
- llms: import("@oclif/core/interfaces").BooleanFlag<boolean>;
9
- yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
- 'organization-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
- 'project-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
- dataset: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
- 'stack-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
- 'studio-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
- };
16
- run(): Promise<Record<string, unknown> | undefined>;
17
- }
@@ -1,59 +0,0 @@
1
- import { Flags } from '@oclif/core';
2
- import { llmsFlagConfig } from '@sanity-labs/oclif-plugin-skills-flag';
3
- import { RuntimeCommand } from '../baseCommands.js';
4
- import { blueprinitCore } from '../cores/blueprinit.js';
5
- import { Logger } from '../utils/logger.js';
6
- export default class InitCommand extends RuntimeCommand {
7
- static hidden = true;
8
- static summary = 'Experimental blueprints-first project init';
9
- static description = `Scaffolds a Blueprint, Studio, and starter function around an existing Sanity project.
10
-
11
- This hidden command is an experiment; its interface and generated files are not stable.`;
12
- static examples = [
13
- '<%= config.bin %> <%= command.id %>',
14
- '<%= config.bin %> <%= command.id %> --yes',
15
- '<%= config.bin %> <%= command.id %> --project-id <id> --dataset <name> --yes',
16
- ];
17
- static flags = {
18
- llms: Flags.boolean(llmsFlagConfig),
19
- yes: Flags.boolean({
20
- char: 'y',
21
- description: 'Skip confirmation prompts',
22
- default: false,
23
- }),
24
- 'organization-id': Flags.string({
25
- description: 'Organization to use when the account has several',
26
- aliases: ['organization', 'organizationId', 'org'],
27
- }),
28
- 'project-id': Flags.string({
29
- description: 'Project to use when the organization has several',
30
- aliases: ['project', 'projectId'],
31
- }),
32
- dataset: Flags.string({
33
- description: 'Dataset to attach',
34
- }),
35
- 'stack-name': Flags.string({
36
- description: 'Name for the new organization-scoped Stack',
37
- }),
38
- 'studio-name': Flags.string({
39
- description: 'Name and hosted slug for the Studio resource',
40
- }),
41
- };
42
- async run() {
43
- const result = await blueprinitCore({
44
- bin: this.config.bin,
45
- log: Logger(this.log.bind(this), this.flags),
46
- flags: {
47
- yes: this.flags.yes,
48
- organizationId: this.flags['organization-id'],
49
- projectId: this.flags['project-id'],
50
- datasetName: this.flags.dataset,
51
- stackName: this.flags['stack-name'],
52
- studioName: this.flags['studio-name'],
53
- },
54
- });
55
- if (!result.success)
56
- this.coreError(result);
57
- return result.json;
58
- }
59
- }
@@ -1,6 +0,0 @@
1
- import type { DetectedStudio } from '../../actions/blueprinit/studio.js';
2
- import type { CoreResult } from '../index.js';
3
- import type { BlueprinitFlowOptions } from './types.js';
4
- export declare function adoptFlow(options: BlueprinitFlowOptions & {
5
- studio: DetectedStudio;
6
- }): Promise<CoreResult>;
@@ -1,119 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { env } from 'node:process';
4
- import { hostedStudioOrigin, slugify } from '../../actions/blueprinit/manifest.js';
5
- import { adoptWorkspace } from '../../actions/blueprinit/workspace.js';
6
- import { listDatasets } from '../../actions/sanity/datasets.js';
7
- import { groupProjectsByOrganization } from '../../actions/sanity/projects.js';
8
- import { check } from '../../utils/display/presenters.js';
9
- import { getLatestNpmVersion } from '../../utils/external/npmjs.js';
10
- import { isInteractive } from '../../utils/interactive.js';
11
- import { createStackAndFinish } from './finish.js';
12
- import { printBlueprintPreview } from './preview.js';
13
- import { confirmUnlessSkipped, promptForStudioName, resourceNamesCollide } from './prompts.js';
14
- import { findProject } from './selection.js';
15
- export async function adoptFlow(options) {
16
- const { bin, dir, flags, log, studio, token } = options;
17
- if (flags.projectId && studio.projectId && flags.projectId !== studio.projectId) {
18
- return { success: false, error: `The Studio uses project "${studio.projectId}".` };
19
- }
20
- if (flags.datasetName && studio.dataset && flags.datasetName !== studio.dataset) {
21
- return { success: false, error: `The Studio uses dataset "${studio.dataset}".` };
22
- }
23
- const projectId = studio.projectId ?? flags.projectId;
24
- const datasetName = studio.dataset ?? flags.datasetName;
25
- if (!projectId || !datasetName) {
26
- return {
27
- success: false,
28
- error: `Found ${studio.configFile}, but could not read a projectId and dataset from it.`,
29
- suggestions: ['Use literal values in the Studio config or pass --project-id and --dataset.'],
30
- };
31
- }
32
- log(check(`Studio detected (${studio.configFile})`));
33
- const grouped = await groupProjectsByOrganization({ token, logger: log });
34
- if (!grouped.ok) {
35
- return { success: false, error: `Could not list organizations: ${grouped.error}` };
36
- }
37
- const match = findProject(grouped.organizations, projectId);
38
- if (!match) {
39
- return {
40
- success: false,
41
- error: `Project "${projectId}" from ${studio.configFile} was not found in your account.`,
42
- };
43
- }
44
- if (flags.organizationId && flags.organizationId !== match.organization.id) {
45
- return {
46
- success: false,
47
- error: `Project "${studio.projectId}" belongs to organization "${match.organization.id}".`,
48
- };
49
- }
50
- const datasets = await listDatasets({ token, projectId: match.project.id, logger: log });
51
- if (!datasets.ok) {
52
- return { success: false, error: `Could not list datasets: ${datasets.error}` };
53
- }
54
- if (!datasets.datasets.some(({ name }) => name === datasetName)) {
55
- return {
56
- success: false,
57
- error: `Dataset "${datasetName}" was not found in project ${match.project.displayName}.`,
58
- };
59
- }
60
- log(check(`Matches project ${match.project.displayName} (${match.project.id}), dataset ${datasetName}`));
61
- log('');
62
- const studioName = await promptForStudioName(flags, isInteractive);
63
- const stackName = flags.stackName
64
- ? slugify(flags.stackName) || match.project.id
65
- : slugify(match.project.displayName) || match.project.id;
66
- if (resourceNamesCollide(stackName, studioName)) {
67
- return {
68
- success: false,
69
- error: `Stack and Studio names both resolve to "${stackName}". Blueprint resource names must be unique.`,
70
- suggestions: ['Pass --stack-name or --studio-name with a different value.'],
71
- };
72
- }
73
- const studioOrigin = hostedStudioOrigin(studioName, env.SANITY_INTERNAL_ENV);
74
- const marker = (file) => (existsSync(join(dir, file)) ? '~' : '+');
75
- printBlueprintPreview({
76
- log,
77
- organizationName: match.organization.name,
78
- projectId: match.project.id,
79
- projectName: match.project.displayName,
80
- datasetName,
81
- studioName,
82
- studioOrigin,
83
- studioSource: '.',
84
- stackName,
85
- });
86
- log('Changes:');
87
- log(" + sanity.blueprint.ts attach project + dataset; add CORS and Studio at '.'");
88
- log(` + .sanity/blueprint.config.json org scope, stack ${stackName}`);
89
- log(` ${marker('.gitignore')} .gitignore`);
90
- log(` ${marker('package.json')} package.json`);
91
- log('');
92
- const confirmed = await confirmUnlessSkipped(flags, isInteractive, 'Adopt this Studio into the Blueprint?');
93
- if (!confirmed)
94
- return { success: false, error: 'Initialization cancelled.' };
95
- const adoption = adoptWorkspace({
96
- dir,
97
- projectId: match.project.id,
98
- displayName: match.project.displayName,
99
- datasetName,
100
- stackName,
101
- studioName,
102
- studioOrigin,
103
- blueprintsVersion: await getLatestNpmVersion('@sanity/blueprints', log),
104
- });
105
- return await createStackAndFinish({
106
- ...options,
107
- organizationId: match.organization.id,
108
- projectId: match.project.id,
109
- datasetName,
110
- stackName,
111
- blueprintFilePath: adoption.blueprintFilePath,
112
- files: adoption.files,
113
- nextSteps: [
114
- ` npx ${bin} blueprints plan`,
115
- ` npx ${bin} blueprints deploy`,
116
- ` npx ${bin} blueprints info`,
117
- ],
118
- });
119
- }
@@ -1,14 +0,0 @@
1
- import type { CoreResult } from '../index.js';
2
- import type { BlueprinitFlowOptions } from './types.js';
3
- interface FinishOptions extends BlueprinitFlowOptions {
4
- organizationId: string;
5
- projectId: string;
6
- datasetName: string;
7
- stackName: string;
8
- blueprintFilePath: string;
9
- files: string[];
10
- nextSteps: string[];
11
- }
12
- export declare function createStackAndFinish(options: FinishOptions): Promise<CoreResult>;
13
- export declare function alignSteps(steps: Array<[command: string, description?: string]>): string[];
14
- export {};
@@ -1,64 +0,0 @@
1
- import { writeConfigFile } from '../../actions/blueprints/config.js';
2
- import { createEmptyStack } from '../../actions/blueprints/stacks.js';
3
- import { check } from '../../utils/display/presenters.js';
4
- export async function createStackAndFinish(options) {
5
- let stack;
6
- try {
7
- stack = await createEmptyStack({
8
- token: options.token,
9
- scopeType: 'organization',
10
- scopeId: options.organizationId,
11
- name: options.stackName,
12
- logger: options.log,
13
- });
14
- }
15
- catch (error) {
16
- const message = error instanceof Error ? error.message : String(error);
17
- return {
18
- success: false,
19
- error: `Local files were written, but Stack creation failed: ${message}`,
20
- suggestions: [
21
- 'Resolve the Stack error, then finish setup with:',
22
- `npx ${options.bin} blueprints init --organization-id ${options.organizationId} --stack-name ${options.stackName}`,
23
- ],
24
- };
25
- }
26
- try {
27
- writeConfigFile(options.blueprintFilePath, {
28
- organizationId: options.organizationId,
29
- stackId: stack.id,
30
- });
31
- }
32
- catch (error) {
33
- const message = error instanceof Error ? error.message : String(error);
34
- return {
35
- success: false,
36
- error: `Stack ${stack.id} was created, but the local Blueprint config could not be written: ${message}`,
37
- suggestions: [
38
- 'Finish setup with:',
39
- `npx ${options.bin} blueprints init --organization-id ${options.organizationId} --stack-id ${stack.id}`,
40
- ],
41
- };
42
- }
43
- options.log(check(`Stack ${stack.name} created (org scope)`));
44
- options.log('The Stack is empty; Blueprint resources have not been deployed.');
45
- options.log('');
46
- options.log('Next steps:');
47
- for (const step of options.nextSteps)
48
- options.log(step);
49
- return {
50
- success: true,
51
- json: {
52
- organizationId: options.organizationId,
53
- projectId: options.projectId,
54
- dataset: options.datasetName,
55
- stackId: stack.id,
56
- stackName: stack.name,
57
- files: [...options.files, '.sanity/blueprint.config.json'],
58
- },
59
- };
60
- }
61
- export function alignSteps(steps) {
62
- const width = Math.max(...steps.map(([command]) => command.length));
63
- return steps.map(([command, description]) => description ? ` ${command.padEnd(width + 2)}${description}` : ` ${command}`);
64
- }
@@ -1,3 +0,0 @@
1
- import type { CoreResult } from '../index.js';
2
- import type { BlueprinitFlowOptions } from './types.js';
3
- export declare function freshFlow(options: BlueprinitFlowOptions): Promise<CoreResult>;
@@ -1,120 +0,0 @@
1
- import { env } from 'node:process';
2
- import { hostedStudioOrigin, STARTER_FUNCTION_NAME, slugify, } from '../../actions/blueprinit/manifest.js';
3
- import { scaffoldWorkspace } from '../../actions/blueprinit/workspace.js';
4
- import { listDatasets } from '../../actions/sanity/datasets.js';
5
- import { groupProjectsByOrganization } from '../../actions/sanity/projects.js';
6
- import { check } from '../../utils/display/presenters.js';
7
- import { getLatestNpmVersion } from '../../utils/external/npmjs.js';
8
- import { isInteractive } from '../../utils/interactive.js';
9
- import { alignSteps, createStackAndFinish } from './finish.js';
10
- import { printBlueprintPreview } from './preview.js';
11
- import { confirmUnlessSkipped, promptForStudioName, resourceNamesCollide } from './prompts.js';
12
- import { chooseDataset, chooseOrganization, chooseProject } from './selection.js';
13
- export async function freshFlow(options) {
14
- const { bin, dir, flags, log, token } = options;
15
- const grouped = await groupProjectsByOrganization({ token, logger: log });
16
- if (!grouped.ok) {
17
- return { success: false, error: `Could not list organizations: ${grouped.error}` };
18
- }
19
- const organizationResult = await chooseOrganization(grouped.organizations, flags.organizationId, isInteractive);
20
- if (!organizationResult.ok) {
21
- return {
22
- success: false,
23
- error: organizationResult.error.message,
24
- suggestions: organizationResult.error.suggestions,
25
- };
26
- }
27
- const { organization, projects = [] } = organizationResult.value;
28
- const projectResult = await chooseProject(projects, flags.projectId, organization.name, isInteractive);
29
- if (!projectResult.ok) {
30
- return {
31
- success: false,
32
- error: projectResult.error.message,
33
- suggestions: projectResult.error.suggestions,
34
- };
35
- }
36
- const project = projectResult.value;
37
- const datasets = await listDatasets({ token, projectId: project.id, logger: log });
38
- if (!datasets.ok) {
39
- return { success: false, error: `Could not list datasets: ${datasets.error}` };
40
- }
41
- const datasetResult = await chooseDataset(datasets.datasets, flags.datasetName, project.displayName, isInteractive);
42
- if (!datasetResult.ok) {
43
- return {
44
- success: false,
45
- error: datasetResult.error.message,
46
- suggestions: datasetResult.error.suggestions,
47
- };
48
- }
49
- const dataset = datasetResult.value;
50
- log(check(`Org: ${organization.name} (${organization.id})`));
51
- log(check(`Project: ${project.displayName} (${project.id}), dataset: ${dataset.name}`));
52
- log('');
53
- const stackName = flags.stackName
54
- ? slugify(flags.stackName) || project.id
55
- : slugify(project.displayName) || project.id;
56
- const studioName = await promptForStudioName(flags, isInteractive);
57
- if (resourceNamesCollide(stackName, studioName)) {
58
- return {
59
- success: false,
60
- error: `Stack and Studio names both resolve to "${stackName}". Blueprint resource names must be unique.`,
61
- suggestions: ['Pass --stack-name or --studio-name with a different value.'],
62
- };
63
- }
64
- const studioOrigin = hostedStudioOrigin(studioName, env.SANITY_INTERNAL_ENV);
65
- printBlueprintPreview({
66
- log,
67
- organizationName: organization.name,
68
- projectId: project.id,
69
- projectName: project.displayName,
70
- datasetName: dataset.name,
71
- studioName,
72
- studioOrigin,
73
- studioSource: `studios/${studioName}`,
74
- stackName,
75
- functionName: STARTER_FUNCTION_NAME,
76
- });
77
- log('Files to write:');
78
- log(' + sanity.blueprint.ts project + dataset (attached), CORS, studio, function');
79
- const studioDirectory = `studios/${studioName}/`;
80
- log(` + ${studioDirectory.padEnd(Math.max(32, studioDirectory.length + 2))}Studio with a "post" type`);
81
- log(` + ${`functions/${STARTER_FUNCTION_NAME}/`.padEnd(32)}sets a post slug from its title`);
82
- log(` + .sanity/blueprint.config.json org scope, stack ${stackName}`);
83
- log(' + .gitignore');
84
- log(' + package.json');
85
- log('');
86
- const confirmed = await confirmUnlessSkipped(flags, isInteractive, `Create this Blueprint workspace for "${project.displayName}"?`);
87
- if (!confirmed)
88
- return { success: false, error: 'Initialization cancelled.' };
89
- const scaffold = scaffoldWorkspace({
90
- dir,
91
- projectId: project.id,
92
- displayName: project.displayName,
93
- datasetName: dataset.name,
94
- stackName,
95
- studioName,
96
- studioOrigin,
97
- blueprintsVersion: await getLatestNpmVersion('@sanity/blueprints', log),
98
- });
99
- return await createStackAndFinish({
100
- ...options,
101
- organizationId: organization.id,
102
- projectId: project.id,
103
- datasetName: dataset.name,
104
- stackName,
105
- blueprintFilePath: scaffold.blueprintFilePath,
106
- files: scaffold.files,
107
- nextSteps: [
108
- ...alignSteps([
109
- ['npm install'],
110
- [`npm run dev -w studios/${studioName}`, 'open the Studio and add a post'],
111
- [`npx ${bin} blueprints plan`, 'preview the deployment'],
112
- [`npx ${bin} blueprints deploy`, 'deploy the resources'],
113
- ]),
114
- '',
115
- 'Test the function on that post:',
116
- ` npx ${bin} functions test ${STARTER_FUNCTION_NAME} --document-id <id>` +
117
- ` --project-id ${project.id} --dataset ${dataset.name} --with-user-token`,
118
- ],
119
- });
120
- }
@@ -1,15 +0,0 @@
1
- import type { Logger } from '../../utils/logger.js';
2
- interface BlueprintPreviewOptions {
3
- log: Logger;
4
- organizationName: string;
5
- projectId: string;
6
- projectName: string;
7
- datasetName: string;
8
- studioName: string;
9
- studioOrigin: string;
10
- studioSource: string;
11
- stackName: string;
12
- functionName?: string;
13
- }
14
- export declare function printBlueprintPreview(options: BlueprintPreviewOptions): void;
15
- export {};
@@ -1,14 +0,0 @@
1
- export function printBlueprintPreview(options) {
2
- options.log('Blueprint plan:');
3
- options.log(` attach Project ${options.projectName} (${options.projectId}) on deploy; retain on Stack removal`);
4
- options.log(` attach Dataset ${options.datasetName} on deploy; retain on Stack removal`);
5
- options.log(` create CORS Origin ${options.studioName}-cors for ${options.studioOrigin} on deploy`);
6
- options.log(` create Studio ${options.studioName} from ${options.studioSource} at ${options.studioOrigin} on deploy`);
7
- if (options.functionName) {
8
- options.log(` create Function ${options.functionName} on deploy`);
9
- }
10
- options.log('');
11
- options.log('Remote action now:');
12
- options.log(` create Stack ${options.stackName} in ${options.organizationName} (empty, organization scope)`);
13
- options.log('');
14
- }
@@ -1,5 +0,0 @@
1
- import type { BlueprinitFlags } from './types.js';
2
- export declare const DEFAULT_STUDIO_NAME = "studio";
3
- export declare function resourceNamesCollide(stackName: string, studioName: string): boolean;
4
- export declare function confirmUnlessSkipped(flags: BlueprinitFlags, interactive: boolean, message: string): Promise<boolean>;
5
- export declare function promptForStudioName(flags: BlueprinitFlags, interactive: boolean): Promise<string>;
@@ -1,22 +0,0 @@
1
- import { confirm, input } from '@inquirer/prompts';
2
- import { slugify } from '../../actions/blueprinit/manifest.js';
3
- export const DEFAULT_STUDIO_NAME = 'studio';
4
- export function resourceNamesCollide(stackName, studioName) {
5
- return stackName === studioName;
6
- }
7
- export async function confirmUnlessSkipped(flags, interactive, message) {
8
- if (flags.yes || !interactive)
9
- return true;
10
- return await confirm({ message, default: true });
11
- }
12
- export async function promptForStudioName(flags, interactive) {
13
- if (flags.studioName)
14
- return slugify(flags.studioName) || DEFAULT_STUDIO_NAME;
15
- if (flags.yes || !interactive)
16
- return DEFAULT_STUDIO_NAME;
17
- const answer = await input({
18
- message: 'Name your Studio and hosted slug?',
19
- default: DEFAULT_STUDIO_NAME,
20
- });
21
- return slugify(answer) || DEFAULT_STUDIO_NAME;
22
- }