UNPKG

@akiver/cs-demo-analyzer

Version:

Analyze and extract data from Counter-Strike demos.

72 lines (71 loc) 2.65 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.analyzeDemo = analyzeDemo; const node_child_process_1 = require("node:child_process"); const promises_1 = __importDefault(require("node:fs/promises")); const platform_1 = require("./platform"); async function analyzeDemo({ demoPath, outputFolderPath, format, source, analyzePositions, minify, onStart, onStdout, onStderr, onEnd, executablePath, }) { await promises_1.default.mkdir(outputFolderPath, { recursive: true }); return new Promise((resolve, reject) => { const binPath = executablePath ?? (0, platform_1.getBinaryPath)(); const args = [ `"${binPath}"`, `-demo-path="${demoPath}"`, `-output="${outputFolderPath}"`, `-format="${format}"`, ]; if (source) { args.push(`-source="${source}"`); } if (analyzePositions) { args.push(`-positions="${analyzePositions}"`); } if (minify) { args.push('-minify'); } const command = args.join(' '); if (onStart) { onStart(command); } const child = (0, node_child_process_1.exec)(command, { windowsHide: true, maxBuffer: undefined }); if (onStdout) { child.stdout?.on('data', (data) => { onStdout(data); }); } if (onStderr) { child.stderr?.on('data', (data) => { onStderr(data); }); } child.on('exit', (code) => { if (onEnd) { onEnd(code); } if (code === 0) { resolve(); } else { reject(); } }); }); } __exportStar(require("./constants"), exports);