diff --git a/packages/cli/src/commands/components/push/actions.ts b/packages/cli/src/commands/components/push/actions.ts index 73428c001..11690b581 100644 --- a/packages/cli/src/commands/components/push/actions.ts +++ b/packages/cli/src/commands/components/push/actions.ts @@ -247,10 +247,10 @@ export const upsertComponentInternalTag = async ( return await pushComponentInternalTag(space, tag); } }; - export const readComponentsFiles = async ( - options: ReadComponentsOptions): Promise => { - const { from, path, separateFiles = false, suffix } = options; + options: ReadComponentsOptions, +): Promise => { + const { from, path = '.storyblok', separateFiles = false, suffix, purpose = 'push-components' } = options; const resolvedPath = resolvePath(path, `components/${from}`); // Check if directory exists first @@ -258,13 +258,34 @@ export const readComponentsFiles = async ( await readdir(resolvedPath); } catch (error) { - const message = `No local components found for space ${chalk.bold(from)}. To push components, you need to pull them first: - -1. Pull the components from your source space: - ${chalk.cyan(`storyblok components pull --space ${from}`)} - -2. Then try pushing again: - ${chalk.cyan(`storyblok components push --space --from ${from}`)}`; + const err = error as NodeJS.ErrnoException; + const notFound = err?.code === 'ENOENT'; + const header = notFound + ? `No local components directory found for space ${chalk.bold(from)}.` + : `Failed to read local components for space ${chalk.bold(from)}.`; + + const nextStep = purpose === 'types-generate' + ? `To generate types, the CLI needs the local component JSON files. +If you ran ${chalk.cyan('storyblok components pull')} with a custom ${chalk.bold('--path')}, +you must use the same path again when running ${chalk.cyan('storyblok types generate')}. + +Example: + ${chalk.cyan(`storyblok components pull --space ${from} --path ./custom-folder`)} + ${chalk.cyan(`storyblok types generate --space ${from} --path ./custom-folder`)}` + : `To push components you need the local component JSON files. +Pull them first with: + ${chalk.cyan(`storyblok components pull --space ${from}`)} + +Then run your push command again: + ${chalk.cyan(`storyblok components push --space --from ${from}`)}`; + + const message = `${header} + +The CLI attempted to read component files from: +${chalk.cyan(resolvedPath)} + +${nextStep} +`; throw new FileSystemError( 'file_not_found', diff --git a/packages/cli/src/commands/components/push/constants.ts b/packages/cli/src/commands/components/push/constants.ts index 08e8e26d9..286e28e25 100644 --- a/packages/cli/src/commands/components/push/constants.ts +++ b/packages/cli/src/commands/components/push/constants.ts @@ -26,7 +26,13 @@ export interface PushComponentsOptions extends CommandOptions { export interface ReadComponentsOptions extends PushComponentsOptions { /** - * The path to read the components file from. + * Local path where component JSON files are located. + * + * ⚠️ Important: When using types generation command, + * if you provide a custom `--path`, it must be the same + * `--path` that was used when running + * `storyblok components pull`. + * * Defaults to `.storyblok/components`. * @default `.storyblok/components` */ @@ -35,4 +41,10 @@ export interface ReadComponentsOptions extends PushComponentsOptions { * Target space */ space?: string; + /** + * Determines the flow: + * - `push-components`: pushing local components to Storyblok + * - `types-generate`: generating type definitions from local JSON files + */ + purpose?: 'push-components' | 'types-generate'; }