Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions src/c2wasm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,48 @@
tasks: Task[];
}

export async function buildCDir(
dirPath: string,
outDir: string,
headersPath: string | undefined,
isXRPL: boolean
): Promise<void> {
// Reading all files in the directory tree
let fileObjects: any[];
try {
fileObjects = readFiles(dirPath);
} catch (error: any) {
console.error(`Error reading files: ${error}`);
process.exit(1);
}

const getCustomHeader = (headersPath: string | undefined): any[] => {

Check warning on line 21 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 21 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
let headerObjects: any[] = [];

Check warning on line 22 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 22 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
if (headersPath) {
try {
headerObjects = readFiles(headersPath).filter(
(file) => file.type === "h"
);
} catch (error: any) {

Check warning on line 28 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 28 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
console.error(`Error reading header files: ${error}`);
process.exit(1);
}
if (headerObjects.length === 0) {
console.log("No header files detected, using default headers...");
console.warn(
"In the feature version, default headers will not be provided. Please provide your own headers."
);
}
} else {
console.log("No header path specified, using default headers...");
console.warn(
"In the feature version, default headers will not be provided. Please provide your own headers."
);
}
return headerObjects;
};

export async function buildCDir(
dirPath: string,
outDir: string,
headersPath: string | undefined,
isXRPL: boolean
): Promise<void> {
// Reading all files in the directory tree
let fileObjects: any[];

Check warning on line 54 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 54 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
try {
fileObjects = readFiles(dirPath);
} catch (error: any) {

Check warning on line 57 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 57 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
console.error(`Error reading files: ${error}`);
process.exit(1);
}

const headerObjects = getCustomHeader(headersPath);

// Building wasm for each file object
await Promise.all(
Expand Down Expand Up @@ -82,20 +93,9 @@
name: filename,
src: fileContent,
};
let headerObjects: any[] = [];
if (headerPath) {
try {
headerObjects = readFiles(headerPath).filter((file) => file.type === "h");
} catch (error: any) {
console.error(`Error reading header files: ${error}`);
process.exit(1);
}
if (headerObjects.length === 0) {
console.log("No header files detected, using default headers...");
}
} else {
console.log("No header path specified, using default headers...");
}

const headerObjects = getCustomHeader(headerPath);

try {
await buildWasm(fileObject, headerObjects, outDir, isXRPL);
} catch (error) {
Expand All @@ -105,8 +105,8 @@
}

// Function to read all files in a directory tree
export function readFiles(dirPath: string): any[] {

Check warning on line 108 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 108 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
const files: any[] = [];

Check warning on line 109 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 109 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
const fileNames = fs.readdirSync(dirPath);
for (const fileName of fileNames) {
const filePath = path.join(dirPath, fileName);
Expand Down Expand Up @@ -174,8 +174,8 @@
}

export async function buildWasm(
fileObject: any,

Check warning on line 177 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 177 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
headerObjects: any[],

Check warning on line 178 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 178 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
outDir: string,
isXRPL: boolean
) {
Expand Down Expand Up @@ -221,7 +221,7 @@
} as BuildResult;
fs.mkdirSync(outDir, { recursive: true });
await saveFileOrError(outDir, filename, result);
} catch (error: any) {

Check warning on line 224 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (16.x)

Unexpected any. Specify a different type

Check warning on line 224 in src/c2wasm/index.ts

View workflow job for this annotation

GitHub Actions / build-and-lint (20.x)

Unexpected any. Specify a different type
throw Error(`Error sending API call: ${error}`);
}
}
Loading