Last active
February 4, 2025 17:08
-
-
Save sgup/c12ea5bfaf9a3ae83dff9012741c2b77 to your computer and use it in GitHub Desktop.
Expo plugin for OP-SQLite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
withPodfileProperties, | |
withDangerousMod, | |
} = require("@expo/config-plugins"); | |
const fs = require("fs"); | |
const path = require("path"); | |
async function readFileAsync(path) { | |
return fs.promises.readFile(path, "utf8"); | |
} | |
async function saveFileAsync(path, content) { | |
return fs.promises.writeFile(path, content, "utf8"); | |
} | |
const withOpSqliteMods = (c) => { | |
c = withStaticPreinstall(c); | |
c = withUseThirdPartySQLitePod(c); | |
return c; | |
}; | |
const withUseThirdPartySQLitePod = (expoConfig) => { | |
return withPodfileProperties(expoConfig, (config) => { | |
config.modResults = { | |
...config.modResults, | |
"expo.updates.useThirdPartySQLitePod": "true", | |
}; | |
return config; | |
}); | |
}; | |
const withStaticPreinstall = (c) => { | |
return withDangerousMod(c, [ | |
"ios", | |
async (config) => { | |
const podfilePath = path.join( | |
config.modRequest.platformProjectRoot, | |
"Podfile", | |
); | |
const podfileContent = await readFileAsync(podfilePath); | |
// Add pre_install hook: | |
const preInstallHook = ` | |
pre_install do |installer| | |
installer.pod_targets.each do |pod| | |
if pod.name.eql?('op-sqlite') | |
def pod.build_type | |
Pod::BuildType.static_library | |
end | |
end | |
end | |
end`; | |
if (!podfileContent.includes("pre_install")) { | |
const updatedContent = podfileContent.replace( | |
/(\n\s*end\s*)$/, | |
`${preInstallHook}\n$1`, | |
); | |
await saveFileAsync(podfilePath, updatedContent); | |
} | |
return config; | |
}, | |
]); | |
}; | |
module.exports = (config) => withOpSqliteMods(config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage in app.config.ts: