Skip to content

Commit

Permalink
Add distribution generation script
Browse files Browse the repository at this point in the history
All distribution assets are sent to dist/ and can be used for production
  • Loading branch information
quantum9Innovation committed Apr 16, 2023
1 parent ff8bee5 commit 607b818
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"test": "jest --runInBand --coverage",
"lint": "scripts/qa.sh",
"debug": "node --inspect-brk ./node_modules/.bin/jest --runInBand",
"retest": "scripts/build.sh; jest --runInBand --coverage"
"retest": "scripts/build.sh; jest --runInBand --coverage",
"dist": "scripts/dist.sh"
},
"private": true,
"repository": "https://github.com/quantum9Innovation/proto.git",
Expand All @@ -28,6 +29,7 @@
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.37.0",
"eslint-config-standard-with-typescript": "^34.0.0",
"eslint-plugin-import": "^2.27.5",
Expand Down
42 changes: 42 additions & 0 deletions api/scripts/dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
echo 'Building API from .'
yarn run tsc -p tsconfig.json
echo 'API built to compiled/'
echo '======================'
echo 'Rebuilding frontend from frontend/src/'
yarn run tsc -p frontend/src/tsconfig.json
echo 'Frontend built to frontend/webjs/'
echo '================================='
echo 'Compiling API to single file'
rm -r dist
yarn run ncc build compiled/run.js -o dist
echo 'API compiled to dist/index.js'
echo '================================='
echo 'Cleaning up generated distributions'
rm -r dist/frontend/src
rm dist/frontend/webjs/*.map
echo 'Cleaned distributions'
echo '====================='
echo 'Generating tarball'
cp package.json dist/package.json
cp config.json dist/config.json
touch dist/bootstrap.sh
printf "#!bin/bash\n" >> dist/bootstrap.sh
printf "cd ..\n" >> dist/bootstrap.sh
printf "mkdir frontend\n" >> dist/bootstrap.sh
printf "mv dist/frontend/index.html frontend/index.html\n" >> dist/bootstrap.sh
printf "cd dist; yarn install\n" >> dist/bootstrap.sh
touch dist/start.sh
printf "#!bin/bash\n" >> dist/start.sh
printf "node .\n" >> dist/start.sh
tar -czvf dist/dist.tar.gz dist
echo 'Tarball generated'
echo '================='
echo $'\nSee the dist/ folder for all generated assets.'
echo 'To start here, run: '
echo '> node dist/index.js'
echo $'\nAlternatively, to run in production, move dist/dist.tar.gz to the desired location'
echo 'Then, run the bootstrapper from within the extracted location: '
echo '> ./bootstrap.sh'
echo 'Make any necessary changes to config.json and then run:'
echo '> ./start.sh'
12 changes: 12 additions & 0 deletions api/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,17 @@ __metadata:
languageName: node
linkType: hard

"@vercel/ncc@npm:^0.36.1":
version: 0.36.1
resolution: "@vercel/ncc@npm:0.36.1"
dependencies:
node-gyp: latest
bin:
ncc: dist/ncc/cli.js
checksum: dcb8db089b07a8fad64c24eef25be6bc2db7ba30582a03236e3a6d332c8653d93a45aba7fe0e01b6d64f3c5b54d23467539ac3664c113f54a9e59341ded79bf9
languageName: node
linkType: hard

"abbrev@npm:^1.0.0":
version: 1.1.1
resolution: "abbrev@npm:1.1.1"
Expand Down Expand Up @@ -4929,6 +4940,7 @@ __metadata:
"@types/supertest": ^2.0.12
"@typescript-eslint/eslint-plugin": ^5.57.1
"@typescript-eslint/parser": ^5.57.1
"@vercel/ncc": ^0.36.1
body-parser: ^1.20.1
eslint: ^8.37.0
eslint-config-standard-with-typescript: ^34.0.0
Expand Down

0 comments on commit 607b818

Please sign in to comment.