mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-11 09:11:50 +00:00
* Fix tsconfig scopes affecting html.js Since it's quite hard to use a DOM library type there, remove the type entirely. * Remove environment variables check Nothing is using them anymore. It can be added back if needed later. * Refactor Texture Packer downloading Refactor local-config.js tasks file into a generic "environment" category consisting of checking if Java is installed, downloading the runnable Texture Packer if it's not yet downloaded and copying the local configuration template; update README accordingly. * Prepare environment only at postinstall Remove environment.prepare task from default build pipelines, add a postinstall script that calls the task, using environment.js as the gulpfile to speed it up. * Remove "docs" tasks and types generation script Remove tasks from docs.js as they are unlikely to do anything meaningful nowadays. Also remove the buildTypes script as it doesn't work anymore. A better solution will be provided in the future. * Simplify some globs Use additional gulp.src options instead of specifying more or complex globs. * Extract built-temp location to a variable Add the src/js/built-temp directory as a new variable in config.js, replace all existing references to built-temp with this variable.
122 lines
4.6 KiB
JavaScript
122 lines
4.6 KiB
JavaScript
import packager from "electron-packager";
|
|
import fs from "fs/promises";
|
|
import gulp from "gulp";
|
|
import path from "path/posix";
|
|
import electronPackageJson from "../electron/package.json" with { type: "json" };
|
|
import { BUILD_VARIANTS } from "./build_variants.js";
|
|
import { getVersion } from "./buildutils.js";
|
|
import { buildProject } from "./typescript.js";
|
|
|
|
import gulpClean from "gulp-clean";
|
|
|
|
const platforms = /** @type {const} */ (["win32", "linux", "darwin"]);
|
|
const architectures = /** @type {const} */ (["x64", "arm64"]);
|
|
|
|
export default Object.fromEntries(
|
|
Object.entries(BUILD_VARIANTS)
|
|
.filter(([variant, variantData]) => variantData.standalone)
|
|
.map(([variant, variantData]) => {
|
|
const tempDestDir = path.join("..", "build_output", variant);
|
|
const electronBaseDir = path.join("..", "electron");
|
|
const tempDestBuildDir = path.join(tempDestDir, "built");
|
|
|
|
function cleanup() {
|
|
return gulp
|
|
.src(tempDestDir, { read: false, allowEmpty: true })
|
|
.pipe(gulpClean({ force: true }));
|
|
}
|
|
|
|
function copyPrefab() {
|
|
const requiredFiles = ["preload.cjs", "node_modules/**/*", "favicon*"];
|
|
return gulp
|
|
.src(requiredFiles, { cwd: electronBaseDir, cwdbase: true, dot: true })
|
|
.pipe(gulp.dest(tempDestBuildDir));
|
|
}
|
|
|
|
async function transpileTypeScript() {
|
|
const tsconfigPath = path.join(electronBaseDir, "tsconfig.json");
|
|
const outDir = path.join(tempDestBuildDir, "dist");
|
|
|
|
buildProject(tsconfigPath, undefined, outDir);
|
|
return Promise.resolve();
|
|
}
|
|
|
|
async function writePackageJson() {
|
|
const pkgJson = structuredClone(electronPackageJson);
|
|
pkgJson.version = getVersion();
|
|
delete pkgJson.scripts;
|
|
|
|
const packageJsonString = JSON.stringify(pkgJson);
|
|
await fs.writeFile(path.join(tempDestBuildDir, "package.json"), packageJsonString);
|
|
}
|
|
|
|
function copyGamefiles() {
|
|
return gulp.src("../build/**/*.*", { base: "../build" }).pipe(gulp.dest(tempDestBuildDir));
|
|
}
|
|
|
|
const prepare = {
|
|
cleanup,
|
|
copyPrefab,
|
|
transpileTypeScript,
|
|
writePackageJson,
|
|
copyGamefiles,
|
|
all: gulp.series(cleanup, copyPrefab, transpileTypeScript, writePackageJson, copyGamefiles),
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @param {typeof platforms[number] | (typeof platforms[number])[]} platform
|
|
* @param {typeof architectures[number] | (typeof architectures[number])[]} arch
|
|
*/
|
|
async function packageStandalone(platform, arch) {
|
|
const appPaths = await packager({
|
|
dir: tempDestBuildDir,
|
|
appCopyright: "tobspr Games",
|
|
appVersion: getVersion(),
|
|
buildVersion: "1.0.0",
|
|
arch,
|
|
platform,
|
|
asar: true,
|
|
executableName: "shapezio",
|
|
icon: path.join(electronBaseDir, "favicon"),
|
|
name: "shapez",
|
|
out: tempDestDir,
|
|
overwrite: true,
|
|
appBundleId: "tobspr.shapezio." + variant,
|
|
appCategoryType: "public.app-category.games",
|
|
});
|
|
|
|
console.log("Packages created:", appPaths);
|
|
await Promise.all(
|
|
appPaths.map(async appPath => {
|
|
await fs.writeFile(
|
|
path.join(appPath, "LICENSE"),
|
|
await fs.readFile(path.join("..", "LICENSE"))
|
|
);
|
|
})
|
|
);
|
|
}
|
|
|
|
const pack = {
|
|
...Object.fromEntries(
|
|
platforms.flatMap(platform =>
|
|
architectures.map(arch => [
|
|
`${platform}-${arch}`,
|
|
() => packageStandalone(platform, arch),
|
|
])
|
|
)
|
|
),
|
|
// TODO: Review this hack forced by readonly types
|
|
all: () => packageStandalone([...platforms], [...architectures]),
|
|
};
|
|
|
|
return [
|
|
variant,
|
|
{
|
|
prepare,
|
|
package: pack,
|
|
},
|
|
];
|
|
})
|
|
);
|