Initial commit
This commit is contained in:
4
src/main.ts
Normal file
4
src/main.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { get_startup_arguments } from "./tiny/env";
|
||||
(async function main(argv: string[]) {
|
||||
console.log(argv);
|
||||
})(get_startup_arguments());
|
||||
36
src/tiny/env.ts
Normal file
36
src/tiny/env.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* JavaScript 运行环境
|
||||
*/
|
||||
export enum JavaScriptRuntime {
|
||||
/** 未知 */
|
||||
Unknown,
|
||||
/** NodeJS 运行时 */
|
||||
NodeJS,
|
||||
/** 浏览器 */
|
||||
Browser,
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前的运行环境
|
||||
*/
|
||||
export function get_runtime(): JavaScriptRuntime {
|
||||
if (typeof window == 'object' && typeof document == 'object') {
|
||||
return JavaScriptRuntime.Browser;
|
||||
} else if (typeof process == 'object' && process.release.name == 'node') {
|
||||
return JavaScriptRuntime.NodeJS;
|
||||
}
|
||||
return JavaScriptRuntime.Unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启动参数
|
||||
*/
|
||||
export function get_startup_arguments(): string[] {
|
||||
switch (get_runtime()) {
|
||||
case JavaScriptRuntime.NodeJS:
|
||||
return process.argv;
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user