Skip to content

Commit

Permalink
feat: update copy and outputter
Browse files Browse the repository at this point in the history
  • Loading branch information
RostiMelk committed Dec 11, 2024
1 parent 88aa215 commit cf18688
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
39 changes: 18 additions & 21 deletions packages/@sanity/cli/src/actions/init-project/initProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export default async function initSanity(
const cliFlags = args.extOptions
const unattended = cliFlags.y || cliFlags.yes
const print = unattended ? noop : output.print
const warn = (msg: string) => output.warn(chalk.yellow.bgBlack(msg))
const success = output.success
const warn = output.warn

const intendedPlan = cliFlags['project-plan']
const intendedCoupon = cliFlags.coupon
Expand All @@ -131,7 +132,6 @@ export default async function initSanity(
const bareOutput = cliFlags.bare
const env = cliFlags.env
const packageManager = cliFlags['package-manager']
const check = chalk.green('✓')

let remoteTemplateInfo: RepoInfo | undefined
if (cliFlags.template && checkIsRemoteTemplate(cliFlags.template)) {
Expand Down Expand Up @@ -259,17 +259,17 @@ export default async function initSanity(
if (hasToken) {
trace.log({step: 'login', alreadyLoggedIn: true})
const user = await getUserData(apiClient)
print(`${check} You are logged in as %s using %s`, user.email, getProviderName(user.provider))
success('You are logged in as %s using %s', user.email, getProviderName(user.provider))
} else if (!unattended) {
trace.log({step: 'login'})
await getOrCreateUser()
}

let introMessage = `${check} Fetching existing projects`
let introMessage = 'Fetching existing projects'
if (cliFlags.quickstart) {
introMessage = `${check} Eject your existing project's Sanity configuration`
introMessage = "Eject your existing project's Sanity configuration"
}
print(introMessage)
success(introMessage)
print('')

const flags = await prepareFlags()
Expand All @@ -282,7 +282,8 @@ export default async function initSanity(

// If user doesn't want to output any template code
if (bareOutput) {
print(`\n${chalk.green('Success!')} Below are your project details:\n`)
success('Below are your project details')
print('')
print(`Project ID: ${chalk.cyan(projectId)}`)
print(`Dataset: ${chalk.cyan(datasetName)}`)
print(
Expand Down Expand Up @@ -706,16 +707,13 @@ export default async function initSanity(
trace.complete()

async function getOrCreateUser() {
print(`We can't find any auth credentials in your Sanity config`)
print('- log in or create a new account\n')
warn('No authentication credentials found in your Sanity config')
print('')

// Provide login options (`sanity login`)
const {extOptions, ...otherArgs} = args
const loginArgs: CliCommandArguments<LoginFlags> = {...otherArgs, extOptions: {}}
await login(loginArgs, {...context, telemetry: trace.newContext('login')})

print("Good stuff, you're now authenticated. You'll need a project to keep your")
print('datasets and collaborators safe and snug.')
}

async function getProjectDetails(): Promise<{
Expand Down Expand Up @@ -876,7 +874,6 @@ export default async function initSanity(
new prompt.Separator(),
...projectChoices,
],
suffix: 'Use ↑↓ to select, Enter to confirm',
})

if (selected === 'new') {
Expand Down Expand Up @@ -1049,20 +1046,20 @@ export default async function initSanity(
type: 'list',
choices: [
{
value: 'moviedb',
name: 'Movie project (schema + sample data)',
},
{
value: 'shopify',
name: 'E-commerce (Shopify)',
value: 'clean',
name: 'Clean project with no predefined schema types',
},
{
value: 'blog',
name: 'Blog (schema)',
},
{
value: 'clean',
name: 'Clean project with no predefined schema types',
value: 'shopify',
name: 'E-commerce (Shopify)',
},
{
value: 'moviedb',
name: 'Movie project (schema + sample data)',
},
],
})
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/cli/src/actions/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export async function login(
})
}

output.print(chalk.green('Login successful'))
output.success('Login successful')
trace.complete()
}

Expand Down Expand Up @@ -335,7 +335,7 @@ async function promptProviders(

const provider = await prompt.single({
type: 'list',
message: 'Login type',
message: 'Please log in or create a new account',
choices: providers.map((choice) => choice.title),
})

Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/cli/src/commands/logout/logoutCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const logoutCommand: CliCommandDefinition = {
// Clear cached telemetry consent
cfg.delete(TELEMETRY_CONSENT_CONFIG_KEY)

output.print(chalk.green('Logged out'))
output.success('Logged out')
},
}

Expand Down
21 changes: 17 additions & 4 deletions packages/@sanity/cli/src/outputters/cliOutputter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@
import chalk from 'chalk'
import ora, {type Options, type Ora} from 'ora'

const SYMBOL_CHECK = chalk.green('✓')
const SYMBOL_WARN = chalk.yellow('⚠')
const SYMBOL_FAIL = chalk.red('✗')

let isFirstClear = true

export default {
print(...args: unknown[]): void {
console.log(...args)
},

success(...args: unknown[]): void {
console.log(`${SYMBOL_CHECK} ${args.join(' ')}`)
},

warn(...args: unknown[]): void {
console.warn(...args)
console.warn(`${SYMBOL_WARN} ${args.join(' ')}`)
},

error(...args: unknown[]): void {
if (args[0] instanceof Error) {
console.error(chalk.red(args[0].stack))
} else {
console.error(...args)
console.error(`${SYMBOL_FAIL} ${args.join(' ')}`)
}
},

Expand All @@ -28,7 +36,12 @@ export default {
isFirstClear = false
},

spinner(options: Options | string): Ora {
return ora(options)
spinner(options: Options): Ora {
const spinner = ora({...options, spinner: 'dots'})
// Override the default `succeed` method to use a green checkmark, instead of the default emoji
spinner.succeed = (text?: string) => spinner.stopAndPersist({text, symbol: SYMBOL_CHECK})
spinner.warn = (text?: string) => spinner.stopAndPersist({text, symbol: SYMBOL_WARN})
spinner.fail = (text?: string) => spinner.stopAndPersist({text, symbol: SYMBOL_FAIL})
return spinner
},
}
1 change: 1 addition & 0 deletions packages/@sanity/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export interface CommandRunnerOptions {

export interface CliOutputter {
print: (...args: unknown[]) => void
success: (...args: unknown[]) => void
warn: (...args: unknown[]) => void
error: (...args: unknown[]) => void
clear: () => void
Expand Down

0 comments on commit cf18688

Please sign in to comment.