mirror of
https://github.com/status-im/codimd.git
synced 2025-01-26 04:01:00 +00:00
lint lib/config
Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
d19908d46f
commit
e6b9ab099f
@ -9,7 +9,9 @@ function getSecret(secret) {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
let dockerSecretConfig: any = {}
|
// eslint-disable-next-line
|
||||||
|
let dockerSecretConfig: Record<string, any> = {}
|
||||||
|
|
||||||
if (fs.existsSync(basePath)) {
|
if (fs.existsSync(basePath)) {
|
||||||
dockerSecretConfig = {
|
dockerSecretConfig = {
|
||||||
dbURL: getSecret('dburl'),
|
dbURL: getSecret('dburl'),
|
||||||
|
@ -34,7 +34,7 @@ const configFilePath = path.resolve(appRootPath, process.env.CMD_CONFIG_FILE ||
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] : undefined
|
const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] : undefined
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line
|
||||||
let config: any = require('./default')
|
let config: any = require('./default')
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
merge(config, require('./defaultSSL'))
|
merge(config, require('./defaultSSL'))
|
||||||
@ -214,7 +214,9 @@ config.defaultNotePath = path.resolve(appRootPath, config.defaultNotePath)
|
|||||||
config.docsPath = path.resolve(appRootPath, config.docsPath)
|
config.docsPath = path.resolve(appRootPath, config.docsPath)
|
||||||
config.uploadsPath = path.resolve(appRootPath, config.uploadsPath)
|
config.uploadsPath = path.resolve(appRootPath, config.uploadsPath)
|
||||||
config.env = env
|
config.env = env
|
||||||
|
|
||||||
// make config readonly
|
// make config readonly
|
||||||
|
// eslint-disable-next-line
|
||||||
config = deepFreeze(config) as any
|
config = deepFreeze(config) as any
|
||||||
|
|
||||||
export = config
|
export = config
|
||||||
|
@ -1,28 +1,28 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
export function toBooleanConfig(configValue) {
|
export function toBooleanConfig(configValue: string | boolean): boolean {
|
||||||
if (configValue && typeof configValue === 'string') {
|
if (configValue && typeof configValue === 'string') {
|
||||||
return (configValue === 'true')
|
return (configValue === 'true')
|
||||||
}
|
}
|
||||||
return configValue
|
return configValue as boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toArrayConfig(configValue, separator = ',', fallback ?: any) {
|
export function toArrayConfig(configValue: string | [], separator = ',', fallback ?: string[]): string[] {
|
||||||
if (configValue && typeof configValue === 'string') {
|
if (configValue && typeof configValue === 'string') {
|
||||||
return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
|
return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
|
||||||
}
|
}
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toIntegerConfig(configValue) {
|
export function toIntegerConfig(configValue: string | number): number {
|
||||||
if (configValue && typeof configValue === 'string') {
|
if (configValue && typeof configValue === 'string') {
|
||||||
return parseInt(configValue)
|
return parseInt(configValue)
|
||||||
}
|
}
|
||||||
return configValue
|
return configValue as number
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGitCommit(repodir) {
|
export function getGitCommit(repodir: string): string {
|
||||||
if (!fs.existsSync(repodir + '/.git/HEAD')) {
|
if (!fs.existsSync(repodir + '/.git/HEAD')) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ export function getGitCommit(repodir) {
|
|||||||
return reference
|
return reference
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGitHubURL(repo, reference) {
|
export function getGitHubURL(repo: string, reference: string): string {
|
||||||
// if it's not a github reference, we handle handle that anyway
|
// if it's not a github reference, we handle handle that anyway
|
||||||
if (!repo.startsWith('https://github.com') && !repo.startsWith('git@github.com')) {
|
if (!repo.startsWith('https://github.com') && !repo.startsWith('git@github.com')) {
|
||||||
return repo
|
return repo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user