|
| 1 | +#!/usr/bin/env node |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +const fs = require("fs"); |
| 5 | +const path = require("path"); |
| 6 | + |
| 7 | +function copyDir(src, dest) { |
| 8 | + if (!fs.existsSync(src)) return; |
| 9 | + fs.mkdirSync(dest, { recursive: true }); |
| 10 | + for (const entry of fs.readdirSync(src)) { |
| 11 | + const srcPath = path.join(src, entry); |
| 12 | + const destPath = path.join(dest, entry); |
| 13 | + const stat = fs.statSync(srcPath); |
| 14 | + if (stat.isDirectory()) { |
| 15 | + copyDir(srcPath, destPath); |
| 16 | + } else { |
| 17 | + fs.copyFileSync(srcPath, destPath); |
| 18 | + } |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +function main() { |
| 23 | + const projectRoot = process.cwd(); |
| 24 | + const iosPath = path.join(projectRoot, "platforms", "ios"); |
| 25 | + if (!fs.existsSync(iosPath)) { |
| 26 | + console.log("iSH rootfs hook: no iOS platform found, skipping."); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + const appDir = fs.readdirSync(iosPath).find((name) => name.endsWith(".xcodeproj")); |
| 31 | + if (!appDir) { |
| 32 | + console.log("iSH rootfs hook: no Xcode project found, skipping."); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + const appName = appDir.replace(/\.xcodeproj$/, ""); |
| 37 | + const srcRootfs = path.join(projectRoot, "src", "ios", "ish-rootfs"); |
| 38 | + const destRootfs = path.join(iosPath, appName, "ish-rootfs"); |
| 39 | + |
| 40 | + if (!fs.existsSync(srcRootfs)) { |
| 41 | + console.log("iSH rootfs hook: src/ios/ish-rootfs not found, skipping."); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + copyDir(srcRootfs, destRootfs); |
| 46 | + console.log("iSH rootfs hook: copied rootfs to", destRootfs); |
| 47 | +} |
| 48 | + |
| 49 | +main(); |
0 commit comments