mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 02:01:51 +00:00
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
|
|
import { exec } from "child_process";
|
||
|
|
import fs from "fs/promises";
|
||
|
|
import gulp from "gulp";
|
||
|
|
import { promisify } from "util";
|
||
|
|
|
||
|
|
const texturePackerUrl =
|
||
|
|
"https://libgdx-nightlies.s3.amazonaws.com/libgdx-runnables/runnable-texturepacker.jar";
|
||
|
|
|
||
|
|
const configTemplatePath = "../src/js/core/config.local.template.js";
|
||
|
|
const configPath = "../src/js/core/config.local.js";
|
||
|
|
|
||
|
|
export async function checkJava() {
|
||
|
|
try {
|
||
|
|
const { stderr } = await promisify(exec)("java -version");
|
||
|
|
console.log(`Found Java:`, stderr);
|
||
|
|
} catch {
|
||
|
|
throw new Error("Java is required to build the texture atlas, but was not found");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function downloadTexturePacker() {
|
||
|
|
const destination = "./runnable-texturepacker.jar";
|
||
|
|
|
||
|
|
try {
|
||
|
|
// If the file exists already, we're done
|
||
|
|
await fs.access(destination);
|
||
|
|
return;
|
||
|
|
} catch {
|
||
|
|
// File does not exist, need to download
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log(`Downloading ${destination}...`);
|
||
|
|
const response = await fetch(texturePackerUrl);
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`Failed to download Texture Packer: ${response.statusText}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
await fs.writeFile(destination, response.body);
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function createLocalConfig() {
|
||
|
|
try {
|
||
|
|
await fs.copyFile(configTemplatePath, configPath, fs.constants.COPYFILE_EXCL);
|
||
|
|
} catch {
|
||
|
|
// The file is already there
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export const prepare = gulp.parallel(gulp.series(checkJava, downloadTexturePacker), createLocalConfig);
|