Skip to content

Commit 9a58890

Browse files
authored
Remove bash build script in favour of typescript (#4)
* Remove bash build script in favour of ts * Update compile-tests workflow * Exit with status 1 on test compilation failure * Using public NPM registry Co-authored-by: Callum Macmillan🍺 <[email protected]>
1 parent e58c122 commit 9a58890

File tree

7 files changed

+434
-110
lines changed

7 files changed

+434
-110
lines changed

.github/workflows/compile-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
working-directory: tests/core
2727
run: |
2828
npm install
29-
./build.sh
29+
npm run build

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.wasm
1+
*.wasm
2+
.DS_Store

tests/core/build.sh

-10
This file was deleted.

tests/core/buildscripts/build.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as process from "process"
2+
import { doesFileHaveExtension, execAsPromise, getPathsInDirectory, mapFileExtension } from "./utility";
3+
4+
async function compileWithAsc(inputFilePath: string, outputFilePath: string) {
5+
return execAsPromise(`npm run asc --silent -- "${inputFilePath}" -o "${outputFilePath}"`);
6+
}
7+
8+
async function compileTests() {
9+
const testSuiteFiles = getPathsInDirectory("testsuite");
10+
const testFiles = testSuiteFiles.filter(filepath => doesFileHaveExtension(filepath, "ts"));
11+
const pendingCompilations = testFiles.map(filepath => compileWithAsc(filepath, mapFileExtension(filepath, "ts", "wasm")));
12+
return Promise.all(pendingCompilations);
13+
}
14+
15+
compileTests()
16+
.then(() => console.log("Tests compiled"))
17+
.catch((e) => {
18+
console.error(`Tests failed to compile: ${e}`);
19+
process.exit(1);
20+
});

tests/core/buildscripts/utility.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as childProcess from "child_process";
2+
import * as fs from "fs";
3+
import * as path from "path";
4+
5+
export async function execAsPromise(command: string): Promise<void> {
6+
return new Promise<void>((resolve, reject) => {
7+
childProcess.exec(command, (error) => {
8+
error ? reject(error) : resolve();
9+
});
10+
});
11+
}
12+
13+
export function getPathsInDirectory(directory: string): string[] {
14+
return fs.readdirSync(directory).map(filepath => path.join(directory, filepath));
15+
}
16+
17+
export function doesFileHaveExtension(filepath: string, extension: string): boolean {
18+
return !!filepath.match(`^.*\\.${extension}$`);
19+
}
20+
21+
export function mapFileExtension(filepath: string, oldExtension: string, newExtension: string): string {
22+
return path.join(path.dirname(filepath), path.basename(filepath, oldExtension) + newExtension);
23+
}

0 commit comments

Comments
 (0)