mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04: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')
|
export const defaultConfig = {
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
domain: '',
|
domain: '',
|
||||||
urlPath: '',
|
urlPath: '',
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
|
@ -1,15 +1,13 @@
|
||||||
'use strict'
|
import fs from 'fs'
|
||||||
|
|
||||||
const fs = require('fs')
|
function getFile (path): string | undefined {
|
||||||
|
|
||||||
function getFile (path) {
|
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export const defaultSSL = {
|
||||||
sslKeyPath: getFile('/run/secrets/key.pem'),
|
sslKeyPath: getFile('/run/secrets/key.pem'),
|
||||||
sslCertPath: getFile('/run/secrets/cert.pem'),
|
sslCertPath: getFile('/run/secrets/cert.pem'),
|
||||||
sslCAPath: getFile('/run/secrets/ca.pem') !== undefined ? [getFile('/run/secrets/ca.pem')] : [],
|
sslCAPath: getFile('/run/secrets/ca.pem') !== undefined ? [getFile('/run/secrets/ca.pem')] : [],
|
|
@ -1,18 +1,18 @@
|
||||||
'use strict'
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
|
|
||||||
const basePath = path.resolve('/run/secrets/')
|
const basePath = path.resolve('/run/secrets/')
|
||||||
|
|
||||||
function getSecret (secret) {
|
function getSecret (secret): string | undefined {
|
||||||
const filePath = path.join(basePath, secret)
|
const filePath = path.join(basePath, secret)
|
||||||
if (fs.existsSync(filePath)) return fs.readFileSync(filePath, 'utf-8')
|
if (fs.existsSync(filePath)) return fs.readFileSync(filePath, 'utf-8')
|
||||||
return undefined
|
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)) {
|
if (fs.existsSync(basePath)) {
|
||||||
module.exports = {
|
dockerSecret = {
|
||||||
dbURL: getSecret('dbURL'),
|
dbURL: getSecret('dbURL'),
|
||||||
sessionSecret: getSecret('sessionsecret'),
|
sessionSecret: getSecret('sessionsecret'),
|
||||||
sslKeyPath: getSecret('sslkeypath'),
|
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')
|
export const environment = {
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
sourceURL: process.env.CMD_SOURCE_URL,
|
sourceURL: process.env.CMD_SOURCE_URL,
|
||||||
domain: process.env.CMD_DOMAIN,
|
domain: process.env.CMD_DOMAIN,
|
||||||
urlPath: process.env.CMD_URL_PATH,
|
urlPath: process.env.CMD_URL_PATH,
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict'
|
import { toArrayConfig, toBooleanConfig, toIntegerConfig } from './utils'
|
||||||
|
|
||||||
const { toBooleanConfig, toArrayConfig, toIntegerConfig } = require('./utils')
|
export const hackmdEnvironment = {
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
domain: process.env.HMD_DOMAIN,
|
domain: process.env.HMD_DOMAIN,
|
||||||
urlPath: process.env.HMD_URL_PATH,
|
urlPath: process.env.HMD_URL_PATH,
|
||||||
port: toIntegerConfig(process.env.HMD_PORT),
|
port: toIntegerConfig(process.env.HMD_PORT),
|
|
@ -1,6 +1,4 @@
|
||||||
'use strict'
|
export const oldDefault = {
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
urlpath: undefined,
|
urlpath: undefined,
|
||||||
urladdport: undefined,
|
urladdport: undefined,
|
||||||
alloworigin: undefined,
|
alloworigin: undefined,
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict'
|
import { toBooleanConfig } from './utils'
|
||||||
|
|
||||||
const { toBooleanConfig } = require('./utils')
|
export const oldEnvironment = {
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
debug: toBooleanConfig(process.env.DEBUG),
|
debug: toBooleanConfig(process.env.DEBUG),
|
||||||
dburl: process.env.DATABASE_URL,
|
dburl: process.env.DATABASE_URL,
|
||||||
urlpath: process.env.URL_PATH,
|
urlpath: process.env.URL_PATH,
|
|
@ -1,32 +1,30 @@
|
||||||
'use strict'
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
const fs = require('fs')
|
export function toBooleanConfig (configValue: string | boolean | undefined): boolean {
|
||||||
const path = require('path')
|
if (typeof configValue === 'string') {
|
||||||
|
|
||||||
exports.toBooleanConfig = function toBooleanConfig (configValue) {
|
|
||||||
if (configValue && typeof configValue === 'string') {
|
|
||||||
return (configValue === 'true')
|
return (configValue === 'true')
|
||||||
}
|
}
|
||||||
return configValue
|
return configValue || false
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.toArrayConfig = function toArrayConfig (configValue, separator = ',', fallback) {
|
export function toArrayConfig (configValue: string | undefined, separator = ',', fallback = []): any[] {
|
||||||
if (configValue && typeof configValue === 'string') {
|
if (configValue) {
|
||||||
return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
|
return (configValue.split(separator).map(arrayItem => arrayItem.trim()))
|
||||||
}
|
}
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.toIntegerConfig = function toIntegerConfig (configValue) {
|
export function toIntegerConfig (configValue): number {
|
||||||
if (configValue && typeof configValue === 'string') {
|
if (configValue && typeof configValue === 'string') {
|
||||||
return parseInt(configValue)
|
return parseInt(configValue)
|
||||||
}
|
}
|
||||||
return configValue
|
return configValue
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getGitCommit = function getGitCommit (repodir) {
|
export function getGitCommit (repodir): string {
|
||||||
if (!fs.existsSync(repodir + '/.git/HEAD')) {
|
if (!fs.existsSync(repodir + '/.git/HEAD')) {
|
||||||
return undefined
|
return ''
|
||||||
}
|
}
|
||||||
let reference = fs.readFileSync(repodir + '/.git/HEAD', 'utf8')
|
let reference = fs.readFileSync(repodir + '/.git/HEAD', 'utf8')
|
||||||
if (reference.startsWith('ref: ')) {
|
if (reference.startsWith('ref: ')) {
|
||||||
|
@ -37,7 +35,7 @@ exports.getGitCommit = function getGitCommit (repodir) {
|
||||||
return reference
|
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 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…
Add table
Add a link
Reference in a new issue