@sanity/cli 6.0.0-alpha.7 → 6.0.0-alpha.8
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 +75 -75
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +2 -1
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +1 -1
- package/dist/actions/init/bootstrapLocalTemplate.d.ts +13 -0
- package/dist/actions/init/bootstrapLocalTemplate.js +136 -0
- package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -0
- package/dist/actions/init/bootstrapRemoteTemplate.d.ts +12 -0
- package/dist/actions/init/bootstrapRemoteTemplate.js +109 -0
- package/dist/actions/init/bootstrapRemoteTemplate.js.map +1 -0
- package/dist/actions/init/bootstrapTemplate.d.ts +18 -0
- package/dist/actions/init/bootstrapTemplate.js +32 -0
- package/dist/actions/init/bootstrapTemplate.js.map +1 -0
- package/dist/actions/init/checkNextJsReactCompatibility.d.ts +9 -0
- package/dist/actions/init/checkNextJsReactCompatibility.js +21 -0
- package/dist/actions/init/checkNextJsReactCompatibility.js.map +1 -0
- package/dist/actions/init/countNestedFolders.d.ts +1 -0
- package/dist/actions/init/countNestedFolders.js +6 -0
- package/dist/actions/init/countNestedFolders.js.map +1 -0
- package/dist/actions/init/createAppCliConfig.d.ts +5 -0
- package/dist/actions/init/createAppCliConfig.js +19 -0
- package/dist/actions/init/createAppCliConfig.js.map +1 -0
- package/dist/actions/init/createCliConfig.d.ts +6 -0
- package/dist/actions/init/createCliConfig.js +27 -0
- package/dist/actions/init/createCliConfig.js.map +1 -0
- package/dist/actions/init/createPackageManifest.d.ts +6 -0
- package/dist/actions/init/createPackageManifest.js +86 -0
- package/dist/actions/init/createPackageManifest.js.map +1 -0
- package/dist/actions/init/createStudioConfig.d.ts +13 -0
- package/dist/actions/init/createStudioConfig.js +41 -0
- package/dist/actions/init/createStudioConfig.js.map +1 -0
- package/dist/actions/init/env/createOrAppendEnvVars.d.ts +12 -0
- package/dist/actions/init/env/createOrAppendEnvVars.js +25 -0
- package/dist/actions/init/env/createOrAppendEnvVars.js.map +1 -0
- package/dist/actions/init/env/parseAndUpdateEnvVars.d.ts +9 -0
- package/dist/actions/init/env/parseAndUpdateEnvVars.js +42 -0
- package/dist/actions/init/env/parseAndUpdateEnvVars.js.map +1 -0
- package/dist/actions/init/env/writeEnvVarsToFile.d.ts +12 -0
- package/dist/actions/init/env/writeEnvVarsToFile.js +49 -0
- package/dist/actions/init/env/writeEnvVarsToFile.js.map +1 -0
- package/dist/actions/init/fetchPostInitPrompt.d.ts +6 -0
- package/dist/actions/init/fetchPostInitPrompt.js +30 -0
- package/dist/actions/init/fetchPostInitPrompt.js.map +1 -0
- package/dist/actions/init/git.d.ts +1 -0
- package/dist/actions/init/git.js +65 -0
- package/dist/actions/init/git.js.map +1 -0
- package/dist/actions/init/processTemplate.d.ts +7 -0
- package/dist/actions/init/processTemplate.js +56 -0
- package/dist/actions/init/processTemplate.js.map +1 -0
- package/dist/actions/init/remoteTemplate.d.ts +0 -3
- package/dist/actions/init/remoteTemplate.js +2 -40
- package/dist/actions/init/remoteTemplate.js.map +1 -1
- package/dist/actions/init/resolvePackageManager.d.ts +10 -0
- package/dist/actions/init/resolvePackageManager.js +20 -0
- package/dist/actions/init/resolvePackageManager.js.map +1 -0
- package/dist/actions/init/setupMCP.d.ts +21 -0
- package/dist/actions/init/setupMCP.js +258 -0
- package/dist/actions/init/setupMCP.js.map +1 -0
- package/dist/actions/init/templates/appQuickstart.d.ts +3 -0
- package/dist/actions/init/templates/appQuickstart.js +28 -0
- package/dist/actions/init/templates/appQuickstart.js.map +1 -0
- package/dist/actions/init/templates/appSanityUi.d.ts +3 -0
- package/dist/actions/init/templates/appSanityUi.js +30 -0
- package/dist/actions/init/templates/appSanityUi.js.map +1 -0
- package/dist/actions/init/templates/blog.d.ts +3 -0
- package/dist/actions/init/templates/blog.js +4 -0
- package/dist/actions/init/templates/blog.js.map +1 -0
- package/dist/actions/init/templates/clean.d.ts +3 -0
- package/dist/actions/init/templates/clean.js +4 -0
- package/dist/actions/init/templates/clean.js.map +1 -0
- package/dist/actions/init/templates/getStarted.d.ts +3 -0
- package/dist/actions/init/templates/getStarted.js +35 -0
- package/dist/actions/init/templates/getStarted.js.map +1 -0
- package/dist/actions/init/templates/index.d.ts +3 -0
- package/dist/actions/init/templates/index.js +23 -0
- package/dist/actions/init/templates/index.js.map +1 -0
- package/dist/actions/init/templates/moviedb.d.ts +3 -0
- package/dist/actions/init/templates/moviedb.js +34 -0
- package/dist/actions/init/templates/moviedb.js.map +1 -0
- package/dist/actions/init/templates/nextjs/index.d.ts +6 -0
- package/dist/actions/init/templates/nextjs/index.js +213 -0
- package/dist/actions/init/templates/nextjs/index.js.map +1 -0
- package/dist/actions/init/templates/nextjs/schemaTypes/blog.d.ts +3 -0
- package/dist/actions/init/templates/nextjs/schemaTypes/blog.js +247 -0
- package/dist/actions/init/templates/nextjs/schemaTypes/blog.js.map +1 -0
- package/dist/actions/init/templates/quickstart.d.ts +3 -0
- package/dist/actions/init/templates/quickstart.js +4 -0
- package/dist/actions/init/templates/quickstart.js.map +1 -0
- package/dist/actions/init/templates/shopify.d.ts +3 -0
- package/dist/actions/init/templates/shopify.js +77 -0
- package/dist/actions/init/templates/shopify.js.map +1 -0
- package/dist/actions/init/templates/shopifyOnline.d.ts +3 -0
- package/dist/actions/init/templates/shopifyOnline.js +49 -0
- package/dist/actions/init/templates/shopifyOnline.js.map +1 -0
- package/dist/actions/init/types.d.ts +15 -0
- package/dist/actions/init/types.js +3 -0
- package/dist/actions/init/types.js.map +1 -0
- package/dist/actions/init/updateInitialTemplateMetadata.d.ts +1 -0
- package/dist/actions/init/updateInitialTemplateMetadata.js +17 -0
- package/dist/actions/init/updateInitialTemplateMetadata.js.map +1 -0
- package/dist/commands/init.d.ts +24 -14
- package/dist/commands/init.js +544 -26
- package/dist/commands/init.js.map +1 -1
- package/dist/prompts/init/nextjs.d.ts +5 -0
- package/dist/prompts/init/nextjs.js +56 -0
- package/dist/prompts/init/nextjs.js.map +1 -0
- package/dist/prompts/init/promptForTypescript.d.ts +0 -1
- package/dist/prompts/init/promptForTypescript.js +0 -6
- package/dist/prompts/init/promptForTypescript.js.map +1 -1
- package/dist/services/mcp.d.ts +10 -0
- package/dist/services/mcp.js +16 -0
- package/dist/services/mcp.js.map +1 -1
- package/dist/services/projects.d.ts +5 -2
- package/dist/services/projects.js +37 -0
- package/dist/services/projects.js.map +1 -1
- package/dist/studioDependencies.d.ts +16 -0
- package/dist/studioDependencies.js +24 -0
- package/dist/studioDependencies.js.map +1 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.js.map +1 -1
- package/dist/typings/deepSortObject.d.js +2 -0
- package/dist/typings/deepSortObject.d.js.map +1 -0
- package/dist/util/copy.d.ts +5 -0
- package/dist/util/copy.js +37 -0
- package/dist/util/copy.js.map +1 -0
- package/dist/util/frameworkPort.d.ts +12 -0
- package/dist/util/frameworkPort.js +61 -0
- package/dist/util/frameworkPort.js.map +1 -0
- package/dist/util/fsUtils.d.ts +2 -0
- package/dist/util/fsUtils.js +34 -0
- package/dist/util/fsUtils.js.map +1 -0
- package/dist/util/getProjectDefaults.d.ts +11 -0
- package/dist/util/getProjectDefaults.js +77 -0
- package/dist/util/getProjectDefaults.js.map +1 -0
- package/dist/util/packageManager/packageManagerChoice.d.ts +2 -0
- package/dist/util/packageManager/packageManagerChoice.js +8 -0
- package/dist/util/packageManager/packageManagerChoice.js.map +1 -1
- package/dist/util/readdirRecursive.d.ts +5 -0
- package/dist/util/readdirRecursive.js +24 -0
- package/dist/util/readdirRecursive.js.map +1 -0
- package/dist/util/resolveLatestVersions.d.ts +7 -0
- package/dist/util/resolveLatestVersions.js +21 -0
- package/dist/util/resolveLatestVersions.js.map +1 -0
- package/oclif.manifest.json +36 -29
- package/package.json +17 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/tryLoadDocumentComponent.ts"],"sourcesContent":["import fs from 'node:fs'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {getPossibleDocumentComponentLocations} from '../getPossibleDocumentComponentLocations.js'\n\n/**\n * @internal\n */\nexport async function tryLoadDocumentComponent(studioRootPath: string) {\n const locations = getPossibleDocumentComponentLocations(studioRootPath)\n\n for (const componentPath of locations) {\n buildDebug('Trying to load document component from %s', componentPath)\n try {\n const component = await
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/build/renderDocumentWorker/tryLoadDocumentComponent.ts"],"sourcesContent":["import fs from 'node:fs'\n\nimport {doImport} from '@sanity/cli-core'\n\nimport {buildDebug} from '../buildDebug.js'\nimport {getPossibleDocumentComponentLocations} from '../getPossibleDocumentComponentLocations.js'\n\n/**\n * @internal\n */\nexport async function tryLoadDocumentComponent(studioRootPath: string) {\n const locations = getPossibleDocumentComponentLocations(studioRootPath)\n\n for (const componentPath of locations) {\n buildDebug('Trying to load document component from %s', componentPath)\n try {\n const component = await doImport(componentPath)\n\n return {\n component,\n modified: Math.floor(fs.statSync(componentPath)?.mtimeMs),\n path: componentPath,\n }\n } catch (err) {\n // Allow \"not found\" errors\n if (err.code !== 'ERR_MODULE_NOT_FOUND') {\n buildDebug('Failed to load document component: %s', err.message)\n throw err\n }\n\n buildDebug('Document component not found at %s', componentPath)\n }\n }\n\n return null\n}\n"],"names":["fs","doImport","buildDebug","getPossibleDocumentComponentLocations","tryLoadDocumentComponent","studioRootPath","locations","componentPath","component","modified","Math","floor","statSync","mtimeMs","path","err","code","message"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AAExB,SAAQC,QAAQ,QAAO,mBAAkB;AAEzC,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,qCAAqC,QAAO,8CAA6C;AAEjG;;CAEC,GACD,OAAO,eAAeC,yBAAyBC,cAAsB;IACnE,MAAMC,YAAYH,sCAAsCE;IAExD,KAAK,MAAME,iBAAiBD,UAAW;QACrCJ,WAAW,6CAA6CK;QACxD,IAAI;YACF,MAAMC,YAAY,MAAMP,SAASM;YAEjC,OAAO;gBACLC;gBACAC,UAAUC,KAAKC,KAAK,CAACX,GAAGY,QAAQ,CAACL,gBAAgBM;gBACjDC,MAAMP;YACR;QACF,EAAE,OAAOQ,KAAK;YACZ,2BAA2B;YAC3B,IAAIA,IAAIC,IAAI,KAAK,wBAAwB;gBACvCd,WAAW,yCAAyCa,IAAIE,OAAO;gBAC/D,MAAMF;YACR;YAEAb,WAAW,sCAAsCK;QACnD;IACF;IAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Output } from '@sanity/cli-core';
|
|
2
|
+
import { type GenerateConfigOptions } from './createStudioConfig.js';
|
|
3
|
+
import { type ProjectTemplate } from './types.js';
|
|
4
|
+
export interface BootstrapLocalOptions {
|
|
5
|
+
output: Output;
|
|
6
|
+
outputPath: string;
|
|
7
|
+
packageName: string;
|
|
8
|
+
templateName: string;
|
|
9
|
+
useTypeScript: boolean;
|
|
10
|
+
variables: GenerateConfigOptions['variables'];
|
|
11
|
+
overwriteFiles?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function bootstrapLocalTemplate(opts: BootstrapLocalOptions): Promise<ProjectTemplate>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { subdebug } from '@sanity/cli-core';
|
|
4
|
+
import { chalk, spinner } from '@sanity/cli-core/ux';
|
|
5
|
+
import { deburr } from 'lodash-es';
|
|
6
|
+
import { studioDependencies } from '../../studioDependencies.js';
|
|
7
|
+
import { copy } from '../../util/copy.js';
|
|
8
|
+
import { resolveLatestVersions } from '../../util/resolveLatestVersions.js';
|
|
9
|
+
import { createAppCliConfig } from './createAppCliConfig.js';
|
|
10
|
+
import { createCliConfig } from './createCliConfig.js';
|
|
11
|
+
import { createPackageManifest } from './createPackageManifest.js';
|
|
12
|
+
import { createStudioConfig } from './createStudioConfig.js';
|
|
13
|
+
import { determineAppTemplate } from './determineAppTemplate.js';
|
|
14
|
+
import templates from './templates/index.js';
|
|
15
|
+
import { updateInitialTemplateMetadata } from './updateInitialTemplateMetadata.js';
|
|
16
|
+
const debug = subdebug('init:bootstrapRemoteTemplate');
|
|
17
|
+
export async function bootstrapLocalTemplate(opts) {
|
|
18
|
+
const { output, outputPath, packageName, templateName, useTypeScript, variables } = opts;
|
|
19
|
+
// packages/@sanity/cli/src/actions/init/ -> packages/@sanity/cli/src/action -> packages/@sanity/cli/src/
|
|
20
|
+
const cliRoot = path.resolve(import.meta.dirname, '../../..');
|
|
21
|
+
const templatesDir = path.join(cliRoot, 'templates');
|
|
22
|
+
const sourceDir = path.join(templatesDir, templateName);
|
|
23
|
+
const sharedDir = path.join(templatesDir, 'shared');
|
|
24
|
+
const isAppTemplate = determineAppTemplate(templateName);
|
|
25
|
+
// Check that we have a template info file (dependencies, plugins etc)
|
|
26
|
+
const template = templates[templateName];
|
|
27
|
+
if (!template) {
|
|
28
|
+
throw new Error(`Template "${templateName}" not defined`);
|
|
29
|
+
}
|
|
30
|
+
// Copy template files
|
|
31
|
+
debug('Copying files from template "%s" to "%s"', templateName, outputPath);
|
|
32
|
+
let spin = spinner('Bootstrapping files from template').start();
|
|
33
|
+
debug(`Copying template from : ${sourceDir}`);
|
|
34
|
+
await copy(sourceDir, outputPath, {
|
|
35
|
+
rename: useTypeScript ? toTypeScriptPath : undefined
|
|
36
|
+
});
|
|
37
|
+
debug(`Copying shared template code from : ${sharedDir}`);
|
|
38
|
+
await copy(path.join(sharedDir, 'gitignore.txt'), outputPath, {
|
|
39
|
+
rename: ()=>'.gitignore'
|
|
40
|
+
});
|
|
41
|
+
if (useTypeScript) {
|
|
42
|
+
await fs.copyFile(path.join(sharedDir, 'tsconfig.json'), path.join(outputPath, 'tsconfig.json'));
|
|
43
|
+
}
|
|
44
|
+
spin.succeed();
|
|
45
|
+
// Merge global and template-specific plugins and dependencies
|
|
46
|
+
// Resolve latest versions of Sanity-dependencies
|
|
47
|
+
spin = spinner('Resolving latest module versions').start();
|
|
48
|
+
const dependencyVersions = await resolveLatestVersions({
|
|
49
|
+
...isAppTemplate ? {} : studioDependencies.dependencies,
|
|
50
|
+
...isAppTemplate ? {} : studioDependencies.devDependencies,
|
|
51
|
+
...template.dependencies,
|
|
52
|
+
...template.devDependencies
|
|
53
|
+
});
|
|
54
|
+
spin.succeed();
|
|
55
|
+
// Use the resolved version for the given dependency
|
|
56
|
+
const dependencies = {};
|
|
57
|
+
for (const dependency of Object.keys({
|
|
58
|
+
...isAppTemplate ? {} : studioDependencies.dependencies,
|
|
59
|
+
...template.dependencies
|
|
60
|
+
})){
|
|
61
|
+
dependencies[dependency] = dependencyVersions[dependency];
|
|
62
|
+
}
|
|
63
|
+
const devDependencies = {};
|
|
64
|
+
for (const dependency of Object.keys({
|
|
65
|
+
...isAppTemplate ? {} : studioDependencies.devDependencies,
|
|
66
|
+
...template.devDependencies
|
|
67
|
+
})){
|
|
68
|
+
devDependencies[dependency] = dependencyVersions[dependency];
|
|
69
|
+
}
|
|
70
|
+
let packageJsonName = packageName;
|
|
71
|
+
/**
|
|
72
|
+
* Currently app init doesn't ask for a name, so we use the last part of the path
|
|
73
|
+
*/ if (isAppTemplate) {
|
|
74
|
+
packageJsonName = deburr(path.basename(outputPath).toLowerCase()).replaceAll(/\s+/g, '-').replaceAll(/[^a-z0-9-]/g, '');
|
|
75
|
+
}
|
|
76
|
+
// Now create a package manifest (`package.json`) with the merged dependencies
|
|
77
|
+
spin = spinner('Creating default project files').start();
|
|
78
|
+
const packageManifest = createPackageManifest({
|
|
79
|
+
dependencies,
|
|
80
|
+
devDependencies,
|
|
81
|
+
isAppTemplate,
|
|
82
|
+
name: packageJsonName,
|
|
83
|
+
scripts: template.scripts
|
|
84
|
+
});
|
|
85
|
+
// ...and a studio config (`sanity.config.[ts|js]`)
|
|
86
|
+
const studioConfig = createStudioConfig({
|
|
87
|
+
template: template.configTemplate,
|
|
88
|
+
variables
|
|
89
|
+
});
|
|
90
|
+
// ...and a CLI config (`sanity.cli.[ts|js]`)
|
|
91
|
+
const cliConfig = isAppTemplate ? createAppCliConfig({
|
|
92
|
+
entry: template.entry,
|
|
93
|
+
organizationId: variables.organizationId
|
|
94
|
+
}) : createCliConfig({
|
|
95
|
+
autoUpdates: variables.autoUpdates,
|
|
96
|
+
dataset: variables.dataset,
|
|
97
|
+
projectId: variables.projectId
|
|
98
|
+
});
|
|
99
|
+
// Write non-template files to disc
|
|
100
|
+
const codeExt = useTypeScript ? 'ts' : 'js';
|
|
101
|
+
await Promise.all([
|
|
102
|
+
isAppTemplate ? Promise.resolve(null) : writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig),
|
|
103
|
+
writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig),
|
|
104
|
+
writeFileIfNotExists('package.json', packageManifest),
|
|
105
|
+
isAppTemplate ? Promise.resolve(null) : writeFileIfNotExists('eslint.config.mjs', `import studio from '@sanity/eslint-config-studio'\n\nexport default [...studio]\n`)
|
|
106
|
+
].filter(Boolean));
|
|
107
|
+
debug('Updating initial template metadata');
|
|
108
|
+
await updateInitialTemplateMetadata(variables.projectId, `cli-${templateName}`);
|
|
109
|
+
// Finish up by providing init process with template-specific info
|
|
110
|
+
spin.succeed();
|
|
111
|
+
return template;
|
|
112
|
+
async function writeFileIfNotExists(fileName, content) {
|
|
113
|
+
const filePath = path.join(outputPath, fileName);
|
|
114
|
+
if (opts.overwriteFiles) {
|
|
115
|
+
// If overwrite is enabled, just write the file
|
|
116
|
+
await fs.writeFile(filePath, content);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
await fs.writeFile(filePath, content, {
|
|
121
|
+
flag: 'wx'
|
|
122
|
+
});
|
|
123
|
+
} catch (err) {
|
|
124
|
+
if (err.code === 'EEXIST') {
|
|
125
|
+
output.warn(`\n${chalk.yellow('⚠')} File "${filePath}" already exists, skipping`);
|
|
126
|
+
} else {
|
|
127
|
+
throw err;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function toTypeScriptPath(originalPath) {
|
|
133
|
+
return originalPath.replace(/\.js$/, '.ts');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//# sourceMappingURL=bootstrapLocalTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/bootstrapLocalTemplate.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {Output, subdebug} from '@sanity/cli-core'\nimport {chalk, spinner} from '@sanity/cli-core/ux'\nimport {deburr} from 'lodash-es'\n\nimport {studioDependencies} from '../../studioDependencies.js'\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 templates from './templates/index.js'\nimport {type ProjectTemplate} from './types.js'\nimport {updateInitialTemplateMetadata} from './updateInitialTemplateMetadata.js'\n\nconst debug = subdebug('init:bootstrapRemoteTemplate')\n\nexport interface 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 ? {} : studioDependencies.dependencies),\n ...(isAppTemplate ? {} : 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 ? {} : 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 ? {} : 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 })\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 isAppTemplate\n ? Promise.resolve(null)\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${chalk.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","subdebug","chalk","spinner","deburr","studioDependencies","copy","resolveLatestVersions","createAppCliConfig","createCliConfig","createPackageManifest","createStudioConfig","determineAppTemplate","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","studioConfig","configTemplate","cliConfig","entry","organizationId","autoUpdates","dataset","projectId","codeExt","Promise","all","writeFileIfNotExists","filter","Boolean","fileName","content","filePath","overwriteFiles","writeFile","flag","err","code","warn","yellow","originalPath","replace"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAgBC,QAAQ,QAAO,mBAAkB;AACjD,SAAQC,KAAK,EAAEC,OAAO,QAAO,sBAAqB;AAClD,SAAQC,MAAM,QAAO,YAAW;AAEhC,SAAQC,kBAAkB,QAAO,8BAA6B;AAC9D,SAAQC,IAAI,QAAO,qBAAoB;AACvC,SAAQC,qBAAqB,QAAO,sCAAqC;AACzE,SAAQC,kBAAkB,QAAO,0BAAyB;AAC1D,SAAQC,eAAe,QAAO,uBAAsB;AACpD,SAAQC,qBAAqB,QAAO,6BAA4B;AAChE,SAAQC,kBAAkB,QAAmC,0BAAyB;AACtF,SAAQC,oBAAoB,QAAO,4BAA2B;AAC9D,OAAOC,eAAe,uBAAsB;AAE5C,SAAQC,6BAA6B,QAAO,qCAAoC;AAEhF,MAAMC,QAAQd,SAAS;AAavB,OAAO,eAAee,uBACpBC,IAA2B;IAE3B,MAAM,EAACC,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAEC,aAAa,EAAEC,SAAS,EAAC,GAAGN;IAClF,yGAAyG;IACzG,MAAMO,UAAUxB,KAAKyB,OAAO,CAAC,YAAYC,OAAO,EAAE;IAClD,MAAMC,eAAe3B,KAAK4B,IAAI,CAACJ,SAAS;IACxC,MAAMK,YAAY7B,KAAK4B,IAAI,CAACD,cAAcN;IAC1C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E1F,CAACC,MAAM,CAACC;IAGXpD,MAAM;IACN,MAAMD,8BAA8BS,UAAUsC,SAAS,EAAE,CAAC,IAAI,EAAExC,cAAc;IAE9E,kEAAkE;IAClEa,KAAKM,OAAO;IACZ,OAAOR;IAEP,eAAeiC,qBAAqBG,QAAgB,EAAEC,OAAe;QACnE,MAAMC,WAAWtE,KAAK4B,IAAI,CAACT,YAAYiD;QAEvC,IAAInD,KAAKsD,cAAc,EAAE;YACvB,+CAA+C;YAC/C,MAAMxE,GAAGyE,SAAS,CAACF,UAAUD;YAC7B;QACF;QAEA,IAAI;YACF,MAAMtE,GAAGyE,SAAS,CAACF,UAAUD,SAAS;gBAACI,MAAM;YAAI;QACnD,EAAE,OAAOC,KAAK;YACZ,IAAIA,IAAIC,IAAI,KAAK,UAAU;gBACzBzD,OAAO0D,IAAI,CAAC,CAAC,EAAE,EAAE1E,MAAM2E,MAAM,CAAC,KAAK,OAAO,EAAEP,SAAS,0BAA0B,CAAC;YAClF,OAAO;gBACL,MAAMI;YACR;QACF;IACF;AACF;AAEA,SAASrC,iBAAiByC,YAAoB;IAC5C,OAAOA,aAAaC,OAAO,CAAC,SAAS;AACvC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Output } from '@sanity/cli-core';
|
|
2
|
+
import { type GenerateConfigOptions } from './createStudioConfig.js';
|
|
3
|
+
import { type RepoInfo } from './remoteTemplate.js';
|
|
4
|
+
export interface BootstrapRemoteOptions {
|
|
5
|
+
output: Output;
|
|
6
|
+
outputPath: string;
|
|
7
|
+
packageName: string;
|
|
8
|
+
repoInfo: RepoInfo;
|
|
9
|
+
variables: GenerateConfigOptions['variables'];
|
|
10
|
+
bearerToken?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function bootstrapRemoteTemplate(opts: BootstrapRemoteOptions): Promise<void>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { subdebug } from '@sanity/cli-core';
|
|
4
|
+
import { logSymbols, spinner } from '@sanity/cli-core/ux';
|
|
5
|
+
import { getMonoRepo, GitHubFileReader, validateTemplate } from '@sanity/template-validator';
|
|
6
|
+
import { frameworks } from '@vercel/frameworks';
|
|
7
|
+
import { detectFrameworkRecord, LocalFileSystemDetector } from '@vercel/fs-detectors';
|
|
8
|
+
import { createCorsOrigin } from '../../services/cors.js';
|
|
9
|
+
import { createToken } from '../../services/tokens.js';
|
|
10
|
+
import { getDefaultPortForFramework } from '../../util/frameworkPort.js';
|
|
11
|
+
import { tryGitInit } from './git.js';
|
|
12
|
+
import { applyEnvVariables, checkIfNeedsApiToken, downloadAndExtractRepo, getGitHubRawContentUrl, tryApplyPackageName } from './remoteTemplate.js';
|
|
13
|
+
import { updateInitialTemplateMetadata } from './updateInitialTemplateMetadata.js';
|
|
14
|
+
const debug = subdebug('init:bootstrapRemoteTemplate');
|
|
15
|
+
const SANITY_DEFAULT_PORT = 3333;
|
|
16
|
+
const READ_TOKEN_LABEL = 'Live Preview API';
|
|
17
|
+
const WRITE_TOKEN_LABEL = 'App Write Token';
|
|
18
|
+
const INITIAL_COMMIT_MESSAGE = 'Initial commit from Sanity CLI';
|
|
19
|
+
const API_READ_TOKEN_ROLE = 'viewer';
|
|
20
|
+
const API_WRITE_TOKEN_ROLE = 'editor';
|
|
21
|
+
export async function bootstrapRemoteTemplate(opts) {
|
|
22
|
+
const { bearerToken, output, outputPath, packageName, repoInfo, variables } = opts;
|
|
23
|
+
const name = [
|
|
24
|
+
repoInfo.username,
|
|
25
|
+
repoInfo.name,
|
|
26
|
+
repoInfo.filePath
|
|
27
|
+
].filter(Boolean).join('/');
|
|
28
|
+
const contentsUrl = getGitHubRawContentUrl(repoInfo);
|
|
29
|
+
const headers = {};
|
|
30
|
+
if (bearerToken) {
|
|
31
|
+
headers.Authorization = `Bearer ${bearerToken}`;
|
|
32
|
+
}
|
|
33
|
+
const spin = spinner(`Bootstrapping files from template "${name}"`).start();
|
|
34
|
+
const corsAdded = [
|
|
35
|
+
SANITY_DEFAULT_PORT
|
|
36
|
+
];
|
|
37
|
+
debug('Validating remote template');
|
|
38
|
+
const fileReader = new GitHubFileReader(contentsUrl, headers);
|
|
39
|
+
const packages = await getMonoRepo(fileReader);
|
|
40
|
+
const validation = await validateTemplate(fileReader, packages);
|
|
41
|
+
if (!validation.isValid) {
|
|
42
|
+
throw new Error(validation.errors.join('\n'));
|
|
43
|
+
}
|
|
44
|
+
debug('Create new directory "%s"', outputPath);
|
|
45
|
+
await mkdir(outputPath, {
|
|
46
|
+
recursive: true
|
|
47
|
+
});
|
|
48
|
+
debug('Downloading and extracting repo to %s', outputPath);
|
|
49
|
+
await downloadAndExtractRepo(outputPath, repoInfo, bearerToken);
|
|
50
|
+
debug('Checking if template needs read token');
|
|
51
|
+
const needsReadToken = await Promise.all((packages ?? [
|
|
52
|
+
''
|
|
53
|
+
]).map((pkg)=>checkIfNeedsApiToken(join(outputPath, pkg), 'read'))).then((results)=>results.some(Boolean));
|
|
54
|
+
const needsWriteToken = await Promise.all((packages ?? [
|
|
55
|
+
''
|
|
56
|
+
]).map((pkg)=>checkIfNeedsApiToken(join(outputPath, pkg), 'write'))).then((results)=>results.some(Boolean));
|
|
57
|
+
debug('Applying environment variables');
|
|
58
|
+
const readToken = needsReadToken ? (await createToken({
|
|
59
|
+
label: READ_TOKEN_LABEL,
|
|
60
|
+
projectId: variables.projectId,
|
|
61
|
+
roleName: API_READ_TOKEN_ROLE
|
|
62
|
+
})).key : undefined;
|
|
63
|
+
const writeToken = needsWriteToken ? (await createToken({
|
|
64
|
+
label: WRITE_TOKEN_LABEL,
|
|
65
|
+
projectId: variables.projectId,
|
|
66
|
+
roleName: API_WRITE_TOKEN_ROLE
|
|
67
|
+
})).key : undefined;
|
|
68
|
+
for (const pkg of packages ?? [
|
|
69
|
+
''
|
|
70
|
+
]){
|
|
71
|
+
const packagePath = join(outputPath, pkg);
|
|
72
|
+
const packageFramework = await detectFrameworkRecord({
|
|
73
|
+
frameworkList: frameworks,
|
|
74
|
+
fs: new LocalFileSystemDetector(packagePath)
|
|
75
|
+
});
|
|
76
|
+
const port = getDefaultPortForFramework(packageFramework?.slug);
|
|
77
|
+
if (corsAdded.includes(port)) {
|
|
78
|
+
debug('Setting CORS origin to http://localhost:%d', port);
|
|
79
|
+
await createCorsOrigin({
|
|
80
|
+
allowCredentials: true,
|
|
81
|
+
origin: `http://localhost:${port}`,
|
|
82
|
+
projectId: variables.projectId
|
|
83
|
+
});
|
|
84
|
+
corsAdded.push(port);
|
|
85
|
+
}
|
|
86
|
+
debug('Applying environment variables to %s', pkg);
|
|
87
|
+
// Next.js uses `.env.local` for local environment variables
|
|
88
|
+
const envName = packageFramework?.slug === 'nextjs' ? '.env.local' : '.env';
|
|
89
|
+
await applyEnvVariables(packagePath, {
|
|
90
|
+
...variables,
|
|
91
|
+
readToken,
|
|
92
|
+
writeToken
|
|
93
|
+
}, envName);
|
|
94
|
+
}
|
|
95
|
+
debug('Setting package name to %s', packageName);
|
|
96
|
+
await tryApplyPackageName(outputPath, packageName);
|
|
97
|
+
debug('Initializing git repository');
|
|
98
|
+
tryGitInit(outputPath, INITIAL_COMMIT_MESSAGE);
|
|
99
|
+
debug('Updating initial template metadata');
|
|
100
|
+
await updateInitialTemplateMetadata(variables.projectId, `external-${name}`);
|
|
101
|
+
spin.succeed();
|
|
102
|
+
if (corsAdded.length > 0) {
|
|
103
|
+
output.log(`${logSymbols.success} CORS origins added (${corsAdded.map((p)=>`localhost:${p}`).join(', ')})`);
|
|
104
|
+
}
|
|
105
|
+
if (readToken) output.log(`${logSymbols.success} API token generated (${READ_TOKEN_LABEL})`);
|
|
106
|
+
if (writeToken) output.log(`${logSymbols.success} API token generated (${WRITE_TOKEN_LABEL})`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=bootstrapRemoteTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/bootstrapRemoteTemplate.ts"],"sourcesContent":["import {mkdir} from 'node:fs/promises'\nimport {join} from 'node:path'\n\nimport {Output, subdebug} from '@sanity/cli-core'\nimport {logSymbols, spinner} from '@sanity/cli-core/ux'\nimport {getMonoRepo, GitHubFileReader, validateTemplate} from '@sanity/template-validator'\nimport {type Framework, frameworks} from '@vercel/frameworks'\nimport {detectFrameworkRecord, LocalFileSystemDetector} from '@vercel/fs-detectors'\n\nimport {createCorsOrigin} from '../../services/cors.js'\nimport {createToken} from '../../services/tokens.js'\nimport {getDefaultPortForFramework} from '../../util/frameworkPort.js'\nimport {type GenerateConfigOptions} from './createStudioConfig.js'\nimport {tryGitInit} from './git.js'\nimport {\n applyEnvVariables,\n checkIfNeedsApiToken,\n downloadAndExtractRepo,\n getGitHubRawContentUrl,\n type RepoInfo,\n tryApplyPackageName,\n} from './remoteTemplate.js'\nimport {updateInitialTemplateMetadata} from './updateInitialTemplateMetadata.js'\n\nconst debug = subdebug('init:bootstrapRemoteTemplate')\n\nexport interface BootstrapRemoteOptions {\n output: Output\n outputPath: string\n packageName: string\n repoInfo: RepoInfo\n variables: GenerateConfigOptions['variables']\n\n bearerToken?: string\n}\n\nconst SANITY_DEFAULT_PORT = 3333\nconst READ_TOKEN_LABEL = 'Live Preview API'\nconst WRITE_TOKEN_LABEL = 'App Write Token'\nconst INITIAL_COMMIT_MESSAGE = 'Initial commit from Sanity CLI'\nconst API_READ_TOKEN_ROLE = 'viewer'\nconst API_WRITE_TOKEN_ROLE = 'editor'\n\nexport async function bootstrapRemoteTemplate(opts: BootstrapRemoteOptions): Promise<void> {\n const {bearerToken, output, outputPath, packageName, repoInfo, variables} = opts\n const name = [repoInfo.username, repoInfo.name, repoInfo.filePath].filter(Boolean).join('/')\n const contentsUrl = getGitHubRawContentUrl(repoInfo)\n const headers: Record<string, string> = {}\n if (bearerToken) {\n headers.Authorization = `Bearer ${bearerToken}`\n }\n const spin = spinner(`Bootstrapping files from template \"${name}\"`).start()\n const corsAdded: number[] = [SANITY_DEFAULT_PORT]\n\n debug('Validating remote template')\n const fileReader = new GitHubFileReader(contentsUrl, headers)\n const packages = await getMonoRepo(fileReader)\n const validation = await validateTemplate(fileReader, packages)\n if (!validation.isValid) {\n throw new Error(validation.errors.join('\\n'))\n }\n\n debug('Create new directory \"%s\"', outputPath)\n await mkdir(outputPath, {recursive: true})\n\n debug('Downloading and extracting repo to %s', outputPath)\n await downloadAndExtractRepo(outputPath, repoInfo, bearerToken)\n\n debug('Checking if template needs read token')\n const needsReadToken = await Promise.all(\n (packages ?? ['']).map((pkg) => checkIfNeedsApiToken(join(outputPath, pkg), 'read')),\n ).then((results) => results.some(Boolean))\n const needsWriteToken = await Promise.all(\n (packages ?? ['']).map((pkg) => checkIfNeedsApiToken(join(outputPath, pkg), 'write')),\n ).then((results) => results.some(Boolean))\n\n debug('Applying environment variables')\n const readToken = needsReadToken\n ? (\n await createToken({\n label: READ_TOKEN_LABEL,\n projectId: variables.projectId,\n roleName: API_READ_TOKEN_ROLE,\n })\n ).key\n : undefined\n const writeToken = needsWriteToken\n ? (\n await createToken({\n label: WRITE_TOKEN_LABEL,\n projectId: variables.projectId,\n roleName: API_WRITE_TOKEN_ROLE,\n })\n ).key\n : undefined\n\n for (const pkg of packages ?? ['']) {\n const packagePath = join(outputPath, pkg)\n const packageFramework: Framework | null = await detectFrameworkRecord({\n frameworkList: frameworks as readonly Framework[],\n fs: new LocalFileSystemDetector(packagePath),\n })\n\n const port = getDefaultPortForFramework(packageFramework?.slug)\n if (corsAdded.includes(port)) {\n debug('Setting CORS origin to http://localhost:%d', port)\n await createCorsOrigin({\n allowCredentials: true,\n origin: `http://localhost:${port}`,\n projectId: variables.projectId,\n })\n corsAdded.push(port)\n }\n\n debug('Applying environment variables to %s', pkg)\n // Next.js uses `.env.local` for local environment variables\n const envName = packageFramework?.slug === 'nextjs' ? '.env.local' : '.env'\n await applyEnvVariables(packagePath, {...variables, readToken, writeToken}, envName)\n }\n\n debug('Setting package name to %s', packageName)\n await tryApplyPackageName(outputPath, packageName)\n\n debug('Initializing git repository')\n tryGitInit(outputPath, INITIAL_COMMIT_MESSAGE)\n\n debug('Updating initial template metadata')\n await updateInitialTemplateMetadata(variables.projectId, `external-${name}`)\n\n spin.succeed()\n if (corsAdded.length > 0) {\n output.log(\n `${logSymbols.success} CORS origins added (${corsAdded.map((p) => `localhost:${p}`).join(', ')})`,\n )\n }\n if (readToken) output.log(`${logSymbols.success} API token generated (${READ_TOKEN_LABEL})`)\n if (writeToken) output.log(`${logSymbols.success} API token generated (${WRITE_TOKEN_LABEL})`)\n}\n"],"names":["mkdir","join","subdebug","logSymbols","spinner","getMonoRepo","GitHubFileReader","validateTemplate","frameworks","detectFrameworkRecord","LocalFileSystemDetector","createCorsOrigin","createToken","getDefaultPortForFramework","tryGitInit","applyEnvVariables","checkIfNeedsApiToken","downloadAndExtractRepo","getGitHubRawContentUrl","tryApplyPackageName","updateInitialTemplateMetadata","debug","SANITY_DEFAULT_PORT","READ_TOKEN_LABEL","WRITE_TOKEN_LABEL","INITIAL_COMMIT_MESSAGE","API_READ_TOKEN_ROLE","API_WRITE_TOKEN_ROLE","bootstrapRemoteTemplate","opts","bearerToken","output","outputPath","packageName","repoInfo","variables","name","username","filePath","filter","Boolean","contentsUrl","headers","Authorization","spin","start","corsAdded","fileReader","packages","validation","isValid","Error","errors","recursive","needsReadToken","Promise","all","map","pkg","then","results","some","needsWriteToken","readToken","label","projectId","roleName","key","undefined","writeToken","packagePath","packageFramework","frameworkList","fs","port","slug","includes","allowCredentials","origin","push","envName","succeed","length","log","success","p"],"mappings":"AAAA,SAAQA,KAAK,QAAO,mBAAkB;AACtC,SAAQC,IAAI,QAAO,YAAW;AAE9B,SAAgBC,QAAQ,QAAO,mBAAkB;AACjD,SAAQC,UAAU,EAAEC,OAAO,QAAO,sBAAqB;AACvD,SAAQC,WAAW,EAAEC,gBAAgB,EAAEC,gBAAgB,QAAO,6BAA4B;AAC1F,SAAwBC,UA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B;gBACrBkE,kBAAkB;gBAClBC,QAAQ,CAAC,iBAAiB,EAAEJ,MAAM;gBAClCT,WAAW9B,UAAU8B,SAAS;YAChC;YACAnB,UAAUiC,IAAI,CAACL;QACjB;QAEArD,MAAM,wCAAwCqC;QAC9C,4DAA4D;QAC5D,MAAMsB,UAAUT,kBAAkBI,SAAS,WAAW,eAAe;QACrE,MAAM5D,kBAAkBuD,aAAa;YAAC,GAAGnC,SAAS;YAAE4B;YAAWM;QAAU,GAAGW;IAC9E;IAEA3D,MAAM,8BAA8BY;IACpC,MAAMd,oBAAoBa,YAAYC;IAEtCZ,MAAM;IACNP,WAAWkB,YAAYP;IAEvBJ,MAAM;IACN,MAAMD,8BAA8Be,UAAU8B,SAAS,EAAE,CAAC,SAAS,EAAE7B,MAAM;IAE3EQ,KAAKqC,OAAO;IACZ,IAAInC,UAAUoC,MAAM,GAAG,GAAG;QACxBnD,OAAOoD,GAAG,CACR,GAAGhF,WAAWiF,OAAO,CAAC,qBAAqB,EAAEtC,UAAUW,GAAG,CAAC,CAAC4B,IAAM,CAAC,UAAU,EAAEA,GAAG,EAAEpF,IAAI,CAAC,MAAM,CAAC,CAAC;IAErG;IACA,IAAI8D,WAAWhC,OAAOoD,GAAG,CAAC,GAAGhF,WAAWiF,OAAO,CAAC,sBAAsB,EAAE7D,iBAAiB,CAAC,CAAC;IAC3F,IAAI8C,YAAYtC,OAAOoD,GAAG,CAAC,GAAGhF,WAAWiF,OAAO,CAAC,sBAAsB,EAAE5D,kBAAkB,CAAC,CAAC;AAC/F"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Output } from '@sanity/cli-core';
|
|
2
|
+
import { type RepoInfo } from './remoteTemplate.js';
|
|
3
|
+
export interface BootstrapTemplateOptions {
|
|
4
|
+
autoUpdates: boolean;
|
|
5
|
+
bearerToken: string | undefined;
|
|
6
|
+
dataset: string;
|
|
7
|
+
organizationId: string | undefined;
|
|
8
|
+
output: Output;
|
|
9
|
+
outputPath: string;
|
|
10
|
+
overwriteFiles: boolean;
|
|
11
|
+
packageName: string;
|
|
12
|
+
projectId: string;
|
|
13
|
+
projectName: string;
|
|
14
|
+
remoteTemplateInfo: RepoInfo | undefined;
|
|
15
|
+
templateName: string;
|
|
16
|
+
useTypeScript: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function bootstrapTemplate({ autoUpdates, bearerToken, dataset, organizationId, output, outputPath, overwriteFiles, packageName, projectId, projectName, remoteTemplateInfo, templateName, useTypeScript, }: BootstrapTemplateOptions): Promise<void | import("./types.js").ProjectTemplate>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { bootstrapLocalTemplate } from './bootstrapLocalTemplate.js';
|
|
2
|
+
import { bootstrapRemoteTemplate } from './bootstrapRemoteTemplate.js';
|
|
3
|
+
export async function bootstrapTemplate({ autoUpdates, bearerToken, dataset, organizationId, output, outputPath, overwriteFiles, packageName, projectId, projectName, remoteTemplateInfo, templateName, useTypeScript }) {
|
|
4
|
+
const bootstrapVariables = {
|
|
5
|
+
autoUpdates,
|
|
6
|
+
dataset,
|
|
7
|
+
organizationId,
|
|
8
|
+
projectId,
|
|
9
|
+
projectName
|
|
10
|
+
};
|
|
11
|
+
if (remoteTemplateInfo) {
|
|
12
|
+
return bootstrapRemoteTemplate({
|
|
13
|
+
bearerToken,
|
|
14
|
+
output,
|
|
15
|
+
outputPath,
|
|
16
|
+
packageName,
|
|
17
|
+
repoInfo: remoteTemplateInfo,
|
|
18
|
+
variables: bootstrapVariables
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return bootstrapLocalTemplate({
|
|
22
|
+
output,
|
|
23
|
+
outputPath,
|
|
24
|
+
overwriteFiles,
|
|
25
|
+
packageName,
|
|
26
|
+
templateName,
|
|
27
|
+
useTypeScript,
|
|
28
|
+
variables: bootstrapVariables
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=bootstrapTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/bootstrapTemplate.ts"],"sourcesContent":["import {Output} from '@sanity/cli-core'\n\nimport {bootstrapLocalTemplate} from './bootstrapLocalTemplate.js'\nimport {bootstrapRemoteTemplate} from './bootstrapRemoteTemplate.js'\nimport {type GenerateConfigOptions} from './createStudioConfig.js'\nimport {type RepoInfo} from './remoteTemplate.js'\n\nexport interface BootstrapTemplateOptions {\n autoUpdates: boolean\n bearerToken: string | undefined\n dataset: string\n organizationId: string | undefined\n output: Output\n outputPath: string\n overwriteFiles: boolean\n packageName: string\n projectId: string\n projectName: string\n remoteTemplateInfo: RepoInfo | undefined\n templateName: string\n useTypeScript: boolean\n}\n\nexport async function bootstrapTemplate({\n autoUpdates,\n bearerToken,\n dataset,\n organizationId,\n output,\n outputPath,\n overwriteFiles,\n packageName,\n projectId,\n projectName,\n remoteTemplateInfo,\n templateName,\n useTypeScript,\n}: BootstrapTemplateOptions) {\n const bootstrapVariables: GenerateConfigOptions['variables'] = {\n autoUpdates,\n dataset,\n organizationId,\n projectId,\n projectName,\n }\n\n if (remoteTemplateInfo) {\n return bootstrapRemoteTemplate({\n bearerToken,\n output,\n outputPath,\n packageName,\n repoInfo: remoteTemplateInfo,\n variables: bootstrapVariables,\n })\n }\n\n return bootstrapLocalTemplate({\n output,\n outputPath,\n overwriteFiles,\n packageName,\n templateName,\n useTypeScript,\n variables: bootstrapVariables,\n })\n}\n"],"names":["bootstrapLocalTemplate","bootstrapRemoteTemplate","bootstrapTemplate","autoUpdates","bearerToken","dataset","organizationId","output","outputPath","overwriteFiles","packageName","projectId","projectName","remoteTemplateInfo","templateName","useTypeScript","bootstrapVariables","repoInfo","variables"],"mappings":"AAEA,SAAQA,sBAAsB,QAAO,8BAA6B;AAClE,SAAQC,uBAAuB,QAAO,+BAA8B;AAoBpE,OAAO,eAAeC,kBAAkB,EACtCC,WAAW,EACXC,WAAW,EACXC,OAAO,EACPC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,cAAc,EACdC,WAAW,EACXC,SAAS,EACTC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,EACZC,aAAa,EACY;IACzB,MAAMC,qBAAyD;QAC7Db;QACAE;QACAC;QACAK;QACAC;IACF;IAEA,IAAIC,oBAAoB;QACtB,OAAOZ,wBAAwB;YAC7BG;YACAG;YACAC;YACAE;YACAO,UAAUJ;YACVK,WAAWF;QACb;IACF;IAEA,OAAOhB,uBAAuB;QAC5BO;QACAC;QACAC;QACAC;QACAI;QACAC;QACAG,WAAWF;IACb;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Output } from '@sanity/cli-core';
|
|
2
|
+
import { VersionedFramework } from './types.js';
|
|
3
|
+
interface CheckCompatibilityOptions {
|
|
4
|
+
detectedFramework: VersionedFramework;
|
|
5
|
+
output: Output;
|
|
6
|
+
outputPath: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function checkNextJsReactCompatibility({ detectedFramework, output, outputPath, }: CheckCompatibilityOptions): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { readPackageJson } from '../../util/readPackageJson.js';
|
|
3
|
+
export async function checkNextJsReactCompatibility({ detectedFramework, output, outputPath }) {
|
|
4
|
+
const packageJson = await readPackageJson(`${outputPath}/package.json`);
|
|
5
|
+
const reactVersion = packageJson?.dependencies?.react;
|
|
6
|
+
if (reactVersion) {
|
|
7
|
+
const isUsingReact19 = semver.coerce(reactVersion)?.major === 19;
|
|
8
|
+
const isUsingNextJs15 = semver.coerce(detectedFramework?.detectedVersion)?.major === 15;
|
|
9
|
+
if (isUsingNextJs15 && isUsingReact19) {
|
|
10
|
+
output.warn('╭────────────────────────────────────────────────────────────╮');
|
|
11
|
+
output.warn('│ │');
|
|
12
|
+
output.warn('│ It looks like you are using Next.js 15 and React 19 │');
|
|
13
|
+
output.warn('│ Please read our compatibility guide. │');
|
|
14
|
+
output.warn('│ https://www.sanity.io/help/react-19 │');
|
|
15
|
+
output.warn('│ │');
|
|
16
|
+
output.warn('╰────────────────────────────────────────────────────────────╯');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=checkNextJsReactCompatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/checkNextJsReactCompatibility.ts"],"sourcesContent":["import {Output} from '@sanity/cli-core'\nimport semver from 'semver'\n\nimport {readPackageJson} from '../../util/readPackageJson.js'\nimport {VersionedFramework} from './types.js'\n\ninterface CheckCompatibilityOptions {\n detectedFramework: VersionedFramework\n output: Output\n outputPath: string\n}\n\nexport async function checkNextJsReactCompatibility({\n detectedFramework,\n output,\n outputPath,\n}: CheckCompatibilityOptions) {\n const packageJson = await readPackageJson(`${outputPath}/package.json`)\n const reactVersion = packageJson?.dependencies?.react\n\n if (reactVersion) {\n const isUsingReact19 = semver.coerce(reactVersion)?.major === 19\n const isUsingNextJs15 = semver.coerce(detectedFramework?.detectedVersion)?.major === 15\n\n if (isUsingNextJs15 && isUsingReact19) {\n output.warn('╭────────────────────────────────────────────────────────────╮')\n output.warn('│ │')\n output.warn('│ It looks like you are using Next.js 15 and React 19 │')\n output.warn('│ Please read our compatibility guide. │')\n output.warn('│ https://www.sanity.io/help/react-19 │')\n output.warn('│ │')\n output.warn('╰────────────────────────────────────────────────────────────╯')\n }\n }\n}\n"],"names":["semver","readPackageJson","checkNextJsReactCompatibility","detectedFramework","output","outputPath","packageJson","reactVersion","dependencies","react","isUsingReact19","coerce","major","isUsingNextJs15","detectedVersion","warn"],"mappings":"AACA,OAAOA,YAAY,SAAQ;AAE3B,SAAQC,eAAe,QAAO,gCAA+B;AAS7D,OAAO,eAAeC,8BAA8B,EAClDC,iBAAiB,EACjBC,MAAM,EACNC,UAAU,EACgB;IAC1B,MAAMC,cAAc,MAAML,gBAAgB,GAAGI,WAAW,aAAa,CAAC;IACtE,MAAME,eAAeD,aAAaE,cAAcC;IAEhD,IAAIF,cAAc;QAChB,MAAMG,iBAAiBV,OAAOW,MAAM,CAACJ,eAAeK,UAAU;QAC9D,MAAMC,kBAAkBb,OAAOW,MAAM,CAACR,mBAAmBW,kBAAkBF,UAAU;QAErF,IAAIC,mBAAmBH,gBAAgB;YACrCN,OAAOW,IAAI,CAAC;YACZX,OAAOW,IAAI,CAAC;YACZX,OAAOW,IAAI,CAAC;YACZX,OAAOW,IAAI,CAAC;YACZX,OAAOW,IAAI,CAAC;YACZX,OAAOW,IAAI,CAAC;YACZX,OAAOW,IAAI,CAAC;QACd;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function countNestedFolders(path: string): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/countNestedFolders.ts"],"sourcesContent":["export function countNestedFolders(path: string): number {\n const separator = path.includes('\\\\') ? '\\\\' : '/'\n return path.split(separator).filter(Boolean).length\n}\n"],"names":["countNestedFolders","path","separator","includes","split","filter","Boolean","length"],"mappings":"AAAA,OAAO,SAASA,mBAAmBC,IAAY;IAC7C,MAAMC,YAAYD,KAAKE,QAAQ,CAAC,QAAQ,OAAO;IAC/C,OAAOF,KAAKG,KAAK,CAACF,WAAWG,MAAM,CAACC,SAASC,MAAM;AACrD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { processTemplate } from './processTemplate.js';
|
|
2
|
+
const defaultAppTemplate = `
|
|
3
|
+
import {defineCliConfig} from 'sanity/cli'
|
|
4
|
+
|
|
5
|
+
export default defineCliConfig({
|
|
6
|
+
app: {
|
|
7
|
+
organizationId: '%organizationId%',
|
|
8
|
+
entry: '%entry%',
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
`;
|
|
12
|
+
export function createAppCliConfig(options) {
|
|
13
|
+
return processTemplate({
|
|
14
|
+
template: defaultAppTemplate,
|
|
15
|
+
variables: options
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=createAppCliConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/createAppCliConfig.ts"],"sourcesContent":["import {processTemplate} from './processTemplate.js'\n\nconst defaultAppTemplate = `\nimport {defineCliConfig} from 'sanity/cli'\n\nexport default defineCliConfig({\n app: {\n organizationId: '%organizationId%',\n entry: '%entry%',\n },\n})\n`\n\nexport interface GenerateCliConfigOptions {\n entry: string\n\n organizationId?: string\n}\n\nexport function createAppCliConfig(options: GenerateCliConfigOptions): string {\n return processTemplate({\n template: defaultAppTemplate,\n variables: options,\n })\n}\n"],"names":["processTemplate","defaultAppTemplate","createAppCliConfig","options","template","variables"],"mappings":"AAAA,SAAQA,eAAe,QAAO,uBAAsB;AAEpD,MAAMC,qBAAqB,CAAC;;;;;;;;;AAS5B,CAAC;AAQD,OAAO,SAASC,mBAAmBC,OAAiC;IAClE,OAAOH,gBAAgB;QACrBI,UAAUH;QACVI,WAAWF;IACb;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { processTemplate } from './processTemplate.js';
|
|
2
|
+
const defaultTemplate = `
|
|
3
|
+
import {defineCliConfig} from 'sanity/cli'
|
|
4
|
+
|
|
5
|
+
export default defineCliConfig({
|
|
6
|
+
api: {
|
|
7
|
+
projectId: '%projectId%',
|
|
8
|
+
dataset: '%dataset%'
|
|
9
|
+
},
|
|
10
|
+
deployment: {
|
|
11
|
+
/**
|
|
12
|
+
* Enable auto-updates for studios.
|
|
13
|
+
* Learn more at https://www.sanity.io/docs/studio/latest-version-of-sanity#k47faf43faf56
|
|
14
|
+
*/
|
|
15
|
+
autoUpdates: __BOOL__autoUpdates__,
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
`;
|
|
19
|
+
export function createCliConfig(options) {
|
|
20
|
+
return processTemplate({
|
|
21
|
+
includeBooleanTransform: true,
|
|
22
|
+
template: defaultTemplate,
|
|
23
|
+
variables: options
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=createCliConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/init/createCliConfig.ts"],"sourcesContent":["import {processTemplate} from './processTemplate.js'\n\nconst defaultTemplate = `\nimport {defineCliConfig} from 'sanity/cli'\n\nexport default defineCliConfig({\n api: {\n projectId: '%projectId%',\n dataset: '%dataset%'\n },\n deployment: {\n /**\n * Enable auto-updates for studios.\n * Learn more at https://www.sanity.io/docs/studio/latest-version-of-sanity#k47faf43faf56\n */\n autoUpdates: __BOOL__autoUpdates__,\n }\n})\n`\n\nexport interface GenerateCliConfigOptions {\n autoUpdates: boolean\n dataset: string\n projectId: string\n}\n\nexport function createCliConfig(options: GenerateCliConfigOptions): string {\n return processTemplate({\n includeBooleanTransform: true,\n template: defaultTemplate,\n variables: options,\n })\n}\n"],"names":["processTemplate","defaultTemplate","createCliConfig","options","includeBooleanTransform","template","variables"],"mappings":"AAAA,SAAQA,eAAe,QAAO,uBAAsB;AAEpD,MAAMC,kBAAkB,CAAC;;;;;;;;;;;;;;;;AAgBzB,CAAC;AAQD,OAAO,SAASC,gBAAgBC,OAAiC;IAC/D,OAAOH,gBAAgB;QACrBI,yBAAyB;QACzBC,UAAUJ;QACVK,WAAWH;IACb;AACF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import sortObject from 'deep-sort-object';
|
|
2
|
+
const manifestPropOrder = [
|
|
3
|
+
'name',
|
|
4
|
+
'private',
|
|
5
|
+
'version',
|
|
6
|
+
'description',
|
|
7
|
+
'main',
|
|
8
|
+
'author',
|
|
9
|
+
'license',
|
|
10
|
+
'scripts',
|
|
11
|
+
'keywords',
|
|
12
|
+
'dependencies',
|
|
13
|
+
'devDependencies'
|
|
14
|
+
];
|
|
15
|
+
export function createPackageManifest(data) {
|
|
16
|
+
const { isAppTemplate } = data;
|
|
17
|
+
const dependencies = data.dependencies ? {
|
|
18
|
+
dependencies: sortObject(data.dependencies)
|
|
19
|
+
} : {};
|
|
20
|
+
const devDependencies = data.devDependencies ? {
|
|
21
|
+
devDependencies: sortObject(data.devDependencies)
|
|
22
|
+
} : {};
|
|
23
|
+
// Don't write a prettier config for SDK apps; we want to allow developers to use their own
|
|
24
|
+
const prettierConfig = isAppTemplate ? {} : {
|
|
25
|
+
prettier: {
|
|
26
|
+
bracketSpacing: false,
|
|
27
|
+
printWidth: 100,
|
|
28
|
+
semi: false,
|
|
29
|
+
singleQuote: true
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const pkg = {
|
|
33
|
+
...getCommonManifest(data),
|
|
34
|
+
keywords: [
|
|
35
|
+
'sanity'
|
|
36
|
+
],
|
|
37
|
+
main: 'package.json',
|
|
38
|
+
scripts: data.scripts || {
|
|
39
|
+
build: 'sanity build',
|
|
40
|
+
deploy: 'sanity deploy',
|
|
41
|
+
'deploy-graphql': 'sanity graphql deploy',
|
|
42
|
+
dev: 'sanity dev',
|
|
43
|
+
start: 'sanity start'
|
|
44
|
+
},
|
|
45
|
+
...dependencies,
|
|
46
|
+
...devDependencies,
|
|
47
|
+
...prettierConfig
|
|
48
|
+
};
|
|
49
|
+
return serializeManifest(pkg);
|
|
50
|
+
}
|
|
51
|
+
function getCommonManifest(data) {
|
|
52
|
+
const pkg = {
|
|
53
|
+
author: data.author,
|
|
54
|
+
description: data.description,
|
|
55
|
+
devDependencies: {},
|
|
56
|
+
license: data.license || 'UNLICENSED',
|
|
57
|
+
name: data.name,
|
|
58
|
+
version: '1.0.0'
|
|
59
|
+
};
|
|
60
|
+
if (pkg.license === 'UNLICENSED') {
|
|
61
|
+
pkg.private = true;
|
|
62
|
+
}
|
|
63
|
+
if (data.gitRemote) {
|
|
64
|
+
pkg.repository = {
|
|
65
|
+
type: 'git',
|
|
66
|
+
url: data.gitRemote
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return pkg;
|
|
70
|
+
}
|
|
71
|
+
function serializeManifest(src) {
|
|
72
|
+
const props = [
|
|
73
|
+
...manifestPropOrder,
|
|
74
|
+
...Object.keys(src)
|
|
75
|
+
];
|
|
76
|
+
const ordered = {};
|
|
77
|
+
for (const prop of props){
|
|
78
|
+
const source = src;
|
|
79
|
+
if (source[prop] !== undefined && ordered[prop] === undefined) {
|
|
80
|
+
ordered[prop] = source[prop];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return `${JSON.stringify(ordered, null, 2)}\n`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=createPackageManifest.js.map
|