Skip to content

Commit 143b8d7

Browse files
authored
refactor: remove fs-extra use core fs for lib SDK extraction
1 parent 96109b6 commit 143b8d7

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

package/scripts/movelib.js

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,66 @@
1-
const fs = require('fs-extra');
1+
const fs = require('fs');
22
const path = require('path');
3-
const fsNative = require('fs');
43

54
let dir = '../../react-native-esc-pos-printer-sdk';
65

7-
if (!fsNative.existsSync(path.join(__dirname, dir))) {
6+
if (!fs.existsSync(path.join(__dirname, dir))) {
87
dir = '../node_modules/react-native-esc-pos-printer-sdk';
98
}
109

1110
const libCurrentPath = path.join(__dirname, dir, 'ios');
12-
1311
const libDestPath = path.join(__dirname, '../ios/PrinterSDK');
1412

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-
2113
const libAndroidCurrentPath = path.join(__dirname, dir, 'android/libs');
22-
2314
const libAndroidDestPath = path.join(__dirname, '../android/libs');
2415

2516
const jnilibAndroidCurrentPath = path.join(__dirname, dir, 'android/jniLibs');
26-
2717
const jnilibAndroidDestPath = path.join(
2818
__dirname,
2919
'../android/src/main/jniLibs'
3020
);
3121

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);
3555
console.log('Android lib copied!');
36-
});
56+
} catch (err) {
57+
console.error(err);
58+
}
3759

38-
fs.copy(jnilibAndroidCurrentPath, jnilibAndroidDestPath, (err) => {
39-
if (err) return console.error(err);
60+
// Copy Android jniLibs
61+
try {
62+
copyDirSync(jnilibAndroidCurrentPath, jnilibAndroidDestPath);
4063
console.log('Android jniLibs copied!');
41-
});
64+
} catch (err) {
65+
console.error(err);
66+
}

0 commit comments

Comments
 (0)