-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/refactor-language-command-updated-dx' into feat…
…ure/pull-components-cmd
- Loading branch information
Showing
32 changed files
with
924 additions
and
873 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { join } from 'node:path' | ||
import { handleAPIError, handleFileSystemError } from '../../utils' | ||
import type { FetchError } from '../../utils/fetch' | ||
import { customFetch } from '../../utils/fetch' | ||
import { resolvePath, saveToFile } from '../../utils/filesystem' | ||
import type { PullLanguagesOptions } from './constants' | ||
import type { RegionCode } from '../../constants' | ||
import type { SpaceInternationalization } from '../../types' | ||
import { getStoryblokUrl } from '../../utils/api-routes' | ||
|
||
export const fetchLanguages = async (space: string, token: string, region: RegionCode): Promise<SpaceInternationalization | undefined> => { | ||
try { | ||
const url = getStoryblokUrl(region) | ||
const response = await customFetch<{ | ||
space: SpaceInternationalization | ||
}>(`${url}/spaces/${space}`, { | ||
headers: { | ||
Authorization: token, | ||
}, | ||
}) | ||
|
||
return { | ||
default_lang_name: response.space.default_lang_name, | ||
languages: response.space.languages, | ||
} | ||
} | ||
catch (error) { | ||
handleAPIError('pull_languages', error as FetchError) | ||
} | ||
} | ||
|
||
export const saveLanguagesToFile = async (space: string, internationalizationOptions: SpaceInternationalization, options: PullLanguagesOptions) => { | ||
try { | ||
const { filename = 'languages', suffix, path } = options | ||
const data = JSON.stringify(internationalizationOptions, null, 2) | ||
const name = suffix ? `${filename}.${suffix}.json` : `${filename}.json` | ||
const resolvedPath = resolvePath(path, `languages/${space}/`) | ||
const filePath = join(resolvedPath, name) | ||
|
||
await saveToFile(filePath, data) | ||
} | ||
catch (error) { | ||
handleFileSystemError('write', error as Error) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.