Last active
July 6, 2018 08:33
-
-
Save ollieatkinson/b8b84a1de3e06946abb76eeeada73574 to your computer and use it in GitHub Desktop.
Generate public API for a swift module using sourcekitten
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
#!/bin/sh | |
cd $(dirname "$0") | |
# Extract the toolchain identifier | |
export TOOLCHAIN_IDENTIFIER=$(/usr/libexec/PlistBuddy -c "Print :Identifier" "$(printenv TOOLCHAIN_DIR)/ToolchainInfo.plist") | |
# Replace the {{KEY}} with the values from the environment variables | |
cat request_template.yml | perl -pe 's/\{\{(\w+)\}\}/$ENV{$1}/eg' > $PROJECT_DIR/request.yml | |
# Perform the sourcekitten request with the generated request yaml, extract the source | |
sourcekitten request --yaml $PROJECT_DIR/request.yml | jq -r '.["key.sourcetext"]' > $PROJECT_DIR/API.swift | |
rm $PROJECT_DIR/request.yml | |
echo "// swiftlint:disable all" | cat - $PROJECT_DIR/API.swift > $PROJECT_DIR/API.swift.orig && mv $PROJECT_DIR/API.swift.orig $PROJECT_DIR/API.swift | |
cd - |
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
key.request: source.request.editor.open.interface | |
key.name: "67107f27-4edd-4bc4-8072-fa27b6564a05" | |
key.compilerargs: | |
- "-target" | |
- "{{NATIVE_ARCH_ACTUAL}}-apple-{{SWIFT_PLATFORM_TARGET_PREFIX}}{{IPHONEOS_DEPLOYMENT_TARGET}}" | |
- "-sdk" | |
- "{{SDK_DIR}}" | |
- "-I" | |
- "{{CONFIGURATION_BUILD_DIR}}" | |
- "-F" | |
- "{{CONFIGURATION_BUILD_DIR}}" | |
- "-I" | |
- "{{CONFIGURATION_BUILD_DIR}}/include" | |
key.modulename: "{{PRODUCT_MODULE_NAME}}" | |
key.toolchains: | |
- "{{TOOLCHAIN_IDENTIFIER}}" | |
key.synthesizedextensions: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/jpsim/SourceKitten
https://github.com/stedolan/jq