|
| 1 | +import { createRequire } from "node:module"; |
| 2 | +import { cpSync, rmSync } from "node:fs"; |
| 3 | +import path from "node:path"; |
| 4 | + |
| 5 | +import { EXAMPLES_DIR } from "./cmake-projects.mjs"; |
| 6 | + |
| 7 | +const ALLOW_LIST = [ |
| 8 | + // "1-getting-started/1_hello_world/napi/", |
| 9 | + "1-getting-started/2_function_arguments/napi/", |
| 10 | + // "1-getting-started/3_callbacks/napi/", |
| 11 | + // "1-getting-started/4_object_factory/napi/" |
| 12 | +]; |
| 13 | + |
| 14 | +console.log("Copying files to", EXAMPLES_DIR); |
| 15 | +// Clean up the destination directory before copying |
| 16 | +rmSync(EXAMPLES_DIR, { recursive: true, force: true }); |
| 17 | + |
| 18 | +const require = createRequire(import.meta.url); |
| 19 | + |
| 20 | +const EXAMPLES_PACKAGE_PATH = require.resolve( |
| 21 | + "node-addon-examples/package.json" |
| 22 | +); |
| 23 | +const SRC_DIR = path.join(path.dirname(EXAMPLES_PACKAGE_PATH), "src"); |
| 24 | +console.log("Copying files from", SRC_DIR); |
| 25 | + |
| 26 | +for (const src of ALLOW_LIST) { |
| 27 | + const srcPath = path.join(SRC_DIR, src); |
| 28 | + const destPath = path.join(EXAMPLES_DIR, src); |
| 29 | + console.log("Copying from", srcPath, "to", destPath); |
| 30 | + cpSync(srcPath, destPath, { recursive: true }); |
| 31 | +} |
0 commit comments