UNPKG

roblox-ts-script

Version:

Dependency of projects using Create-Roblox-TS-Script.

55 lines (41 loc) 1.23 kB
import os from "os"; import path from "path"; import { watch } from "fs"; import { executeCommand, error, hasArgs } from "./shared/functions.js"; import build from "./build/index.js"; let lock = false; const _package = hasArgs(false, "--package", "-p"); const sync = !_package && hasArgs(false, "--sync", "-s"); function watchFolder(root, folder) { watch(folder, async function (_event, path) { if (lock || !path) return; lock = true; try { await build(root, true, sync, _package); } catch {} lock = false; }); } function getRojo() { const directory = path.resolve(os.homedir(), ".rokit", "bin"); return Bun.which("rojo", { PATH: directory }); } async function syncRojo(rojoConfig) { const rojo = getRojo(); if (!rojo) { error(true, "'rojo' not found."); } await executeCommand(rojo, ["plugin", "install"]); await executeCommand(rojo, ["serve", rojoConfig]); } export default async function (root) { const config = { folder: path.resolve(root, "src"), rojoConfig: path.resolve(root, "assets", "rojo", "studio"), }; try { await build(root, true, sync, _package); } catch {} watchFolder(root, config.folder); if (sync) syncRojo(config.rojoConfig); }