UNPKG

eyereasoner

Version:

Distributing the [EYE](https://github.com/eyereasoner/eye) reasoner for browser and node using WebAssembly.

51 lines (50 loc) 2.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertToPosixPath = convertToPosixPath; exports.mainFunc = mainFunc; const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const readline_1 = __importDefault(require("readline")); const __1 = require(".."); const query_1 = require("../query"); function convertToPosixPath(filePath, pathLib = path_1.default) { // For the Emscripten FS, we need to ensure posix separators // for any relative sub-path that may have been typed in // on w32 as subdir\socrates.n3 // First normalize the path to handle any path oddities const normalizedPath = pathLib.normalize(filePath); // Then split by platform-specific separator and join with POSIX separator return normalizedPath.split(pathLib.sep).join(pathLib.posix.sep); } async function mainFunc(proc) { const rl = readline_1.default.promises.createInterface({ input: proc.stdin, output: proc.stdout, }); const Module = await (0, __1.SwiplEye)(); const posixArgv = []; // Make any local files available to the reasoner for (const arg of proc.argv.slice(2)) { const p = path_1.default.join(proc.cwd(), arg); if (fs_1.default.existsSync(p)) { const posixPath = convertToPosixPath(arg); posixArgv.push(posixPath); // Create any subdirectories needed for this file path const dirname = path_1.default.dirname(posixPath); // @ts-ignore: mkdirTree exists in Emscripten FS but is not typed. // https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/72434 Module.FS.mkdirTree(dirname); // Now write the file to the correct path Module.FS.writeFile(posixPath, fs_1.default.readFileSync(p)); } else { // For non-filepath arguments, keep them as-is posixArgv.push(arg); } } await (0, query_1.qaQuery)(Module, 'main', posixArgv, (q) => rl.question(`${q}\n|: `)); rl.close(); }