Skip to content
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

CLI: Add "features" question & auto-install test addon & improve test-addon compatibility #30202

Merged
merged 216 commits into from
Feb 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
216 commits
Select commit Hold shift + click to select a range
bde2134
ink in core and esm in create-storybook
ndelangen Jan 7, 2025
7e4592d
ink in init
ndelangen Jan 7, 2025
9f88950
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 7, 2025
59d7c63
fix
ndelangen Jan 7, 2025
6462b7b
keep other package dist bundling unchanged
ndelangen Jan 7, 2025
3a19d00
fix
ndelangen Jan 7, 2025
71df9d9
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 7, 2025
b5f7b2e
support ink types
ndelangen Jan 7, 2025
25d7e76
use esm of CLI
ndelangen Jan 7, 2025
760ce6d
fixes for check to support for moduleresolution=bundler
ndelangen Jan 7, 2025
c44aca3
add cjs
ndelangen Jan 7, 2025
321de92
undo shim change in prepare script
ndelangen Jan 7, 2025
9683316
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 7, 2025
20844fc
disable parallelism as it's not letting me see the issue, and i canno…
ndelangen Jan 7, 2025
57bc122
rendering with ink embedded in vite
ndelangen Jan 7, 2025
0eec9b0
add `node` condition for chalk
ndelangen Jan 7, 2025
e84572d
fix
ndelangen Jan 7, 2025
0f42062
unit test pass?
ndelangen Jan 8, 2025
b843a68
Discard changes to .circleci/config.yml
ndelangen Jan 8, 2025
199b5bf
fix linting
ndelangen Jan 8, 2025
5da8301
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 8, 2025
0fccec9
fix linting
ndelangen Jan 8, 2025
fb51e3b
add first demo story of an ink component
ndelangen Jan 8, 2025
1a5fe81
Discard changes to code/lib/cli-storybook/test/default/cli.test.cjs
ndelangen Jan 8, 2025
7440621
cleanup
ndelangen Jan 8, 2025
21c04b7
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 9, 2025
9541d3e
cleanup
ndelangen Jan 9, 2025
1e75423
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 9, 2025
5ff6089
typings
ndelangen Jan 9, 2025
90f12d7
update the target environment so we do not need TLA plugin, which see…
ndelangen Jan 9, 2025
69d64f8
cleanup
ndelangen Jan 9, 2025
a876450
fix types
ndelangen Jan 9, 2025
94843bf
patch away the top-level-away and devtools from ink to fix https://cl…
ndelangen Jan 9, 2025
b79205f
Revert "patch away the top-level-away and devtools from ink to fix ht…
ndelangen Jan 9, 2025
49f2c44
fix dev
ndelangen Jan 9, 2025
35505ec
fix dev actually
ndelangen Jan 9, 2025
f02c1a7
centered
ndelangen Jan 9, 2025
211318f
fix firefox Intl.Segmenter in chromatic
ndelangen Jan 9, 2025
580cf60
try to fix
ndelangen Jan 9, 2025
234c8da
alt solution
ndelangen Jan 9, 2025
6555742
add debug
ndelangen Jan 9, 2025
fe1e4c7
debug
ndelangen Jan 9, 2025
098a52e
Merge changes from POC
ghengeveld Jan 10, 2025
02cffc8
conditional ink stories, do not add when running vitest
ndelangen Jan 10, 2025
c97f554
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 10, 2025
2cbdd8e
fix windows compilation problem with pathing
ndelangen Jan 10, 2025
e821aae
remove story I added fro debugging purposes
ndelangen Jan 10, 2025
660aa3c
trying to fix the include pattern
ndelangen Jan 10, 2025
18b4f8d
again
ndelangen Jan 10, 2025
82851be
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 10, 2025
f6975ff
cleanup
ndelangen Jan 10, 2025
ec64802
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 13, 2025
1cdcb1a
split the create-storybook CLI into a modern & legacy part, based on …
ndelangen Jan 13, 2025
8c9d6af
add comments
ndelangen Jan 13, 2025
b5d1593
render the app
ndelangen Jan 13, 2025
6423249
wip
ghengeveld Jan 14, 2025
cfd010a
Merge pull request #30256 from storybookjs/gert/cli-with-ink
ndelangen Jan 14, 2025
b6e2afe
version accurate
ndelangen Jan 14, 2025
b530642
scaffold reducer state
ndelangen Jan 14, 2025
cf905a2
adding more input
ndelangen Jan 14, 2025
4b9f6cf
cleanup
ndelangen Jan 14, 2025
bbdae44
add more steps details
ndelangen Jan 15, 2025
54b0998
add a run step && cleanup
ndelangen Jan 15, 2025
9983643
add node utils via context, so storybook doesn't run into it
ndelangen Jan 15, 2025
d5ca217
crude install
ndelangen Jan 15, 2025
dcd3d1f
add require for resolving to context, use ni for package manager oper…
ndelangen Jan 15, 2025
a59ea66
reduce bloat
ndelangen Jan 16, 2025
af7ec07
fix
ndelangen Jan 16, 2025
75019af
fixes & add place for metrics component
ndelangen Jan 16, 2025
d8fc245
handle steps as a straight line. each step can skip itself in a useEf…
ndelangen Jan 16, 2025
df22449
cleanup
ndelangen Jan 16, 2025
ab86684
I guess we can keep it
ndelangen Jan 16, 2025
9c70158
move Confirm component
ndelangen Jan 16, 2025
195c39f
simplify
ndelangen Jan 16, 2025
8ff6e74
figured out a way to cancel
ndelangen Jan 16, 2025
f58c72d
track errors from procedures
ndelangen Jan 16, 2025
4817715
more error handling in interllation procedure
ndelangen Jan 16, 2025
3fe3307
better error handling
ndelangen Jan 16, 2025
a4c188e
improve error handling (no meaningless error if a meaningful one was …
ndelangen Jan 16, 2025
212b99f
install with versions & improve UI
ndelangen Jan 17, 2025
4bf774d
improve UI
ndelangen Jan 17, 2025
924fb94
uppercase to indicate <enter> will select that
ndelangen Jan 20, 2025
133f948
refactor, to reduce long files
ndelangen Jan 20, 2025
3de4555
move check to context
ndelangen Jan 20, 2025
dde08df
more stories
ndelangen Jan 20, 2025
9dc465b
cleanup
ndelangen Jan 20, 2025
25e2024
cleanup
ndelangen Jan 20, 2025
d41f56d
context changes
ndelangen Jan 20, 2025
1276642
fixes
ndelangen Jan 20, 2025
10bf2e7
fixes
ndelangen Jan 20, 2025
d9f0590
fix
ndelangen Jan 20, 2025
076929d
add story
ndelangen Jan 20, 2025
03c8751
cleanup
ndelangen Jan 20, 2025
b28651c
Add telemetry
ghengeveld Jan 20, 2025
174473c
improve
ndelangen Jan 21, 2025
6443b00
Omit directory for privacy reasons
ghengeveld Jan 21, 2025
2a2f9b0
Rename files
ghengeveld Jan 21, 2025
dbdb3a1
Merge branch 'norbert/cli-with-ink' into gert/init-telemetry
ghengeveld Jan 21, 2025
2ad4e6f
Merge pull request #30313 from storybookjs/gert/init-telemetry
ghengeveld Jan 21, 2025
17eb077
fix
ndelangen Jan 21, 2025
68fd581
fix
ndelangen Jan 21, 2025
d281b9a
improve error handling
ndelangen Jan 21, 2025
3114096
cleanup
ndelangen Jan 21, 2025
23379b3
cleanup
ndelangen Jan 21, 2025
9e3968d
add completion & spinners to procedures && add telemetry as tracked task
ndelangen Jan 21, 2025
5b2bbab
have some fun, I got the user's name
ndelangen Jan 21, 2025
db1e037
improve header
ndelangen Jan 22, 2025
90f0a74
improve error handling of installation
ndelangen Jan 22, 2025
4958640
fixes
ndelangen Jan 22, 2025
89c404c
fix typo
ndelangen Jan 22, 2025
e003420
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 22, 2025
8b13cb1
Disable telemetry notification when running create-storybook because …
ghengeveld Jan 22, 2025
7a167e0
Implement checks
ghengeveld Jan 22, 2025
16a7433
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 22, 2025
958e81e
fix intents
ndelangen Jan 22, 2025
7ea83ed
no default in CLI, but set defaults in the component instead. This wa…
ndelangen Jan 23, 2025
1a6be9c
no default intents in app
ndelangen Jan 23, 2025
3159795
Implement first set of actual checks
ghengeveld Jan 23, 2025
7044963
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 23, 2025
fb670b9
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 23, 2025
e8d1fdf
add crude config generation
ndelangen Jan 24, 2025
8a58dbe
add main config generation
ndelangen Jan 24, 2025
da9991b
improve config generation
ndelangen Jan 24, 2025
1368d0d
improve messaging of configDir check
ndelangen Jan 24, 2025
e9abc33
previewConfig file generation
ndelangen Jan 24, 2025
5661454
Various prerequisite checks
ghengeveld Jan 24, 2025
2f2472c
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 24, 2025
426013c
Cleanup comments
ghengeveld Jan 24, 2025
f83bd4b
add a map for package names
ndelangen Jan 24, 2025
4302698
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Jan 24, 2025
6266659
add detection
ndelangen Jan 27, 2025
29e75e1
I suppose we could do it like this
ndelangen Jan 27, 2025
e858811
add cwd
ndelangen Jan 27, 2025
6b9ec5d
Wrapup Vitest compatibility checks
ghengeveld Jan 27, 2025
6f059c1
Add new compatibility checks to old create-storybook CLI
ghengeveld Jan 28, 2025
a594eea
Fix installation process
ghengeveld Jan 28, 2025
8468f6f
remove unused ink
ndelangen Jan 29, 2025
88f3cbc
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 29, 2025
ef2f0e6
make intents question optional && more cleanup
ndelangen Jan 29, 2025
c3b2f8b
improve check
ndelangen Jan 29, 2025
46771c5
cleanup
ndelangen Jan 29, 2025
f4f1e3b
fix typing
ndelangen Jan 29, 2025
457a447
cleanup
ndelangen Jan 29, 2025
1c0dd49
fix
ndelangen Jan 29, 2025
9028541
do not run on CI
ndelangen Jan 29, 2025
6a6e89b
Merge branch 'next' into norbert/cli-with-ink
ndelangen Jan 31, 2025
e433a08
cleanup
ndelangen Jan 31, 2025
6867b54
add intents to telemetry
ndelangen Jan 31, 2025
da37286
cleanup
ndelangen Jan 31, 2025
8e0d959
cleanup
ndelangen Jan 31, 2025
fe2dc28
cleanup
ndelangen Jan 31, 2025
5bad95b
cleanup
ndelangen Jan 31, 2025
2a2806f
prebundle create-storybook more
ndelangen Jan 31, 2025
2ff6044
remove prettier as a dependency
ndelangen Jan 31, 2025
5adcfd5
direct depend on storybook/core
ndelangen Jan 31, 2025
d43667d
fix forgotten usages of storybook/internal
ndelangen Jan 31, 2025
43029f5
Add support for extending existing Vitest workspace file
ghengeveld Jan 31, 2025
dc10757
Handle non-interactive (non TTY) mode
ghengeveld Jan 31, 2025
35656f0
add CLi flag for intents & send original intent to telemetry
ndelangen Jan 31, 2025
78a2d72
Don't default to migrating to nextjs-vite
ghengeveld Jan 31, 2025
0063c5e
Check for framework compatibility with addon-test
ghengeveld Jan 31, 2025
8c13344
Force storybook package version for sb add command
ghengeveld Feb 3, 2025
985843b
Avoid caret syntax in addon version string when using PR canary
ghengeveld Feb 3, 2025
1dd4f35
Move templates to directory and include them in dist
ghengeveld Feb 3, 2025
14b609a
remove dependency on core from create-storybook
ndelangen Feb 3, 2025
96c4ab2
ignore some types issues, not generate types for create-storybook
ndelangen Feb 3, 2025
fa56300
cleanup
ndelangen Feb 3, 2025
35224f1
fixes
ndelangen Feb 3, 2025
9b97c5d
deal with no linting in test
ndelangen Feb 3, 2025
d4531ab
Merge branch 'next' into norbert/cli-with-ink
ndelangen Feb 3, 2025
674194b
fix checks
ndelangen Feb 3, 2025
7ef841f
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Feb 3, 2025
3cd19d6
skip failing test
ndelangen Feb 3, 2025
b4de21b
knip fix
ndelangen Feb 3, 2025
b701414
large
ndelangen Feb 4, 2025
a9d4f39
move templates to top-level package
ndelangen Feb 4, 2025
eecb7f3
cleanup
ndelangen Feb 4, 2025
e08bf93
Update existing config file and only fall back to creating a workspac…
ghengeveld Feb 4, 2025
078ba9c
Move templates to addon root so we don't need to copy it to dist
ghengeveld Feb 4, 2025
6decde5
Fix template path
ghengeveld Feb 4, 2025
09ccce4
add semver to regular deps
ndelangen Feb 4, 2025
a2a9f27
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Feb 4, 2025
8b1aa95
do not install addon-interactions when test intent is set, as it will…
ndelangen Feb 4, 2025
3d1a386
fixes
ndelangen Feb 4, 2025
fe0a73b
try both panel names
ndelangen Feb 4, 2025
ec2e1a2
more
ndelangen Feb 4, 2025
7f2ab10
fix e2e test for addon-interactions by skipping them wheb appropriate
ndelangen Feb 4, 2025
f787874
do not add experimental-addon-test when non interactive CLI, this is …
ndelangen Feb 4, 2025
c99a686
add extra CI step to test intents
ndelangen Feb 5, 2025
ff5316e
fix
ndelangen Feb 5, 2025
4e104e6
fix
ndelangen Feb 5, 2025
baec739
in one step...
ndelangen Feb 5, 2025
0b7a8e6
Refactor sandbox setup to write either workspace or config file based…
ghengeveld Feb 5, 2025
cbc93ee
add extends true, as @JReinhold suggested
ndelangen Feb 5, 2025
a3a3440
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Feb 5, 2025
ccae917
Merge branch 'next' into norbert/cli-with-ink
ndelangen Feb 5, 2025
c7599ae
Support updating Vite config with test property, and check for Vitest…
ghengeveld Feb 5, 2025
46bc666
fix checks
ndelangen Feb 5, 2025
e4c4b31
Fix EXTENDS_WORKSPACE template value
ghengeveld Feb 5, 2025
ce2f2ae
add jiti to root
ndelangen Feb 5, 2025
566c28c
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Feb 5, 2025
a30ec76
update test
ndelangen Feb 5, 2025
2875796
Merge branch 'next' into norbert/cli-with-ink
ndelangen Feb 6, 2025
6fd5f85
fix review comment https://github.com/storybookjs/storybook/pull/3020…
ndelangen Feb 6, 2025
6dc6aa4
fix review comments
ndelangen Feb 6, 2025
2847a36
remove comment
ndelangen Feb 6, 2025
68ed7a9
Remove commented-out code related to Ink-based CLI
ghengeveld Feb 6, 2025
2b2f47e
Merge branch 'next' into norbert/cli-with-ink
ndelangen Feb 6, 2025
270bfed
Merge branch 'norbert/cli-with-ink' of https://github.com/storybookjs…
ndelangen Feb 6, 2025
615ffa5
cleanup
ndelangen Feb 10, 2025
26847e8
merge in next
ndelangen Feb 10, 2025
d564e1a
cleanup
ndelangen Feb 10, 2025
e6c0ba8
Merge branch 'next' into norbert/cli-with-ink
ndelangen Feb 10, 2025
ad7a5a0
rename intents to features
ndelangen Feb 11, 2025
2abf798
Check for project type compatibility with addon-test _after_ promptin…
ghengeveld Feb 11, 2025
865a0c0
Disable docs if docs feature is not selected and omit docs entries if…
ghengeveld Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement first set of actual checks
  • Loading branch information
ghengeveld committed Jan 23, 2025
commit 3159795a3f2f75b5b6d369fdd836343810624952
4 changes: 3 additions & 1 deletion code/lib/create-storybook/src/bin/modernInputs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { z } from 'zod';

export type Framework = (typeof supportedFrameworks)[number];

// TODO: sync this/pull this from core
export const supportedFrameworks = [
'angular',
@@ -55,7 +57,7 @@ export const supportedFrameworksMap = {
qwik: 'Qwik',
solid: 'Solid',
sveltekit: 'SvelteKit',
} satisfies Record<(typeof supportedFrameworks)[number], string>;
} satisfies Record<Framework, string>;

export const modernInputs = z.strictObject({
intents: z //
3 changes: 2 additions & 1 deletion code/lib/create-storybook/src/ink/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as child_process from 'node:child_process';
import * as fs from 'node:fs/promises';
import { createRequire } from 'node:module';
import path from 'node:path';
import process from 'node:process';

import React, { type ComponentProps } from 'react';
@@ -40,7 +41,6 @@ export type Input = z.infer<typeof inputs> & {
export async function run(options: z.infer<typeof inputs>) {
const input: Input = {
...options,
intents: ['dev', ...options.intents.filter((v) => v !== 'dev')],
width: process.stdout.columns || 120,
height: process.stdout.rows || 40,
};
@@ -49,6 +49,7 @@ export async function run(options: z.infer<typeof inputs>) {
process.stdout.write('\n');
const context: ComponentProps<typeof AppContext.Provider>['value'] = {
fs,
path,
process,
child_process,
require,
10 changes: 5 additions & 5 deletions code/lib/create-storybook/src/ink/procedures/Installation.tsx
Original file line number Diff line number Diff line change
@@ -21,23 +21,23 @@ const deriveDependencies = (state: Procedure['state']): string[] => {
format(`@storybook/${state.framework}` as keyof typeof versions),
];

if (state.features.includes(`onboarding`)) {
if (state.features?.includes(`onboarding`)) {
dependencies.push(format(`@storybook/addon-onboarding`));
}

if (state.features.includes(`essentials`)) {
if (state.features?.includes(`essentials`)) {
dependencies.push(format(`@storybook/addon-essentials`));
}

if (state.features.includes(`vrt`)) {
if (state.features?.includes(`vrt`)) {
dependencies.push('@chromatic-com/storybook@^3');
}

if (state.intents.includes(`docs`) && !state.features.includes(`essentials`)) {
if (state.intents?.includes(`docs`) && !state.features?.includes(`essentials`)) {
dependencies.push(format(`@storybook/addon-docs`));
}

if (state.intents.includes(`test`)) {
if (state.intents?.includes(`test`)) {
dependencies.push(format(`@storybook/test`));
dependencies.push(format('@storybook/addon-a11y'));
dependencies.push(format(`@storybook/experimental-addon-test`));
159 changes: 6 additions & 153 deletions code/lib/create-storybook/src/ink/steps/Check.tsx
Original file line number Diff line number Diff line change
@@ -1,157 +1,15 @@
import type { FC } from 'react';
import React, { type Dispatch, useContext, useEffect, useState } from 'react';

import { Spinner } from '@inkjs/ui';
import figureSet from 'figures';
import { Box, Text } from 'ink';
import { Box } from 'ink';

import { ACTIONS, type Action, type State } from '.';
import { Confirm } from '../components/Confirm';
import { AppContext } from '../utils/context';
import { getKeys } from '../utils/getKeys';

interface Check {
condition: (state: State) => Promise<CompatibilityResult>;
render: FC<{
s: CompatibilityResult;
setter: (val: CompatibilityResult) => void;
dispatch: Dispatch<Action>;
}>;
}

/*
* Checks:
*
* - When configDir already exists, prompt:
* - Yes -> overwrite (delete)
* - No -> exit
* - When selecting framework nextjs & intent includes test, prompt for experimental-nextjs-vite *
* - Yes -> migrate
* - No -> ignore test intent
* - When selecting framework that doesn't support test addon, prompt for ignoring test intent
* - Yes -> ignore test intent
* - No -> exit
* - Detect existing Vitest/MSW version, if mismatch prompt for ignoring test intent
* - Yes -> ignore test intent
* - No -> exit
* - Check for presence of nextjs when using @storybook/nextjs, if mismatch prompt
* - Yes -> continue
* - No -> exit
* - Check if existing Vitest workspace file can be safaley modified, if not prompt:
* - Yes -> ignore test intent
* - No -> exit
* - Check if existing Vite config file can be safaley modified, if not prompt:
* - Yes -> ignore test intent
* - No -> exit
* -
*/

const checks = {
checkA: {
condition: async (state) => {
return { type: 'incompatible', reasons: ['reason 1', 'reason 2'] };
},
render: ({ s, setter, dispatch }) => {
switch (s.type) {
case 'ignored': {
return (
<Box>
<Text>{figureSet.smiley}</Text>
</Box>
);
}
case 'compatible': {
return (
<Box>
<Text>{figureSet.tick}</Text>
</Box>
);
}
case 'incompatible': {
return (
<Box gap={1}>
<Text>{figureSet.cross}</Text>
<Text>Do you want to continue?</Text>
<Confirm
onChange={(answer) => {
if (answer) {
setter({ type: 'ignored' });
} else {
dispatch({
type: ACTIONS.EXIT,
payload: { code: 1, reasons: s.reasons },
});
}
}}
/>
</Box>
);
}
default: {
return (
<Box gap={1}>
<Spinner />
<Text>We're checking compatibility...</Text>
</Box>
);
}
}
},
},
checkB: {
condition: async (state) => {
return { type: 'compatible' };
},
render: ({ s, setter, dispatch }) => {
switch (s.type) {
case 'ignored': {
return (
<Box>
<Text>{figureSet.smiley}</Text>
</Box>
);
}
case 'compatible': {
return (
<Box>
<Text>{figureSet.tick}</Text>
</Box>
);
}
case 'incompatible': {
return (
<Box gap={1}>
<Text>{figureSet.cross}</Text>
<Text>Do you want to continue 2?</Text>
<Confirm
onChange={(answer) => {
if (answer) {
setter({ type: 'ignored' });
} else {
dispatch({
type: ACTIONS.EXIT,
payload: { code: 1, reasons: s.reasons },
});
}
}}
/>
</Box>
);
}
default: {
return (
<Box gap={1}>
<Spinner />
<Text>We're checking compatibility...</Text>
</Box>
);
}
}
},
},
} satisfies Record<string, Check>;
import type { CompatibilityResult } from './checks';
import { checks } from './checks';

export function CHECK({ state, dispatch }: { state: State; dispatch: Dispatch<Action> }) {
const context = useContext(AppContext);
const [results, setResults] = useState(
getKeys(checks).reduce(
(acc, key) => ({ ...acc, [key]: { type: 'loading' as const } }),
@@ -161,7 +19,7 @@ export function CHECK({ state, dispatch }: { state: State; dispatch: Dispatch<Ac

useEffect(() => {
getKeys(checks).forEach((key) =>
checks[key].condition(state).then(
checks[key].condition(context, state).then(
(res) => setResults((val) => ({ ...val, [key]: res })),
(err) => setResults((val) => ({ ...val, [key]: { type: 'incompatible', reasons: [err] } }))
)
@@ -184,6 +42,7 @@ export function CHECK({ state, dispatch }: { state: State; dispatch: Dispatch<Ac
<Box key={key}>
<R
s={results[key]}
state={state}
setter={(val) => setResults((current) => ({ ...current, [key]: val }))}
dispatch={dispatch}
/>
@@ -193,9 +52,3 @@ export function CHECK({ state, dispatch }: { state: State; dispatch: Dispatch<Ac
</Box>
);
}

type CompatibilityResult =
| { type: 'loading' }
| { type: 'ignored' }
| { type: 'compatible' }
| { type: 'incompatible'; reasons: any[] };
4 changes: 2 additions & 2 deletions code/lib/create-storybook/src/ink/steps/Intents.tsx
Original file line number Diff line number Diff line change
@@ -27,10 +27,10 @@ export function INTENTS({ state, dispatch }: { state: State; dispatch: Dispatch<
}
}, []);

if (state.features) {
if (state.intents) {
return (
<Box>
<Text>Features are set to {state.features.join(', ')}</Text>
<Text>Intents are set to {state.intents.join(', ')}</Text>
</Box>
);
}
84 changes: 84 additions & 0 deletions code/lib/create-storybook/src/ink/steps/checks/configDir.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';

import { Spinner } from '@inkjs/ui';
import figureSet from 'figures';
import { Box, Text } from 'ink';

import { ACTIONS } from '..';
import { Confirm } from '../../components/Confirm';
import { type Check, CompatibilityType } from './index';

/**
* When configDir already exists, prompt:
*
* - Yes -> overwrite (delete)
* - No -> exit
*/
const name = 'configDir';
export const configDir: Check = {
condition: async (context, state) => {
if (context.fs && context.path) {
return context.fs
.stat(context.path.join(state.directory, '.storybook'))
.then(() => ({
type: CompatibilityType.INCOMPATIBLE,
reasons: ['.storybook directory already exists'],
}))
.catch(() => ({ type: CompatibilityType.COMPATIBLE }));
}
return {
type: CompatibilityType.INCOMPATIBLE,
reasons: ['Missing fs or path on context'],
};
},
render: ({ s, setter, dispatch }) => {
switch (s.type) {
case CompatibilityType.IGNORED: {
return (
<Box>
<Text>
{figureSet.smiley} {name}: ignored
</Text>
</Box>
);
}
case CompatibilityType.COMPATIBLE: {
return (
<Box>
<Text>
{figureSet.tick} {name}: OK
</Text>
</Box>
);
}
case CompatibilityType.INCOMPATIBLE: {
return (
<Box gap={1}>
<Text>{figureSet.cross}</Text>
<Text>configDir already exists. Do you want to continue?</Text>
<Confirm
onChange={(answer) => {
if (answer) {
setter({ type: 'ignored' });
} else {
dispatch({
type: ACTIONS.EXIT,
payload: { code: 1, reasons: s.reasons },
});
}
}}
/>
</Box>
);
}
default: {
return (
<Box gap={1}>
<Spinner />
<Text>{name}: Checking if directory exists...</Text>
</Box>
);
}
}
},
};
Loading
Loading