From 5081d235d059fd2d7d727958cfd1f98aeed084ee Mon Sep 17 00:00:00 2001 From: alvarosabu Date: Thu, 12 Dec 2024 10:43:25 +0100 Subject: [PATCH] feat: pass space data as an object to the save components to files action --- src/commands/components/actions.ts | 27 +++++++-------------------- src/commands/components/index.ts | 18 +++++------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/commands/components/actions.ts b/src/commands/components/actions.ts index f5cdb44..ed911df 100644 --- a/src/commands/components/actions.ts +++ b/src/commands/components/actions.ts @@ -56,6 +56,11 @@ export interface SpaceComponentPreset { description: string } +export interface SpaceData { + components: SpaceComponent[] + groups: SpaceComponentGroup[] + presets: SpaceComponentPreset[] +} /** * Resolves the nested folder structure based on component group hierarchy. * @param groupUuid - The UUID of the component group. @@ -113,11 +118,10 @@ export const fetchComponentPresets = async (space: string, token: string, region export const saveComponentsToFiles = async ( space: string, - components: SpaceComponent[], - groups: SpaceComponentGroup[], - presets: SpaceComponentPreset[], + spaceData: SpaceData, options: PullComponentsOptions, ) => { + const { components, groups, presets } = spaceData const { filename = 'components', suffix = space, path, separateFiles } = options const resolvedPath = resolvePath(path, 'components') @@ -163,20 +167,3 @@ export const saveComponentsToFiles = async ( handleFileSystemError('write', error as Error) } } - -export const saveComponentPresetsToFiles = async ( - space: string, - presets: SpaceComponentPreset[], - options: PullComponentsOptions, -) => { - const { filename = 'presets', suffix = space, path } = options - - try { - const resolvedPath = resolvePath(path, 'components') - const filePath = join(resolvedPath, `${filename}.${suffix}.json`) - await saveToFile(filePath, JSON.stringify(presets, null, 2)) - } - catch (error) { - handleFileSystemError('write', error as Error) - } -} diff --git a/src/commands/components/index.ts b/src/commands/components/index.ts index 959d458..f072489 100644 --- a/src/commands/components/index.ts +++ b/src/commands/components/index.ts @@ -52,7 +52,11 @@ componentsCommand } // Save everything using the new structure - await saveComponentsToFiles(space, components, groups || [], presets || [], { ...options, path }) + await saveComponentsToFiles( + space, + { components, groups: groups || [], presets: presets || [] }, + { ...options, path }, + ) if (separateFiles) { if (filename !== 'components') { @@ -64,18 +68,6 @@ componentsCommand const msgFilename = `${filename}.${suffix}.json` konsola.ok(`Components downloaded successfully in ${chalk.hex(colorPalette.PRIMARY)(path ? `${path}/${msgFilename}` : `./storyblok/components/${msgFilename}`)}`) } - - // Fetch component groups - /* const componentGroups = await fetchComponentGroups(space, state.password, state.region) - - if (!componentGroups || componentGroups.length === 0) { - konsola.warn(`No component groups found in the space ${space}`) - return - } - - await saveComponentsToFiles(space, componentGroups, { ...options, path, filename: 'groups' }) - - konsola.ok(`Component groups downloaded successfully in ${chalk.hex(colorPalette.PRIMARY)(path ? `${path}/groups.${suffix}.json` : `./storyblok/components/groups.${suffix}.json`)}`) */ } catch (error) { handleError(error as Error, verbose)