From e038d912a03c8d09e7c0bd749d947a3baa18afa0 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 17 Sep 2024 18:46:18 -0500 Subject: [PATCH] Update example with fixed types. Fix gulp and add github action --- .github/workflows/distribute.yml | 85 +++++++++++++++++++++ README.md | 11 ++- gulpfile.mjs | 122 +++++++++++++------------------ package.json | 5 +- src/aircraft/example.ts | 2 +- src/types/global.d.ts | 42 +++++------ 6 files changed, 170 insertions(+), 97 deletions(-) create mode 100644 .github/workflows/distribute.yml diff --git a/.github/workflows/distribute.yml b/.github/workflows/distribute.yml new file mode 100644 index 0000000..041a6f5 --- /dev/null +++ b/.github/workflows/distribute.yml @@ -0,0 +1,85 @@ +name: 'Build' +on: + pull_request: + push: + branches: + - main +jobs: + artifacts: + name: 'Create release' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: install node + uses: actions/setup-node@v3 + with: + cache: 'npm' + + - name: npm install + run: | + npm install + + - name: gulp build + run: | + npm run build + + # Create a zip from what's in this repo + - name: Archive Release + uses: thedoctor0/zip-release@0.7.5 + with: + type: 'zip' + directory: 'dist/' + path: '../' + filename: 'vmsacars_config.zip' + exclusions: '*.git* /*node_modules/* .editorconfig dist' + command: "mkdir -p dist" + + # List all the files that have been created + - name: 'List files' + run: | + find dist/ -maxdepth 2 -type f + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v3 + with: + name: acars-package + path: 'dist/*' + + # + # Now publish it up + # + publish: + runs-on: ubuntu-latest + needs: [ 'artifacts' ] + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/') + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: acars-package + + # You can uncomment the method you want to use to upload + # Create the environment variables appropriately to set it up + + # Upload via SFTP. See details here: + # https://github.com/marketplace/actions/sftp-uploader + + #- name: SFTP uploader + # uses: wangyucode/sftp-upload-action@v2.0.2 + # with: + # host: ${{ secrets.SFTP_HOST }} + # password: ${{ secrets.SFTP_PASSWORD }} + # localDir: 'dist' + # remoteDir: ${{ secrets.SFTP_REMOTE_PATH }} + + # Upload to an S3 bucket + # https://github.com/actions-marketplace-validations/shallwefootball_upload-s3-action + #- name: Upload S3 + # uses: shallwefootball/s3-upload-action@master + # with: + # aws_key_id: ${{ secrets.S3_BUILD_ARTIFACTS_ACCESS_KEY_ID }} + # aws_secret_access_key: ${{ secrets.S3_BUILD_ARTIFACTS_SECRET_ACCESS_KEY}} + # aws_bucket: ${{ secrets.S3_BUCKET_NAME }} + # source_dir: 'dist/' + # destination_dir: '' diff --git a/README.md b/README.md index 9d0603d..af15521 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,13 @@ Typescript ensures that the interfaces required are following, and that the prop are returned so ACARS can run them. While Typescript isn't required, it's best to use it to ensure proper values are passed - especially around enums. +This PDK includes build scripts to: + +- Convert Typescript to JS, with type checking/linting +- Stamp the distribution package with versioning +- Github Actions to build and deploy +- Scripts to help with development + --- # Setup @@ -61,8 +68,8 @@ Github Actions to then upload this zip somewhere for ACARS to download. #### Automatically build and copy to ACARS -This will setup a watch, and then automatically transpile and then copy the contents of the `dist` folder -into the `ACARS_PROFILE_PATH` directory that's defined in the `.env` file. +This will setup a watch, and then automatically transpile and then copy the contents of the +`dist` folder into the `ACARS_PROFILE_PATH` directory that's defined in the `.env` file. ```shell npm run dev diff --git a/gulpfile.mjs b/gulpfile.mjs index ed79d5e..41811c6 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -1,20 +1,20 @@ import dotconfig from '@dotenvx/dotenvx' import { deleteAsync } from 'del' +import fs from 'fs' import { dest, series, src, watch } from 'gulp' import eslint from 'gulp-eslint-new' -import rsync from 'gulp-rsync' import ts from 'gulp-typescript' -import merge2 from 'merge2' dotconfig.config() +// console.log(process.env) /** * Different paths we use... */ const paths = { - src: 'src', - dest: 'dist', + src: './src', + dist: './dist', /** * ACARS scripts/config directory. This, by default, points to the home directory @@ -28,41 +28,62 @@ const paths = { */ const tsProject = ts.createProject('tsconfig.json') +function build_ts() { + return tsProject.src() + .pipe(eslint()) + .pipe(eslint.failAfterError()) + .pipe(tsProject()) + .js.pipe(dest(paths.dist)) +} + +function copy_package() { + return src([paths.src + '/package.json']) + .pipe(dest(paths.dist)) +} + /** * Build the project, copy the appropriate files over */ -export async function build() { - return merge2( - // Build the TS files - tsProject.src() - .pipe(eslint()) - .pipe(eslint.failAfterError()) - .pipe(tsProject()) - .js.pipe(dest(paths.dest)), - - - // Copy the package json file over - src([paths.src + '/package.json']).pipe(dest(paths.dest)), - ) -} +export const build = series(build_ts, copy_package) /** * Copy the files from dist into ACARS_SCRIPTS_PATH * - * @returns {Promise} */ -export async function copy() { +export function copy() { console.log(`Copying files to ${paths.acars}`) - return src([paths.dest + '/**/*']).pipe(dest(paths.acars)) + + return src(['./**/*'], { 'cwd': paths.dist }) + .pipe(dest(paths.acars)) } /** - * Build a distribution zip file, which can be easily uploaded + * The build steps that run from the csproj + * Force the output path to go into our build directory + */ +export const csbuild = series( + async () => { + paths.acars = '../Content/config/default' + }, + build, + copy, +) + +/** + * TODO: Build the distribution zip file */ -export function dist() { +function build_dist() { } +/** + * Build a distribution zip file, which can be easily uploaded + */ +export const dist = series( + build, + build_dist, +) + /** * Watch the src folder for updates, compile them and then copy them * to the config directory. ACARS should auto-reload @@ -87,53 +108,14 @@ export { watchFiles as watch } * Clean up the /dest directory */ export async function clean() { - await deleteAsync([paths.dest]) -} - -/** - * Internal task to copy files over to the PDK distribution - * @returns {Promise} - */ -export async function pdk() { - const source = '.' - const pdk_path = process.env.PDK_DISTRIBUTION_DIRECTORY - - const files = [ - `${source}/**/*`, - `!${source}/bin`, - `!${source}/dist`, - `!${source}/node_modules`, - `!${source}/obj`, - `!${source}/.env`, - `!${source}/nuget.config`, - `!${source}/Content.Source.*`, - ] - - src([source]).pipe(rsync({ - root: '.', - destination: pdk_path, - recursive: true, - exclude: [ - `${source}/bin`, - `${source}/dist`, - `${source}/node_modules`, - `${source}/obj`, - `${source}/.env`, - `${source}/nuget.config`, - `${source}/Content.Source.*`, - ], - })) - - /*const deleteFiles = [ - `${pdk_path}/dist`, - `${pdk_path}/node_modules`, - `!${pdk_path}/src/aircraft/Example.ts`, - `!${pdk_path}/src/rules/example.ts`, - ] - - await deleteAsync(deleteFiles, { - force: true, - })*/ + try { + if (await fs.promises.exists(paths.dist)) { + await deleteAsync([paths.dist]) + await Promise.resolve() + } + } catch (e) { + console.log(e) + } } /** diff --git a/package.json b/package.json index e8afe20..698db73 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "main": "app.js", "scripts": { "build": "gulp build", + "clean": "gulp clean", "copy": "gulp copy", - "buildcopy": "cross-env ACARS_SCRIPTS_PATH=../Content/config/default gulp build copy", + "csbuild": "gulp csbuild", "tsbuild": "tsc --build", "lint": "eslint --fix", "format": "prettier --ignore-path .gitignore --write \"src/**/*.+(js|ts|json)\"", @@ -28,9 +29,7 @@ "eslint": "^9.9.1", "gulp": "^5.0.0", "gulp-eslint-new": "^2.3.0", - "gulp-rsync": "^0.1.0", "gulp-typescript": "^6.0.0-alpha.1", - "gulp-util": "^3.0.8", "merge2": "^1.4.1", "prettier": "^3.3.3", "typescript": "^5.5.4" diff --git a/src/aircraft/example.ts b/src/aircraft/example.ts index 8bdc101..28c27d2 100644 --- a/src/aircraft/example.ts +++ b/src/aircraft/example.ts @@ -35,7 +35,7 @@ export default class Example extends AircraftConfig { * @return {boolean} */ match(title: string, icao: string, config_path: string): boolean { - return ['example', 'aircraft'].every(title.includes) + return ['example', 'aircraft'].every((w) => title.includes(w)) } beaconLights(): FeatureState { diff --git a/src/types/global.d.ts b/src/types/global.d.ts index de5c500..b45d0f4 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -1,27 +1,6 @@ import { RuleValue } from './rule' import { AircraftFeature } from '../defs' -declare global { - namespace console { - /** - * Log this item out only once - * - * @param args - */ - function once(...args: any[]): void {} - /** - * @param args - */ - function log(...args: any[]): void {} - /** A debug message */ - function debug(...args: any[]): void {} - /** A debug message */ - function error(...args: any[]): void {} - /** A debug message */ - function trace(...args: any[]): void {} - } -} - declare global { namespace Acars { /** @@ -103,3 +82,24 @@ declare global { ): boolean {} } } + +declare global { + namespace console { + /** + * Log this item out only once + * + * @param args + */ + function once(...args: any[]): void {} + /** + * @param args + */ + function log(...args: any[]): void {} + /** A debug message */ + function debug(...args: any[]): void {} + /** A debug message */ + function error(...args: any[]): void {} + /** A debug message */ + function trace(...args: any[]): void {} + } +}