Files
NativeScript/tns-platform-declarations/typings-gen.sh
Martin Bektchiev 1c0218ea15 feat(tns-platform-declarations): Generate iOS typings from iOS 12.1 SDK (#6693)
* feat(tns-platform-declarations): Generate iOS typings from iOS 12.1 SDK

* Instructions for generating iOS typescript definitions
* Refactor `typings-gen.sh` to use {N} CLI and generate fuller
metadata for the system libraries
* Automatically generate `ios.d.ts` wrapper
* Add interop pointers and references as alternatives
to `string` for `char*` args
(implemented in https://github.com/NativeScript/ios-runtime/pull/1022)

BREAKING CHANGE: Several enum values have changed because
    they have been wrongly generated.

    To migrate your app or plugin code use the new names of the
    following:
    *  enum NSUnderlineStyle:
        - `StyleNone` -> `None`
        - `StyleSingle` -> `Single`
        - `StyleThick` -> `Thick`
        - `StyleDouble` -> `Double`
     * enum AVAudioSessionErrorCode:
        - `CodeNone` -> `None`
        - `CodeMediaServicesFailed` -> `MediaServicesFailed`
        - `CodeIsBusy` -> `IsBusy`
        - `CodeIncompatibleCategory` -> `IncompatibleCategory`
        - `CodeCannotInterruptOthers` -> `CannotInterruptOthers`
        - `CodeMissingEntitlement` -> `MissingEntitlement`
        - `CodeSiriIsRecording` -> `SiriIsRecording`
        - `CodeCannotStartPlaying` -> `CannotStartPlaying`
        - `CodeCannotStartRecording` -> `CannotStartRecording`
        - `CodeBadParam` -> `BadParam`
        - `CodeResourceNotAvailable` -> `ResourceNotAvailable`
        - `CodeUnspecified` -> `Unspecified`

* fix(ui/text-base): Update NSUnderlineStyle.StyleSingle constant

After the typings regeneration its and several others' names have
changed to the expected `NSUnderlineStyle.Single`.

* fix(tns-platform-declarations): Restore deprecated enum values

In order to not introduce a breaking change in a patch version, we
are keeping `Style...` and `Code...` values that have been wrongly
generated till now. In the next major/minor release of the package
when the typings are regenerated we can safely remove them.

Revert to using the deprecated one's in `text-base.ios.ts` so that
the introduction of this breaking change doesn't slip in undetected.

* fix(application.ios): Directly call presetnNativeScriptApp

We've been using `performSelectorWithObject` but it's
declaration has been manually added. Moreover it's more
convenient to directly call the method.
2018-12-13 17:04:13 +02:00

53 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e -o pipefail
IOS_RUNTIME_VERSION=$1
METADATA_GENERATOR_PATH=$2
if [ -z "$1" ]
then
printf "Usage:\n"
printf "./typings-gen.sh <tns-ios-npm-version> [<objc-metadata-generator-binary>]\n"
printf "\n\nExample:\n"
printf "./typings-gen.sh rc ~/work/ios-runtime/cmake-build/metadataGenerator/bin/objc-metadata-generator\n\n"
exit -1
fi
if [ -n "$METADATA_GENERATOR_PATH" -a ! -f "$METADATA_GENERATOR_PATH" ]
then
echo "error: Specified metadata generator binary \"$METADATA_GENERATOR_PATH\" does not exist!"
exit -2
fi
echo "Creating typings project with tns-ios@$IOS_RUNTIME_VERSION..."
rm -rf ios-typings-prj
tns create --js ios-typings-prj
tns platform add ios@$IOS_RUNTIME_VERSION --path ios-typings-prj/
if [ -n "$METADATA_GENERATOR_PATH" ]
then
echo "Replacing metadata generator binary with: $METADATA_GENERATOR_PATH"
rm ios-typings-prj/platforms/ios/internal/metadata-generator/bin/objc-metadata-generator
cp $METADATA_GENERATOR_PATH ios-typings-prj/platforms/ios/internal/metadata-generator/bin/objc-metadata-generator
fi
echo "Building project and generating typings..."
TNS_TYPESCRIPT_DECLARATIONS_PATH=$(pwd)/ios-typings-prj/typings tns build ios --debug --path ios-typings-prj/
echo "Deleting old ios typings (ios/objc-x86_64)..."
rm ios/objc-x86_64/*
echo "Moving generated typings to ios/objc-x86_64..."
mv ios-typings-prj/typings/x86_64/* ios/objc-x86_64/
echo "Emitting (ios/ios.d.ts)..."
pushd ios
echo '/// <reference path="interop.d.ts" />' > ios.d.ts
for i in `ls objc-x86_64/*.d.ts`; do
echo "/// <reference path=\"$i\" />" >> ios.d.ts
done
echo 'declare function __collect(): void;' >> ios.d.ts
popd