diff --git a/package.json b/package.json index 2cbb525..6c0dd83 100644 --- a/package.json +++ b/package.json @@ -1,162 +1,162 @@ -{ - "name": "react-native-vosk", - "version": "2.1.2", - "description": "Speech recognition module for react native using Vosk library", - "types": "lib/typescript/src/index.d.ts", - "main": "lib/commonjs/index.js", - "module": "lib/module/index.js", - "react-native": "src/index.ts", - "files": [ - "src", - "lib", - "android", - "ios", - "plugin/build", - "cpp", - "app.plugin.js", - "*.podspec", - "react-native.config.js", - "!ios/build", - "!android/build", - "!android/gradle", - "!android/gradlew", - "!android/gradlew.bat", - "!android/local.properties", - "!**/__tests__", - "!**/__fixtures__", - "!**/__mocks__", - "!**/.*" - ], - "scripts": { - "example": "yarn workspace react-native-vosk-example", - "test": "jest", - "typecheck": "tsc", - "lint": "eslint \"**/*.{js,ts,tsx}\"", - "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib", - "prepare": "bob build && tsc --project plugin/tsconfig.json", - "release": "release-it" - }, - "keywords": [ - "react-native", - "ios", - "android", - "vosk", - "speech-to-text", - "speech-recognition", - "asr", - "offline" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/riderodd/react-native-vosk.git" - }, - "author": "riderodd (https://github.com/riderodd)", - "license": "MIT", - "bugs": { - "url": "https://github.com/riderodd/react-native-vosk/issues" - }, - "homepage": "https://github.com/riderodd/react-native-vosk#readme", - "publishConfig": { - "registry": "https://registry.npmjs.org/" - }, - "devDependencies": { - "@commitlint/config-conventional": "^19.8.1", - "@eslint/compat": "^1.3.2", - "@eslint/eslintrc": "^3.3.1", - "@eslint/js": "^9.35.0", - "@evilmartians/lefthook": "^1.12.3", - "@expo/config-plugins": "^54.0.1", - "@react-native-community/cli": "20.0.1", - "@react-native/babel-preset": "0.81.1", - "@react-native/eslint-config": "^0.81.1", - "@release-it/conventional-changelog": "^10.0.1", - "@types/jest": "^29.5.14", - "@types/react": "^19.1.0", - "commitlint": "^19.8.1", - "del-cli": "^6.0.0", - "eslint": "^9.35.0", - "eslint-config-prettier": "^10.1.8", - "eslint-plugin-jest": "^29.0.1", - "eslint-plugin-prettier": "^5.5.4", - "expo-module-scripts": "^5.0.7", - "jest": "^29.7.0", - "prettier": "^3.6.2", - "react": "19.1.0", - "react-native": "0.81.1", - "react-native-builder-bob": "^0.40.13", - "release-it": "^19.0.4", - "turbo": "^2.5.6", - "typescript": "^5.9.2" - }, - "peerDependencies": { - "react": "*", - "react-native": "*" - }, - "workspaces": [ - "example" - ], - "packageManager": "yarn@3.8.7+sha512.bbe7e310ff7fd20dc63b111110f96fe18192234bb0d4f10441fa6b85d2b644c8923db8fbe6d7886257ace948440ab1f83325ad02af457a1806cdc97f03d2508e", - "engines": { - "node": ">= 18.0.0" - }, - "jest": { - "preset": "react-native", - "modulePathIgnorePatterns": [ - "/example/node_modules", - "/lib/" - ] - }, - "commitlint": { - "extends": [ - "@commitlint/config-conventional" - ] - }, - "release-it": { - "git": { - "commitMessage": "chore: release ${version}", - "tagName": "v${version}" - }, - "npm": { - "publish": false - }, - "github": { - "release": true - }, - "plugins": { - "@release-it/conventional-changelog": { - "preset": { - "name": "angular" - } - } - } - }, - "prettier": { - "quoteProps": "consistent", - "singleQuote": true, - "tabWidth": 2, - "trailingComma": "es5", - "useTabs": false - }, - "react-native-builder-bob": { - "source": "src", - "output": "lib", - "targets": [ - "module", - "commonjs", - "typescript" - ] - }, - "codegenConfig": { - "name": "VoskSpec", - "type": "modules", - "jsSrcsDir": "src", - "android": { - "javaPackageName": "com.vosk" - } - }, - "create-react-native-library": { - "languages": "kotlin-objc", - "type": "turbo-module", - "version": "0.54.2" - } -} +{ + "name": "react-native-vosk", + "version": "2.1.3", + "description": "Speech recognition module for react native using Vosk library", + "types": "lib/typescript/src/index.d.ts", + "main": "lib/commonjs/index.js", + "module": "lib/module/index.js", + "react-native": "src/index.ts", + "files": [ + "src", + "lib", + "android", + "ios", + "plugin/build", + "cpp", + "app.plugin.js", + "*.podspec", + "react-native.config.js", + "!ios/build", + "!android/build", + "!android/gradle", + "!android/gradlew", + "!android/gradlew.bat", + "!android/local.properties", + "!**/__tests__", + "!**/__fixtures__", + "!**/__mocks__", + "!**/.*" + ], + "scripts": { + "example": "yarn workspace react-native-vosk-example", + "test": "jest", + "typecheck": "tsc", + "lint": "eslint \"**/*.{js,ts,tsx}\"", + "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib", + "prepare": "bob build && tsc --project plugin/tsconfig.json", + "release": "release-it" + }, + "keywords": [ + "react-native", + "ios", + "android", + "vosk", + "speech-to-text", + "speech-recognition", + "asr", + "offline" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/riderodd/react-native-vosk.git" + }, + "author": "riderodd (https://github.com/riderodd)", + "license": "MIT", + "bugs": { + "url": "https://github.com/riderodd/react-native-vosk/issues" + }, + "homepage": "https://github.com/riderodd/react-native-vosk#readme", + "publishConfig": { + "registry": "https://registry.npmjs.org/" + }, + "devDependencies": { + "@commitlint/config-conventional": "^19.8.1", + "@eslint/compat": "^1.3.2", + "@eslint/eslintrc": "^3.3.1", + "@eslint/js": "^9.35.0", + "@evilmartians/lefthook": "^1.12.3", + "@expo/config-plugins": "^54.0.1", + "@react-native-community/cli": "20.0.1", + "@react-native/babel-preset": "0.81.1", + "@react-native/eslint-config": "^0.81.1", + "@release-it/conventional-changelog": "^10.0.1", + "@types/jest": "^29.5.14", + "@types/react": "^19.1.0", + "commitlint": "^19.8.1", + "del-cli": "^6.0.0", + "eslint": "^9.35.0", + "eslint-config-prettier": "^10.1.8", + "eslint-plugin-jest": "^29.0.1", + "eslint-plugin-prettier": "^5.5.4", + "expo-module-scripts": "^5.0.7", + "jest": "^29.7.0", + "prettier": "^3.6.2", + "react": "19.1.0", + "react-native": "0.81.1", + "react-native-builder-bob": "^0.40.13", + "release-it": "^19.0.4", + "turbo": "^2.5.6", + "typescript": "^5.9.2" + }, + "peerDependencies": { + "react": "*", + "react-native": "*" + }, + "workspaces": [ + "example" + ], + "packageManager": "yarn@3.8.7+sha512.bbe7e310ff7fd20dc63b111110f96fe18192234bb0d4f10441fa6b85d2b644c8923db8fbe6d7886257ace948440ab1f83325ad02af457a1806cdc97f03d2508e", + "engines": { + "node": ">= 18.0.0" + }, + "jest": { + "preset": "react-native", + "modulePathIgnorePatterns": [ + "/example/node_modules", + "/lib/" + ] + }, + "commitlint": { + "extends": [ + "@commitlint/config-conventional" + ] + }, + "release-it": { + "git": { + "commitMessage": "chore: release ${version}", + "tagName": "v${version}" + }, + "npm": { + "publish": false + }, + "github": { + "release": true + }, + "plugins": { + "@release-it/conventional-changelog": { + "preset": { + "name": "angular" + } + } + } + }, + "prettier": { + "quoteProps": "consistent", + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false + }, + "react-native-builder-bob": { + "source": "src", + "output": "lib", + "targets": [ + "module", + "commonjs", + "typescript" + ] + }, + "codegenConfig": { + "name": "VoskSpec", + "type": "modules", + "jsSrcsDir": "src", + "android": { + "javaPackageName": "com.vosk" + } + }, + "create-react-native-library": { + "languages": "kotlin-objc", + "type": "turbo-module", + "version": "0.54.2" + } +} diff --git a/plugin/src/withVosk.ts b/plugin/src/withVosk.ts index bd6124a..0d277e1 100644 --- a/plugin/src/withVosk.ts +++ b/plugin/src/withVosk.ts @@ -4,6 +4,7 @@ import { withXcodeProject, withGradleProperties, createRunOncePlugin, + IOSConfig, } from '@expo/config-plugins'; import fs from 'fs'; import path from 'path'; @@ -30,32 +31,24 @@ const withVosk: ConfigPlugin = (config, props) => { if (models.length) { withXcodeProject(config, (configMod) => { const project = configMod.modResults; - const iosRoot = configMod.modRequest.platformProjectRoot; // /ios + const iosRoot = configMod.modRequest.projectRoot; // /ios + IOSConfig.XcodeUtils.ensureGroupRecursively(project, 'Resources'); models.forEach((relModelPath: string) => { - const absSource = path.join( - configMod.modRequest.projectRoot, - relModelPath - ); + const absSource = path.relative(iosRoot, relModelPath); if (!fs.existsSync(absSource)) { console.warn( '[react-native-vosk] iOS model path not found: ' + absSource ); return; } - const modelFolderName = path.basename(absSource); - // Destination inside ios folder (copy folder to keep it under version control if needed) - const destFolder = path.join(iosRoot, modelFolderName); - if (!fs.existsSync(destFolder)) { - fs.cpSync(absSource, destFolder, { recursive: true }); - } - - // Add to Xcode project if not already - const projectRelative = modelFolderName; - const fileRef = project.hasFile(projectRelative); - if (!fileRef) { - project.addResourceFile(projectRelative, { variantGroup: false }); - } + IOSConfig.XcodeUtils.addResourceFileToGroup({ + filepath: absSource, + groupName: 'Resources', + project, + isBuildFile: true, + verbose: true, + }); }); return configMod;