Skip to content

Commit

Permalink
Fix TS errors, update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticFqx committed Jul 27, 2023
1 parent 63c4ea7 commit 36ca2a4
Show file tree
Hide file tree
Showing 36 changed files with 575 additions and 166 deletions.
61 changes: 36 additions & 25 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,64 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
uses: bahmutov/npm-install@v1
run: npm install && sudo apt install genisoimage

- name: Load game.config.json
uses: antifree/[email protected]
with:
useLockFile: false
filename: 'game.config.json'
prefix: game

- name: Build project
run: npm run build

- name: Upload production-ready build files
uses: actions/upload-artifact@v2
with:
name: production-files
path: ./dist

deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'

steps:
- name: Download artifact
uses: actions/download-artifact@v2
- name: Load meta.json
uses: antifree/[email protected]
with:
name: production-files
path: ./built/
filename: 'dist/meta.json'
prefix: meta

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./built/unpacked
publish_dir: ./dist/web

- name: Create release
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: false
title: "Rerooted latest build"
title: "${{ env.game_title }} latest build"
files: |
./dist/${{ env.meta_title }}-web.zip
./dist/${{ env.meta_title }}-win.zip
./dist/${{ env.meta_title }}-mac.dmg
./dist/${{ env.meta_title }}-linux.zip
- name: Upload to Itch
if: ${{env.game_itch_upload == 'true'}}
uses: Ayowel/[email protected]
with:
butler_key: ${{ secrets.BUTLER_CREDENTIALS }}
itch_user: ${{ env.game_itch_username }}
itch_game: ${{ env.game_itch_game }}
files: |
/home/runner/work/uprooting/uprooting/built/Rerooted-GGJ2023-release.zip
/home/runner/work/uprooting/uprooting/built/game-web.zip
./dist/${{ env.meta_title }}-web.zip
./dist/${{ env.meta_title }}-win.zip
./dist/${{ env.meta_title }}-mac.dmg
./dist/${{ env.meta_title }}-linux.zip
auto_channel: true
butler_version: "latest"
check_signature: false
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ dist-ssr

# Editor directories and files
.vscode/*
!.vscode/launch.json
!.vscode/settings.json
!.vscode/extensions.json
.idea
.DS_Store
Expand All @@ -40,4 +42,7 @@ src/neutralino.js
# Misc files
.cache/
.firebase/
*.zip
*.zip
src/version.json
neutralino.config.json
__neutralino_globals.js
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
18 changes: 18 additions & 0 deletions automation/build-cleanup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PluginOption } from 'vite';
import { rimrafSync } from 'rimraf';
import { writeFileSync } from 'fs';
import { build_path, title_dashed } from './constants';

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

export default function buildCleanup() {
return {
name: 'build-cleanup',
apply: 'build',
enforce: 'post',
closeBundle: BuildCleanup,
} as PluginOption;
}
31 changes: 31 additions & 0 deletions automation/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { execSync } from 'child_process';
import { platform } from 'os';
import { team, title, description, neutralino } from '../game.config.json';

export { team, title, description, neutralino };

const tryCatch = <T>(fun: () => T, fallback: T): T => {
try {
return fun();
} catch(e) {
return fallback;
}
}

export const git_count = tryCatch(() => execSync('git rev-list --count HEAD').toString().trim(), "-1");
export const git_short = tryCatch(() => execSync('git rev-parse --short HEAD').toString().trim(), "no-git");
export const git_version = `v${git_count}.${git_short}`;

export const year_current = new Date().getFullYear();
export const year_initial = tryCatch(() => Number(platform() == 'win32'
? execSync('git log --reverse | findstr "Date"').toString().match(/(\d+) \+/)?.[1]
: execSync('git log --reverse | grep "Date" -m 1').toString().match(/(\d+) \+/)?.[1]
), year_current);
export const year_copyright = year_initial == year_current
? `${year_initial}` : `${year_initial} - ${year_current}`;

export const team_dashed = team.toLowerCase().replace(/\s/gi, '-');
export const title_dashed = title.toLowerCase().replace(/\s/gi, '-');
export const game_dir = `${team_dashed}-${title_dashed}`;
export const build_path = `./dist/${game_dir}/`;

5 changes: 5 additions & 0 deletions automation/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { execSync } from 'child_process';
import WriteNeuConfig from './write-neu-config';

WriteNeuConfig();
execSync('vite', { stdio: 'inherit' });
20 changes: 20 additions & 0 deletions automation/git-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PluginOption } from 'vite';
import { writeFileSync } from 'fs';
import { git_count, git_short, git_version, title, team } from './constants';

const WriteGitVersion = () => {
writeFileSync('./src/version.json', JSON.stringify({
title,
team,
count: git_count,
short: git_short,
version: git_version
}));
}

export default function writeGitVersion() {
return {
name: 'write-version-json',
buildStart: WriteGitVersion
} as PluginOption;
}
25 changes: 25 additions & 0 deletions automation/linux-bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { PluginOption } from 'vite';
import { title_dashed, game_dir, build_path } from './constants';
import { mkdirSync, copyFileSync } from 'fs';

const BuildWinApp = () => {
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`);
};

export default function buildWinApp() {
return {
name: 'build-linux-bundle',
apply: 'build',
closeBundle: BuildWinApp,
} as PluginOption;
}
64 changes: 64 additions & 0 deletions automation/mac-bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { PluginOption } from 'vite';
import { team, title, git_count, git_version, team_dashed,
title_dashed, game_dir, build_path, year_copyright } from './constants';
import { execSync } from 'child_process';
import { mkdirSync, writeFileSync, copyFileSync, renameSync } from 'fs';

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

const plist = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSHumanReadableCopyright</key>
<string>${title} ${git_version} © ${team} ${year_copyright}</string>
<key>CFBundleExecutable</key>
<string>game</string>
<key>CFBundleIdentifier</key>
<string>com.${team_dashed}.${title_dashed}</string>
<key>CFBundleName</key>
<string>${title}</string>
<key>CFBundleIconFile</key>
<string>icon.png</string>
<key>CFBundleShortVersionString</key>
<string>0.${git_count}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>IFMajorVersion</key>
<integer>0</integer>
<key>IFMinorVersion</key>
<integer>${git_count}</integer>
</dict>
</plist>`;

const out_dir = `./dist/mac/${title}`;

mkdirSync(`./dist/mac/`);
mkdirSync(out_dir);
mkdirSync(`${out_dir}/Contents`);
mkdirSync(`${out_dir}/Contents/MacOS`);
mkdirSync(`${out_dir}/Contents/Resources`);

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/MacOS/resources.neu`);
copyFileSync(`./src/public/icon.png`, `${out_dir}/Contents/Resources/icon.png`);
renameSync(out_dir, `${out_dir}.app`);

try {
execSync(`mkisofs -J -R -o ./dist/${title_dashed}-mac.dmg -mac-name -V "${title}" -apple -v -dir-mode 777 -file-mode 777 "./dist/mac/"`);
} catch (err) {
console.log(`Failed to build dmg`);
}
};

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

export default function neuBuild(): PluginOption {
return {
name: 'neu-build',
apply: 'build',
enforce: 'pre',
closeBundle() {
console.log('Building game app');
WriteNeuConfig();
execSync('neu build');
},
};
}
10 changes: 10 additions & 0 deletions automation/neu-dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { exec } from 'child_process';
import WriteNeuConfig from './write-neu-config';

WriteNeuConfig();
const vite = exec('vite');
vite.stdout?.pipe(process.stdout);
exec('neu run --frontend-lib-dev -- --window-enable-inspector=true').on('close', () => {
vite.kill();
process.exit();
});
38 changes: 38 additions & 0 deletions automation/neu-inject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { PluginOption } from 'vite';
import { readFileSync } from 'fs';

const tryCatch = <T>(fun: () => T, fallback: T): T => {
try {
return fun();
} catch(e) {
return fallback;
}
}

const getGlobalsPath = () => {
const isDev = process.env.NODE_ENV == 'development';
const authInfo = JSON.parse(tryCatch(() => readFileSync('.tmp/auth_info.json').toString(), '{}'));
const port = authInfo.port;
return `${(isDev && port) ? `http://localhost:${port}/` : ''}__neutralino_globals.js`
}

export default function neuInject(): PluginOption {
return {
name: 'neu-inject',
transformIndexHtml: (html) => {
return {
html,
tags: [{
tag: 'script',
injectTo: 'head-prepend',
attrs: {
src: getGlobalsPath()
},
}]
};
}
};
}



43 changes: 43 additions & 0 deletions automation/neu-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"applicationId": "chocobois-jam-template",
"version": "1.0.0",
"defaultMode": "window",
"port": 0,
"documentRoot": "/dist/web",
"url": "/",
"enableServer": true,
"enableNativeAPI": true,
"tokenSecurity": "one-time",
"logging": {
"enabled": true,
"writeToLogFile": false
},
"nativeAllowList": ["app.exit", "window.center"],
"modes": {
"window": {
"title": "Chocobois Game Jam Template",
"width": 1440,
"height": 845,
"minWidth": 960,
"minHeight": 570,
"fullScreen": false,
"alwaysOnTop": false,
"icon": "src/public/icon.png",
"enableInspector": false,
"borderless": false,
"maximize": false,
"hidden": false,
"resizable": true,
"exitProcessOnClose": true
}
},
"cli": {
"binaryName": "chocobois-jam-template",
"resourcesPath": "/dist/",
"binaryVersion": "4.12.0",
"frontendLibrary": {
"patchFile": "/src/index.html",
"devUrl": "http://127.0.0.1:5173/"
}
}
}
Loading

0 comments on commit 36ca2a4

Please sign in to comment.