2022-12-03 04:23:18 +00:00
|
|
|
import packager from "electron-packager";
|
2024-04-24 21:30:01 +00:00
|
|
|
import fs from "fs/promises";
|
|
|
|
|
import gulp from "gulp";
|
2025-03-21 14:30:13 +00:00
|
|
|
import path from "path/posix";
|
|
|
|
|
import electronPackageJson from "../electron/package.json" with { type: "json" };
|
2022-12-03 04:23:18 +00:00
|
|
|
import { BUILD_VARIANTS } from "./build_variants.js";
|
2025-03-21 14:30:13 +00:00
|
|
|
import { getVersion } from "./buildutils.js";
|
|
|
|
|
import { buildProject } from "./typescript.js";
|
2022-12-03 04:23:18 +00:00
|
|
|
|
|
|
|
|
import gulpClean from "gulp-clean";
|
2022-05-30 05:00:14 +00:00
|
|
|
|
2024-04-16 18:50:36 +00:00
|
|
|
const platforms = /** @type {const} */ (["win32", "linux", "darwin"]);
|
|
|
|
|
const architectures = /** @type {const} */ (["x64", "arm64"]);
|
2020-05-09 14:45:23 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
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 }));
|
|
|
|
|
}
|
2021-03-09 09:07:19 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
function copyPrefab() {
|
|
|
|
|
const requiredFiles = [
|
2025-03-21 14:30:13 +00:00
|
|
|
path.join(electronBaseDir, "preload.cjs"),
|
2024-04-24 21:30:01 +00:00
|
|
|
path.join(electronBaseDir, "node_modules", "**", "*.*"),
|
|
|
|
|
path.join(electronBaseDir, "node_modules", "**", ".*"),
|
|
|
|
|
path.join(electronBaseDir, "favicon*"),
|
|
|
|
|
];
|
|
|
|
|
return gulp.src(requiredFiles, { base: electronBaseDir }).pipe(gulp.dest(tempDestBuildDir));
|
|
|
|
|
}
|
2021-03-09 09:07:19 +00:00
|
|
|
|
2025-03-21 14:30:13 +00:00
|
|
|
async function transpileTypeScript() {
|
|
|
|
|
const tsconfigPath = path.join(electronBaseDir, "tsconfig.json");
|
|
|
|
|
const outDir = path.join(tempDestBuildDir, "dist");
|
2021-03-09 09:07:19 +00:00
|
|
|
|
2025-03-21 14:30:13 +00:00
|
|
|
buildProject(tsconfigPath, undefined, outDir);
|
|
|
|
|
return Promise.resolve();
|
2021-03-09 09:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-21 14:30:13 +00:00
|
|
|
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);
|
2024-04-24 21:30:01 +00:00
|
|
|
}
|
2024-04-16 18:50:36 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
function copyGamefiles() {
|
|
|
|
|
return gulp.src("../build/**/*.*", { base: "../build" }).pipe(gulp.dest(tempDestBuildDir));
|
2024-04-16 18:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
const prepare = {
|
|
|
|
|
cleanup,
|
|
|
|
|
copyPrefab,
|
2025-03-21 14:30:13 +00:00
|
|
|
transpileTypeScript,
|
2024-04-24 21:30:01 +00:00
|
|
|
writePackageJson,
|
|
|
|
|
copyGamefiles,
|
2025-03-21 14:30:13 +00:00
|
|
|
all: gulp.series(cleanup, copyPrefab, transpileTypeScript, writePackageJson, copyGamefiles),
|
2024-04-24 21:30:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @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"))
|
|
|
|
|
);
|
|
|
|
|
})
|
2024-04-16 18:50:36 +00:00
|
|
|
);
|
|
|
|
|
}
|
2022-04-13 13:43:58 +00:00
|
|
|
|
2024-04-24 21:30:01 +00:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
})
|
|
|
|
|
);
|