1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-10 00:31:51 +00:00

Slight improvements for the build process (#19)

* Unify the version source

Changes the development config to use version from package.json and
makes the production config use the same utility function. Also removes
the version file as it's no longer needed.

* Remove some Steam references from build process

Removes files needed to publish the game on Steam and related tasks that
can be only used by the developer anyway. Only the build process is
affected, the actual game part still supports Steam integration.

* Refactor/add packaging tasks

Adds new Gulp tasks to create a distributable package of the game. A
task for macOS is not provided because signing needs to be figured out
first. Package creation tasks are also aliased in package.json for
future usage in external tools or CI. Aside from that, alternative
methods of downloading the libGDX Texture Packer are dropped.
This commit is contained in:
Даниїл Григор'єв 2024-04-14 19:03:27 +03:00 committed by GitHub
parent b55001dd1a
commit c2855d528d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 50 additions and 298 deletions

3
.gitignore vendored
View File

@ -54,9 +54,6 @@ config.local.js
# Editor artifacts
*.*.swp
*.*.swo
app.vdf
steamtmp
build_output
built_vdfs
tmp

View File

@ -7,7 +7,7 @@ WORKDIR /shapez.io
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg default-jre \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*
COPY package.json yarn.lock ./
RUN yarn
@ -20,7 +20,6 @@ WORKDIR /shapez.io
COPY res ./res
COPY src/html ./src/html
COPY src/css ./src/css
COPY version ./version
COPY sync-translations.js ./
COPY translations ./translations
COPY src/js ./src/js

View File

@ -60,7 +60,10 @@ and does not intend to provide compatibility for older clients.
- [Node.js 16](https://nodejs.org/en/about/previous-releases)
(not 17+, see <https://github.com/tobspr-games/shapez.io/issues/1473>)
- [Yarn 1](https://classic.yarnpkg.com/en/docs/install) (not 2, we haven't migrated yet)
- [Java](https://www.oracle.com/java/technologies/downloads/) (or [OpenJDK](https://openjdk.org/)) (to run texture packer)
- [Java](https://www.oracle.com/java/technologies/downloads/) (or [OpenJDK](https://openjdk.org/)) to run the texture packer
- [cURL](https://curl.se/download.html)[^1] to download the texture packer
[^1]: cURL is already installed on most Windows, Linux and macOS systems.
### Development
@ -72,13 +75,11 @@ and does not intend to provide compatibility for older clients.
### Release
> [!CAUTION]
> Release steps are currently unchecked and unmaintained and will likely be revised in the future.
> [!IMPORTANT]
> While there is partial macOS support, it is not tested and adapted yet. Therefore, macOS package creation task is not provided.
- Run `yarn` in the root folder and in `electron/`.
- In the root folder, run `yarn gulp build.standalone-steam`.
- Run `yarn gulp standalone.standalone-steam.prepare`.
- Run `yarn gulp standalone.standalone-steam.package.$PLATFORM` where `$PLATFORM` is `win64`, `linux64`, or `darwin64` depending on your system.
- In the root folder, run `yarn package-$PLATFORM` where `$PLATFORM` is `win32` or `linux` depending on your system.
- The build will be found under `build_output/standalone-steam` as `shapez-...-x64`.
## Credits

View File

@ -3,7 +3,6 @@
* standalone: boolean,
* environment?: 'dev' | 'staging' | 'prod',
* electronBaseDir?: string,
* steamAppId?: number,
* executableName?: string
* }>}
*/
@ -23,6 +22,5 @@ export const BUILD_VARIANTS = {
"standalone-steam": {
standalone: true,
executableName: "shapez",
steamAppId: 1318690,
},
};

View File

@ -1,7 +1,6 @@
import glob from "glob";
import { execSync } from "child_process";
import fs from "fs";
import path from "path/posix";
export function getRevision(useLast = false) {
const commitHash = execSync("git rev-parse --short " + (useLast ? "HEAD^1" : "HEAD")).toString("ascii");
@ -30,7 +29,8 @@ export function getTag() {
}
export function getVersion() {
return fs.readFileSync(path.join("..", "version")).toString().trim();
// Use the version number specified in package.json
return JSON.parse(fs.readFileSync("../package.json", "utf-8")).version;
}
/**

View File

@ -258,16 +258,22 @@ for (const variant in BUILD_VARIANTS) {
gulp.task(buildName, gulp.series("utils.cleanup", buildName + ".all", "step.postbuild"));
// bundle
// Tasks for creating distributable packages
if (data.standalone) {
gulp.task(
"bundle." + variant + ".from-windows",
gulp.series(buildName, "standalone." + variant + ".build-from-windows")
);
gulp.task(
"bundle." + variant + ".from-darwin",
gulp.series(buildName, "standalone." + variant + ".build-from-darwin")
);
// TODO: Figure out macOS support as a non-published app
const packagePlatforms = ["win32", "linux"];
for (const platform of packagePlatforms) {
gulp.task(
`package.${variant}.${platform}`,
gulp.series(
`build.${variant}`,
"utils.cleanBuildOutputFolder",
`standalone.${variant}.prepare`,
`standalone.${variant}.package.${platform}`
)
);
}
}
// serve
@ -287,15 +293,5 @@ gulp.task(
gulp.series("utils.requireCleanWorkingTree", "build.web-shapezio", "ftp.upload.prod")
);
// Bundling (pre upload)
gulp.task(
"bundle.steam.from-darwin",
gulp.series("utils.cleanBuildOutputFolder", "bundle.standalone-steam.from-darwin")
);
gulp.task(
"bundle.steam.from-windows",
gulp.series("utils.cleanBuildOutputFolder", "bundle.standalone-steam.from-windows")
);
// Default task (dev, localhost)
gulp.task("default", gulp.series("serve.standalone-steam"));

View File

@ -96,28 +96,12 @@ export default function gulptasksImageResources(gulp, buildFolder) {
execute("java -version");
// Now check and try downloading runnable-texturepacker.jar (22MB)
if (!fs.existsSync("./runnable-texturepacker.jar")) {
const safeLink = JSON.stringify(runnableTPSource);
const commands = [
// linux/macos if installed
`wget -O runnable-texturepacker.jar ${safeLink}`,
// linux/macos, latest windows 10
`curl -o runnable-texturepacker.jar ${safeLink}`,
// windows 10 / updated windows 7+
"powershell.exe -Command (new-object System.Net.WebClient)" +
`.DownloadFile(${safeLink.replace(/"/g, "'")}, 'runnable-texturepacker.jar')`,
// windows 7+, vulnerability exploit
`certutil.exe -urlcache -split -f ${safeLink} runnable-texturepacker.jar`,
];
const escapedLink = JSON.stringify(runnableTPSource);
while (commands.length) {
try {
execute(commands.shift());
break;
} catch {
if (!commands.length) {
throw new Error("Failed to download runnable-texturepacker.jar!");
}
}
try {
execute(`curl -o runnable-texturepacker.jar ${escapedLink}`);
} catch {
throw new Error("Failed to download runnable-texturepacker.jar!");
}
}

View File

@ -24,7 +24,7 @@ export default function gulptasksStandalone(gulp) {
}
const tempDestDir = path.join("..", "build_output", variant);
const taskPrefix = "standalone." + variant;
const electronBaseDir = path.join("..", variantData.electronBaseDir || "electron");
const electronBaseDir = path.join("..", "electron");
const tempDestBuildDir = path.join(tempDestDir, "built");
gulp.task(taskPrefix + ".prepare.cleanup", () => {
@ -40,16 +40,6 @@ export default function gulptasksStandalone(gulp) {
return gulp.src(requiredFiles, { base: electronBaseDir }).pipe(gulp.dest(tempDestBuildDir));
});
gulp.task(taskPrefix + ".prepare.writeAppId", cb => {
if (variantData.steamAppId) {
fs.writeFileSync(
path.join(tempDestBuildDir, "steam_appid.txt"),
String(variantData.steamAppId)
);
}
cb();
});
gulp.task(taskPrefix + ".prepare.writePackageJson", cb => {
const packageJsonString = JSON.stringify(
{
@ -94,8 +84,7 @@ export default function gulptasksStandalone(gulp) {
taskPrefix + ".prepare.copyPrefab",
taskPrefix + ".prepare.writePackageJson",
taskPrefix + ".prepare.minifyCode",
taskPrefix + ".prepare.copyGamefiles",
taskPrefix + ".prepare.writeAppId"
taskPrefix + ".prepare.copyGamefiles"
)
);
@ -155,41 +144,18 @@ export default function gulptasksStandalone(gulp) {
return;
}
if (variantData.steamAppId) {
fs.writeFileSync(
path.join(appPath, "LICENSE"),
fs.readFileSync(path.join("..", "LICENSE"))
);
if (platform === "linux") {
// Write launcher script
fs.writeFileSync(
path.join(appPath, "LICENSE"),
fs.readFileSync(path.join("..", "LICENSE"))
path.join(appPath, "play.sh"),
'#!/usr/bin/env bash\n./shapezio --no-sandbox "$@"\n'
);
fs.writeFileSync(
path.join(appPath, "steam_appid.txt"),
String(variantData.steamAppId)
);
if (platform === "linux") {
// Write launcher script
fs.writeFileSync(
path.join(appPath, "play.sh"),
'#!/usr/bin/env bash\n./shapezio --no-sandbox "$@"\n'
);
fs.chmodSync(path.join(appPath, "play.sh"), 0o775);
}
if (platform === "darwin") {
if (!isRelease) {
// Needs special location
fs.writeFileSync(
path.join(
appPath,
"shapez.app",
"Contents",
"MacOS",
"steam_appid.txt"
),
String(variantData.steamAppId)
);
}
}
fs.chmodSync(path.join(appPath, "play.sh"), 0o775);
}
});
@ -203,7 +169,7 @@ export default function gulptasksStandalone(gulp) {
}
// Manual signing with patched @electron/osx-sign (we need --no-strict)
gulp.task(taskPrefix + ".package.darwin64", cb =>
gulp.task(taskPrefix + ".package.darwin", cb =>
packageStandalone(
"darwin",
"x64",
@ -212,26 +178,6 @@ export default function gulptasksStandalone(gulp) {
const appFileInner = path.join(appFile, "shapez.app");
console.warn("++ Signing ++");
if (variantData.steamAppId) {
const appIdDest = path.join(
path.join(appFileInner, "Contents", "MacOS"),
"steam_appid.txt"
);
// console.warn("++ Preparing ++");
// fse.copySync(path.join(tempDestBuildDir, "steam_appid.txt"), appIdDest);
console.warn("Signing steam_appid.txt");
execSync(
`codesign --force --verbose --options runtime --timestamp --no-strict --sign "${
process.env.SHAPEZ_CLI_APPLE_CERT_NAME
}" --entitlements "${path.join("entitlements.plist")}" ${appIdDest}`,
{
cwd: appFile,
}
);
}
console.warn("Base dir:", appFile);
signAsync({
@ -275,58 +221,7 @@ export default function gulptasksStandalone(gulp) {
)
);
gulp.task(taskPrefix + ".package.win64", cb => packageStandalone("win32", "x64", cb));
gulp.task(taskPrefix + ".package.linux64", cb => packageStandalone("linux", "x64", cb));
gulp.task(
taskPrefix + ".build-from-windows",
gulp.series(
taskPrefix + ".prepare",
gulp.parallel(taskPrefix + ".package.win64", taskPrefix + ".package.linux64")
)
);
gulp.task(
taskPrefix + ".build-from-darwin",
gulp.series(taskPrefix + ".prepare", gulp.parallel(taskPrefix + ".package.darwin64"))
);
gulp.task(taskPrefix + ".package.win32", cb => packageStandalone("win32", "x64", cb));
gulp.task(taskPrefix + ".package.linux", cb => packageStandalone("linux", "x64", cb));
}
// Steam helpers
gulp.task("standalone.prepareVDF", cb => {
const hash = getRevision();
const version = getVersion();
// for (const platform of ["steampipe", "steampipe-darwin"]) {
const templatesSource = path.join("steampipe", "templates");
const templatesDest = path.join("steampipe", "built_vdfs");
const variables = {
PROJECT_DIR: path.resolve(path.join("..")).replace(/\\/g, "/"),
BUNDLE_DIR: path.resolve(path.join("..", "build_output")).replace(/\\/g, "/"),
TMP_DIR: path.resolve(path.join("steampipe", "tmp")).replace(/\\/g, "/"),
// BUILD_DESC: "v" + version + " @ " + hash,
VDF_DIR: path.resolve(path.join("steampipe", "built_vdfs")).replace(/\\/g, "/"),
};
const files = fs.readdirSync(templatesSource);
for (const file of files) {
if (!file.endsWith(".vdf")) {
continue;
}
variables.BUILD_DESC = file.replace(".vdf", "") + " - v" + version + " @ " + hash;
let content = fs.readFileSync(path.join(templatesSource, file)).toString("utf-8");
content = content.replace(/\$([^$]+)\$/gi, (_, variable) => {
if (!variables[variable]) {
throw new Error("Unknown variable " + variable + " in " + file);
}
return variables[variable];
});
fs.writeFileSync(path.join(templatesDest, file), content, { encoding: "utf8" });
}
cb();
});
}

View File

@ -1 +0,0 @@
steamtemp

View File

@ -1,14 +0,0 @@
"appbuild"
{
"appid" "1318690"
"desc" "$BUILD_DESC$"
"buildoutput" "$TMP_DIR$"
"contentroot" ""
"setlive" ""
"preview" "0"
"local" ""
"depots"
{
"1318693" "$VDF_DIR$/standalone-darwin.vdf"
}
}

View File

@ -1,15 +0,0 @@
"appbuild"
{
"appid" "1318690"
"desc" "$BUILD_DESC$"
"buildoutput" "$TMP_DIR$"
"contentroot" ""
"setlive" ""
"preview" "0"
"local" ""
"depots"
{
"1318691" "$VDF_DIR$\standalone-windows.vdf"
"1318692" "$VDF_DIR$\standalone-linux.vdf"
}
}

View File

@ -1,12 +0,0 @@
"DepotBuildConfig"
{
"DepotID" "1318693"
"contentroot" "$BUNDLE_DIR$\standalone-steam\shapez-darwin-x64"
"FileMapping"
{
"LocalPath" "*"
"DepotPath" "."
"recursive" "1"
}
"FileExclusion" "*.pdb"
}

View File

@ -1,12 +0,0 @@
"DepotBuildConfig"
{
"DepotID" "1318692"
"contentroot" "$BUNDLE_DIR$\standalone-steam\shapez-linux-x64"
"FileMapping"
{
"LocalPath" "*"
"DepotPath" "."
"recursive" "1"
}
"FileExclusion" "*.pdb"
}

View File

@ -1,12 +0,0 @@
"DepotBuildConfig"
{
"DepotID" "1318691"
"contentroot" "$BUNDLE_DIR$\standalone-steam\shapez-win32-x64"
"FileMapping"
{
"LocalPath" "*"
"DepotPath" "."
"recursive" "1"
}
"FileExclusion" "*.pdb"
}

View File

@ -1,3 +0,0 @@
#!/bin/sh
yarn gulp standalone.prepareVDF
steamcmd.sh +login $STEAM_UPLOAD_SHAPEZ_ID $STEAM_UPLOAD_SHAPEZ_USER +run_app_build $PWD/built_vdfs/app-darwin-demo.vdf +quit

View File

@ -1,3 +0,0 @@
#!/bin/sh
yarn gulp standalone.prepareVDF
steamcmd.sh +login $STEAM_UPLOAD_SHAPEZ_ID $STEAM_UPLOAD_SHAPEZ_USER +run_app_build $PWD/built_vdfs/app-darwin.vdf +quit

View File

@ -1,3 +0,0 @@
@echo off
cmd /c yarn gulp standalone.prepareVDF
steamcmd +login %STEAM_UPLOAD_SHAPEZ_ID% %STEAM_UPLOAD_SHAPEZ_USER% +run_app_build %cd%/built_vdfs/app-winlinux-demo.vdf +quit

View File

@ -1,3 +0,0 @@
@echo off
cmd /c yarn gulp standalone.prepareVDF
steamcmd +login %STEAM_UPLOAD_SHAPEZ_ID% %STEAM_UPLOAD_SHAPEZ_USER% +run_app_build %cd%/built_vdfs/app-winlinux.vdf +quit

View File

@ -18,43 +18,4 @@ export default function gulptasksTranslations(gulp) {
});
gulp.task("translations.fullBuild", gulp.series("translations.convertToJson"));
gulp.task("translations.prepareSteamPage", cb => {
const files = fs.readdirSync(translationsSourceDir);
files
.filter(name => name.endsWith(".yaml"))
.forEach(fname => {
console.log("Loading", fname);
const languageName = fname.replace(".yaml", "");
const abspath = path.join(translationsSourceDir, fname);
const destpath = path.join(translationsSourceDir, "tmp", languageName + "-store.txt");
const contents = fs.readFileSync(abspath, { encoding: "utf-8" });
const data = YAML.parse(contents);
const storePage = data.steamPage;
const content = `
[img]{STEAM_APP_IMAGE}/extras/store_page_gif.gif[/img]
${storePage.intro.replace(/\n/gi, "\n\n")}
[h2]${storePage.what_others_say}[/h2]
[list]
[*] [i]${storePage.nothernlion_comment}[/i] [b]- Northernlion, YouTube[/b]
[*] [i]${storePage.notch_comment}[/i] [b]- Notch[/b]
[*] [i]${storePage.steam_review_comment}[/i] [b]- Steam User[/b]
[/list]
`;
fs.writeFileSync(destpath, content.replace(/(\n[ \t\r]*)/gi, "\n").trim(), {
encoding: "utf-8",
});
});
cb();
});
}

View File

@ -3,9 +3,7 @@ import TerserPlugin from "terser-webpack-plugin";
import webpack from "webpack";
const { DefinePlugin, IgnorePlugin } = webpack;
import DeadCodePlugin from "webpack-deadcode-plugin";
import pj from "../package.json" assert { type: "json" };
const { version } = pj;
import { getAllResourceImages, getRevision } from "./buildutils.js";
import { getAllResourceImages, getRevision, getVersion } from "./buildutils.js";
const globalDefs = {
"assert": "false && window.assert",
@ -16,7 +14,7 @@ const globalDefs = {
"G_APP_ENVIRONMENT": JSON.stringify("release"),
"G_BUILD_TIME": new Date().getTime().toString(),
"G_BUILD_COMMIT_HASH": JSON.stringify(getRevision()),
"G_BUILD_VERSION": JSON.stringify(version),
"G_BUILD_VERSION": JSON.stringify(getVersion()),
"G_ALL_UI_IMAGES": JSON.stringify(getAllResourceImages()),
"G_IS_RELEASE": "true",

View File

@ -11,7 +11,9 @@
"gulp": "gulp --cwd gulp",
"lint": "eslint src/js",
"prettier-all": "prettier --write src/**/*.* && prettier --write gulp/**/*.*",
"buildTypes": "tsc src/js/application.js --declaration --allowJs --emitDeclarationOnly --skipLibCheck --out types.js"
"buildTypes": "tsc src/js/application.js --declaration --allowJs --emitDeclarationOnly --skipLibCheck --out types.js",
"package-win32": "gulp package.standalone-steam.win32",
"package-linux": "gulp package.standalone-steam.linux"
},
"dependencies": {
"ajv": "^6.10.2",

View File

@ -1 +0,0 @@
1.5.6