Skip to content

Commit

Permalink
Use own bundling methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticFqx committed Mar 26, 2024
1 parent 5633ba6 commit eec0ff3
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 54 deletions.
2 changes: 2 additions & 0 deletions automation/build-cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { build_path, title_dashed } from './constants';

const BuildCleanup = () => {
rimrafSync(build_path);
rimrafSync('./dist/neutralino.config.json');
rimrafSync('./neutralino.config.json');
writeFileSync('./dist/meta.json', JSON.stringify({title: title_dashed}));
}

Expand Down
14 changes: 7 additions & 7 deletions automation/linux-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import { PluginOption } from 'vite';
import { title_dashed, game_dir, build_path } from './constants';
import { mkdirSync, copyFileSync } from 'fs';

const BuildWinApp = () => {
const BundleLinuxApp = () => {
console.log(`Packaging Linux app...`);

const out_dir = `./dist/linux/${title_dashed}`;

mkdirSync('./dist/linux');
mkdirSync(out_dir);

copyFileSync(`${build_path}/${game_dir}-linux_x64`, `${out_dir}/${title_dashed}-x64`);
copyFileSync(`${build_path}/${game_dir}-linux_arm64`, `${out_dir}/${title_dashed}-arm64`);
copyFileSync(`${build_path}/${game_dir}-linux_armhf`, `${out_dir}/${title_dashed}-armhf`);
copyFileSync(`${build_path}/resources.neu`, `${out_dir}/resources.neu`);
copyFileSync(`bin/neutralino-linux_x64`, `${out_dir}/${title_dashed}-x64`);
copyFileSync(`bin/neutralino-linux_arm64`, `${out_dir}/${title_dashed}-arm64`);
copyFileSync(`bin/neutralino-linux_armhf`, `${out_dir}/${title_dashed}-armhf`);
copyFileSync(`bin/resources.neu`, `${out_dir}/resources.neu`);
};

export default function buildWinApp() {
export default function bundleLinuxApp() {
return {
name: 'build-linux-bundle',
apply: 'build',
closeBundle: BuildWinApp,
closeBundle: BundleLinuxApp,
} as PluginOption;
}
10 changes: 5 additions & 5 deletions automation/mac-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { team, title, git_count, git_version, team_dashed,
import { execSync } from 'child_process';
import { mkdirSync, writeFileSync, copyFileSync, renameSync } from 'fs';

const BuildMacApp = () => {
const BundleMacApp = () => {
console.log(`Packaging Mac dmg...`);

const bootstrapper = `#!/usr/bin/env bash
Expand Down Expand Up @@ -49,8 +49,8 @@ exec "\${MACOS}/game" --path="\${CONTENTS}/Resources" --enable-extensions=true`;

writeFileSync(`${out_dir}/Contents/MacOS/bootstrapper`, bootstrapper);
writeFileSync(`${out_dir}/Contents/info.plist`, plist);
copyFileSync(`${build_path}/${game_dir}-mac_universal`, `${out_dir}/Contents/MacOS/game`);
copyFileSync(`${build_path}/resources.neu`, `${out_dir}/Contents/Resources/resources.neu`);
copyFileSync(`bin/neutralino-mac_universal`, `${out_dir}/Contents/MacOS/game`);
copyFileSync(`bin/resources.neu`, `${out_dir}/Contents/Resources/resources.neu`);
copyFileSync(`./src/public/icon.png`, `${out_dir}/Contents/Resources/icon.png`);
renameSync(out_dir, `${out_dir}.app`);

Expand All @@ -61,10 +61,10 @@ exec "\${MACOS}/game" --path="\${CONTENTS}/Resources" --enable-extensions=true`;
}
};

export default function buildMacApp() {
export default function bundleMacApp() {
return {
name: 'build-mac-bundle',
apply: 'build',
closeBundle: BuildMacApp,
closeBundle: BundleMacApp,
} as PluginOption;
}
8 changes: 4 additions & 4 deletions automation/neu-build.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { execSync } from 'child_process';
import { PluginOption } from 'vite';
import WriteNeuConfig from './write-neu-config';
import { createPackage } from '@electron/asar';

export default function neuBuild(): PluginOption {
return {
name: 'neu-build',
apply: 'build',
enforce: 'pre',
closeBundle() {
async closeBundle() {
console.log('Building game app');
WriteNeuConfig();
execSync('neu build');
WriteNeuConfig(true);
await createPackage('dist', 'bin/resources.neu');
},
};
}
10 changes: 5 additions & 5 deletions automation/win-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { mkdirSync, copyFileSync, readFileSync, writeFileSync } from 'fs';
import { NtExecutable, NtExecutableResource, Data, Resource } from 'resedit';
import pngToIco from 'png-to-ico';

const BuildWinApp = async () => {
const BundleWinApp = async () => {
console.log(`Packaging Windows exe...`);

const out_dir = `./dist/win/${title_dashed}`;

mkdirSync('./dist/win');
mkdirSync(out_dir);
copyFileSync(`${build_path}/resources.neu`, `${out_dir}/resources.neu`);
copyFileSync(`bin/resources.neu`, `${out_dir}/resources.neu`);

const data = readFileSync(`${build_path}/${game_dir}-win_x64.exe`);
const data = readFileSync(`bin/neutralino-win_x64.exe`);
const exe = NtExecutable.from(data);
const res = NtExecutableResource.from(exe);

Expand Down Expand Up @@ -41,13 +41,13 @@ const BuildWinApp = async () => {
writeFileSync(`${out_dir}/${title}.exe`, Buffer.from(exe.generate()));
};

export default function buildWinApp() {
export default function bundleWinApp() {
return {
name: 'build-windows-bundle',
apply: 'build',
enforce: 'pre',
closeBundle: {
handler: BuildWinApp,
handler: BundleWinApp,
sequential: true
},
} as PluginOption;
Expand Down
10 changes: 7 additions & 3 deletions automation/write-neu-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import { team, title, team_dashed, title_dashed, git_count, neutralino } from '.
import neuConf from './neu-template.json';
import { writeFileSync } from 'fs';

export default function WriteNeuConfig() {
export default function WriteNeuConfig(isProd: boolean) {
neuConf.applicationId = `${team_dashed}.${title_dashed}`;
neuConf.modes.window.title = `${title} by ${team}`;
neuConf.cli.binaryName = `${team_dashed}-${title_dashed}`;
neuConf.version = `0.0.${git_count}`;
if(process.env.NODE_ENV == 'development') {
if(isProd) {
neuConf.documentRoot = "/web/";
neuConf.cli.resourcesPath = "/";
neuConf.modes.window.icon = "/web/icon.png";
} else {
neuConf.tokenSecurity = 'none';
}

neuConf.nativeAllowList = [...neuConf.nativeAllowList, ...neutralino.allow];

writeFileSync('neutralino.config.json', JSON.stringify(neuConf));
writeFileSync(isProd ? 'dist/neutralino.config.json' : 'neutralino.config.json', JSON.stringify(neuConf));
writeFileSync('./src/public/__neutralino_globals.js', '// Dummy file');
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
"postinstall": "vite-node automation/setup.ts"
},
"dependencies": {
"@neutralinojs/lib": "^5.0.1",
"@neutralinojs/lib": "^5.1.0",
"phaser": "^3.80.1",
"phaser3-rex-plugins": "^1.80.1"
},
"devDependencies": {
"@electron/asar": "^3.2.9",
"@neutralinojs/neu": "^11.0.1",
"png-to-ico": "^2.1.8",
"resedit": "^2.0.0",
"rimraf": "^5.0.5",
"sharp": "^0.33.2",
"sharp": "^0.33.3",
"terser": "^5.29.2",
"typescript": "^5.4.2",
"vite": "^5.1.6",
"typescript": "^5.4.3",
"vite": "^5.2.6",
"vite-node": "^1.4.0",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-image-optimizer": "^1.1.7",
Expand Down
1 change: 0 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta charset="UTF-8" />
<title>%VITE_GAME_TITLE% by %VITE_GAME_TEAM%</title>
<base href="./">
<link rel="icon" type="image/png" href="./icon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./style.css">
Expand Down
18 changes: 0 additions & 18 deletions typings/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
/// <reference types="vite/client" />

declare var NL_TOKEN: string;
declare var NL_OS: 'Linux' | 'Windows' | 'Darwin';
declare var NL_APPID: string;
declare var NL_APPVERSION: string;
declare var NL_PORT: number;
declare var NL_MODE: 'window' | 'browser' | 'cloud' | 'chrome';
declare var NL_VERSION: string;
declare var NL_CVERSION: string;
declare var NL_CWD: string;
declare var NL_PATH: string;
declare var NL_ARGS: string[];
declare var NL_PID: number;
declare var NL_RESMODE: 'bundle' | 'directory';
declare var NL_EXTENABLED: boolean;
declare var NL_COMMIT: string;
declare var NL_CCOMMIT: string;
declare var NL_CMETHODS: any[];
14 changes: 7 additions & 7 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import getGitVersion from './automation/git-version';
import preImageOptimizer from './automation/pre-image-optimizer';
import neuBuild from './automation/neu-build';
import neuInject from './automation/neu-inject';
import buildWinApp from './automation/win-bundle';
import buildMacApp from './automation/mac-bundle';
import buildLinuxApp from './automation/linux-bundle';
import bundleWinApp from './automation/win-bundle';
import bundleMacApp from './automation/mac-bundle';
import bundleLinuxApp from './automation/linux-bundle';
import buildCleanup from './automation/build-cleanup';

import { title, team, description, title_dashed } from './automation/constants';
Expand All @@ -29,11 +29,11 @@ export default () => {
typescript: true,
}),
preImageOptimizer(),
neuBuild(),
neuInject(),
buildWinApp(),
buildMacApp(),
buildLinuxApp(),
neuBuild(),
bundleWinApp(),
bundleMacApp(),
bundleLinuxApp(),
zip({
inDir: './dist/web',
outDir: './dist',
Expand Down

0 comments on commit eec0ff3

Please sign in to comment.