diff --git a/api/package.json b/api/package.json index 49b40d4..f247f22 100644 --- a/api/package.json +++ b/api/package.json @@ -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", @@ -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", diff --git a/api/scripts/dist.sh b/api/scripts/dist.sh new file mode 100755 index 0000000..6ece52b --- /dev/null +++ b/api/scripts/dist.sh @@ -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' diff --git a/api/yarn.lock b/api/yarn.lock index f86022c..b2eba82 100644 --- a/api/yarn.lock +++ b/api/yarn.lock @@ -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" @@ -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