From 6b9de74ebbfbf07fe78c1d119c2d5c3e344b0426 Mon Sep 17 00:00:00 2001 From: Alex McBean Date: Sat, 15 Jan 2022 18:45:16 +0000 Subject: [PATCH] NPM Package (WIP) --- bin/index.js | 8 ++++++++ lib/build.js | 10 ++++++++++ package-lock.json | 15 +++++++++------ package.json | 8 ++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 bin/index.js create mode 100644 lib/build.js diff --git a/bin/index.js b/bin/index.js new file mode 100644 index 00000000..7302a862 --- /dev/null +++ b/bin/index.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node +/* eslint-disable strict */ + +const [,, ...args] = process.argv; + +const { build } = require('../lib/build'); + +build(args[0], args[1]); diff --git a/lib/build.js b/lib/build.js new file mode 100644 index 00000000..12ab47ca --- /dev/null +++ b/lib/build.js @@ -0,0 +1,10 @@ +/* eslint-disable strict */ + +const { execSync } = require('child_process'); +const pkg = require('pkg'); + +exports.build = async function (package, output) { + console.log(`Building server executable with package: ${package} and output: ${output} `); + execSync('nest build'); + await pkg.exec(['dist/main.js', '--public-packages', '*', '-t', `${package}`, '--output', `${output}`]); +}; diff --git a/package-lock.json b/package-lock.json index 70d90292..ddba0b19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,9 @@ "winston-daily-rotate-file": "^4.5.5", "xml2js": "^0.4.23" }, + "bin": { + "fbw-local-api": "bin/index.js" + }, "devDependencies": { "@flybywiresim/eslint-config": "^0.2.3", "@nestjs/cli": "^8.0.0", @@ -2721,9 +2724,9 @@ } }, "node_modules/async": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.2.tgz", - "integrity": "sha512-H0E+qZaDEfx/FY4t7iLRv1W2fFI6+pyCeTw1uN20AQPiwqwM6ojPxHxdLv4z8hi2DtnW9BOckSspLucW7pIE5g==" + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", + "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" }, "node_modules/asynckit": { "version": "0.4.0", @@ -13441,9 +13444,9 @@ "peer": true }, "async": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/async/-/async-3.2.2.tgz", - "integrity": "sha512-H0E+qZaDEfx/FY4t7iLRv1W2fFI6+pyCeTw1uN20AQPiwqwM6ojPxHxdLv4z8hi2DtnW9BOckSspLucW7pIE5g==" + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", + "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" }, "asynckit": { "version": "0.4.0", diff --git a/package.json b/package.json index 1c55389d..efd86099 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,9 @@ "author": "", "private": true, "license": "GNu", + "bin": { + "fbw-local-api": "./bin/index.js" + }, "scripts": { "prebuild": "rimraf dist", "build": "nest build", @@ -80,5 +83,10 @@ ], "coverageDirectory": "../coverage", "testEnvironment": "node" + }, + "pkg": { + "targets": [ + "node16-win-x64" + ] } }