diff --git a/package.json b/package.json index bb913c6..f806cd2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "access": "public" }, "scripts": { - "build": "tsc -p tsconfig.json && mkdir -p dist/src && cp src/schemas.trust-*.json dist/src/", + "build": "tsc -p tsconfig.json && node scripts/copy-schemas.mjs", "test": "node --test dist/test/receipt.test.js dist/test/trust.test.js", "pretest": "npm run build", "example:basic": "node dist/examples/basic-agent.js", diff --git a/scripts/copy-schemas.mjs b/scripts/copy-schemas.mjs new file mode 100644 index 0000000..e684c6b --- /dev/null +++ b/scripts/copy-schemas.mjs @@ -0,0 +1,19 @@ +import { copyFile, mkdir, readdir } from 'node:fs/promises'; +import path from 'node:path'; + +const sourceDir = 'src'; +const destinationDir = path.join('dist', 'src'); +const schemaPattern = /^schemas\.trust-.*\.json$/; + +await mkdir(destinationDir, { recursive: true }); + +const sourceEntries = await readdir(sourceDir, { withFileTypes: true }); +const schemaFiles = sourceEntries + .filter((entry) => entry.isFile() && schemaPattern.test(entry.name)) + .map((entry) => entry.name); + +await Promise.all( + schemaFiles.map((fileName) => + copyFile(path.join(sourceDir, fileName), path.join(destinationDir, fileName)), + ), +);