UNPKG

@knighted/duel

Version:
34 lines (33 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCompileFiles = exports.getRealPathAsFileUrl = exports.logError = exports.log = void 0; const node_url_1 = require("node:url"); const promises_1 = require("node:fs/promises"); const node_child_process_1 = require("node:child_process"); const node_process_1 = require("node:process"); const node_os_1 = require("node:os"); const log = (color = '\x1b[30m', msg = '') => { // eslint-disable-next-line no-console console.log(`${color}%s\x1b[0m`, msg); }; exports.log = log; const logError = log.bind(null, '\x1b[31m'); exports.logError = logError; const getRealPathAsFileUrl = async (path) => { const realPath = await (0, promises_1.realpath)(path); const asFileUrl = (0, node_url_1.pathToFileURL)(realPath).href; return asFileUrl; }; exports.getRealPathAsFileUrl = getRealPathAsFileUrl; const getCompileFiles = (tscBinPath, wd = (0, node_process_1.cwd)()) => { const { stdout } = (0, node_child_process_1.spawnSync)(tscBinPath, ['--listFilesOnly'], { cwd: wd, shell: node_process_1.platform === 'win32', }); // Exclude node_modules and empty strings. return stdout .toString() .split(node_os_1.EOL) .filter(path => !/node_modules|^$/.test(path)); }; exports.getCompileFiles = getCompileFiles;