2022-03-12 13:43:54 +00:00
|
|
|
import * as plugins from './plugins.js';
|
2018-06-04 21:25:19 +00:00
|
|
|
|
2022-03-12 13:43:54 +00:00
|
|
|
import { dirname } from 'path';
|
|
|
|
import { fileURLToPath } from 'url';
|
2018-07-03 12:40:58 +00:00
|
|
|
|
2022-03-12 13:43:54 +00:00
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
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];
|
2022-03-12 13:43:54 +00:00
|
|
|
|
|
|
|
const tsNodeLoaderPath = plugins.path.join(__dirname, 'loader.js')
|
|
|
|
const pathToLoad = plugins.path.join(process.cwd(), pathToTsFile);
|
2022-03-12 13:52:42 +00:00
|
|
|
process.argv.splice(0, 3); // this ensures transparent arguments for the child process
|
2022-03-12 13:43:54 +00:00
|
|
|
|
|
|
|
const smartshellInstance = new plugins.smartshell.Smartshell({
|
|
|
|
executor: 'bash'
|
|
|
|
});
|
|
|
|
|
2022-03-12 17:54:19 +00:00
|
|
|
// note: -> reduce on emtpy array does not work
|
|
|
|
// thus check needed before reducing the argv array
|
2022-03-12 17:50:17 +00:00
|
|
|
smartshellInstance.exec(`node --loader ${tsNodeLoaderPath} ${pathToLoad} ${process.argv.length > 0 ? process.argv.reduce((prevArg, currentArg) => {
|
2022-03-12 13:43:54 +00:00
|
|
|
return prevArg + ' ' + currentArg;
|
2022-03-12 17:50:17 +00:00
|
|
|
}) : ''}`);
|
2022-03-12 13:43:54 +00:00
|
|
|
|
2020-06-01 19:38:19 +00:00
|
|
|
};
|