simplejsble 0.0.20 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplejsble",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "React Native Bluetooth Low Energy library using SimpleBLE with Nitro Modules",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -23,10 +23,12 @@
23
23
  "react-native.config.js",
24
24
  "nitro.json",
25
25
  "*.podspec",
26
+ "scripts/",
26
27
  "README.md"
27
28
  ],
28
29
  "scripts": {
29
30
  "prepack": "node scripts/prepare-package.js",
31
+ "postinstall": "node scripts/postinstall.js",
30
32
  "typecheck": "tsc --noEmit",
31
33
  "build": "tsc --composite false",
32
34
  "clean": "rm -rf android/build android/.cxx android/.gradle lib",
@@ -0,0 +1,138 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ // Find the project root by looking for package.json with react-native or react-native-macos
5
+ function findProjectRoot() {
6
+ let currentDir = process.cwd();
7
+ const maxDepth = 10;
8
+ let depth = 0;
9
+
10
+ while (depth < maxDepth) {
11
+ const packageJsonPath = path.join(currentDir, 'package.json');
12
+ if (fs.existsSync(packageJsonPath)) {
13
+ try {
14
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
15
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
16
+ if (deps['react-native-macos'] || deps['react-native']) {
17
+ return currentDir;
18
+ }
19
+ } catch (e) {
20
+ // Continue searching
21
+ }
22
+ }
23
+ const parentDir = path.dirname(currentDir);
24
+ if (parentDir === currentDir) break;
25
+ currentDir = parentDir;
26
+ depth++;
27
+ }
28
+
29
+ return null;
30
+ }
31
+
32
+ // Check if the fix already exists in Podfile
33
+ function hasFix(content) {
34
+ return content.includes('NativeNitroModules+NewArch.mm') &&
35
+ content.includes('EXCLUDED_SOURCE_FILE_NAMES');
36
+ }
37
+
38
+ // Add the fix to the Podfile
39
+ function addFixToPodfile(podfilePath) {
40
+ let content = fs.readFileSync(podfilePath, 'utf8');
41
+
42
+ if (hasFix(content)) {
43
+ console.log('✓ Podfile already has the NitroModules fix');
44
+ return;
45
+ }
46
+
47
+ // Find the post_install block
48
+ const postInstallRegex = /post_install\s+do\s+\|installer\|/;
49
+ const match = content.match(postInstallRegex);
50
+
51
+ if (!match) {
52
+ console.warn('⚠️ Could not find post_install block in Podfile. Please add the fix manually.');
53
+ return;
54
+ }
55
+
56
+ // Find the end of the post_install block
57
+ let insertPosition = match.index + match[0].length;
58
+ let braceCount = 0;
59
+ let inString = false;
60
+ let stringChar = null;
61
+
62
+ for (let i = insertPosition; i < content.length; i++) {
63
+ const char = content[i];
64
+ const prevChar = i > 0 ? content[i - 1] : '';
65
+
66
+ // Handle string literals
67
+ if (!inString && (char === '"' || char === "'")) {
68
+ inString = true;
69
+ stringChar = char;
70
+ } else if (inString && char === stringChar && prevChar !== '\\') {
71
+ inString = false;
72
+ stringChar = null;
73
+ }
74
+
75
+ if (!inString) {
76
+ if (char === '{') braceCount++;
77
+ if (char === '}') {
78
+ braceCount--;
79
+ if (braceCount < 0) {
80
+ insertPosition = i;
81
+ break;
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ // The fix code to insert
88
+ const fixCode = `
89
+
90
+ # Fix for NitroModules: Exclude New Architecture file when not enabled
91
+ installer.pods_project.targets.each do |target|
92
+ if target.name == 'NitroModules' && ENV['RCT_NEW_ARCH_ENABLED'] != '1'
93
+ # Exclude the file from build phase
94
+ target.source_build_phase.files.each do |file|
95
+ if file.file_ref && file.file_ref.path && file.file_ref.path.include?('NativeNitroModules+NewArch.mm')
96
+ file.settings = { 'COMPILER_FLAGS' => '-w' }
97
+ target.source_build_phase.remove_file_reference(file.file_ref) if file.file_ref
98
+ end
99
+ end
100
+
101
+ # Exclude using build settings
102
+ target.build_configurations.each do |config|
103
+ excluded_files = config.build_settings['EXCLUDED_SOURCE_FILE_NAMES'] || []
104
+ excluded_files << '**/NativeNitroModules+NewArch.mm'
105
+ config.build_settings['EXCLUDED_SOURCE_FILE_NAMES'] = excluded_files.uniq
106
+ end
107
+ end
108
+ end`;
109
+
110
+ // Insert the fix before the closing 'end'
111
+ const beforeEnd = content.substring(0, insertPosition);
112
+ const afterEnd = content.substring(insertPosition);
113
+
114
+ const newContent = beforeEnd + fixCode + afterEnd;
115
+
116
+ fs.writeFileSync(podfilePath, newContent, 'utf8');
117
+ console.log('✓ Added NitroModules fix to Podfile');
118
+ }
119
+
120
+ // Main execution
121
+ const projectRoot = findProjectRoot();
122
+
123
+ if (!projectRoot) {
124
+ console.log('⚠️ Could not find React Native project root. Skipping Podfile fix.');
125
+ process.exit(0);
126
+ }
127
+
128
+ // Check for macOS Podfile
129
+ const macosPodfile = path.join(projectRoot, 'macos', 'Podfile');
130
+ if (fs.existsSync(macosPodfile)) {
131
+ addFixToPodfile(macosPodfile);
132
+ }
133
+
134
+ // Check for iOS Podfile (in case they also use iOS)
135
+ const iosPodfile = path.join(projectRoot, 'ios', 'Podfile');
136
+ if (fs.existsSync(iosPodfile)) {
137
+ addFixToPodfile(iosPodfile);
138
+ }
@@ -0,0 +1,64 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const packageDir = path.resolve(__dirname, '..');
5
+ const repoRoot = path.resolve(packageDir, '../../..');
6
+
7
+ // Directories to clean before packing (native build artifacts only, not lib/)
8
+ const dirsToClean = [
9
+ 'android/build',
10
+ 'android/.cxx',
11
+ 'android/.gradle',
12
+ 'ios/build',
13
+ ];
14
+
15
+ // Directories/files to copy from repo root
16
+ const itemsToCopy = [
17
+ 'simpleble',
18
+ 'simpledroidbridge',
19
+ 'cmake',
20
+ 'dependencies',
21
+ 'VERSION',
22
+ ];
23
+
24
+ console.log('Preparing package for npm publish...');
25
+ console.log(`Package dir: ${packageDir}`);
26
+ console.log(`Repo root: ${repoRoot}`);
27
+
28
+ // Clean build artifacts first
29
+ console.log('\nCleaning build artifacts...');
30
+ dirsToClean.forEach((dir) => {
31
+ const dirPath = path.join(packageDir, dir);
32
+ if (fs.existsSync(dirPath)) {
33
+ fs.rmSync(dirPath, { recursive: true, force: true });
34
+ console.log(`✓ Cleaned: ${dir}`);
35
+ }
36
+ });
37
+ console.log('');
38
+
39
+ itemsToCopy.forEach((item) => {
40
+ const src = path.join(repoRoot, item);
41
+ const dest = path.join(packageDir, item);
42
+
43
+ if (!fs.existsSync(src)) {
44
+ console.warn(`Warning: ${src} does not exist, skipping...`);
45
+ return;
46
+ }
47
+
48
+ // Remove existing copy if it exists
49
+ if (fs.existsSync(dest)) {
50
+ fs.rmSync(dest, { recursive: true, force: true });
51
+ }
52
+
53
+ // Copy directory or file
54
+ const stat = fs.statSync(src);
55
+ if (stat.isDirectory()) {
56
+ fs.cpSync(src, dest, { recursive: true });
57
+ console.log(`✓ Copied directory: ${item}`);
58
+ } else {
59
+ fs.copyFileSync(src, dest);
60
+ console.log(`✓ Copied file: ${item}`);
61
+ }
62
+ });
63
+
64
+ console.log('Package preparation complete!');