Skip to content

Commit

Permalink
build: use js for build script (#1709)
Browse files Browse the repository at this point in the history
* use js for build script

* Remove install python step (#2)

Co-authored-by: Niklas Steiner <[email protected]>
Co-authored-by: Benjamin Dupont <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2020
1 parent 5d4c518 commit 23622c0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 69 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ jobs:
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Setup Python 3
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Set BUILT_DATE_TIME
run: echo "BUILT_DATE_TIME=$(date -u -Iseconds)" >> $GITHUB_ENV
- name: Generate layout.json
Expand All @@ -38,14 +34,15 @@ jobs:
- name: Get and delete master pre-release zip asset
run: |
echo 'checking for first release asset...'
assetId=$( \
assets=$( \
curl --location --request GET \
--url https://api.github.com/repos/${{ github.repository }}/releases/${{ env.MASTER_PRE_RELEASE_ID }}/assets \
| python3 -c "import sys,json; assets=json.load(sys.stdin); print(assets[0]['id'] if len(assets) > 0 else 'none')" \
--url https://api.github.com/repos/${{ github.repository }}/releases/${{ env.MASTER_PRE_RELEASE_ID }}/assets
)
if [ $assetId = "none" ]; then
if [ $(echo $assets | jq '.[0].size') -eq '0' ]; then
echo 'no asset to delete'
else
assetId=$(echo $assets | jq '.[0].id')
echo 'deleting asset '$assetId
curl --request DELETE \
--url https://api.github.com/repos/${{ github.repository }}/releases/assets/$assetId \
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Setup Python 3
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Generate layout.json and update manifest.json
run: |
npm install
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/A32NX/html_ui/Pages/VCockpit/Instruments/generated
!/docs/**
!/src/**
!/scripts/**
!.gitignore
!CODEOWNERS
!package.json
Expand Down
54 changes: 0 additions & 54 deletions A32NX/build.py

This file was deleted.

2 changes: 0 additions & 2 deletions manifest-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"OlderHistory": ""
}
},
"package_version": "0.4.1",
"title": "A32NX",
"dependencies": [
{
Expand All @@ -27,7 +26,6 @@
}
],
"content_type": "AIRCRAFT",
"total_package_size": "00000000000221782906",
"minimum_game_version": "1.9.5",
"manufacturer": "Airbus"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lint-fix": "npm run lint -- --fix",
"prettier": "prettier --write **/*.json **/*.yml src/instruments/**/*.css",
"build:instruments": "rollup -c src/instruments/rollup.config.js",
"build:msfs": "cd A32NX && python build.py",
"build:msfs": "node scripts/build.js",
"build": "npm run build:instruments && npm run build:msfs"
},
"husky": {
Expand Down
44 changes: 44 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

const fs = require('fs');
const path = require('path');

function* readdir(d) {
for (const dirent of fs.readdirSync(d, { withFileTypes: true })) {
if (['layout.json', 'manifest.json'].includes(dirent.name)) {
continue;
}
const resolved = path.join(d, dirent.name);
if (dirent.isDirectory()) {
yield* readdir(resolved);
} else {
yield resolved;
}
}
}

const MS_FILETIME_EPOCH = 116444736000000000n;
const A32NX = path.resolve(__dirname, '..', 'A32NX');

const contentEntries = [];
let totalPackageSize = 0;

for (const filename of readdir(A32NX)) {
const stat = fs.statSync(filename, { bigint: true });
contentEntries.push({
path: path.relative(A32NX, filename.replace(path.sep, '/')),
size: Number(stat.size),
date: Number((stat.mtimeNs / 100n) + MS_FILETIME_EPOCH),
});
totalPackageSize += Number(stat.size);
}

fs.writeFileSync(path.join(A32NX, 'layout.json'), JSON.stringify({
content: contentEntries,
}, null, 2));

fs.writeFileSync(path.join(A32NX, 'manifest.json'), JSON.stringify({
...require('../manifest-base.json'),
package_version: require('../package.json').version,
total_package_size: totalPackageSize.toString().padStart(20, '0'),
}, null, 2));

0 comments on commit 23622c0

Please sign in to comment.