2022-05-25 18:55:35 +00:00
|
|
|
const configPlugin = require('@expo/config-plugins');
|
|
|
|
|
const generateCode = require('@expo/config-plugins/build/utils/generateCode');
|
|
|
|
|
const pkg = require('onnxruntime-react-native/package.json');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
const withOrt = (config) => {
|
|
|
|
|
// Add build dependency to gradle file
|
|
|
|
|
config = configPlugin.withAppBuildGradle(config, (config) => {
|
|
|
|
|
if (config.modResults.language === 'groovy') {
|
2024-08-14 23:51:22 +00:00
|
|
|
config.modResults.contents = generateCode.mergeContents({
|
|
|
|
|
src: config.modResults.contents,
|
|
|
|
|
newSrc: " implementation project(':onnxruntime-react-native')",
|
|
|
|
|
tag: 'onnxruntime-react-native',
|
|
|
|
|
anchor: /^dependencies[ \t]*\{$/,
|
|
|
|
|
offset: 1,
|
|
|
|
|
comment: ' // onnxruntime-react-native',
|
|
|
|
|
}).contents;
|
2022-05-25 18:55:35 +00:00
|
|
|
} else {
|
|
|
|
|
throw new Error('Cannot add ONNX Runtime maven gradle because the build.gradle is not groovy');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add build dependency to pod file
|
|
|
|
|
config = configPlugin.withDangerousMod(config, [
|
|
|
|
|
'ios',
|
|
|
|
|
(config) => {
|
2023-12-19 00:20:46 +00:00
|
|
|
const podFilePath = path.join(config.modRequest.platformProjectRoot, 'Podfile');
|
2024-08-14 23:51:22 +00:00
|
|
|
const contents = fs.readFileSync(podFilePath, { encoding: 'utf-8' });
|
|
|
|
|
const updatedContents = generateCode.mergeContents({
|
|
|
|
|
src: contents,
|
|
|
|
|
newSrc: " pod 'onnxruntime-react-native', :path => '../node_modules/onnxruntime-react-native'",
|
|
|
|
|
tag: 'onnxruntime-react-native',
|
|
|
|
|
anchor: /^target.+do$/,
|
|
|
|
|
offset: 1,
|
|
|
|
|
comment: ' # onnxruntime-react-native',
|
|
|
|
|
}).contents;
|
2022-05-25 18:55:35 +00:00
|
|
|
fs.writeFileSync(podFilePath, updatedContents);
|
|
|
|
|
return config;
|
2024-08-14 23:51:22 +00:00
|
|
|
},
|
2022-05-25 18:55:35 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-14 23:51:22 +00:00
|
|
|
exports.default = configPlugin.createRunOncePlugin(withOrt, pkg.name, pkg.version);
|