Skip to content

Commit 322efc8

Browse files
author
Cédric Belin
committed
Finalize the TS port
1 parent f297721 commit 322efc8

File tree

14 files changed

+288
-290
lines changed

14 files changed

+288
-290
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Setup HashLink VM
2-
![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)
2+
![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)
33

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

bin/setup_hashlink.cjs

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

etc/eslint.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export default ts.config(
152152
"@typescript-eslint/array-type": ["error", {default: "array-simple"}],
153153
"@typescript-eslint/class-methods-use-this": "off",
154154
"@typescript-eslint/consistent-return": "error",
155+
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
155156
"@typescript-eslint/consistent-type-exports": "error",
156157
"@typescript-eslint/consistent-type-imports": "error",
157158
"@typescript-eslint/default-param-last": "error",

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function dist() {
3333
/** Performs the static analysis of source code. */
3434
export async function lint() {
3535
await npx("tsc", "--build", "tsconfig.json", "--noEmit");
36-
await npx("eslint", "--config=etc/eslint.js", "gulpfile.js", "example", "src", "test");
36+
await npx("eslint", "--config=etc/eslint.js", "gulpfile.js", "src", "test");
3737
}
3838

3939
/** Publishes the package. */

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ async function main(): Promise<void> {
2020
}
2121

2222
// Start the application.
23-
main().catch(error => setFailed(error instanceof Error ? error : String(error)));
23+
main().catch((error: unknown) => setFailed(error instanceof Error ? error : String(error)));

src/release.coffee

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/release.d.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/release.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import process from "node:process";
2+
import semver, {SemVer} from "semver";
3+
import data from "./data.json" with {type: "json"};
4+
5+
/**
6+
* Represents a GitHub release.
7+
*/
8+
export class Release {
9+
10+
/**
11+
* The latest release.
12+
*/
13+
static get latest(): Release|null {
14+
return this.#data.at(0) ?? null;
15+
}
16+
17+
/**
18+
* The base URL of the releases.
19+
*/
20+
static readonly #baseUrl: URL = new URL("https://github.com/HaxeFoundation/hashlink/");
21+
22+
/**
23+
* The list of all releases.
24+
*/
25+
static readonly #data: Release[] = data.map(release => new this(release.version, release.assets as ReleaseAsset[]));
26+
27+
/**
28+
* The associated assets.
29+
*/
30+
assets: ReleaseAsset[];
31+
32+
/**
33+
* The version number.
34+
*/
35+
version: string;
36+
37+
/**
38+
* Creates a new release.
39+
* @param version The version number.
40+
* @param assets The associated assets.
41+
*/
42+
constructor(version: string, assets: ReleaseAsset[] = []) {
43+
this.assets = assets;
44+
this.version = version;
45+
}
46+
47+
/**
48+
* Value indicating whether this release exists.
49+
*/
50+
get exists(): boolean {
51+
return Release.#data.some(release => release.version == this.version);
52+
}
53+
54+
/**
55+
* Value indicating whether this release is provided as source code.
56+
*/
57+
get isSource(): boolean {
58+
return !this.getAsset(process.platform);
59+
}
60+
61+
/**
62+
* The associated Git tag.
63+
*/
64+
get tag(): string {
65+
const {major, minor, patch} = new SemVer(this.version);
66+
return patch > 0 ? `${major}.${minor}.${patch}` : `${major}.${minor}`;
67+
}
68+
69+
/**
70+
* The download URL.
71+
*/
72+
get url(): URL {
73+
const asset = this.getAsset(process.platform);
74+
return new URL(asset ? `releases/download/${this.tag}/${asset.file}` : `archive/refs/tags/${this.tag}.zip`, Release.#baseUrl);
75+
}
76+
77+
/**
78+
* Finds a release that matches the specified version constraint.
79+
* @param constraint The version constraint.
80+
* @returns The release corresponding to the specified constraint, or `null` if not found.
81+
*/
82+
static find(constraint: string): Release|null {
83+
return this.#data.find(release => semver.satisfies(release.version, constraint)) ?? null;
84+
}
85+
86+
/**
87+
* Gets the release corresponding to the specified version.
88+
* @param version The version number of a release.
89+
* @returns The release corresponding to the specified version, or `null` if not found.
90+
*/
91+
static get(version: string): Release|null {
92+
return this.#data.find(release => release.version == version) ?? null;
93+
}
94+
95+
/**
96+
* Gets the asset corresponding to the specified platform.
97+
* @param platform The target platform.
98+
* @returns The asset corresponding to the specified platform, or `null` if not found.
99+
*/
100+
getAsset(platform: NodeJS.Platform): ReleaseAsset|null {
101+
return this.assets.find(asset => asset.platform == platform) ?? null;
102+
}
103+
}
104+
105+
/**
106+
* Represents an asset of a GitHub release.
107+
*/
108+
export type ReleaseAsset = {
109+
110+
/**
111+
* The target file.
112+
*/
113+
file: string;
114+
115+
/**
116+
* The target platform.
117+
*/
118+
platform: NodeJS.Platform;
119+
}

src/setup.coffee

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)