ts: lib/config/utils.js

Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
Raccoon 2021-06-12 07:06:51 +08:00
parent 2a376db0fc
commit 294283f64f
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38

View File

@ -1,30 +1,28 @@
'use strict'
import * as fs from "fs";
import * as path from "path";
const fs = require('fs')
const path = require('path')
exports.toBooleanConfig = function toBooleanConfig (configValue) {
export function toBooleanConfig(configValue) {
if (configValue && typeof configValue === 'string') {
return (configValue === 'true')
}
return configValue
}
exports.toArrayConfig = function toArrayConfig (configValue, separator = ',', fallback) {
export function toArrayConfig(configValue, separator = ',', fallback) {
if (configValue && typeof configValue === 'string') {
return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
}
return fallback
}
exports.toIntegerConfig = function toIntegerConfig (configValue) {
export function toIntegerConfig(configValue) {
if (configValue && typeof configValue === 'string') {
return parseInt(configValue)
}
return configValue
}
exports.getGitCommit = function getGitCommit (repodir) {
export function getGitCommit(repodir) {
if (!fs.existsSync(repodir + '/.git/HEAD')) {
return undefined
}
@ -37,7 +35,7 @@ exports.getGitCommit = function getGitCommit (repodir) {
return reference
}
exports.getGitHubURL = function getGitHubURL (repo, reference) {
export function getGitHubURL(repo, reference) {
// if it's not a github reference, we handle handle that anyway
if (!repo.startsWith('https://github.com') && !repo.startsWith('git@github.com')) {
return repo