Skip to content

Commit

Permalink
Update example with fixed types. Fix gulp and add github action
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Sep 17, 2024
1 parent f01f12c commit e038d91
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 97 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
# 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: ''
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
122 changes: 52 additions & 70 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<void>}
*/
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
Expand All @@ -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<void>}
*/
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)
}
}

/**
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)\"",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/aircraft/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 21 additions & 21 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down Expand Up @@ -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 {}
}
}

0 comments on commit e038d91

Please sign in to comment.