@mentra/bluetooth-sdk 0.1.16 → 0.1.17

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.
@@ -3,45 +3,19 @@ import Foundation
3
3
  /// Defaults for the public Bluetooth SDK surface.
4
4
  enum BluetoothSdkDefaults {
5
5
  static var sdkVersion: String? {
6
- #if SWIFT_PACKAGE
7
- normalizedSdkVersion(swiftPackageSdkVersion)
8
- #else
9
- packageVersion(from: sdkBundle)
10
- #endif
6
+ normalizedSdkVersion(swiftPackageSdkVersion)
11
7
  }
12
8
 
13
9
  static let voiceActivityDetectionEnabled = false
14
- private static let swiftPackageSdkVersion = "__MENTRA_BLUETOOTH_SDK_VERSION__"
10
+ private static let swiftPackageSdkVersion = "0.1.17"
15
11
  private static let swiftPackageSdkVersionPlaceholder = "__MENTRA" + "_BLUETOOTH_SDK_VERSION__"
16
12
 
17
- private static var sdkBundle: Bundle {
18
- #if SWIFT_PACKAGE
19
- Bundle.module
20
- #else
21
- Bundle(for: BluetoothSdkBundleToken.self)
22
- #endif
23
- }
24
-
25
- private static func packageVersion(from bundle: Bundle) -> String? {
26
- let version = bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
27
- let build = bundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String
28
-
29
- for candidate in [version, build] {
30
- if let sdkVersion = normalizedSdkVersion(candidate) {
31
- return sdkVersion
32
- }
33
- }
34
-
35
- return nil
36
- }
37
-
38
13
  private static func normalizedSdkVersion(_ value: String?) -> String? {
39
14
  guard let value else {
40
15
  return nil
41
16
  }
42
17
  let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
43
18
  guard !trimmed.isEmpty,
44
- trimmed != "1.0",
45
19
  trimmed != swiftPackageSdkVersionPlaceholder
46
20
  else {
47
21
  return nil
@@ -49,5 +23,3 @@ enum BluetoothSdkDefaults {
49
23
  return trimmed
50
24
  }
51
25
  }
52
-
53
- private final class BluetoothSdkBundleToken {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mentra/bluetooth-sdk",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "SDK for communicating with smart glasses",
5
5
  "main": "build/index.js",
6
6
  "react-native": "src/index.ts",
@@ -59,6 +59,7 @@
59
59
  "!ios/Pods/**",
60
60
  "plugin/build",
61
61
  "README.md",
62
+ "scripts",
62
63
  "src",
63
64
  "!src/__tests__"
64
65
  ],
@@ -68,6 +69,8 @@
68
69
  "clean": "expo-module clean",
69
70
  "test": "expo-module test",
70
71
  "prepare": "expo-module prepare",
72
+ "prepack": "node scripts/inject-ios-sdk-version.mjs",
73
+ "postpack": "node scripts/inject-ios-sdk-version.mjs --restore",
71
74
  "prepublishOnly": "expo-module prepublishOnly",
72
75
  "lint": "expo-module lint",
73
76
  "expo-module": "expo-module",
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs/promises"
4
+ import path from "node:path"
5
+ import { fileURLToPath } from "node:url"
6
+
7
+ const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
8
+ const packageJsonPath = path.join(packageRoot, "package.json")
9
+ const sourcePath = path.join(packageRoot, "ios/Source/BluetoothSdkDefaults.swift")
10
+ const backupPath = path.join(packageRoot, ".bluetooth-sdk-version-prepack-backup")
11
+ const restore = process.argv.includes("--restore")
12
+
13
+ const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"))
14
+ const version = packageJson.version
15
+
16
+ if (typeof version !== "string" || version.trim() === "") {
17
+ throw new Error("mobile/modules/bluetooth-sdk/package.json is missing a version")
18
+ }
19
+
20
+ const placeholder = 'private static let swiftPackageSdkVersion = "__MENTRA_BLUETOOTH_SDK_VERSION__"'
21
+ const injectedVersion = `private static let swiftPackageSdkVersion = "${version}"`
22
+
23
+ async function pathExists(filePath) {
24
+ try {
25
+ await fs.access(filePath)
26
+ return true
27
+ } catch {
28
+ return false
29
+ }
30
+ }
31
+
32
+ if (restore) {
33
+ if (!(await pathExists(backupPath))) {
34
+ console.log("No iOS SDK version prepack backup found; nothing to restore.")
35
+ process.exit(0)
36
+ }
37
+
38
+ await fs.writeFile(sourcePath, await fs.readFile(backupPath, "utf8"))
39
+ await fs.rm(backupPath)
40
+ console.log("Restored placeholder iOS SDK version after packing.")
41
+ process.exit(0)
42
+ }
43
+
44
+ if (await pathExists(backupPath)) {
45
+ throw new Error("Found an existing iOS SDK version prepack backup. Run `npm run postpack` before packing again.")
46
+ }
47
+
48
+ const originalSource = await fs.readFile(sourcePath, "utf8")
49
+ let packedSource
50
+
51
+ if (originalSource.includes(placeholder)) {
52
+ packedSource = originalSource.replace(placeholder, injectedVersion)
53
+ } else if (originalSource.includes(injectedVersion)) {
54
+ packedSource = originalSource
55
+ } else {
56
+ throw new Error("BluetoothSdkDefaults.swift does not contain the expected SDK version placeholder.")
57
+ }
58
+
59
+ await fs.writeFile(backupPath, originalSource)
60
+
61
+ if (packedSource !== originalSource) {
62
+ await fs.writeFile(sourcePath, packedSource)
63
+ }
64
+
65
+ console.log(`Injected iOS SDK version ${version} for npm packaging.`)