From 35e122005aff60dff6bda2db76a719750cd30f78 Mon Sep 17 00:00:00 2001 From: ffrostflame <80861876+ffrostflame@users.noreply.github.com> Date: Sat, 15 Jul 2023 22:36:56 -0400 Subject: [PATCH] create standalone.js --- standalone.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 standalone.js diff --git a/standalone.js b/standalone.js new file mode 100644 index 0000000..edac2b8 --- /dev/null +++ b/standalone.js @@ -0,0 +1,51 @@ +const { + mkdirSync, + writeFileSync +} = require("fs"); +const { copySync } = require("fs-extra"); +const { join, dirname, basename } = require("path"); +const { execFile } = require("child_process"); +const { rimraf } = require("rimraf"); + +async function buildStandalone() { + return new Promise((resolve) => { + const projectName = basename(dirname(__filename)); + + const srcDir = join(projectName, "../src"); + const packageDir = join(projectName, "../Packages"); + const destinationDir = join(projectName, "../standalone"); + const destSrcDir = join(destinationDir, "./src"); + const standaloneProject = join(projectName, "../standalone.project.json"); + + mkdirSync(destinationDir); + mkdirSync(destSrcDir); + writeFileSync( + join(destinationDir, "./init.luau"), + "return require(script.src)" + ); + writeFileSync( + standaloneProject, + `{"name": "${projectName}","tree": {"$path" : "standalone"}}` + ); + + copySync(packageDir, destinationDir); + copySync(srcDir, destSrcDir); + + execFile( + "rojo", + ["build", "-o=standalone.rbxm", "standalone.project.json"], + () => { + rimraf(destinationDir) + .catch((err) => { + console.log(err); + }) + .then(() => { + rimraf(standaloneProject); + resolve(); + }); + } + ); + }); +} + +buildStandalone() \ No newline at end of file