UNPKG

dynamic-loader-plugin

Version:

Dynamic asset loader for Phaser 3 with priority-based loading

48 lines (47 loc) 2.32 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const scanner_1 = require("../src/loader/scanner"); const [customAssetDir, customOutputPath] = process.argv.slice(2); const DEFAULT_ASSETS_DIR = path_1.default.join(process.cwd(), "assets"); const DEFAULT_OUTPUT_PATH = path_1.default.join(process.cwd(), "manifest.json"); const ASSETS_DIR = customAssetDir || DEFAULT_ASSETS_DIR; const OUTPUT_PATH = customOutputPath || DEFAULT_OUTPUT_PATH; function generateManifest() { return __awaiter(this, void 0, void 0, function* () { try { //exist is now depreciated so usinf existsSync for checking directory existance if (!(0, fs_1.existsSync)(ASSETS_DIR)) { throw new Error("Assets directory is missing!"); } const manifest = yield (0, scanner_1.scanAssets)(ASSETS_DIR); const outputDir = path_1.default.dirname(OUTPUT_PATH); if (!(0, fs_1.existsSync)(outputDir)) { (0, fs_1.mkdirSync)(outputDir, { recursive: true }); } //@tushar-output manifest.json (0, fs_1.writeFileSync)(OUTPUT_PATH, JSON.stringify(manifest, null, 2)); } catch (error) { if (error instanceof Error) { console.error(error.message); } process.exit(1); } }); } generateManifest();