Skip to content

Commit cb69248

Browse files
committed
type definition refactoring
1 parent f0a8d3f commit cb69248

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

types/index.d.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ export type FormatOptions = {
116116
* `,
117117
* }
118118
*/
119-
120119
export interface SFCFileInfo {
121120
path: string
122121
content: string
@@ -157,6 +156,40 @@ export interface SFCFileInfo {
157156
declare function squeeze (basePath: string, files: SFCFileInfo[]): MetaLocaleMessage
158157
declare function infuse (basePath: string, sources: SFCFileInfo[], meta: MetaLocaleMessage, options?: FormatOptions): SFCFileInfo[]
159158

159+
/**
160+
* Provider factory function
161+
*/
162+
export type ProviderFactory<T = {}> = (configration: ProviderConfiguration<T>) => Provider
163+
164+
/**
165+
* Provider interface
166+
*/
167+
export interface Provider {
168+
/**
169+
* push the resource to localization service
170+
* @param resource the resource that push to localization service
171+
* @param dryRun whether the CLI run as dryRun mode
172+
*/
173+
push (resource: ProviderPushResource, dryRun: boolean): Promise<void>
174+
/**
175+
* pull the resource from localization service
176+
* @param locales locales that pull from localization service, if empty, you must pull the all locale messages
177+
* @param dryRun whether the CLI run as dryRun mode
178+
* @returns the resource of localization service
179+
*/
180+
pull (locales: Locale[], dryRun: boolean): Promise<ProviderPullResource>
181+
}
182+
183+
/**
184+
* mode that can be processed with provider push
185+
* - 'file-path':
186+
* To use when the provider uses the locale message directly from the file.
187+
* for example, used for file uploading.
188+
* When specified that mode, `ProviderPushResource` are passed from the CLI as `files`.
189+
* - 'locale-message':
190+
* To use when the provider uses the locale message.
191+
* When specified that mode, `ProviderPushResource` are passed from the CLI as `messaegs`.
192+
*/
160193
export type ProviderPushMode = 'file-path' | 'locale-message'
161194

162195
export type ProviderPushFileInfo = {
@@ -172,13 +205,6 @@ export type ProviderPushResource = {
172205

173206
export type ProviderPullResource = LocaleMessages
174207

175-
export interface Provider {
176-
push (resource: ProviderPushResource, dryRun: boolean): Promise<void>
177-
pull (locales: Locale[], dryRun: boolean): Promise<ProviderPullResource>
178-
}
179-
180-
export type ProviderFactory<T = {}> = (configration: ProviderConfiguration<T>) => Provider
181-
182208
/**
183209
* ProviderConfiguration provider fields structure
184210
* e.g.
@@ -189,7 +215,6 @@ export type ProviderFactory<T = {}> = (configration: ProviderConfiguration<T>) =
189215
* "pushMode": "file-path"
190216
* }
191217
*/
192-
193218
export interface ProviderConfiguration<T = {}> {
194219
provider: { [key in keyof ProviderConfigurationValue<T>]: ProviderConfigurationValue<T>[key] }
195220
pushMode: ProviderPushMode

0 commit comments

Comments
 (0)