|
| 1 | +import fs from "node:fs"; |
| 2 | +import path from "node:path"; |
| 3 | +import cp from "node:child_process"; |
| 4 | + |
| 5 | +import { TESTS_DIR } from "./utils.mts"; |
| 6 | + |
| 7 | +const NODE_REPO_URL = "git@github.com:nodejs/node.git"; |
| 8 | +const NODE_REPO_DIR = path.resolve(import.meta.dirname, "../node"); |
| 9 | + |
| 10 | +const ALLOW_LIST = [ |
| 11 | + "js-native-api/common.h", |
| 12 | + "js-native-api/common-inl.h", |
| 13 | + "js-native-api/entry_point.h", |
| 14 | + "js-native-api/2_function_arguments", |
| 15 | +]; |
| 16 | + |
| 17 | +console.log("Copying files to", TESTS_DIR); |
| 18 | + |
| 19 | +// Clean up the destination directory before copying |
| 20 | +// fs.rmSync(EXAMPLES_DIR, { recursive: true, force: true }); |
| 21 | + |
| 22 | +if (!fs.existsSync(NODE_REPO_DIR)) { |
| 23 | + console.log( |
| 24 | + "Sparse and shallow cloning Node.js repository to", |
| 25 | + NODE_REPO_DIR |
| 26 | + ); |
| 27 | + |
| 28 | + // Init a new git repository |
| 29 | + cp.execFileSync("git", ["init", NODE_REPO_DIR], { |
| 30 | + stdio: "inherit", |
| 31 | + }); |
| 32 | + // Set the remote origin to the Node.js repository |
| 33 | + cp.execFileSync("git", ["remote", "add", "origin", NODE_REPO_URL], { |
| 34 | + stdio: "inherit", |
| 35 | + cwd: NODE_REPO_DIR, |
| 36 | + }); |
| 37 | + // Enable sparse checkout |
| 38 | + cp.execFileSync("git", ["sparse-checkout", "set", "test/js-native-api"], { |
| 39 | + stdio: "inherit", |
| 40 | + cwd: NODE_REPO_DIR, |
| 41 | + }); |
| 42 | + // Pull the latest changes from the master branch |
| 43 | + console.log("Pulling latest changes from Node.js repository..."); |
| 44 | + cp.execFileSync("git", ["pull", "--depth=1", "origin", "main"], { |
| 45 | + stdio: "inherit", |
| 46 | + cwd: NODE_REPO_DIR, |
| 47 | + }); |
| 48 | +} |
| 49 | +const SRC_DIR = path.join(NODE_REPO_DIR, "test"); |
| 50 | +console.log("Copying files from", SRC_DIR); |
| 51 | + |
| 52 | +for (const src of ALLOW_LIST) { |
| 53 | + const srcPath = path.join(SRC_DIR, src); |
| 54 | + const destPath = path.join(TESTS_DIR, src); |
| 55 | + |
| 56 | + if (fs.existsSync(destPath)) { |
| 57 | + console.warn( |
| 58 | + `Destination path ${destPath} already exists - skipping copy of ${src}.` |
| 59 | + ); |
| 60 | + continue; |
| 61 | + } |
| 62 | + |
| 63 | + console.log("Copying from", srcPath, "to", destPath); |
| 64 | + fs.cpSync(srcPath, destPath, { recursive: true }); |
| 65 | +} |
0 commit comments