@sanity/cli 3.74.0 → 3.74.2-corel.18
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/bin/xdg-open +1066 -0
- package/lib/_chunks-cjs/cli.js +127 -73
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/index.d.mts +9 -0
- package/lib/index.d.ts +9 -0
- package/package.json +8 -8
- package/src/actions/init-project/bootstrapLocalTemplate.ts +32 -20
- package/src/actions/init-project/createCliConfig.ts +5 -47
- package/src/actions/init-project/createCoreAppCliConfig.ts +23 -0
- package/src/actions/init-project/createPackageManifest.ts +1 -1
- package/src/actions/init-project/createStudioConfig.ts +4 -27
- package/src/actions/init-project/determineCoreAppTemplate.ts +13 -0
- package/src/actions/init-project/initProject.ts +21 -2
- package/src/actions/init-project/processTemplate.ts +55 -0
- package/src/actions/init-project/templates/coreApp.ts +31 -0
- package/src/actions/init-project/templates/index.ts +2 -0
- package/src/types.ts +10 -0
- package/templates/core-app/src/App.tsx +26 -0
package/lib/_chunks-cjs/cli.js
CHANGED
@@ -46514,23 +46514,8 @@ var typescriptExports = requireTypescript(), typescript = /* @__PURE__ */ loadEn
|
|
46514
46514
|
__proto__: null,
|
46515
46515
|
default: typescript
|
46516
46516
|
}, [typescriptExports]);
|
46517
|
-
|
46518
|
-
|
46519
|
-
|
46520
|
-
export default defineCliConfig({
|
46521
|
-
api: {
|
46522
|
-
projectId: '%projectId%',
|
46523
|
-
dataset: '%dataset%'
|
46524
|
-
},
|
46525
|
-
/**
|
46526
|
-
* Enable auto-updates for studios.
|
46527
|
-
* Learn more at https://www.sanity.io/docs/cli#auto-updates
|
46528
|
-
*/
|
46529
|
-
autoUpdates: __BOOL__autoUpdates__,
|
46530
|
-
})
|
46531
|
-
`;
|
46532
|
-
function createCliConfig(options2) {
|
46533
|
-
const variables = options2, template = defaultTemplate$1.trimStart(), ast = mainExports.parse(template, { parser });
|
46517
|
+
function processTemplate(options2) {
|
46518
|
+
const { template, variables, includeBooleanTransform = !1 } = options2, ast = mainExports.parse(template.trimStart(), { parser });
|
46534
46519
|
return traverse__default.default(ast, {
|
46535
46520
|
StringLiteral: {
|
46536
46521
|
enter({ node }) {
|
@@ -46544,24 +46529,60 @@ function createCliConfig(options2) {
|
|
46544
46529
|
node.value = typeof newValue == "string" ? newValue : "";
|
46545
46530
|
}
|
46546
46531
|
},
|
46547
|
-
|
46548
|
-
|
46549
|
-
|
46550
|
-
|
46551
|
-
|
46552
|
-
/^__BOOL__(.+?)__$/,
|
46553
|
-
|
46554
|
-
|
46555
|
-
|
46556
|
-
|
46557
|
-
|
46558
|
-
|
46559
|
-
|
46560
|
-
path2.replaceWith({ type: "BooleanLiteral", value });
|
46532
|
+
...includeBooleanTransform && {
|
46533
|
+
Identifier: {
|
46534
|
+
enter(path2) {
|
46535
|
+
if (!path2.node.name.startsWith("__BOOL__"))
|
46536
|
+
return;
|
46537
|
+
const variableName = path2.node.name.replace(/^__BOOL__(.+?)__$/, "$1");
|
46538
|
+
if (!(variableName in variables))
|
46539
|
+
throw new Error(`Template variable '${variableName.toString()}' not defined`);
|
46540
|
+
const value = variables[variableName];
|
46541
|
+
if (typeof value != "boolean")
|
46542
|
+
throw new Error(`Expected boolean value for '${variableName.toString()}'`);
|
46543
|
+
path2.replaceWith({ type: "BooleanLiteral", value });
|
46544
|
+
}
|
46561
46545
|
}
|
46562
46546
|
}
|
46563
46547
|
}), mainExports.print(ast, { quote: "single" }).code;
|
46564
46548
|
}
|
46549
|
+
const defaultTemplate$1 = `
|
46550
|
+
import {defineCliConfig} from 'sanity/cli'
|
46551
|
+
|
46552
|
+
export default defineCliConfig({
|
46553
|
+
api: {
|
46554
|
+
projectId: '%projectId%',
|
46555
|
+
dataset: '%dataset%'
|
46556
|
+
},
|
46557
|
+
/**
|
46558
|
+
* Enable auto-updates for studios.
|
46559
|
+
* Learn more at https://www.sanity.io/docs/cli#auto-updates
|
46560
|
+
*/
|
46561
|
+
autoUpdates: __BOOL__autoUpdates__,
|
46562
|
+
})
|
46563
|
+
`;
|
46564
|
+
function createCliConfig(options2) {
|
46565
|
+
return processTemplate({
|
46566
|
+
template: defaultTemplate$1,
|
46567
|
+
variables: options2,
|
46568
|
+
includeBooleanTransform: !0
|
46569
|
+
});
|
46570
|
+
}
|
46571
|
+
const defaultCoreAppTemplate = `
|
46572
|
+
import {defineCliConfig} from 'sanity/cli'
|
46573
|
+
|
46574
|
+
export default defineCliConfig({
|
46575
|
+
__experimental_coreAppConfiguration: {
|
46576
|
+
appLocation: '%appLocation%'
|
46577
|
+
},
|
46578
|
+
})
|
46579
|
+
`;
|
46580
|
+
function createCoreAppCliConfig(options2) {
|
46581
|
+
return processTemplate({
|
46582
|
+
template: defaultCoreAppTemplate,
|
46583
|
+
variables: options2
|
46584
|
+
});
|
46585
|
+
}
|
46565
46586
|
/*!
|
46566
46587
|
* isobject <https://github.com/jonschlinkert/isobject>
|
46567
46588
|
*
|
@@ -46630,7 +46651,7 @@ function createPackageManifest(data) {
|
|
46630
46651
|
...getCommonManifest(data),
|
46631
46652
|
main: "package.json",
|
46632
46653
|
keywords: ["sanity"],
|
46633
|
-
scripts: {
|
46654
|
+
scripts: data.scripts || {
|
46634
46655
|
dev: "sanity dev",
|
46635
46656
|
start: "sanity start",
|
46636
46657
|
build: "sanity build",
|
@@ -46699,25 +46720,42 @@ export default defineConfig({
|
|
46699
46720
|
};
|
46700
46721
|
function createStudioConfig(options2) {
|
46701
46722
|
const variables = { ...defaultVariables, ...options2.variables };
|
46702
|
-
|
46703
|
-
|
46704
|
-
|
46705
|
-
|
46706
|
-
StringLiteral: {
|
46707
|
-
enter({ node }) {
|
46708
|
-
const value = node.value;
|
46709
|
-
if (!value.startsWith("%") || !value.endsWith("%"))
|
46710
|
-
return;
|
46711
|
-
const variableName = value.slice(1, -1);
|
46712
|
-
if (!(variableName in variables))
|
46713
|
-
throw new Error(`Template variable '${value}' not defined`);
|
46714
|
-
const newValue = variables[variableName];
|
46715
|
-
node.value = typeof newValue == "string" ? newValue : "";
|
46716
|
-
}
|
46717
|
-
}
|
46718
|
-
}), mainExports.print(ast, { quote: "single" }).code;
|
46723
|
+
return typeof options2.template == "function" ? options2.template(variables).trimStart() : processTemplate({
|
46724
|
+
template: options2.template || defaultTemplate,
|
46725
|
+
variables
|
46726
|
+
});
|
46719
46727
|
}
|
46720
|
-
const
|
46728
|
+
const coreAppTemplates = ["core-app"];
|
46729
|
+
function determineCoreAppTemplate(templateName) {
|
46730
|
+
return coreAppTemplates.includes(templateName);
|
46731
|
+
}
|
46732
|
+
const blogTemplate = {}, cleanTemplate = {}, coreAppTemplate = {
|
46733
|
+
dependencies: {
|
46734
|
+
"@sanity/sdk": "^0.0.0-alpha",
|
46735
|
+
"@sanity/sdk-react": "^0.0.0-alpha",
|
46736
|
+
react: "^19",
|
46737
|
+
"react-dom": "^19"
|
46738
|
+
},
|
46739
|
+
devDependencies: {
|
46740
|
+
/*
|
46741
|
+
* this will be changed to eslint-config sanity,
|
46742
|
+
* eslint.config generation will be a fast follow
|
46743
|
+
*/
|
46744
|
+
"@sanity/eslint-config-studio": "^5.0.1",
|
46745
|
+
"@types/react": "^18.0.25",
|
46746
|
+
eslint: "^9.9.0",
|
46747
|
+
prettier: "^3.0.2",
|
46748
|
+
sanity: "^3",
|
46749
|
+
typescript: "^5.1.6"
|
46750
|
+
},
|
46751
|
+
appLocation: "./src/App.tsx",
|
46752
|
+
scripts: {
|
46753
|
+
// this will eventually run a concurrently process with another in-flight utility
|
46754
|
+
dev: "sanity app dev",
|
46755
|
+
build: "sanity app build",
|
46756
|
+
start: "sanity app start"
|
46757
|
+
}
|
46758
|
+
}, configTemplate$3 = `
|
46721
46759
|
import {defineConfig, isDev} from 'sanity'
|
46722
46760
|
import {visionTool} from '@sanity/vision'
|
46723
46761
|
import {structureTool} from 'sanity/structure'
|
@@ -46895,6 +46933,7 @@ export default defineConfig({
|
|
46895
46933
|
}, templates = {
|
46896
46934
|
blog: blogTemplate,
|
46897
46935
|
clean: cleanTemplate,
|
46936
|
+
"core-app": coreAppTemplate,
|
46898
46937
|
"get-started": getStartedTemplate,
|
46899
46938
|
moviedb: movieTemplate,
|
46900
46939
|
shopify: shopifyTemplate$1,
|
@@ -46915,7 +46954,7 @@ async function updateInitialTemplateMetadata(apiClient, projectId, templateName)
|
|
46915
46954
|
}
|
46916
46955
|
}
|
46917
46956
|
async function bootstrapLocalTemplate(opts, context) {
|
46918
|
-
const { apiClient, cliRoot, output } = context, templatesDir = path__default.default.join(cliRoot, "templates"), { outputPath, templateName, useTypeScript, packageName, variables } = opts, sourceDir = path__default.default.join(templatesDir, templateName), sharedDir = path__default.default.join(templatesDir, "shared"), template = templates[templateName];
|
46957
|
+
const { apiClient, cliRoot, output } = context, templatesDir = path__default.default.join(cliRoot, "templates"), { outputPath, templateName, useTypeScript, packageName, variables } = opts, sourceDir = path__default.default.join(templatesDir, templateName), sharedDir = path__default.default.join(templatesDir, "shared"), isCoreAppTemplate = determineCoreAppTemplate(templateName), template = templates[templateName];
|
46919
46958
|
if (!template)
|
46920
46959
|
throw new Error(`Template "${templateName}" not defined`);
|
46921
46960
|
loadEnv.debug('Copying files from template "%s" to "%s"', templateName, outputPath);
|
@@ -46930,19 +46969,20 @@ async function bootstrapLocalTemplate(opts, context) {
|
|
46930
46969
|
schemaUrl: opts.schemaUrl
|
46931
46970
|
})), spinner.succeed(), spinner = output.spinner("Resolving latest module versions").start();
|
46932
46971
|
const dependencyVersions = await resolveLatestVersions({
|
46933
|
-
...studioDependencies.dependencies,
|
46934
|
-
...studioDependencies.devDependencies,
|
46935
|
-
...template.dependencies || {}
|
46972
|
+
...isCoreAppTemplate ? {} : studioDependencies.dependencies,
|
46973
|
+
...isCoreAppTemplate ? {} : studioDependencies.devDependencies,
|
46974
|
+
...template.dependencies || {},
|
46975
|
+
...template.devDependencies || {}
|
46936
46976
|
});
|
46937
46977
|
spinner.succeed();
|
46938
46978
|
const dependencies = Object.keys({
|
46939
|
-
...studioDependencies.dependencies,
|
46979
|
+
...isCoreAppTemplate ? {} : studioDependencies.dependencies,
|
46940
46980
|
...template.dependencies
|
46941
46981
|
}).reduce(
|
46942
46982
|
(deps, dependency) => (deps[dependency] = dependencyVersions[dependency], deps),
|
46943
46983
|
{}
|
46944
46984
|
), devDependencies = Object.keys({
|
46945
|
-
...studioDependencies.devDependencies,
|
46985
|
+
...isCoreAppTemplate ? {} : studioDependencies.devDependencies,
|
46946
46986
|
...template.devDependencies
|
46947
46987
|
}).reduce(
|
46948
46988
|
(deps, dependency) => (deps[dependency] = dependencyVersions[dependency], deps),
|
@@ -46952,27 +46992,30 @@ async function bootstrapLocalTemplate(opts, context) {
|
|
46952
46992
|
const packageManifest = await createPackageManifest({
|
46953
46993
|
name: packageName,
|
46954
46994
|
dependencies,
|
46955
|
-
devDependencies
|
46956
|
-
|
46995
|
+
devDependencies,
|
46996
|
+
scripts: template.scripts
|
46997
|
+
}), studioConfig = createStudioConfig({
|
46957
46998
|
template: template.configTemplate,
|
46958
46999
|
variables
|
46959
|
-
}), cliConfig =
|
47000
|
+
}), cliConfig = isCoreAppTemplate ? createCoreAppCliConfig({ appLocation: template.appLocation }) : createCliConfig({
|
46960
47001
|
projectId: variables.projectId,
|
46961
47002
|
dataset: variables.dataset,
|
46962
47003
|
autoUpdates: variables.autoUpdates
|
46963
47004
|
}), codeExt = useTypeScript ? "ts" : "js";
|
46964
|
-
return await Promise.all(
|
46965
|
-
|
46966
|
-
|
46967
|
-
|
46968
|
-
|
46969
|
-
|
46970
|
-
|
47005
|
+
return await Promise.all(
|
47006
|
+
[
|
47007
|
+
isCoreAppTemplate ? Promise.resolve(null) : writeFileIfNotExists(`sanity.config.${codeExt}`, studioConfig),
|
47008
|
+
writeFileIfNotExists(`sanity.cli.${codeExt}`, cliConfig),
|
47009
|
+
writeFileIfNotExists("package.json", packageManifest),
|
47010
|
+
writeFileIfNotExists(
|
47011
|
+
"eslint.config.mjs",
|
47012
|
+
`import studio from '@sanity/eslint-config-studio'
|
46971
47013
|
|
46972
47014
|
export default [...studio]
|
46973
47015
|
`
|
46974
|
-
|
46975
|
-
|
47016
|
+
)
|
47017
|
+
].filter(Boolean)
|
47018
|
+
), loadEnv.debug("Updating initial template metadata"), await updateInitialTemplateMetadata(apiClient, variables.projectId, `cli-${templateName}`), spinner.succeed(), template;
|
46976
47019
|
async function writeFileIfNotExists(fileName, content) {
|
46977
47020
|
const filePath = path__default.default.join(outputPath, fileName);
|
46978
47021
|
try {
|
@@ -52591,7 +52634,7 @@ ${err.message}`);
|
|
52591
52634
|
} else unattended || (trace.log({ step: "login" }), await getOrCreateUser());
|
52592
52635
|
let introMessage = "Fetching existing projects";
|
52593
52636
|
cliFlags.quickstart && (introMessage = "Eject your existing project's Sanity configuration"), success(introMessage), print("");
|
52594
|
-
const flags = await prepareFlags(), { projectId, displayName, isFirstProject, datasetName, schemaUrl } = await getProjectDetails(), sluggedName = lodashExports.deburr(displayName.toLowerCase()).replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
|
52637
|
+
const flags = await prepareFlags(), isCoreAppTemplate = cliFlags.template ? determineCoreAppTemplate(cliFlags.template) : !1, { projectId, displayName, isFirstProject, datasetName, schemaUrl } = await getProjectDetails(), sluggedName = lodashExports.deburr(displayName.toLowerCase()).replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
|
52595
52638
|
if (bareOutput) {
|
52596
52639
|
success("Below are your project details"), print(""), print(`Project ID: ${chalk2.cyan(projectId)}`), print(`Dataset: ${chalk2.cyan(datasetName)}`), print(
|
52597
52640
|
`
|
@@ -52781,11 +52824,15 @@ ${chalk2.green("Success!")} Your Sanity configuration files has been added to th
|
|
52781
52824
|
}[pkgManager];
|
52782
52825
|
outputPath === process.cwd() ? (print(`
|
52783
52826
|
${chalk2.green("Success!")} Now, use this command to continue:
|
52784
|
-
`), print(
|
52785
|
-
|
52827
|
+
`), print(
|
52828
|
+
`${chalk2.cyan(devCommand)} - to run ${isCoreAppTemplate ? "your Sanity application" : "Sanity Studio"}
|
52829
|
+
`
|
52830
|
+
)) : (print(`
|
52786
52831
|
${chalk2.green("Success!")} Now, use these commands to continue:
|
52787
|
-
`), print(`First: ${chalk2.cyan(`cd ${outputPath}`)} - to enter project\u2019s directory`), print(
|
52788
|
-
`
|
52832
|
+
`), print(`First: ${chalk2.cyan(`cd ${outputPath}`)} - to enter project\u2019s directory`), print(
|
52833
|
+
`Then: ${chalk2.cyan(devCommand)} -to run ${isCoreAppTemplate ? "your Sanity application" : "Sanity Studio"}
|
52834
|
+
`
|
52835
|
+
)), print("Other helpful commands"), print("npx sanity docs - to open the documentation in a browser"), print("npx sanity manage - to open the project settings in a browser"), print("npx sanity help - to explore the CLI manual");
|
52789
52836
|
const sendInvite = isFirstProject && await prompt2.single({
|
52790
52837
|
type: "confirm",
|
52791
52838
|
message: "We have an excellent developer community, would you like us to send you an invitation to join?",
|
@@ -52812,6 +52859,13 @@ ${chalk2.green("Success!")} Now, use these commands to continue:
|
|
52812
52859
|
isFirstProject: data.isFirstProject
|
52813
52860
|
}), data;
|
52814
52861
|
}
|
52862
|
+
if (isCoreAppTemplate)
|
52863
|
+
return {
|
52864
|
+
projectId: "",
|
52865
|
+
displayName: "",
|
52866
|
+
isFirstProject: !1,
|
52867
|
+
datasetName: ""
|
52868
|
+
};
|
52815
52869
|
loadEnv.debug("Prompting user to select or create a project");
|
52816
52870
|
const project = await getOrCreateProject();
|
52817
52871
|
loadEnv.debug(`Project with name ${project.displayName} selected`), loadEnv.debug("Prompting user to select or create a dataset");
|