mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-15 04:11:58 +00:00
Migrate config templates to TypeScript
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
b6ad2b2625
commit
3340780157
10 changed files with 43 additions and 59 deletions
|
@ -1,8 +1,6 @@
|
|||
'use strict'
|
||||
import os from 'os'
|
||||
|
||||
const os = require('os')
|
||||
|
||||
module.exports = {
|
||||
export const defaultConfig = {
|
||||
domain: '',
|
||||
urlPath: '',
|
||||
host: '0.0.0.0',
|
|
@ -1,15 +1,13 @@
|
|||
'use strict'
|
||||
import fs from 'fs'
|
||||
|
||||
const fs = require('fs')
|
||||
|
||||
function getFile (path) {
|
||||
function getFile (path): string | undefined {
|
||||
if (fs.existsSync(path)) {
|
||||
return path
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export const defaultSSL = {
|
||||
sslKeyPath: getFile('/run/secrets/key.pem'),
|
||||
sslCertPath: getFile('/run/secrets/cert.pem'),
|
||||
sslCAPath: getFile('/run/secrets/ca.pem') !== undefined ? [getFile('/run/secrets/ca.pem')] : [],
|
|
@ -1,18 +1,18 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const basePath = path.resolve('/run/secrets/')
|
||||
|
||||
function getSecret (secret) {
|
||||
function getSecret (secret): string | undefined {
|
||||
const filePath = path.join(basePath, secret)
|
||||
if (fs.existsSync(filePath)) return fs.readFileSync(filePath, 'utf-8')
|
||||
return undefined
|
||||
}
|
||||
|
||||
export let dockerSecret: { s3: { accessKeyId: string | undefined; secretAccessKey: string | undefined }; github: { clientID: string | undefined; clientSecret: string | undefined }; facebook: { clientID: string | undefined; clientSecret: string | undefined }; google: { clientID: string | undefined; hostedDomain: string | undefined; clientSecret: string | undefined }; sessionSecret: string | undefined; sslKeyPath: string | undefined; twitter: { consumerSecret: string | undefined; consumerKey: string | undefined }; dropbox: { clientID: string | undefined; clientSecret: string | undefined; appKey: string | undefined }; gitlab: { clientID: string | undefined; clientSecret: string | undefined }; imgur: string | undefined; sslCertPath: string | undefined; sslCAPath: string | undefined; dhParamPath: string | undefined; dbURL: string | undefined; azure: { connectionString: string | undefined } }
|
||||
|
||||
if (fs.existsSync(basePath)) {
|
||||
module.exports = {
|
||||
dockerSecret = {
|
||||
dbURL: getSecret('dbURL'),
|
||||
sessionSecret: getSecret('sessionsecret'),
|
||||
sslKeyPath: getSecret('sslkeypath'),
|
|
@ -1,16 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
exports.Environment = {
|
||||
development: 'development',
|
||||
production: 'production',
|
||||
test: 'test'
|
||||
}
|
||||
|
||||
exports.Permission = {
|
||||
freely: 'freely',
|
||||
editable: 'editable',
|
||||
limited: 'limited',
|
||||
locked: 'locked',
|
||||
protected: 'protected',
|
||||
private: 'private'
|
||||
}
|
14
lib/config/enum.ts
Normal file
14
lib/config/enum.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
export enum Environment {
|
||||
development = 'development',
|
||||
production = 'production',
|
||||
test = 'test'
|
||||
}
|
||||
|
||||
export enum Permission {
|
||||
freely = 'freely',
|
||||
editable = 'editable',
|
||||
limited = 'limited',
|
||||
locked = 'locked',
|
||||
protected = 'protected',
|
||||
private = 'private'
|
||||
}
|
|
@ -1,8 +1,6 @@
|
|||
'use strict'
|
||||
import { toArrayConfig, toBooleanConfig, toIntegerConfig } from './utils'
|
||||
|
||||
const { toBooleanConfig, toArrayConfig, toIntegerConfig } = require('./utils')
|
||||
|
||||
module.exports = {
|
||||
export const environment = {
|
||||
sourceURL: process.env.CMD_SOURCE_URL,
|
||||
domain: process.env.CMD_DOMAIN,
|
||||
urlPath: process.env.CMD_URL_PATH,
|
|
@ -1,8 +1,6 @@
|
|||
'use strict'
|
||||
import { toArrayConfig, toBooleanConfig, toIntegerConfig } from './utils'
|
||||
|
||||
const { toBooleanConfig, toArrayConfig, toIntegerConfig } = require('./utils')
|
||||
|
||||
module.exports = {
|
||||
export const hackmdEnvironment = {
|
||||
domain: process.env.HMD_DOMAIN,
|
||||
urlPath: process.env.HMD_URL_PATH,
|
||||
port: toIntegerConfig(process.env.HMD_PORT),
|
|
@ -1,6 +1,4 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
export const oldDefault = {
|
||||
urlpath: undefined,
|
||||
urladdport: undefined,
|
||||
alloworigin: undefined,
|
|
@ -1,8 +1,6 @@
|
|||
'use strict'
|
||||
import { toBooleanConfig } from './utils'
|
||||
|
||||
const { toBooleanConfig } = require('./utils')
|
||||
|
||||
module.exports = {
|
||||
export const oldEnvironment = {
|
||||
debug: toBooleanConfig(process.env.DEBUG),
|
||||
dburl: process.env.DATABASE_URL,
|
||||
urlpath: process.env.URL_PATH,
|
|
@ -1,32 +1,30 @@
|
|||
'use strict'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
exports.toBooleanConfig = function toBooleanConfig (configValue) {
|
||||
if (configValue && typeof configValue === 'string') {
|
||||
export function toBooleanConfig (configValue: string | boolean | undefined): boolean {
|
||||
if (typeof configValue === 'string') {
|
||||
return (configValue === 'true')
|
||||
}
|
||||
return configValue
|
||||
return configValue || false
|
||||
}
|
||||
|
||||
exports.toArrayConfig = function toArrayConfig (configValue, separator = ',', fallback) {
|
||||
if (configValue && typeof configValue === 'string') {
|
||||
export function toArrayConfig (configValue: string | undefined, separator = ',', fallback = []): any[] {
|
||||
if (configValue) {
|
||||
return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
exports.toIntegerConfig = function toIntegerConfig (configValue) {
|
||||
export function toIntegerConfig (configValue): number {
|
||||
if (configValue && typeof configValue === 'string') {
|
||||
return parseInt(configValue)
|
||||
}
|
||||
return configValue
|
||||
}
|
||||
|
||||
exports.getGitCommit = function getGitCommit (repodir) {
|
||||
export function getGitCommit (repodir): string {
|
||||
if (!fs.existsSync(repodir + '/.git/HEAD')) {
|
||||
return undefined
|
||||
return ''
|
||||
}
|
||||
let reference = fs.readFileSync(repodir + '/.git/HEAD', 'utf8')
|
||||
if (reference.startsWith('ref: ')) {
|
||||
|
@ -37,7 +35,7 @@ exports.getGitCommit = function getGitCommit (repodir) {
|
|||
return reference
|
||||
}
|
||||
|
||||
exports.getGitHubURL = function getGitHubURL (repo, reference) {
|
||||
export function getGitHubURL (repo, reference): string {
|
||||
// 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
|
Loading…
Reference in a new issue