UNPKG

rune

Version:

CLI to upload your games to Rune

36 lines (35 loc) 1.52 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.findShortestPathFileThatEndsWith = exports.getGameFiles = void 0; const promises_1 = __importDefault(require("fs/promises")); const glob_1 = __importDefault(require("glob")); const util_1 = require("util"); const glob = (0, util_1.promisify)(glob_1.default); async function getGameFiles(gameDir) { const paths = await glob(`${ // glob can only work with forward slashes, but path module operates with // double backward slashes on Windows process.platform === "win32" ? gameDir.replace(/\\/g, "/") : gameDir}/**/*`, { nodir: true, // excluding files and directories that start with . dot: false, }); return Promise.all(paths.map(async (path) => ({ path, size: (await promises_1.default.stat(path)).size, ...((path.endsWith("/index.html") || path.endsWith("/logic.js")) && { content: await promises_1.default.readFile(path, "utf-8"), }), }))); } exports.getGameFiles = getGameFiles; function findShortestPathFileThatEndsWith(files, fileName) { return files .filter((file) => file.path === fileName || file.path.endsWith(`/${fileName}`)) .sort((a, b) => a.path.length - b.path.length) .at(0); } exports.findShortestPathFileThatEndsWith = findShortestPathFileThatEndsWith;