@sanity/cli 3.93.1-next.8.cf0bf8550a → 3.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/cli.js +1 -1
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/package.json +10 -11
- package/templates/blog/README.md +1 -1
- package/templates/clean/README.md +1 -1
- package/templates/ecommerce/README.md +1 -1
- package/templates/get-started/README.md +1 -1
- package/templates/moviedb/README.md +1 -1
- package/templates/quickstart/README.md +1 -1
- package/src/CommandRunner.ts +0 -219
- package/src/__telemetry__/cli.telemetry.ts +0 -29
- package/src/__telemetry__/init.telemetry.ts +0 -95
- package/src/actions/codemod/codemodAction.ts +0 -109
- package/src/actions/codemod/mods/deskRename.ts +0 -19
- package/src/actions/codemod/mods/index.ts +0 -9
- package/src/actions/codemod/mods/partsTypeDirective.ts +0 -28
- package/src/actions/codemod/mods/reactIconsV3.ts +0 -54
- package/src/actions/codemod/types.ts +0 -10
- package/src/actions/init-plugin/bootstrapFromTemplate.ts +0 -196
- package/src/actions/init-project/bootstrapLocalTemplate.ts +0 -201
- package/src/actions/init-project/bootstrapRemoteTemplate.ts +0 -118
- package/src/actions/init-project/createAppCliConfig.ts +0 -24
- package/src/actions/init-project/createCliConfig.ts +0 -31
- package/src/actions/init-project/createPackageManifest.ts +0 -102
- package/src/actions/init-project/createStudioConfig.ts +0 -53
- package/src/actions/init-project/determineAppTemplate.ts +0 -13
- package/src/actions/init-project/fsUtils.ts +0 -40
- package/src/actions/init-project/git.ts +0 -59
- package/src/actions/init-project/initProject.ts +0 -1708
- package/src/actions/init-project/processTemplate.ts +0 -55
- package/src/actions/init-project/promptForDatasetName.ts +0 -68
- package/src/actions/init-project/prompts/index.ts +0 -51
- package/src/actions/init-project/prompts/nextjs.ts +0 -59
- package/src/actions/init-project/readPackageJson.ts +0 -17
- package/src/actions/init-project/templates/appQuickstart.ts +0 -23
- package/src/actions/init-project/templates/appSanityUi.ts +0 -25
- package/src/actions/init-project/templates/blog.ts +0 -5
- package/src/actions/init-project/templates/clean.ts +0 -5
- package/src/actions/init-project/templates/getStarted.ts +0 -37
- package/src/actions/init-project/templates/index.ts +0 -24
- package/src/actions/init-project/templates/moviedb.ts +0 -35
- package/src/actions/init-project/templates/nextjs/index.ts +0 -238
- package/src/actions/init-project/templates/nextjs/schemaTypes/blog.ts +0 -252
- package/src/actions/init-project/templates/quickstart.ts +0 -5
- package/src/actions/init-project/templates/shopify.ts +0 -78
- package/src/actions/init-project/templates/shopifyOnline.ts +0 -50
- package/src/actions/init-project/updateInitialTemplateMetadata.ts +0 -24
- package/src/actions/login/login.telemetry.ts +0 -18
- package/src/actions/login/login.ts +0 -350
- package/src/actions/login/types.ts +0 -19
- package/src/actions/project/createProject.ts +0 -36
- package/src/actions/telemetry/setTelemetryConsent.ts +0 -101
- package/src/actions/typegen/generate.telemetry.ts +0 -20
- package/src/actions/typegen/generateAction.ts +0 -210
- package/src/actions/versions/findSanityModuleVersions.ts +0 -185
- package/src/actions/yarn/events.ts +0 -73
- package/src/cli.ts +0 -350
- package/src/cliClient.ts +0 -62
- package/src/commands/blueprints/addBlueprintsCommand.ts +0 -155
- package/src/commands/blueprints/blueprintsGroup.ts +0 -10
- package/src/commands/blueprints/configBlueprintsCommand.ts +0 -86
- package/src/commands/blueprints/deployBlueprintsCommand.ts +0 -63
- package/src/commands/blueprints/destroyBlueprintsCommand.ts +0 -78
- package/src/commands/blueprints/infoBlueprintsCommand.ts +0 -55
- package/src/commands/blueprints/initBlueprintsCommand.ts +0 -99
- package/src/commands/blueprints/logsBlueprintsCommand.ts +0 -66
- package/src/commands/blueprints/planBlueprintsCommand.ts +0 -51
- package/src/commands/blueprints/stacksBlueprintsCommand.ts +0 -66
- package/src/commands/codemod/codemodCommand.ts +0 -32
- package/src/commands/debug/debugCommand.ts +0 -26
- package/src/commands/debug/printDebugInfo.ts +0 -243
- package/src/commands/docs/docsCommand.ts +0 -20
- package/src/commands/functions/devFunctionsCommand.ts +0 -73
- package/src/commands/functions/envFunctionsCommand.ts +0 -105
- package/src/commands/functions/functionsGroup.ts +0 -10
- package/src/commands/functions/logsFunctionsCommand.ts +0 -94
- package/src/commands/functions/testFunctionsCommand.ts +0 -93
- package/src/commands/help/helpCommand.ts +0 -21
- package/src/commands/help/showHelp.ts +0 -58
- package/src/commands/index.ts +0 -72
- package/src/commands/init/initCommand.ts +0 -123
- package/src/commands/install/installCommand.ts +0 -38
- package/src/commands/learn/learnCommand.ts +0 -20
- package/src/commands/login/loginCommand.ts +0 -29
- package/src/commands/logout/logoutCommand.ts +0 -52
- package/src/commands/manage/manageCommand.ts +0 -24
- package/src/commands/projects/listProjectsCommand.ts +0 -62
- package/src/commands/projects/projectsGroup.ts +0 -10
- package/src/commands/telemetry/disableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/enableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/telemetryGroup.ts +0 -10
- package/src/commands/telemetry/telemetryStatusCommand.ts +0 -89
- package/src/commands/typegen/generateTypesCommand.ts +0 -56
- package/src/commands/typegen/typegenGroup.ts +0 -10
- package/src/commands/versions/printVersionResult.ts +0 -51
- package/src/commands/versions/versionsCommand.ts +0 -13
- package/src/config.ts +0 -14
- package/src/debug.ts +0 -3
- package/src/index.ts +0 -6
- package/src/outputters/cliOutputter.ts +0 -47
- package/src/packageManager/getInstallCommand.ts +0 -26
- package/src/packageManager/getUpgradeCommand.ts +0 -52
- package/src/packageManager/index.ts +0 -33
- package/src/packageManager/installPackages.ts +0 -99
- package/src/packageManager/packageManagerChoice.ts +0 -204
- package/src/packageManager/uninstallPackages.ts +0 -44
- package/src/packageManager/yarnStub.ts +0 -22
- package/src/prompters/cliPrompter.ts +0 -9
- package/src/run.ts +0 -8
- package/src/studioDependencies.ts +0 -25
- package/src/types.ts +0 -387
- package/src/util/canLaunchBrowser.ts +0 -12
- package/src/util/cliWorker.ts +0 -34
- package/src/util/clientWrapper.ts +0 -119
- package/src/util/copy.ts +0 -50
- package/src/util/createExpiringConfig.ts +0 -80
- package/src/util/createTelemetryStore.ts +0 -204
- package/src/util/detectRuntime.ts +0 -12
- package/src/util/dynamicRequire.ts +0 -17
- package/src/util/frameworkPort.ts +0 -63
- package/src/util/generateCommandsDocumentation.ts +0 -62
- package/src/util/getCliConfig.ts +0 -172
- package/src/util/getCliVersion.ts +0 -22
- package/src/util/getLocalVersion.ts +0 -35
- package/src/util/getProjectDefaults.ts +0 -103
- package/src/util/getProviderName.ts +0 -9
- package/src/util/getUserConfig.ts +0 -15
- package/src/util/isCi.ts +0 -7
- package/src/util/isCommandGroup.ts +0 -7
- package/src/util/isInteractive.ts +0 -3
- package/src/util/isTrueish.ts +0 -8
- package/src/util/journeyConfig.ts +0 -280
- package/src/util/loadEnv.ts +0 -110
- package/src/util/mergeCommands.ts +0 -78
- package/src/util/neatStack.ts +0 -30
- package/src/util/noSuchCommandText.ts +0 -91
- package/src/util/parseArguments.ts +0 -76
- package/src/util/pathExists.ts +0 -14
- package/src/util/readJson.ts +0 -6
- package/src/util/readdirRecursive.ts +0 -26
- package/src/util/remoteTemplate.ts +0 -320
- package/src/util/resolveLatestVersions.ts +0 -24
- package/src/util/resolveRootDir.ts +0 -59
- package/src/util/telemetryDisclosure.ts +0 -45
- package/src/util/updateNotifier.ts +0 -158
- package/src/util/writeJson.ts +0 -6
- package/src/workers/getAndWriteJourneySchema.ts +0 -7
- package/src/workers/getCliConfig.ts +0 -14
- package/src/workers/typegenGenerate.ts +0 -228
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.94.0",
|
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"bin",
|
|
44
44
|
"codemods",
|
|
45
45
|
"lib",
|
|
46
|
-
"src",
|
|
47
46
|
"templates"
|
|
48
47
|
],
|
|
49
48
|
"scripts": {
|
|
@@ -59,32 +58,32 @@
|
|
|
59
58
|
"dependencies": {
|
|
60
59
|
"@babel/traverse": "^7.27.4",
|
|
61
60
|
"@sanity/client": "^7.6.0",
|
|
62
|
-
"@sanity/codegen": "3.
|
|
61
|
+
"@sanity/codegen": "3.94.0",
|
|
63
62
|
"@sanity/runtime-cli": "^8.1.0",
|
|
64
63
|
"@sanity/telemetry": "^0.8.0",
|
|
65
64
|
"@sanity/template-validator": "^2.4.3",
|
|
66
|
-
"@sanity/util": "3.
|
|
65
|
+
"@sanity/util": "3.94.0",
|
|
67
66
|
"chalk": "^4.1.2",
|
|
68
67
|
"debug": "^4.3.4",
|
|
69
68
|
"decompress": "^4.2.0",
|
|
70
69
|
"esbuild": "0.25.5",
|
|
71
70
|
"esbuild-register": "^3.6.0",
|
|
72
71
|
"get-it": "^8.6.9",
|
|
73
|
-
"groq-js": "^1.17.
|
|
72
|
+
"groq-js": "^1.17.1",
|
|
74
73
|
"pkg-dir": "^5.0.0",
|
|
75
74
|
"prettier": "^3.5.3",
|
|
76
75
|
"semver": "^7.3.5",
|
|
77
76
|
"validate-npm-package-name": "^3.0.0"
|
|
78
77
|
},
|
|
79
78
|
"devDependencies": {
|
|
80
|
-
"@repo/eslint-config": "3.
|
|
81
|
-
"@repo/package.config": "3.
|
|
82
|
-
"@repo/test-config": "3.
|
|
79
|
+
"@repo/eslint-config": "3.94.0",
|
|
80
|
+
"@repo/package.config": "3.94.0",
|
|
81
|
+
"@repo/test-config": "3.94.0",
|
|
83
82
|
"@rexxars/gitconfiglocal": "^3.0.1",
|
|
84
|
-
"@rollup/plugin-node-resolve": "^
|
|
83
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
85
84
|
"@sanity/eslint-config-studio": "^5.0.2",
|
|
86
85
|
"@sanity/generate-help-url": "^3.0.0",
|
|
87
|
-
"@sanity/types": "3.
|
|
86
|
+
"@sanity/types": "3.94.0",
|
|
88
87
|
"@types/babel__traverse": "^7.20.5",
|
|
89
88
|
"@types/configstore": "^5.0.1",
|
|
90
89
|
"@types/cpx": "^1.5.2",
|
|
@@ -137,5 +136,5 @@
|
|
|
137
136
|
"engines": {
|
|
138
137
|
"node": ">=18"
|
|
139
138
|
},
|
|
140
|
-
"gitHead": "
|
|
139
|
+
"gitHead": "e1dbdccb42e5551644aa17861f557ea475d0cceb"
|
|
141
140
|
}
|
package/templates/blog/README.md
CHANGED
|
@@ -7,5 +7,5 @@ Now you can do the following things:
|
|
|
7
7
|
- [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
|
|
8
8
|
- Check out the example frontend: [React/Next.js](https://github.com/sanity-io/tutorial-sanity-blog-react-next)
|
|
9
9
|
- [Read the blog post about this template](https://www.sanity.io/blog/build-your-own-blog-with-sanity-and-next-js?utm_source=readme)
|
|
10
|
-
- [Join the community
|
|
10
|
+
- [Join the Sanity community](https://www.sanity.io/community/join?utm_source=readme)
|
|
11
11
|
- [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
|
|
@@ -5,5 +5,5 @@ Congratulations, you have now installed the Sanity Content Studio, an open-sourc
|
|
|
5
5
|
Now you can do the following things:
|
|
6
6
|
|
|
7
7
|
- [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
|
|
8
|
-
- [Join the community
|
|
8
|
+
- [Join the Sanity community](https://www.sanity.io/community/join?utm_source=readme)
|
|
9
9
|
- [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
|
|
@@ -7,5 +7,5 @@ Now you can do the following things:
|
|
|
7
7
|
- [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
|
|
8
8
|
- Check out the example frontend: [Vue/Nuxt.js](https://github.com/sanity-io/example-ecommerce-snipcart-vue)
|
|
9
9
|
- [Read the blog post about this template](https://www.sanity.io/blog/e-commerce-vue-nuxt-snipcart?uutm_source=readme)
|
|
10
|
-
- [Join the community
|
|
10
|
+
- [Join the Sanity community](https://www.sanity.io/community/join?utm_source=readme)
|
|
11
11
|
- [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
|
|
@@ -5,5 +5,5 @@ Congratulations, you have now installed the Sanity Content Studio, an open-sourc
|
|
|
5
5
|
Now you can do the following things:
|
|
6
6
|
|
|
7
7
|
- [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
|
|
8
|
-
- [Join the community
|
|
8
|
+
- [Join the Sanity community](https://www.sanity.io/community/join?utm_source=readme)
|
|
9
9
|
- [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
|
|
@@ -6,5 +6,5 @@ Now you can do the following things:
|
|
|
6
6
|
|
|
7
7
|
- [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
|
|
8
8
|
- Check out one of the example frontends: [React](https://github.com/sanity-io/example-frontend-next-js) | [React Native](https://github.com/sanity-io/example-app-react-native) | [Vue](https://github.com/sanity-io/example-frontend-vue-js) | [PHP](https://github.com/sanity-io/example-frontend-silex-twig)
|
|
9
|
-
- [Join the community
|
|
9
|
+
- [Join the Sanity community](https://www.sanity.io/community/join?utm_source=readme)
|
|
10
10
|
- [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
|
|
@@ -5,5 +5,5 @@ Congratulations, you have now installed Sanity Studio, an open-source real-time
|
|
|
5
5
|
Now you can do the following things:
|
|
6
6
|
|
|
7
7
|
- [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
|
|
8
|
-
- [Join the community
|
|
8
|
+
- [Join the Sanity community](https://www.sanity.io/community/join?utm_source=readme)
|
|
9
9
|
- [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
|
package/src/CommandRunner.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import {cloneDeep, sortBy} from 'lodash'
|
|
3
|
-
|
|
4
|
-
import {baseCommands} from './commands'
|
|
5
|
-
import {debug} from './debug'
|
|
6
|
-
import cliOutputter from './outputters/cliOutputter'
|
|
7
|
-
import {cliPackageManager} from './packageManager'
|
|
8
|
-
import {prompt as cliPrompter} from './prompters/cliPrompter'
|
|
9
|
-
import {
|
|
10
|
-
type CliCommandArguments,
|
|
11
|
-
type CliCommandContext,
|
|
12
|
-
type CliCommandDefinition,
|
|
13
|
-
type CliCommandGroupDefinition,
|
|
14
|
-
type CliConfig,
|
|
15
|
-
type CliOutputter,
|
|
16
|
-
type CliPrompter,
|
|
17
|
-
type CommandRunnerOptions,
|
|
18
|
-
type ResolvedCliCommand,
|
|
19
|
-
type SanityJson,
|
|
20
|
-
} from './types'
|
|
21
|
-
import {getClientWrapper} from './util/clientWrapper'
|
|
22
|
-
import {
|
|
23
|
-
generateCommandDocumentation,
|
|
24
|
-
generateCommandsDocumentation,
|
|
25
|
-
} from './util/generateCommandsDocumentation'
|
|
26
|
-
import {type CliConfigResult} from './util/getCliConfig'
|
|
27
|
-
import {isCommandGroup} from './util/isCommandGroup'
|
|
28
|
-
import {getNoSuchCommandText} from './util/noSuchCommandText'
|
|
29
|
-
|
|
30
|
-
interface Handlers {
|
|
31
|
-
outputter: CliOutputter
|
|
32
|
-
prompter: CliPrompter
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type CommandOrGroup = CliCommandDefinition | CliCommandGroupDefinition
|
|
36
|
-
|
|
37
|
-
export class CommandRunner {
|
|
38
|
-
public handlers: Handlers
|
|
39
|
-
public commands: CommandOrGroup[]
|
|
40
|
-
public commandGroups: Record<string, (CliCommandDefinition | CliCommandGroupDefinition)[]>
|
|
41
|
-
|
|
42
|
-
constructor(handlers: Handlers, commands: CommandOrGroup[] = baseCommands) {
|
|
43
|
-
this.handlers = handlers
|
|
44
|
-
this.commands = sortBy(commands, 'name')
|
|
45
|
-
this.commandGroups = {}
|
|
46
|
-
for (const cmd of this.commands) {
|
|
47
|
-
const group = ('group' in cmd && cmd.group) || 'default'
|
|
48
|
-
this.commandGroups[group] = this.commandGroups[group] || []
|
|
49
|
-
this.commandGroups[group].push(cmd)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!handlers.outputter || !handlers.prompter) {
|
|
53
|
-
throw new Error('`prompter` and `outputter` handlers must be defined')
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async runCommand(
|
|
58
|
-
commandOrGroup: string,
|
|
59
|
-
args: CliCommandArguments,
|
|
60
|
-
options: CommandRunnerOptions,
|
|
61
|
-
): Promise<unknown> {
|
|
62
|
-
if (!commandOrGroup) {
|
|
63
|
-
this.handlers.outputter.print(generateCommandsDocumentation(this.commandGroups))
|
|
64
|
-
return Promise.resolve()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// We might modify arguments for easier parsing in subcommand
|
|
68
|
-
const cmdArgs = cloneDeep(args)
|
|
69
|
-
const subCommandName = args.argsWithoutOptions[0]
|
|
70
|
-
|
|
71
|
-
const commandInfo = this.resolveCommand(commandOrGroup, subCommandName)
|
|
72
|
-
if (!commandInfo) {
|
|
73
|
-
throw new Error(getNoSuchCommandText(commandOrGroup, subCommandName, this.commandGroups))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const command = commandInfo.command
|
|
77
|
-
|
|
78
|
-
if (!isCommandGroup(command) && command.group && command.group !== 'default') {
|
|
79
|
-
cmdArgs.argsWithoutOptions = args.argsWithoutOptions.slice(1)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const output = this.handlers.outputter
|
|
83
|
-
const prompt = this.handlers.prompter
|
|
84
|
-
|
|
85
|
-
const {cliConfig, ...commandOptions} = options
|
|
86
|
-
const apiClient = getClientWrapper(
|
|
87
|
-
cliConfig?.config?.api || null,
|
|
88
|
-
cliConfig?.path || (cliConfig?.version === 2 ? 'sanity.json' : 'sanity.cli.js'),
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
const context: CliCommandContext = {
|
|
92
|
-
output,
|
|
93
|
-
prompt,
|
|
94
|
-
apiClient,
|
|
95
|
-
chalk,
|
|
96
|
-
cliPackageManager,
|
|
97
|
-
...commandOptions,
|
|
98
|
-
commandRunner: this,
|
|
99
|
-
...getVersionedContextParams(cliConfig),
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (isCommandGroup(command)) {
|
|
103
|
-
return context.output.print(generateCommandsDocumentation(this.commandGroups, command.name))
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (typeof command.action !== 'function') {
|
|
107
|
-
const cmdName = command.name || commandOrGroup || '<unknown>'
|
|
108
|
-
debug(`Command "${cmdName}" doesnt have a valid "action"-property, showing help`)
|
|
109
|
-
const groupName = command.group && command.group !== 'default' ? command.group : null
|
|
110
|
-
return context.output.print(generateCommandDocumentation(command, groupName, subCommandName))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
debug(`Running command "${command.name}"`)
|
|
114
|
-
return command.action(cmdArgs, context)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
resolveCommand(commandOrGroup: string, subCommandName?: string): ResolvedCliCommand | null {
|
|
118
|
-
// First, see if there is a group with the given name, if a subcommand is provided
|
|
119
|
-
if (this.commandGroups[commandOrGroup] && subCommandName) {
|
|
120
|
-
debug(`Found group for name "${commandOrGroup}", resolving subcommand`)
|
|
121
|
-
|
|
122
|
-
const subCommand = this.resolveSubcommand(
|
|
123
|
-
this.commandGroups[commandOrGroup],
|
|
124
|
-
subCommandName,
|
|
125
|
-
commandOrGroup,
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
debug(
|
|
129
|
-
subCommand
|
|
130
|
-
? `Subcommand resolved to "${subCommand.commandName}"`
|
|
131
|
-
: `Subcommand with name "${subCommandName}" not found`,
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
return subCommand
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// No group? See if there's a command within the default group
|
|
138
|
-
debug(`No group found with name "${commandOrGroup}", looking for command`)
|
|
139
|
-
const command = this.commandGroups.default.find((cmd) => cmd.name === commandOrGroup)
|
|
140
|
-
if (command) {
|
|
141
|
-
debug(`Found command in default group with name "${commandOrGroup}"`)
|
|
142
|
-
return {
|
|
143
|
-
command: command,
|
|
144
|
-
commandName: command.name,
|
|
145
|
-
parentName: 'default',
|
|
146
|
-
isGroup: false,
|
|
147
|
-
isCommand: true,
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
debug(`No default command with name "${commandOrGroup}" found, giving up`)
|
|
152
|
-
return null
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
resolveSubcommand(
|
|
156
|
-
group: (CliCommandDefinition | CliCommandGroupDefinition)[],
|
|
157
|
-
subCommandName: string,
|
|
158
|
-
parentGroupName: string,
|
|
159
|
-
): ResolvedCliCommand | null {
|
|
160
|
-
if (!subCommandName) {
|
|
161
|
-
return null
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const subCommand = group.find((cmd) => cmd.name === subCommandName)
|
|
165
|
-
if (!subCommand) {
|
|
166
|
-
throw new Error(getNoSuchCommandText(subCommandName, parentGroupName, this.commandGroups))
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return {
|
|
170
|
-
command: subCommand,
|
|
171
|
-
commandName: subCommandName,
|
|
172
|
-
parentName: parentGroupName,
|
|
173
|
-
isGroup: false,
|
|
174
|
-
isCommand: true,
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
resolveHelpForGroup(): ResolvedCliCommand {
|
|
179
|
-
const command = this.commandGroups.default.find((cmd) => cmd.name === 'help')
|
|
180
|
-
if (!command) {
|
|
181
|
-
throw new Error('Failed to find default `help` command')
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
command,
|
|
186
|
-
commandName: 'help',
|
|
187
|
-
isGroup: false,
|
|
188
|
-
isCommand: true,
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function getCliRunner(commands: CommandOrGroup[]): CommandRunner {
|
|
194
|
-
return new CommandRunner(
|
|
195
|
-
{
|
|
196
|
-
outputter: cliOutputter,
|
|
197
|
-
prompter: cliPrompter,
|
|
198
|
-
},
|
|
199
|
-
commands,
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function getVersionedContextParams(
|
|
204
|
-
cliConfig: CliConfigResult | null,
|
|
205
|
-
):
|
|
206
|
-
| {sanityMajorVersion: 2; cliConfig?: SanityJson; cliConfigPath?: string}
|
|
207
|
-
| {sanityMajorVersion: 3; cliConfig?: CliConfig; cliConfigPath?: string} {
|
|
208
|
-
return cliConfig?.version === 2
|
|
209
|
-
? {
|
|
210
|
-
sanityMajorVersion: 2,
|
|
211
|
-
cliConfig: cliConfig?.config || undefined,
|
|
212
|
-
cliConfigPath: cliConfig?.path || undefined,
|
|
213
|
-
}
|
|
214
|
-
: {
|
|
215
|
-
sanityMajorVersion: 3,
|
|
216
|
-
cliConfig: cliConfig?.config || undefined,
|
|
217
|
-
cliConfigPath: cliConfig?.path || undefined,
|
|
218
|
-
}
|
|
219
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {defineTrace} from '@sanity/telemetry'
|
|
2
|
-
|
|
3
|
-
interface CLITraceData {
|
|
4
|
-
/**
|
|
5
|
-
* Command flags, without the core options (help, debug, version etc)
|
|
6
|
-
*/
|
|
7
|
-
groupOrCommand: string
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Command arguments, eg any arguments after `sanity <command>` (no flags)
|
|
11
|
-
*/
|
|
12
|
-
commandArguments: string[]
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Arguments after the ended argument list (--)
|
|
16
|
-
*/
|
|
17
|
-
extraArguments: string[]
|
|
18
|
-
coreOptions: {
|
|
19
|
-
help?: boolean
|
|
20
|
-
debug?: boolean
|
|
21
|
-
version?: boolean
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const CliCommand = defineTrace<CLITraceData>({
|
|
26
|
-
name: 'CLI Command Executed',
|
|
27
|
-
version: 1,
|
|
28
|
-
description: 'A CLI command was executed',
|
|
29
|
-
})
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import {defineTrace} from '@sanity/telemetry'
|
|
2
|
-
|
|
3
|
-
interface StartStep {
|
|
4
|
-
step: 'start'
|
|
5
|
-
flags: Record<string, string | number | undefined | boolean>
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface LoginStep {
|
|
9
|
-
step: 'login'
|
|
10
|
-
alreadyLoggedIn?: boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface FetchJourneyConfigStep {
|
|
14
|
-
step: 'fetchJourneyConfig'
|
|
15
|
-
projectId: string
|
|
16
|
-
datasetName: string
|
|
17
|
-
displayName: string
|
|
18
|
-
isFirstProject: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface CreateOrSelectProjectStep {
|
|
22
|
-
step: 'createOrSelectProject'
|
|
23
|
-
projectId: string
|
|
24
|
-
selectedOption: 'create' | 'select' | 'none'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface CreateOrSelectDatasetStep {
|
|
28
|
-
step: 'createOrSelectDataset'
|
|
29
|
-
datasetName: string
|
|
30
|
-
selectedOption: 'create' | 'select' | 'none'
|
|
31
|
-
visibility: 'private' | 'public'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface UseDefaultPlanCoupon {
|
|
35
|
-
step: 'useDefaultPlanCoupon'
|
|
36
|
-
selectedOption: 'yes' | 'no'
|
|
37
|
-
coupon?: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface UseDefaultPlanId {
|
|
41
|
-
step: 'useDefaultPlanId'
|
|
42
|
-
selectedOption: 'yes' | 'no'
|
|
43
|
-
planId?: string
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface UseDetectedFrameworkStep {
|
|
47
|
-
step: 'useDetectedFramework'
|
|
48
|
-
selectedOption: 'yes' | 'no'
|
|
49
|
-
detectedFramework?: string
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface UseTypeScriptStep {
|
|
53
|
-
step: 'useTypeScript'
|
|
54
|
-
selectedOption: 'yes' | 'no'
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface SelectTemplateStep {
|
|
58
|
-
step: 'selectProjectTemplate'
|
|
59
|
-
selectedOption: string
|
|
60
|
-
}
|
|
61
|
-
interface ImportTemplateDatasetStep {
|
|
62
|
-
step: 'importTemplateDataset'
|
|
63
|
-
selectedOption: 'yes' | 'no'
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
interface SendCommunityInviteStep {
|
|
67
|
-
step: 'sendCommunityInvite'
|
|
68
|
-
selectedOption: 'yes' | 'no'
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
interface SelectPackageManagerStep {
|
|
72
|
-
step: 'selectPackageManager'
|
|
73
|
-
selectedOption: string
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
type InitStepResult =
|
|
77
|
-
| StartStep
|
|
78
|
-
| LoginStep
|
|
79
|
-
| FetchJourneyConfigStep
|
|
80
|
-
| CreateOrSelectProjectStep
|
|
81
|
-
| CreateOrSelectDatasetStep
|
|
82
|
-
| UseDetectedFrameworkStep
|
|
83
|
-
| UseTypeScriptStep
|
|
84
|
-
| ImportTemplateDatasetStep
|
|
85
|
-
| SendCommunityInviteStep
|
|
86
|
-
| SelectPackageManagerStep
|
|
87
|
-
| SelectTemplateStep
|
|
88
|
-
| UseDefaultPlanCoupon
|
|
89
|
-
| UseDefaultPlanId
|
|
90
|
-
|
|
91
|
-
export const CLIInitStepCompleted = defineTrace<InitStepResult>({
|
|
92
|
-
name: 'CLI Init Step Completed',
|
|
93
|
-
version: 1,
|
|
94
|
-
description: 'User completed a step in the CLI init flow',
|
|
95
|
-
})
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-process-exit, no-sync */
|
|
2
|
-
import childProcess from 'node:child_process'
|
|
3
|
-
import fs from 'node:fs'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
|
|
6
|
-
import {type CliCommandAction, type CliCommandContext} from '../../types'
|
|
7
|
-
import mods from './mods'
|
|
8
|
-
import {type CodeMod} from './types'
|
|
9
|
-
|
|
10
|
-
export interface CodeModFlags {
|
|
11
|
-
extensions?: string
|
|
12
|
-
verify?: boolean
|
|
13
|
-
dry?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const codemodAction: CliCommandAction<CodeModFlags> = async function codemodAction(
|
|
17
|
-
args,
|
|
18
|
-
context,
|
|
19
|
-
) {
|
|
20
|
-
const {output, cliRoot, workDir} = context
|
|
21
|
-
const [name] = args.argsWithoutOptions
|
|
22
|
-
const cliFlags = args.extOptions
|
|
23
|
-
if (!name) {
|
|
24
|
-
printMods(output)
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Make a record where all the keys of the available codemods are lowercased,
|
|
29
|
-
// eg `reactIconsV3` turns into `{reacticonsv3: CodeMod}`
|
|
30
|
-
const normalizedMods: Record<string, CodeMod> = {}
|
|
31
|
-
for (const [originalName, mod] of Object.entries(mods)) {
|
|
32
|
-
normalizedMods[originalName.toLowerCase()] = mod
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Verify that mod exists
|
|
36
|
-
const mod = normalizedMods[name.toLowerCase()]
|
|
37
|
-
if (!mod) {
|
|
38
|
-
throw new Error(`Codemod with name "${name}" not found`)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Verify if there is any verification deefined, and user has not opted out of it
|
|
42
|
-
if (typeof mod.verify === 'function' && cliFlags.verify !== false) {
|
|
43
|
-
await mod.verify(context)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// If extensions are defined, they come in as CSV, so split and normalize them
|
|
47
|
-
const exts = cliFlags.extensions
|
|
48
|
-
? cliFlags.extensions.split(',').map((ext) => ext.trim().replace(/^\./, ''))
|
|
49
|
-
: ['js', 'ts', 'tsx']
|
|
50
|
-
|
|
51
|
-
const dryRun = Boolean(typeof cliFlags.dry === 'undefined' ? false : cliFlags.dry)
|
|
52
|
-
|
|
53
|
-
// We use npx to run jscodeshift, so verify that it exists and works before using it
|
|
54
|
-
ensureNpx()
|
|
55
|
-
|
|
56
|
-
// If there is a gitignore in the target folder, we want to use that to know
|
|
57
|
-
// which folders to ignore - eg `dist`, `coverage` or whatever
|
|
58
|
-
const hasGitIgnore = fs.existsSync(path.join(workDir, '.gitignore'))
|
|
59
|
-
|
|
60
|
-
// Build the CLI command arguments
|
|
61
|
-
const modPath = path.resolve(path.join(cliRoot, 'codemods', mod.filename))
|
|
62
|
-
const cmdArgs = [
|
|
63
|
-
'jscodeshift',
|
|
64
|
-
'--ignore-pattern',
|
|
65
|
-
'node_modules',
|
|
66
|
-
'--ignore-pattern',
|
|
67
|
-
'dist',
|
|
68
|
-
hasGitIgnore && '--ignore-config',
|
|
69
|
-
hasGitIgnore && '.gitignore',
|
|
70
|
-
'-t',
|
|
71
|
-
modPath,
|
|
72
|
-
'--extensions',
|
|
73
|
-
exts.join(','),
|
|
74
|
-
dryRun && '--dry',
|
|
75
|
-
workDir,
|
|
76
|
-
].filter((item): item is string => typeof item === 'string')
|
|
77
|
-
|
|
78
|
-
const child = childProcess.spawn('npx', cmdArgs, {
|
|
79
|
-
stdio: 'inherit',
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
process.on('SIGINT', () => {
|
|
83
|
-
child.kill(2)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
child.on('close', (code) => {
|
|
87
|
-
process.exit(code || undefined)
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
function printMods(output: CliCommandContext['output']) {
|
|
91
|
-
output.print('Available code modifications:\n')
|
|
92
|
-
|
|
93
|
-
for (const [modName, mod] of Object.entries(mods)) {
|
|
94
|
-
output.print(`${modName} - ${mod.purpose}`)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function ensureNpx() {
|
|
99
|
-
try {
|
|
100
|
-
const npxHelp = childProcess.execSync('npx --help', {encoding: 'utf8'})
|
|
101
|
-
if (!npxHelp.includes('npm')) {
|
|
102
|
-
throw new Error('Not the npx we expected')
|
|
103
|
-
}
|
|
104
|
-
} catch {
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Failed to run "npx" - required to run codemods. Do you have a recent version of npm installed?`,
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {type CodeMod} from '../types'
|
|
2
|
-
|
|
3
|
-
const purpose = 'Transform `sanity/desk` imports to `sanity/structure`'
|
|
4
|
-
const description = `
|
|
5
|
-
Modifies all code paths that are found to import from 'sanity/desk' to instead import from
|
|
6
|
-
'sanity/structure', and renames any renamed members.
|
|
7
|
-
|
|
8
|
-
from: import {deskTool} from 'sanity/desk'
|
|
9
|
-
to: import {structureTool} from 'sanity/structure'
|
|
10
|
-
|
|
11
|
-
from: import {StructureBuilder} from 'sanity/desk'
|
|
12
|
-
to: import {StructureBuilder} from 'sanity/structure'
|
|
13
|
-
`.trim()
|
|
14
|
-
|
|
15
|
-
export const deskRename: CodeMod = {
|
|
16
|
-
purpose,
|
|
17
|
-
description,
|
|
18
|
-
filename: 'deskRename.js',
|
|
19
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {type CodeMod} from '../types'
|
|
2
|
-
|
|
3
|
-
const purpose = 'Add parts types directive to all ts/tsx files that has one or more part imports'
|
|
4
|
-
const description = `
|
|
5
|
-
Adds a '///<reference types="@sanity/types/parts" />' header to all source files that has one or more part imports.
|
|
6
|
-
For example:
|
|
7
|
-
|
|
8
|
-
Before:
|
|
9
|
-
---- somefile.ts
|
|
10
|
-
import client from 'part:@sanity/base/client'
|
|
11
|
-
//…
|
|
12
|
-
----
|
|
13
|
-
|
|
14
|
-
After:
|
|
15
|
-
---- somefile.ts
|
|
16
|
-
///<reference types="@sanity/types/parts" />
|
|
17
|
-
import client from 'part:@sanity/base/client'
|
|
18
|
-
//…
|
|
19
|
-
----
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
`.trim()
|
|
23
|
-
|
|
24
|
-
export const partsTypeDirective: CodeMod = {
|
|
25
|
-
purpose,
|
|
26
|
-
description,
|
|
27
|
-
filename: 'partsTypeDirective.js',
|
|
28
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
|
|
3
|
-
import resolveFrom from 'resolve-from'
|
|
4
|
-
import semverCompare from 'semver-compare'
|
|
5
|
-
|
|
6
|
-
import {type PackageJson} from '../../../types'
|
|
7
|
-
import {readJson} from '../../../util/readJson'
|
|
8
|
-
import {type CodeMod} from '../types'
|
|
9
|
-
|
|
10
|
-
const purpose = 'Transform react-icons v2 imports to v3 form'
|
|
11
|
-
const description = `
|
|
12
|
-
Modifies all found react-icons import and require statements from their v2 form
|
|
13
|
-
to the path structure used in react-icons v3. For instance:
|
|
14
|
-
|
|
15
|
-
from: import {MdPerson} from 'react-icons/lib/md'
|
|
16
|
-
to: import {MdPerson} from 'react-icons/md'
|
|
17
|
-
|
|
18
|
-
from: import PersonIcon from 'react-icons/lib/md/person'
|
|
19
|
-
to: import {MdPerson as PersonIcon} from 'react-icons/md'
|
|
20
|
-
`.trim()
|
|
21
|
-
|
|
22
|
-
export const reactIconsV3: CodeMod = {
|
|
23
|
-
purpose,
|
|
24
|
-
description,
|
|
25
|
-
filename: 'reactIconsV3.js',
|
|
26
|
-
verify: async (context) => {
|
|
27
|
-
const {workDir} = context
|
|
28
|
-
|
|
29
|
-
const studioPkg = await maybeReadJson(path.join(workDir, 'package.json'))
|
|
30
|
-
const dependencies = (studioPkg && studioPkg.dependencies) || {}
|
|
31
|
-
const dependencyVersion = (dependencies['react-icons'] || '').replace(/^[\^~]/, '')
|
|
32
|
-
if (!dependencyVersion) {
|
|
33
|
-
throw new Error('Could not find react-icons declared as dependency in package.json')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (semverCompare(dependencyVersion, '3.0.0') < 0) {
|
|
37
|
-
throw new Error('react-icons declared in package.json dependencies is lower than 3.0.0')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const iconPkgPath = resolveFrom.silent(workDir, 'react-icons/package.json')
|
|
41
|
-
const iconPkg = iconPkgPath && (await maybeReadJson(iconPkgPath))
|
|
42
|
-
if (iconPkg && semverCompare(iconPkg.version, '3.0.0') < 0) {
|
|
43
|
-
throw new Error('The installed version of react-icon seems to be < 3.0.0')
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function maybeReadJson(jsonPath: string): Promise<PackageJson | null> {
|
|
49
|
-
try {
|
|
50
|
-
return await readJson(jsonPath)
|
|
51
|
-
} catch {
|
|
52
|
-
return null
|
|
53
|
-
}
|
|
54
|
-
}
|