diff --git a/manifest-base.json b/manifest-base.json new file mode 100644 index 00000000..4a288740 --- /dev/null +++ b/manifest-base.json @@ -0,0 +1,14 @@ +{ + "creator": "FlyByWire Simulations", + "release_notes": { + "neutral": { + "LastUpdate": "", + "OlderHistory": "" + } + }, + "title": "SimBridge", + "dependencies": [], + "content_type": "TOOL", + "minimum_game_version": "1.27.21.0", + "manufacturer": "FlyByWire Simulations" +} diff --git a/package.json b/package.json index c998b755..d95d3feb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "build": "npm run build:server && npm run build:mcdu", "build:mcdu": "webpack --config apps/mcdu/webpack.config.js", "build:server": "nest build server", - "build:exec": "npm run build && npx pkg-exe-build build && npm run copy:deps", + "build:exec": "npm run build && npx pkg-exe-build build && npm run copy:deps && npm run build:manifest", + "build:manifest": "node scripts/manifest.js", "copy:deps": "npm run copy:resources && npm run copy:modules && copyfiles -s -f LICENSE build && npm run fetch:terrain", "copy:resources": "copyfiles -s -f apps/server/src/config/properties.json ./node_modules/pdf-to-printer/dist/SumatraPDF.exe build/resources", "copy:modules": "npm run copy:traybin && npm run copy:pdfjs && npm run copy:nodehide && npm run copy:sharp && npm run copy:open", @@ -98,7 +99,7 @@ "@babel/preset-react": "^7.16.7", "@babel/runtime": "^7.17.2", "@flybywiresim/eslint-config": "^0.2.3", - "@flybywiresim/fragmenter": "^0.6.1", + "@flybywiresim/fragmenter": "^0.7.1", "@nestjs/cli": "^8.0.0", "@nestjs/schematics": "^8.0.0", "@nestjs/testing": "^8.0.0", diff --git a/scripts/manifest.js b/scripts/manifest.js new file mode 100644 index 00000000..dd5afa41 --- /dev/null +++ b/scripts/manifest.js @@ -0,0 +1,43 @@ +const fs = require('fs') +const path = require('path') +const child_process = require('child_process') + +const executeGitCommand = (command) => { + return child_process.execSync(command) + .toString('utf8') + .replace(/[\n\r]+$/, ''); +} + +const BASE_DIR = './build'; +const MANIFEST_PATH = 'manifest.json'; +const MANIFEST_BASE = require('../manifest-base.json') +const GIT_COMMIT_SHA = process.env.GITHUB_SHA + ? process.env.GITHUB_SHA.substring(0, 9) + : executeGitCommand('git rev-parse --short HEAD'); + +const generatePackageSize = () => { + console.log("Generating Package Size") + let totalPackageSize = 0; + + for (const filename of fs.readdirSync(BASE_DIR)) { + const stat = fs.statSync(path.join(BASE_DIR,filename), { bigint: true }); + totalPackageSize += Number(stat.size); + } + + return totalPackageSize +} + +const build_manifest = () => { + try { + console.log('Building manifest') + fs.writeFileSync(path.join(BASE_DIR, MANIFEST_PATH), JSON.stringify({ + ...MANIFEST_BASE, + package_version: require('../package.json').version + `-${GIT_COMMIT_SHA}`, + total_package_size: generatePackageSize().toString().padStart(20, '0'), + }, null, 2)) + } catch (error) { + console.error(error) + } +} + +build_manifest()