Skip to content

Commit

Permalink
Finalize the TS port
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jan 29, 2025
1 parent f297721 commit 322efc8
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 290 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Setup HashLink VM
![Node.js](https://badgen.net/badge/node/%3E%3D20.0.0/green) ![Action](https://badgen.net/badge/action/v6.0.0/blue) ![License](https://badgen.net/badge/license/MIT/blue)
![Node.js](https://badgen.net/badge/node/%3E%3D20.0.0/green) ![Action](https://badgen.net/badge/action/v6.1.0/blue) ![License](https://badgen.net/badge/license/MIT/blue)

Set up your [GitHub Actions](https://docs.github.com/en/actions) workflow with a specific version of the [HashLink VM](https://hashlink.haxe.org).

Expand Down
48 changes: 24 additions & 24 deletions bin/setup_hashlink.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions etc/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default ts.config(
"@typescript-eslint/array-type": ["error", {default: "array-simple"}],
"@typescript-eslint/class-methods-use-this": "off",
"@typescript-eslint/consistent-return": "error",
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/default-param-last": "error",
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function dist() {
/** Performs the static analysis of source code. */
export async function lint() {
await npx("tsc", "--build", "tsconfig.json", "--noEmit");
await npx("eslint", "--config=etc/eslint.js", "gulpfile.js", "example", "src", "test");
await npx("eslint", "--config=etc/eslint.js", "gulpfile.js", "src", "test");
}

/** Publishes the package. */
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ async function main(): Promise<void> {
}

// Start the application.
main().catch(error => setFailed(error instanceof Error ? error : String(error)));
main().catch((error: unknown) => setFailed(error instanceof Error ? error : String(error)));
50 changes: 0 additions & 50 deletions src/release.coffee

This file was deleted.

83 changes: 0 additions & 83 deletions src/release.d.ts

This file was deleted.

119 changes: 119 additions & 0 deletions src/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import process from "node:process";
import semver, {SemVer} from "semver";
import data from "./data.json" with {type: "json"};

/**
* Represents a GitHub release.
*/
export class Release {

/**
* The latest release.
*/
static get latest(): Release|null {
return this.#data.at(0) ?? null;
}

/**
* The base URL of the releases.
*/
static readonly #baseUrl: URL = new URL("https://github.com/HaxeFoundation/hashlink/");

/**
* The list of all releases.
*/
static readonly #data: Release[] = data.map(release => new this(release.version, release.assets as ReleaseAsset[]));

/**
* The associated assets.
*/
assets: ReleaseAsset[];

/**
* The version number.
*/
version: string;

/**
* Creates a new release.
* @param version The version number.
* @param assets The associated assets.
*/
constructor(version: string, assets: ReleaseAsset[] = []) {
this.assets = assets;
this.version = version;
}

/**
* Value indicating whether this release exists.
*/
get exists(): boolean {
return Release.#data.some(release => release.version == this.version);
}

/**
* Value indicating whether this release is provided as source code.
*/
get isSource(): boolean {
return !this.getAsset(process.platform);
}

/**
* The associated Git tag.
*/
get tag(): string {
const {major, minor, patch} = new SemVer(this.version);
return patch > 0 ? `${major}.${minor}.${patch}` : `${major}.${minor}`;
}

/**
* The download URL.
*/
get url(): URL {
const asset = this.getAsset(process.platform);
return new URL(asset ? `releases/download/${this.tag}/${asset.file}` : `archive/refs/tags/${this.tag}.zip`, Release.#baseUrl);
}

/**
* Finds a release that matches the specified version constraint.
* @param constraint The version constraint.
* @returns The release corresponding to the specified constraint, or `null` if not found.
*/
static find(constraint: string): Release|null {
return this.#data.find(release => semver.satisfies(release.version, constraint)) ?? null;
}

/**
* Gets the release corresponding to the specified version.
* @param version The version number of a release.
* @returns The release corresponding to the specified version, or `null` if not found.
*/
static get(version: string): Release|null {
return this.#data.find(release => release.version == version) ?? null;
}

/**
* Gets the asset corresponding to the specified platform.
* @param platform The target platform.
* @returns The asset corresponding to the specified platform, or `null` if not found.
*/
getAsset(platform: NodeJS.Platform): ReleaseAsset|null {
return this.assets.find(asset => asset.platform == platform) ?? null;
}
}

/**
* Represents an asset of a GitHub release.
*/
export type ReleaseAsset = {

/**
* The target file.
*/
file: string;

/**
* The target platform.
*/
platform: NodeJS.Platform;
}
94 changes: 0 additions & 94 deletions src/setup.coffee

This file was deleted.

Loading

0 comments on commit 322efc8

Please sign in to comment.