|
| 1 | +import fs from "node:fs"; |
| 2 | +import assert from "node:assert/strict"; |
| 3 | +import path from "node:path"; |
| 4 | + |
| 5 | +import { EXAMPLES_DIR } from "./cmake-projects.mjs"; |
| 6 | + |
| 7 | +const EXPECTED_ANDROID_ARCHS = ["armeabi-v7a", "arm64-v8a", "x86_64", "x86"]; |
| 8 | + |
| 9 | +const EXPECTED_XCFRAMEWORK_PLATFORMS = [ |
| 10 | + "ios-arm64", |
| 11 | + "ios-arm64-simulator", |
| 12 | + "macos-arm64_x86_64", |
| 13 | + "tvos-arm64", |
| 14 | + "tvos-arm64-simulator", |
| 15 | + "xros-arm64", |
| 16 | + "xros-arm64-simulator", |
| 17 | +]; |
| 18 | + |
| 19 | +async function verifyAndroidDirectory(dirent: fs.Dirent) { |
| 20 | + for (const arch of EXPECTED_ANDROID_ARCHS) { |
| 21 | + const archDir = path.join(dirent.parentPath, dirent.name, arch); |
| 22 | + for (const file of await fs.promises.readdir(archDir, { |
| 23 | + withFileTypes: true, |
| 24 | + })) { |
| 25 | + assert(file.isFile()); |
| 26 | + assert( |
| 27 | + !file.name.endsWith(".node"), |
| 28 | + `Unexpected .node file: ${path.join(file.parentPath, file.name)}` |
| 29 | + ); |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +async function verifyXcframework(dirent: fs.Dirent) { |
| 35 | + for (const arch of EXPECTED_XCFRAMEWORK_PLATFORMS) { |
| 36 | + const archDir = path.join(dirent.parentPath, dirent.name, arch); |
| 37 | + for (const file of await fs.promises.readdir(archDir, { |
| 38 | + withFileTypes: true, |
| 39 | + })) { |
| 40 | + assert( |
| 41 | + file.isDirectory(), |
| 42 | + "Expected only directories in xcframework arch directory" |
| 43 | + ); |
| 44 | + assert(file.name.endsWith(".framework"), "Expected framework directory"); |
| 45 | + const frameworkDir = path.join(file.parentPath, file.name); |
| 46 | + for (const file of await fs.promises.readdir(frameworkDir, { |
| 47 | + withFileTypes: true, |
| 48 | + })) { |
| 49 | + if (file.isDirectory()) { |
| 50 | + assert.equal( |
| 51 | + file.name, |
| 52 | + "Headers", |
| 53 | + "Unexpected directory in xcframework" |
| 54 | + ); |
| 55 | + } else { |
| 56 | + assert( |
| 57 | + file.isFile(), |
| 58 | + "Expected only directory and files in framework" |
| 59 | + ); |
| 60 | + if (file.name === "Info.plist") { |
| 61 | + // TODO: Verify the contents of the Info.plist file |
| 62 | + continue; |
| 63 | + } else { |
| 64 | + assert( |
| 65 | + !file.name.endsWith(".node"), |
| 66 | + `Didn't expected a .node file in xcframework: ${path.join( |
| 67 | + frameworkDir, |
| 68 | + file.name |
| 69 | + )}` |
| 70 | + ); |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +for (const dirent of await fs.promises.readdir(EXAMPLES_DIR, { |
| 79 | + withFileTypes: true, |
| 80 | + recursive: true, |
| 81 | +})) { |
| 82 | + if (!dirent.isDirectory()) { |
| 83 | + continue; |
| 84 | + } |
| 85 | + if (dirent.name.endsWith(".android.node")) { |
| 86 | + await verifyAndroidDirectory(dirent); |
| 87 | + } else if (dirent.name.endsWith(".xcframework")) { |
| 88 | + await verifyXcframework(dirent); |
| 89 | + } |
| 90 | +} |
0 commit comments