|
1 | | -const fs = require('fs-extra'); |
| 1 | +const fs = require('fs'); |
2 | 2 | const path = require('path'); |
3 | | -const fsNative = require('fs'); |
4 | 3 |
|
5 | 4 | let dir = '../../react-native-esc-pos-printer-sdk'; |
6 | 5 |
|
7 | | -if (!fsNative.existsSync(path.join(__dirname, dir))) { |
| 6 | +if (!fs.existsSync(path.join(__dirname, dir))) { |
8 | 7 | dir = '../node_modules/react-native-esc-pos-printer-sdk'; |
9 | 8 | } |
10 | 9 |
|
11 | 10 | const libCurrentPath = path.join(__dirname, dir, 'ios'); |
12 | | - |
13 | 11 | const libDestPath = path.join(__dirname, '../ios/PrinterSDK'); |
14 | 12 |
|
15 | | -// copy iOS sdk |
16 | | -fs.copy(libCurrentPath, libDestPath, (err) => { |
17 | | - if (err) return console.error(err); |
18 | | - console.log('iOS SDK copied!'); |
19 | | -}); |
20 | | - |
21 | 13 | const libAndroidCurrentPath = path.join(__dirname, dir, 'android/libs'); |
22 | | - |
23 | 14 | const libAndroidDestPath = path.join(__dirname, '../android/libs'); |
24 | 15 |
|
25 | 16 | const jnilibAndroidCurrentPath = path.join(__dirname, dir, 'android/jniLibs'); |
26 | | - |
27 | 17 | const jnilibAndroidDestPath = path.join( |
28 | 18 | __dirname, |
29 | 19 | '../android/src/main/jniLibs' |
30 | 20 | ); |
31 | 21 |
|
32 | | -// copy Android sdk |
33 | | -fs.copy(libAndroidCurrentPath, libAndroidDestPath, (err) => { |
34 | | - if (err) return console.error(err); |
| 22 | +// Helper to recursively copy directory |
| 23 | +function copyDirSync(src, dest) { |
| 24 | + if (!fs.existsSync(src)) return; |
| 25 | + |
| 26 | + if (!fs.existsSync(dest)) { |
| 27 | + fs.mkdirSync(dest, { recursive: true }); |
| 28 | + } |
| 29 | + |
| 30 | + const entries = fs.readdirSync(src, { withFileTypes: true }); |
| 31 | + |
| 32 | + for (const entry of entries) { |
| 33 | + const srcPath = path.join(src, entry.name); |
| 34 | + const destPath = path.join(dest, entry.name); |
| 35 | + |
| 36 | + if (entry.isDirectory()) { |
| 37 | + copyDirSync(srcPath, destPath); |
| 38 | + } else { |
| 39 | + fs.copyFileSync(srcPath, destPath); |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// Copy iOS SDK |
| 45 | +try { |
| 46 | + copyDirSync(libCurrentPath, libDestPath); |
| 47 | + console.log('iOS SDK copied!'); |
| 48 | +} catch (err) { |
| 49 | + console.error(err); |
| 50 | +} |
| 51 | + |
| 52 | +// Copy Android libs |
| 53 | +try { |
| 54 | + copyDirSync(libAndroidCurrentPath, libAndroidDestPath); |
35 | 55 | console.log('Android lib copied!'); |
36 | | -}); |
| 56 | +} catch (err) { |
| 57 | + console.error(err); |
| 58 | +} |
37 | 59 |
|
38 | | -fs.copy(jnilibAndroidCurrentPath, jnilibAndroidDestPath, (err) => { |
39 | | - if (err) return console.error(err); |
| 60 | +// Copy Android jniLibs |
| 61 | +try { |
| 62 | + copyDirSync(jnilibAndroidCurrentPath, jnilibAndroidDestPath); |
40 | 63 | console.log('Android jniLibs copied!'); |
41 | | -}); |
| 64 | +} catch (err) { |
| 65 | + console.error(err); |
| 66 | +} |
0 commit comments