33 lines
2.2 KiB
JavaScript
33 lines
2.2 KiB
JavaScript
// node tools/mcp/sync.js <пути от src/> … — записать исходники из src/ в открытый плейс через Studio MCP
|
||
// (без Rojo). Новые скрипты создаются через multi_edit, существующие обновляются через execute_luau.
|
||
const fs = require('fs'), path = require('path'), os = require('os'), { execFileSync } = require('child_process');
|
||
const SRC = path.join(__dirname, '..', '..', 'src');
|
||
const ROOTS = {
|
||
'ReplicatedFirst': 'game.ReplicatedFirst', 'ReplicatedStorage': 'game.ReplicatedStorage',
|
||
'ServerScriptService': 'game.ServerScriptService', 'StarterPlayer/StarterPlayerScripts': 'game.StarterPlayer.StarterPlayerScripts',
|
||
};
|
||
const steps = [];
|
||
for (const rel of process.argv.slice(2)) {
|
||
const norm = rel.replace(/\\/g, '/');
|
||
const rootKey = Object.keys(ROOTS).find(k => norm.startsWith(k + '/'));
|
||
if (!rootKey) throw new Error('неизвестная папка: ' + rel);
|
||
const file = path.basename(norm);
|
||
let name, cls;
|
||
if (file.endsWith('.server.lua')) { name = file.slice(0, -11); cls = 'Script'; }
|
||
else if (file.endsWith('.client.lua')) { name = file.slice(0, -11); cls = 'LocalScript'; }
|
||
else { name = file.slice(0, -4); cls = 'ModuleScript'; }
|
||
const src = fs.readFileSync(path.join(SRC, norm), 'utf8').replace(/^/, '');
|
||
let lvl = 1; while (src.includes(']' + '='.repeat(lvl) + ']')) lvl++;
|
||
const eq = '='.repeat(lvl);
|
||
steps.push({ tool: 'execute_luau', args: { datamodel_type: 'Edit', code: `local s = ${ROOTS[rootKey]}:FindFirstChild(${JSON.stringify(name)})
|
||
if not s or s.ClassName ~= ${JSON.stringify(cls)} then return ${JSON.stringify(name)} .. " НЕТ В ПЛЕЙСЕ" end
|
||
local src = [${eq}[${src}]${eq}]
|
||
local ok = pcall(function() game:GetService("ScriptEditorService"):UpdateSourceAsync(s, function() return src end) end)
|
||
if not ok then s.Source = src end
|
||
return ${JSON.stringify(name)} .. " ok " .. #s.Source` } });
|
||
}
|
||
const tmp = path.join(os.tmpdir(), 'fishing-sync-' + process.pid + '.json');
|
||
fs.writeFileSync(tmp, JSON.stringify(steps));
|
||
process.stdout.write(execFileSync('node', [path.join(__dirname, 'run.js'), tmp], { encoding: 'utf8', maxBuffer: 1 << 26 }));
|
||
fs.unlinkSync(tmp);
|