tsrun/ts/index.ts

33 lines
919 B
TypeScript
Raw Normal View History

2018-06-04 21:25:19 +00:00
import * as path from 'path';
2018-07-02 07:03:26 +00:00
import * as tsNode from 'ts-node';
import { CompilerOptions } from 'typescript';
2018-06-04 21:25:19 +00:00
2020-06-01 18:32:33 +00:00
const defaultTsNodeOptions: tsNode.CreateOptions = {
2019-04-30 10:33:07 +00:00
compilerOptions: {
2022-03-11 16:26:50 +00:00
lib: ['dom'],
2021-10-06 11:06:24 +00:00
target: <any>'es2020', // Script Target should be a string -> 2 is for ES2015
2019-04-30 10:33:07 +00:00
experimentalDecorators: true,
2021-06-23 13:26:55 +00:00
esModuleInterop: true,
2021-06-23 13:45:34 +00:00
strictNullChecks: false,
2022-03-11 16:26:50 +00:00
moduleResolution: <any>'node12',
module: <any>'es2020',
2021-10-06 11:06:24 +00:00
importsNotUsedAsValues: <any>'preserve',
2019-04-30 10:33:07 +00:00
} as CompilerOptions,
2021-06-23 13:26:55 +00:00
skipIgnore: true,
2022-03-11 16:56:08 +00:00
esm: true,
2018-07-03 12:44:57 +00:00
};
tsNode.register(defaultTsNodeOptions);
2018-06-04 21:25:19 +00:00
2020-06-01 19:37:11 +00:00
export const runCli = async () => {
2018-06-25 08:23:15 +00:00
// contents of argv array
// process.argv[0] -> node Executable
// process.argv[1] -> tsrun executable
2018-07-03 12:44:57 +00:00
const pathToTsFile = process.argv[2];
2018-06-25 08:23:15 +00:00
const pathToLoad = path.join(process.cwd(), pathToTsFile);
2021-06-23 13:57:57 +00:00
process.argv.splice(2, 1);
2021-06-24 08:58:46 +00:00
// console.log(process.argv);
2018-06-05 21:40:59 +00:00
import(pathToLoad);
2020-06-01 19:38:19 +00:00
};