-
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.
feat: opt config load and add husky (#12)
* feat: opt config load and add husky * fix: alter code comment
- Loading branch information
Showing
15 changed files
with
505 additions
and
201 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -19,8 +19,8 @@ jest-stare/ | |
.dist/ | ||
_dist/ | ||
.vscode | ||
.env | ||
.history | ||
.yarn/install-state.gz | ||
|
||
.yarn/cache | ||
.yarn/cache | ||
.config*.json |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
|
||
echo "Running lint-staged..." | ||
npx lint-staged |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* eslint-disable no-process-env */ | ||
|
||
import localeConfig from '../locales'; | ||
|
||
const getRedisConfig = (db = 0, options: Record<string, unknown> = {}) => ({ | ||
host: process.env.REDIS_HOST, | ||
port: parseInt(process.env.REDIS_PORT, 10), | ||
password: process.env.REDIS_PWD, | ||
db, | ||
...options, | ||
}); | ||
|
||
/* | ||
default中的配置项,会被config.xxxx.ts中相同配置项覆盖 | ||
*/ | ||
export default { | ||
koa: { | ||
port: Number(process.env.PORT), | ||
globalPrefix: process.env.GLOBAL_PREFIX, | ||
}, | ||
midwayLogger: { | ||
default: { | ||
enableFile: false, | ||
enableConsole: false, | ||
}, | ||
}, | ||
redis: getRedisConfig(parseInt(process.env.REDIS_DB, 10)), | ||
mongoose: { | ||
dataSource: { | ||
default: { | ||
uri: process.env.MONGODB_URI, | ||
options: { | ||
user: process.env.MONGODB_USER, | ||
pass: process.env.MONGODB_PASSWORD, | ||
}, | ||
}, | ||
}, | ||
}, | ||
NODE_ENV: process.env.NODE_ENV, | ||
aws: { | ||
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID, | ||
awsSecretKey: process.env.AWS_SECRET_KEY, | ||
awsRegion: process.env.AWS_REGION, | ||
}, | ||
keys: process.env.COOKIE_SIGN_KEY, | ||
i18n: { | ||
defaultLocale: 'en-us', | ||
localeTable: localeConfig, | ||
fallbacks: { | ||
'*': 'en-us', | ||
}, | ||
writeCookie: false, | ||
resolver: false, | ||
}, | ||
}; |
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,21 +1,3 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable no-process-env */ | ||
|
||
import { MidwayConfig } from '@midwayjs/core'; | ||
import { merge } from 'lodash'; | ||
|
||
import { baseConfig } from './base'; | ||
|
||
export default (): MidwayConfig => { | ||
return merge(baseConfig, { | ||
koa: { | ||
port: 7001, | ||
}, | ||
midwayLogger: { | ||
default: { | ||
console: false, | ||
file: false, | ||
}, | ||
}, | ||
}) as MidwayConfig; | ||
}; | ||
export default {} as MidwayConfig; |
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,5 +1,3 @@ | ||
import { baseConfig } from './base'; | ||
import { MidwayConfig } from '@midwayjs/core'; | ||
|
||
import type { MidwayConfig } from '@midwayjs/core'; | ||
|
||
export default baseConfig as MidwayConfig; | ||
export default {} as MidwayConfig; |
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,5 +1,3 @@ | ||
import { baseConfig } from './base'; | ||
import { MidwayConfig } from '@midwayjs/core'; | ||
|
||
import type { MidwayConfig } from '@midwayjs/core'; | ||
|
||
export default baseConfig as MidwayConfig; | ||
export default {} as MidwayConfig; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable no-process-env */ | ||
import { join, resolve } from 'path'; | ||
|
||
import * as dotenv from 'dotenv'; | ||
|
||
export const ServerSecretsPath = resolve( | ||
'/', | ||
'mnt', | ||
'secrets', | ||
`onekey-eks-dashboard-${process.env.NODE_ENV}.json` | ||
); | ||
export const ServerConfigPath = resolve('/', 'mnt', 'config', 'config.json'); | ||
|
||
function loadJsonConfigFile(file: string, errorMessage: string) { | ||
try { | ||
dotenv.populate(process.env, require(file)); | ||
} catch (error) { | ||
console.log(errorMessage, file); | ||
} | ||
} | ||
|
||
/* | ||
加载线上配置文件 | ||
*/ | ||
loadJsonConfigFile(ServerConfigPath, 'No config found path:'); | ||
loadJsonConfigFile(ServerSecretsPath, 'No secrets found path:'); | ||
loadJsonConfigFile( | ||
join(__dirname, '..', '.config.json'), | ||
'No local json config found' | ||
); | ||
|
||
/* | ||
加载本地配置文件,注意.config.json和.env只需要一个即可,两个都存在的话,.config.json会覆盖.env | ||
*/ | ||
dotenv.config({ | ||
path: join(__dirname, '..', '.env'), | ||
}); |
Oops, something went wrong.