chai-latte
Version:
Build expressive & readable fluent interface libraries.
31 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tsnode = void 0;
const tslib_1 = require("tslib");
const child_process_1 = tslib_1.__importDefault(require("child_process"));
const getBinPath = () => {
const buffer = child_process_1.default.execSync('npm bin', { stdio: 'pipe' });
return buffer.toString().trim();
};
const mergeScriptWithArguments = (script, ...variables) => {
const scriptCopy = [...script];
return variables.reduce((acc, variable, index) => {
const mergedString = acc + scriptCopy.shift() + variable;
const isLastVariable = index === variables.length - 1;
if (isLastVariable) {
return mergedString + scriptCopy.shift();
}
return mergedString;
}, '');
};
const tsnode = (script, ...variables) => {
const binPath = getBinPath();
const tsNodePath = `${binPath}/ts-node`;
const mergedString = mergeScriptWithArguments(script, ...variables);
const child = child_process_1.default.execSync(`${tsNodePath} -e "
${mergedString}
"`);
return child.toString();
};
exports.tsnode = tsnode;
//# sourceMappingURL=tsnode.js.map