"use strict"; // @ts-ignore // import { EDITOR } from 'cc/env'; Object.defineProperty(exports, "__esModule", { value: true }); exports.addChunks = exports.path = exports.fs = void 0; const effect_utils_1 = require("../effect-utils"); const useNpm = true; //(EDITOR || (globalThis as any).electron); exports.fs = useNpm && globalThis.require('fs-extra'); exports.path = useNpm && globalThis.require('path'); const { basename, dirname, extname, join, relative } = exports.path || {}; const { readFileSync, readdirSync, statSync } = exports.fs || {}; let _addedChunks = false; async function addChunks() { if (_addedChunks) { return; } _addedChunks = true; const enginePath = (await Editor.Message.request('engine', 'query-engine-info')).typescript.path; // 添加所有 builtin 头文件 const builtinChunkDir = join(enginePath, './editor/assets/chunks'); const builtinChunks = (() => { const arr = []; function step(dir) { const names = readdirSync(dir); names.forEach((name) => { const file = join(dir, name); if (/\.chunk$/.test(name)) { arr.push(file); } else if (statSync(file).isDirectory()) { step(file); } }); } step(builtinChunkDir); return arr; })(); for (let i = 0; i < builtinChunks.length; ++i) { const name = basename(builtinChunks[i], '.chunk'); const content = readFileSync(builtinChunks[i], { encoding: 'utf8' }); await (0, effect_utils_1.addChunk)(name, content); const relativeName = relative(builtinChunkDir, builtinChunks[i]).replace('.chunk', '').replace(/\\/g, '/'); await (0, effect_utils_1.addChunk)(relativeName, content); } } exports.addChunks = addChunks; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWZmZWN0LWhlYWRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb250cmlidXRpb25zL2VmZmVjdC1oZWFkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLGFBQWE7QUFDYixtQ0FBbUM7OztBQUVuQyxrREFBMkM7QUFFM0MsTUFBTSxNQUFNLEdBQUcsSUFBSSxDQUFDLENBQUEsMkNBQTJDO0FBQ2xELFFBQUEsRUFBRSxHQUFHLE1BQU0sSUFBSSxVQUFVLENBQUMsT0FBTyxDQUFDLFVB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vY2h1bmtzJyk7XG4gICAgY29uc3QgYnVpbHRpbkNodW5rcyA9ICgoKSA9PiB7XG4gICAgICAgIGNvbnN0IGFycjogc3RyaW5nW10gPSBbXTtcbiAgICAgICAgZnVuY3Rpb24gc3RlcChkaXI6IHN0cmluZykge1xuICAgICAgICAgICAgY29uc3QgbmFtZXM6IHN0cmluZ1tdID0gcmVhZGRpclN5bmMoZGlyKTtcbiAgICAgICAgICAgIG5hbWVzLmZvckVhY2goKG5hbWUpID0+IHtcbiAgICAgICAgICAgICAgICBjb25zdCBmaWxlID0gam9pbihkaXIsIG5hbWUpO1xuICAgICAgICAgICAgICAgIGlmICgvXFwuY2h1bmskLy50ZXN0KG5hbWUpKSB7XG4gICAgICAgICAgICAgICAgICAgIGFyci5wdXNoKGZpbGUpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3RhdFN5bmMoZmlsZSkuaXNEaXJlY3RvcnkoKSkge1xuICAgICAgICAgICAgICAgICAgICBzdGVwKGZpbGUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHN0ZXAoYnVpbHRpbkNodW5rRGlyKTtcbiAgICAgICAgcmV0dXJuIGFycjtcbiAgICB9KSgpO1xuXG4gICAgZm9yIChsZXQgaSA9IDA7IGkgPCBidWlsdGluQ2h1bmtzLmxlbmd0aDsgKytpKSB7XG4gICAgICAgIGNvbnN0IG5hbWUgPSBiYXNlbmFtZShidWlsdGluQ2h1bmtzW2ldLCAnLmNodW5rJyk7XG4gICAgICAgIGNvbnN0IGNvbnRlbnQgPSByZWFkRmlsZVN5bmMoYnVpbHRpbkNodW5rc1tpXSwgeyBlbmNvZGluZzogJ3V0ZjgnIH0pO1xuICAgICAgICBhd2FpdCBhZGRDaHVuayhuYW1lLCBjb250ZW50KTtcbiAgICAgICAgY29uc3QgcmVsYXRpdmVOYW1lID0gcmVsYXRpdmUoYnVpbHRpbkNodW5rRGlyLCBidWlsdGluQ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