-
Notifications
You must be signed in to change notification settings - Fork 4
feat(init): signpost sanity new to logged-out users #1581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <!-- auto-generated --> | ||
| --- | ||
| '@sanity/cli': minor | ||
| --- | ||
|
|
||
| feat(init): signpost sanity new to logged-out users |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import {afterEach, describe, expect, test, vi} from 'vitest' | ||
|
|
||
| import {renderNewCommandBanner} from '../newCommandBanner.js' | ||
|
|
||
| function render(): string { | ||
| const log = vi.fn() | ||
| renderNewCommandBanner({error: vi.fn() as never, log, warn: vi.fn()}) | ||
| return ( | ||
| log.mock.calls | ||
| .map(([line]) => String(line ?? '')) | ||
| .join('\n') | ||
| // eslint-disable-next-line no-control-regex -- strip ANSI styling | ||
| .replaceAll(/\u001B\[[0-9;]*m/g, '') | ||
| // eslint-disable-next-line no-control-regex -- strip OSC 8 hyperlink wrappers | ||
| .replaceAll(/\u001B\]8;;[^\u0007]*\u0007/g, '') | ||
| ) | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs() | ||
| }) | ||
|
|
||
| describe('#renderNewCommandBanner', () => { | ||
| test('renders the two-ways-to-start signpost box, blank-line padded', () => { | ||
| const banner = render() | ||
|
|
||
| expect(banner).toContain('Two ways to start') | ||
| expect(banner).toContain('sanity init') | ||
| expect(banner).toContain('sanity new') | ||
| expect(banner).toContain('claim it within 72 hours') | ||
| expect(banner).toContain('https://sanity.new') | ||
| expect(banner).toContain('╭') // boxed — the one-time signpost keeps its box | ||
| expect(banner.startsWith('\n')).toBe(true) | ||
| expect(banner.endsWith('\n')).toBe(true) | ||
| }) | ||
|
|
||
| test('ignores the retired SANITY_NEW_BANNER switch', () => { | ||
| vi.stubEnv('SANITY_NEW_BANNER', '3') | ||
|
|
||
| expect(render()).toContain('Two ways to start') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import {styleText} from 'node:util' | ||
|
|
||
| import {boxen} from '@sanity/cli-core/ux' | ||
|
|
||
| import {hyperlink as link} from '../../util/terminalLink.js' | ||
| import {type InitContext} from './types.js' | ||
|
|
||
| const SANITY_NEW_URL = 'https://sanity.new' | ||
|
|
||
| /** | ||
| * The fork-in-the-road signpost shown before init's interactive login takes over the terminal: | ||
| * frames `init` and `new` as two equally valid front doors. A one-time boxed moment is | ||
| * deliberate here — unlike the recurring claim reminders, it renders once per init run, so the | ||
| * box draws the eye without training anyone to skim past it. (Three prototype treatments | ||
| * existed behind a `SANITY_NEW_BANNER` env switch during evaluation; UAT standardized on this | ||
| * one and dropped the switch.) | ||
| */ | ||
| export function renderNewCommandBanner(output: InitContext['output']): void { | ||
| output.log('') | ||
| output.log( | ||
| boxen( | ||
| `${styleText('bold', 'Two ways to start')} | ||
|
|
||
| ${styleText('cyan', 'sanity init')} Log in and set up a Studio ${styleText('dim', "(you're here)")} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can tighten the wording here maybe: Two ways to start |
||
| ${styleText('cyan', 'sanity new')} No login — mint a project now, claim it within 72 hours | ||
|
|
||
| Learn how it works: ${link(SANITY_NEW_URL, SANITY_NEW_URL)}`, | ||
| { | ||
| borderColor: 'cyan', | ||
| borderStyle: 'round', | ||
| padding: 1, | ||
| }, | ||
| ), | ||
| ) | ||
| output.log('') | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely to be agent read maybe:
"To create a project without logging in, run
sanity new(use --json formachine-readable output). Claim it with a Sanity account within 72 hours
to keep it. Fetch https://sanity.new to learn more."