-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
257 additions
and
201 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,52 +1,64 @@ | ||
import { Parser } from '../utils'; | ||
import { BitbucketAPI, ConfigConstants, GithubAPI, LanguageCodes, Platform, SortBy } from "../constants"; | ||
import { BitbucketAPI, ConfigConstants, GithubAPI, LanguageCodes, OpenAIAPI, OpenAIModels, Platform, SortBy } from "../constants"; | ||
|
||
export interface IAPIConfig { | ||
baseUrl: string; | ||
token: string; | ||
}; | ||
|
||
export interface ICIConfig extends IAPIConfig { | ||
platform: Platform | undefined; | ||
owner: string; | ||
repo: string; | ||
}; | ||
|
||
export interface IAIConfig extends IAPIConfig { | ||
model: OpenAIModels | string, | ||
organization?: string, | ||
}; | ||
|
||
export interface IBaseConfig { | ||
baseLanguage: LanguageCodes; | ||
localesDir: string; | ||
targetLanguages: LanguageCodes[]; | ||
apiKey: string; | ||
email: string; | ||
sortBy: SortBy | ||
} | ||
export interface ICIConfig { | ||
platform: Platform | undefined, | ||
owner: string, | ||
repo: string, | ||
apiBaseUrl: string, | ||
apiToken: string | ||
} | ||
|
||
export interface ILibConfig extends ICIConfig, IBaseConfig {} | ||
sortBy: SortBy; | ||
ai: IAIConfig; | ||
ci?: ICIConfig; | ||
}; | ||
|
||
export const baseConfig: IBaseConfig = { | ||
baseLanguage: LanguageCodes.English, | ||
localesDir: ConfigConstants.localesDir, | ||
targetLanguages: [LanguageCodes.English, LanguageCodes.Turkish], | ||
apiKey: ConfigConstants.openAIKey, | ||
email: ConfigConstants.email, | ||
sortBy: SortBy.asceding | ||
sortBy: SortBy.asceding, | ||
ai: { | ||
baseUrl: OpenAIAPI.baseUrl, | ||
token: OpenAIAPI.token, | ||
model: OpenAIAPI.model | ||
}, | ||
}; | ||
|
||
|
||
export function loadConfig(configPath: string, packageJsonPath: string): ILibConfig { | ||
export function loadConfig(configPath: string, packageJsonPath: string): IBaseConfig { | ||
|
||
const configuration = require(configPath); | ||
const pkg = require(packageJsonPath); | ||
|
||
if(!pkg.repository?.url) { | ||
throw new Error(`[Localize AI][Config] repository information not found in ${packageJsonPath}`); | ||
throw new Error(`[Localize AI][loadConfig] repository information not found in ${packageJsonPath}`); | ||
} | ||
const { platform, owner, repo } = Parser.parseRepositoryUrl(pkg.repository.url); | ||
|
||
const ciConfig: ICIConfig = { | ||
platform, | ||
owner, | ||
repo, | ||
apiBaseUrl: (platform === Platform.github) ? GithubAPI.baseUrl || '' : (platform === Platform.bitbucket) ? BitbucketAPI.baseUrl || '' : '', | ||
apiToken: (platform === Platform.github) ? GithubAPI.token || '' : (platform === Platform.bitbucket) ? BitbucketAPI.token || '' : '' | ||
baseUrl: (platform === Platform.github) ? GithubAPI.baseUrl || '' : (platform === Platform.bitbucket) ? BitbucketAPI.baseUrl || '' : '', | ||
token: (platform === Platform.github) ? GithubAPI.token || '' : (platform === Platform.bitbucket) ? BitbucketAPI.token || '' : '' | ||
}; | ||
|
||
|
||
return { ...baseConfig, ...ciConfig, ...configuration }; | ||
return { ...baseConfig, ci: { ...ciConfig }, ...configuration }; | ||
}; |
Oops, something went wrong.