-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@artusx/utils): simplify bootstrap and utils
- Loading branch information
Showing
10 changed files
with
60 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { main } from './bootstrap'; | ||
import path from 'path'; | ||
import { bootstrap } from '@artusx/utils'; | ||
|
||
main(); | ||
const ROOT_DIR = path.resolve(__dirname); | ||
|
||
bootstrap({ root: ROOT_DIR }); |
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,3 +1,6 @@ | ||
import { bootstrap } from '@artusx/utils/bootstrap'; | ||
import path from 'path'; | ||
import { bootstrap } from '@artusx/utils'; | ||
|
||
bootstrap(); | ||
const ROOT_DIR = path.resolve(__dirname); | ||
|
||
bootstrap({ root: ROOT_DIR }); |
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,6 @@ | ||
import path from 'path'; | ||
import { bootstrap } from '@artusx/utils'; | ||
|
||
const ROOT_DIR = path.resolve(__dirname); | ||
|
||
bootstrap({ root: ROOT_DIR }); |
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,15 +1,20 @@ | ||
import path from 'path'; | ||
import dotenv from 'dotenv'; | ||
import { Application } from './application'; | ||
|
||
dotenv.config(); | ||
|
||
export const bootstrap = async (options?: object, configDir?: string) => { | ||
export const bootstrap = async (options: Options) => { | ||
const { root, configDir = 'config', ...rest } = options || {}; | ||
const app = await Application.start({ | ||
...options, | ||
root: path.resolve(__dirname), | ||
configDir: configDir || 'config', | ||
...rest, | ||
root, | ||
configDir, | ||
}); | ||
|
||
return app; | ||
}; | ||
|
||
export type Options = Record<string, any> & { | ||
root: string; | ||
configDir?: string; | ||
}; |
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,46 +1,45 @@ | ||
export const getEnv = <T>(key: string, type?: string): T => { | ||
const value = process.env[key] || ''; | ||
|
||
let target: unknown = value; | ||
|
||
if (type === 'boolean') { | ||
target = Boolean(value); | ||
} | ||
|
||
if (type === 'number') { | ||
target = parseInt(value); | ||
} | ||
|
||
return target as T; | ||
}; | ||
|
||
export const getApiId = () => { | ||
const api_id = process.env.API_ID; | ||
const apiID = getEnv<Number>('API_ID', 'number'); | ||
|
||
if (!api_id) { | ||
if (!apiID) { | ||
return; | ||
} | ||
|
||
return parseInt(api_id); | ||
return apiID; | ||
}; | ||
|
||
export const getProxy = () => { | ||
const proxy_ip = process.env.PROXY_IP; | ||
const proxy_port = process.env.PROXY_PORT; | ||
const proxy_socket_type = process.env.PROXY_SOCKET_TYPE; | ||
const ip = getEnv<string>('PROXY_IP'); | ||
const port = getEnv<Number>('PROXY_PORT', 'number'); | ||
const socksType = getEnv<Number>('PROXY_SOCKET_TYPE', 'number'); | ||
|
||
if (!proxy_ip || !proxy_port || !proxy_socket_type) { | ||
if (!ip || !port || !socksType) { | ||
return; | ||
} | ||
|
||
const proxy_protocol = proxy_socket_type === '5' ? 'socks5' : 'socks4'; | ||
|
||
const proxyString = `${proxy_protocol}://${proxy_ip}:${proxy_port}`; | ||
const protocol = socksType === 5 ? 'socks5' : 'socks4'; | ||
const proxyString = `${protocol}://${ip}:${port}`; | ||
|
||
return { | ||
ip: proxy_ip, | ||
port: parseInt(proxy_port), | ||
socksType: parseInt(proxy_socket_type), | ||
ip, | ||
port, | ||
socksType, | ||
proxyString, | ||
}; | ||
}; | ||
|
||
export const getEnv = <T>(key: string, type?: string): T => { | ||
const value = process.env[key] || ''; | ||
|
||
let target: unknown = value; | ||
|
||
if (type === 'boolean') { | ||
target = Boolean(value); | ||
} | ||
|
||
if (type === 'number') { | ||
target = parseInt(value); | ||
} | ||
|
||
return target as T; | ||
}; |