tsrun/ts/index.ts

39 lines
1.1 KiB
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: {
lib: ['es2017'],
2019-04-08 14:17:57 +00:00
target: <any>'es2017', // Script Target should be a string -> 2 is for ES2015
2019-04-30 10:33:07 +00:00
experimentalDecorators: true,
esModuleInterop: true
} as CompilerOptions,
skipIgnore: true
2018-07-03 12:44:57 +00:00
};
2018-12-05 23:21:20 +00:00
if (process.argv.includes('--web')) {
const previousCompilerOptions = defaultTsNodeOptions.compilerOptions as CompilerOptions;
defaultTsNodeOptions.compilerOptions = {
...previousCompilerOptions,
2019-04-08 14:17:57 +00:00
lib: ['es2016', 'es2017', 'dom'],
2020-06-01 18:19:37 +00:00
target: <any>'es2017' // Script Target should be a string -> 2 is for ES2015
2019-03-02 22:03:05 +00:00
};
2018-12-05 23:21:20 +00:00
}
if (process.argv.includes('--nocache')) {
// currently caching is not used
}
tsNode.register(defaultTsNodeOptions);
2018-06-04 21:25:19 +00:00
if (process.env.CLI_CALL_TSRUN) {
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);
2018-06-05 21:40:59 +00:00
import(pathToLoad);
}