Skip to content

Commit 5e90bda

Browse files
authored
[MOB-9124] Migrate to TS (#163)
* Add tsconfig.json * Add types/cordova and typescript dev dependencies * Migrate ArgsRegistry to TS * Migrate BugReporting to TS * Migrate FeatureRequests to TS * Migrate Instabug module to TS * Migrate Replies to TS * Migrate Surveys to TS * Migrate Index to TS * Use ArgsRegistry for some enums on Android * Use ArgsRegistry for some enums on iOS * Ignore compiled JS files * Add types field * Add scripts field * Compile TS project in test jobs * Update index.ts syntax to work with Ionic * Use string literals for some enums * Update some tsconfig properties * Fix setString key type * Trigger IntelliSense in sample app * Add a wrapper function for cordova.exec * Make success and error callbacks optional * Update CHANGELOG.md * Exit CI steps if adding platform failed * Revert "Exit CI steps if adding platform failed" This reverts commit 43e9d36.
1 parent 014cd59 commit 5e90bda

28 files changed

+1291
-1234
lines changed

.circleci/config.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ orbs:
66
jobs:
77

88
test_android:
9-
working_directory: ~/project/example
9+
working_directory: ~/project
1010
executor:
1111
name: android/android-machine
1212
resource-class: xlarge
@@ -17,27 +17,36 @@ jobs:
1717
- run:
1818
name: Install Cordova CLI
1919
command: npm install -g cordova
20+
- run:
21+
name: Install Node Packages
22+
command: yarn
23+
- run:
24+
name: Compile TS Project
25+
command: yarn build
2026
- run:
2127
name: Install Android Platform
28+
working_directory: example
2229
command: cordova platform add android || true
2330
- run:
2431
name: Install Plugins
32+
working_directory: example
2533
command: cordova plugins add --link ../ tests
2634
- run:
2735
name: Install Build Tools v30.0.3
28-
command: sdkmanager "build-tools;30.0.3"
36+
working_directory: example
37+
command: sdkmanager "build-tools;30.0.3"
2938
- android/start-emulator-and-run-tests:
30-
run-tests-working-directory: platforms/android
39+
run-tests-working-directory: example/platforms/android
3140
system-image: system-images;android-30;google_apis;x86
3241
additional-avd-args: -d "Nexus 5"
33-
post-emulator-launch-assemble-command: cordova build android
42+
post-emulator-launch-assemble-command: cd example && cordova build android
3443
test-command: ./gradlew app:connectedAndroidTest
3544
- android/run-tests:
36-
working-directory: platforms/android
45+
working-directory: example/platforms/android
3746
test-command: ./gradlew test
3847

3948
test_ios:
40-
working_directory: ~/project/example
49+
working_directory: ~/project
4150
macos:
4251
xcode: 13.3.0
4352
steps:
@@ -46,18 +55,27 @@ jobs:
4655
- run:
4756
name: Install Cordova CLI
4857
command: npm install -g cordova
58+
- run:
59+
name: Install Node Packages
60+
command: yarn
61+
- run:
62+
name: Compile TS Project
63+
command: yarn build
4964
- run:
5065
name: Install iOS Platform
66+
working_directory: example
5167
command: cordova platform add ios || true
5268
- run:
5369
name: Install Plugins
70+
working_directory: example
5471
command: cordova plugins add --link ../ tests
5572
- run:
5673
name: Build iOS App
74+
working_directory: example
5775
command: cordova build ios
5876
- run:
5977
name: Run Tests
60-
working_directory: platforms/ios
78+
working_directory: example/platforms/ios
6179
command: |
6280
xcodebuild -allowProvisioningUpdates \
6381
-workspace InstabugExample.xcworkspace \

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99

1010
local.properties
1111
node_modules/
12+
www/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
3+
* Adds TypeScript support
4+
15
## v11.0.1 (2022-08-24)
26

37
* Fixes ArgsRegistry import on iOS

example/www/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
document.addEventListener("deviceready", onDeviceReady, false);
22

33
function onDeviceReady() {
4+
/** @type {import('instabug-cordova/www/Instabug')} */
45
var Instabug = cordova.require("instabug-cordova.Instabug");
6+
/** @type {import('instabug-cordova/www/BugReporting')} */
57
var BugReporting = cordova.require("instabug-cordova.BugReporting");
68

79
console.log("Running cordova-" + cordova.platformId + "@" + cordova.version);

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"bugs": "https://github.com/Instabug/Instabug-Cordova/issues",
99
"license": "Apache 2.0 License",
1010
"main": "www/index.js",
11+
"types": "www/index.d.ts",
1112
"keywords": [
1213
"ecosystem:cordova",
1314
"cordova",
@@ -18,5 +19,13 @@
1819
"errors",
1920
"exceptions",
2021
"logging"
21-
]
22+
],
23+
"scripts": {
24+
"build": "tsc",
25+
"prepack": "yarn build"
26+
},
27+
"devDependencies": {
28+
"@types/cordova": "^0.0.34",
29+
"typescript": "^4.8.2"
30+
}
2231
}

plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
<!-- js -->
2424
<js-module src="www/ArgsRegistry.js" />
25+
<js-module src="www/IBGCordova.js" />
2526
<js-module src="www/Instabug.js" name="Instabug">
2627
<clobbers target="InstabugLib.Instabug" />
2728
</js-module>

src/android/IBGPlugin.java

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,15 +1056,10 @@ public void setSessionProfilerEnabled(final CallbackContext callbackContext, JSO
10561056
* visual or disabled.
10571057
*/
10581058
public void setReproStepsMode(final CallbackContext callbackContext, JSONArray args) {
1059-
String reproStepsMode = args.optString(0);
10601059
try {
1061-
if (reproStepsMode.equals("enabledWithNoScreenshots")) {
1062-
Instabug.setReproStepsState(State.ENABLED_WITH_NO_SCREENSHOTS);
1063-
} else if (reproStepsMode.equals("enabled")) {
1064-
Instabug.setReproStepsState(State.ENABLED);
1065-
} else if (reproStepsMode.equals("disabled")) {
1066-
Instabug.setReproStepsState(State.DISABLED);
1067-
}
1060+
final String reproStepsMode = args.optString(0);
1061+
final State parsedMode = ArgsRegistry.reproStepsModes.get(reproStepsMode);
1062+
Instabug.setReproStepsState(parsedMode);
10681063
callbackContext.success();
10691064
} catch (IllegalStateException e) {
10701065
callbackContext.error(errorMsg);
@@ -1153,10 +1148,10 @@ public void setShouldShowSurveysWelcomeScreen(final CallbackContext callbackCont
11531148
* @param callbackContext Used when calling back into JavaScript
11541149
*/
11551150
public void setLocale(final CallbackContext callbackContext, JSONArray args) {
1156-
String locale = args.optString(0);
11571151
try {
1158-
InstabugLocale instabugLocale = parseLocale(locale);
1159-
Instabug.setLocale(new Locale(instabugLocale.getCode(), instabugLocale.getCountry()));
1152+
final String locale = args.optString(0);
1153+
final InstabugLocale parsedLocale = ArgsRegistry.locales.get(locale);
1154+
Instabug.setLocale(new Locale(parsedLocale.getCode(), parsedLocale.getCountry()));
11601155
callbackContext.success();
11611156
} catch (IllegalStateException e) {
11621157
callbackContext.error(errorMsg);
@@ -1201,52 +1196,6 @@ public static int parseInvocationOption(String invocationOption) {
12011196
} else return -1;
12021197
}
12031198

1204-
/**
1205-
* Convenience method for converting string to Locale.
1206-
*
1207-
* @param locale
1208-
* String shortcode for locale
1209-
*/
1210-
public static InstabugLocale parseLocale(String locale) {
1211-
if ("arabic".equals(locale)) {
1212-
return InstabugLocale.ARABIC;
1213-
} else if ("azerbaijani".equals(locale)) {
1214-
return InstabugLocale.AZERBAIJANI;
1215-
} else if ("chineseSimplified".equals(locale)) {
1216-
return InstabugLocale.SIMPLIFIED_CHINESE;
1217-
} else if ("chineseTraditional".equals(locale)) {
1218-
return InstabugLocale.TRADITIONAL_CHINESE;
1219-
} else if ("danish".equals(locale)) {
1220-
return InstabugLocale.DANISH;
1221-
} else if ("english".equals(locale)) {
1222-
return InstabugLocale.ENGLISH;
1223-
} else if ("french".equals(locale)) {
1224-
return InstabugLocale.FRENCH;
1225-
} else if ("german".equals(locale)) {
1226-
return InstabugLocale.GERMAN;
1227-
} else if ("italian".equals(locale)) {
1228-
return InstabugLocale.ITALIAN;
1229-
} else if ("japanese".equals(locale)) {
1230-
return InstabugLocale.JAPANESE;
1231-
} else if ("korean".equals(locale)) {
1232-
return InstabugLocale.KOREAN;
1233-
} else if ("polish".equals(locale)) {
1234-
return InstabugLocale.POLISH;
1235-
} else if ("portugueseBrazil".equals(locale)) {
1236-
return InstabugLocale.PORTUGUESE_BRAZIL;
1237-
} else if ("russian".equals(locale)) {
1238-
return InstabugLocale.RUSSIAN;
1239-
} else if ("spanish".equals(locale)) {
1240-
return InstabugLocale.SPANISH;
1241-
} else if ("swedish".equals(locale)) {
1242-
return InstabugLocale.SWEDISH;
1243-
} else if ("turkish".equals(locale)) {
1244-
return InstabugLocale.TURKISH;
1245-
} else if ("czech".equals(locale)) {
1246-
return InstabugLocale.CZECH;
1247-
} else return InstabugLocale.ENGLISH;
1248-
}
1249-
12501199
/**
12511200
* Convenience method for converting string to InvocationOption.
12521201
*

src/android/util/ArgsRegistry.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.instabug.library.invocation.util.InstabugFloatingButtonEdge;
88
import com.instabug.library.invocation.util.InstabugVideoRecordingButtonPosition;
99
import com.instabug.library.ui.onboarding.WelcomeMessage;
10+
import com.instabug.library.visualusersteps.State;
11+
import com.instabug.library.internal.module.InstabugLocale;
1012

1113
import java.util.ArrayList;
1214
import java.util.HashMap;
@@ -111,4 +113,32 @@ public ArrayList<T> getAll(ArrayList<String> keys) {
111113
put("reproStepsListEmptyStateDescription", Key.REPRO_STEPS_LIST_EMPTY_STATE_DESCRIPTION);
112114
put("reproStepsListItemTitle", Key.REPRO_STEPS_LIST_ITEM_NUMBERING_TITLE);
113115
}};
116+
117+
public static final ArgsMap<State> reproStepsModes = new ArgsMap<State>() {{
118+
put("enabled", State.ENABLED);
119+
put("disabled", State.DISABLED);
120+
put("enabledWithNoScreenshots", State.ENABLED_WITH_NO_SCREENSHOTS);
121+
}};
122+
123+
public static final ArgsMap<InstabugLocale> locales = new ArgsMap<InstabugLocale>() {{
124+
put("arabic", InstabugLocale.ARABIC);
125+
put("azerbaijani", InstabugLocale.AZERBAIJANI);
126+
put("chineseSimplified", InstabugLocale.SIMPLIFIED_CHINESE);
127+
put("chineseTraditional", InstabugLocale.TRADITIONAL_CHINESE);
128+
put("danish", InstabugLocale.DANISH);
129+
put("dutch", InstabugLocale.NETHERLANDS);
130+
put("english", InstabugLocale.ENGLISH);
131+
put("french", InstabugLocale.FRENCH);
132+
put("german", InstabugLocale.GERMAN);
133+
put("italian", InstabugLocale.ITALIAN);
134+
put("japanese", InstabugLocale.JAPANESE);
135+
put("korean", InstabugLocale.KOREAN);
136+
put("polish", InstabugLocale.POLISH);
137+
put("portugueseBrazil", InstabugLocale.PORTUGUESE_BRAZIL);
138+
put("russian", InstabugLocale.RUSSIAN);
139+
put("spanish", InstabugLocale.SPANISH);
140+
put("swedish", InstabugLocale.SWEDISH);
141+
put("turkish", InstabugLocale.TURKISH);
142+
put("czech", InstabugLocale.CZECH);
143+
}};
114144
}

0 commit comments

Comments
 (0)