Initial commit

This commit is contained in:
2020-05-17 14:36:52 +08:00
commit 8a10db1037
9 changed files with 146 additions and 0 deletions

4
src/main.ts Normal file
View 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
View 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 [];
}
}