-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a428dd6
commit 67539d7
Showing
11 changed files
with
233 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/sanity/src/_internal/cli/commands/app/appGroup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {type CliCommandGroupDefinition} from '@sanity/cli' | ||
|
||
const appGroup: CliCommandGroupDefinition = { | ||
name: 'app', | ||
signature: '[COMMAND]', | ||
isGroupRoot: true, | ||
description: 'Manages non-studio applications', | ||
} | ||
|
||
export default appGroup |
52 changes: 52 additions & 0 deletions
52
packages/sanity/src/_internal/cli/commands/app/buildCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
type CliCommandArguments, | ||
type CliCommandContext, | ||
type CliCommandDefinition, | ||
} from '@sanity/cli' | ||
|
||
import {type BuildSanityStudioCommandFlags} from '../../actions/build/buildAction' | ||
|
||
const helpText = ` | ||
Options | ||
--source-maps Enable source maps for built bundles (increases size of bundle) | ||
--no-minify Skip minifying built JavaScript (speeds up build, increases size of bundle) | ||
-y, --yes Unattended mode, answers "yes" to any "yes/no" prompt and otherwise uses defaults | ||
Examples | ||
sanity app build | ||
sanity app build --no-minify --source-maps | ||
` | ||
|
||
const appBuildCommand: CliCommandDefinition = { | ||
name: 'build', | ||
group: 'app', | ||
signature: '[OUTPUT_DIR]', | ||
description: 'Builds the Sanity application configuration into a static bundle', | ||
action: async ( | ||
args: CliCommandArguments<BuildSanityStudioCommandFlags>, | ||
context: CliCommandContext, | ||
overrides?: {basePath?: string}, | ||
) => { | ||
const buildAction = await getBuildAction() | ||
|
||
return buildAction(args, context, overrides) | ||
}, | ||
helpText, | ||
} | ||
|
||
async function getBuildAction() { | ||
// NOTE: in dev-mode we want to include from `src` so we need to use `.ts` extension | ||
// NOTE: this `if` statement is not included in the output bundle | ||
if (__DEV__) { | ||
// eslint-disable-next-line import/extensions,@typescript-eslint/consistent-type-imports | ||
const mod: typeof import('../../actions/build/buildAction') = require('../../actions/build/buildAction.ts') | ||
|
||
return mod.default | ||
} | ||
|
||
const mod = await import('../../actions/build/buildAction') | ||
|
||
return mod.default | ||
} | ||
|
||
export default appBuildCommand |
58 changes: 58 additions & 0 deletions
58
packages/sanity/src/_internal/cli/commands/app/devCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
type CliCommandArguments, | ||
type CliCommandContext, | ||
type CliCommandDefinition, | ||
} from '@sanity/cli' | ||
|
||
import {type StartDevServerCommandFlags} from '../../actions/dev/devAction' | ||
|
||
const helpText = ` | ||
Notes | ||
Changing the hostname or port number might require a new entry to the CORS-origins allow list. | ||
Options | ||
--port <port> TCP port to start server on. [default: 3333] | ||
--host <host> The local network interface at which to listen. [default: "127.0.0.1"] | ||
Examples | ||
sanity app dev --host=0.0.0.0 | ||
sanity app dev --port=1942 | ||
` | ||
|
||
const appDevCommand: CliCommandDefinition = { | ||
name: 'dev', | ||
group: 'app', | ||
signature: '[--port <port>] [--host <host>]', | ||
description: 'Starts a local dev server for your Sanity application with live reloading', | ||
action: async ( | ||
args: CliCommandArguments<StartDevServerCommandFlags>, | ||
context: CliCommandContext, | ||
) => { | ||
const devAction = await getDevAction() | ||
|
||
return devAction(args, context) | ||
}, | ||
helpText, | ||
} | ||
|
||
export async function getDevAction(): Promise< | ||
( | ||
args: CliCommandArguments<StartDevServerCommandFlags>, | ||
context: CliCommandContext, | ||
) => Promise<void> | ||
> { | ||
// NOTE: in dev-mode we want to include from `src` so we need to use `.ts` extension | ||
// NOTE: this `if` statement is not included in the output bundle | ||
if (__DEV__) { | ||
// eslint-disable-next-line import/extensions,@typescript-eslint/consistent-type-imports | ||
const mod: typeof import('../../actions/dev/devAction') = require('../../actions/dev/devAction.ts') | ||
|
||
return mod.default | ||
} | ||
|
||
const mod = await import('../../actions/dev/devAction') | ||
|
||
return mod.default | ||
} | ||
|
||
export default appDevCommand |
84 changes: 84 additions & 0 deletions
84
packages/sanity/src/_internal/cli/commands/app/startCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
type CliCommandArguments, | ||
type CliCommandContext, | ||
type CliCommandDefinition, | ||
} from '@sanity/cli' | ||
|
||
import {type StartPreviewServerCommandFlags} from '../../actions/preview/previewAction' | ||
import {isInteractive} from '../../util/isInteractive' | ||
import {getDevAction} from '../dev/devCommand' | ||
|
||
const helpText = ` | ||
Notes | ||
Changing the hostname or port number might require a new CORS-entry to be added. | ||
Options | ||
--port <port> TCP port to start server on. [default: 3333] | ||
--host <host> The local network interface at which to listen. [default: "127.0.0.1"] | ||
Examples | ||
sanity app start --host=0.0.0.0 | ||
sanity app start --port=1942 | ||
sanity app start some/build-output-dir | ||
` | ||
|
||
const appStartCommand: CliCommandDefinition = { | ||
name: 'start', | ||
group: 'app', | ||
signature: '[BUILD_OUTPUT_DIR] [--port <port>] [--host <host>]', | ||
description: 'Previews a built Sanity application', | ||
action: async ( | ||
args: CliCommandArguments<StartPreviewServerCommandFlags>, | ||
context: CliCommandContext, | ||
) => { | ||
const {output, chalk, prompt} = context | ||
const previewAction = await getPreviewAction() | ||
|
||
const error = (msg: string) => output.warn(chalk.red.bgBlack(msg)) | ||
|
||
try { | ||
await previewAction(args, context) | ||
} catch (err) { | ||
if (err.name !== 'BUILD_NOT_FOUND') { | ||
throw err | ||
} | ||
|
||
error(err.message) | ||
error('\n') | ||
|
||
const shouldRunDevServer = | ||
isInteractive && | ||
(await prompt.single({ | ||
message: 'Do you want to start a development server instead?', | ||
type: 'confirm', | ||
})) | ||
|
||
if (shouldRunDevServer) { | ||
const devAction = await getDevAction() | ||
await devAction(args, context) | ||
} else { | ||
// Indicate that this isn't an expected exit | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(1) | ||
} | ||
} | ||
}, | ||
helpText, | ||
} | ||
|
||
async function getPreviewAction() { | ||
// NOTE: in dev-mode we want to include from `src` so we need to use `.ts` extension | ||
// NOTE: this `if` statement is not included in the output bundle | ||
if (__DEV__) { | ||
// eslint-disable-next-line import/extensions,@typescript-eslint/consistent-type-imports | ||
const mod: typeof import('../../actions/preview/previewAction') = require('../../actions/preview/previewAction.ts') | ||
|
||
return mod.default | ||
} | ||
|
||
const mod = await import('../../actions/preview/previewAction') | ||
|
||
return mod.default | ||
} | ||
|
||
export default appStartCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters