UNPKG

smartech-base-expo-plugin

Version:

Smartech Base Expo SDK's React Native Plugin For React Native Projects.

121 lines (119 loc) 6.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AutoFetchLocationKey = exports.dependencyRegex = exports.smartechHanselEncryptionKey = exports.dependency = exports.smartechInitSnippetJava = exports.smartechInitSnippetKotlin = exports.smartechTestDeviceSnippet = exports.hanselTestDeviceUpdatedSnippet = exports.hanselTestDeviceSnippet = exports.smartechInitSnippet = exports.appBuildGradlePath = exports.repositorySnippet = void 0; exports.repositorySnippet = `repositories { maven { url 'https://artifacts.netcore.co.in/artifactory/android' } }`; exports.appBuildGradlePath = './android/app/build.gradle'; exports.smartechInitSnippet = { importStatementJava: `import com.netcore.android.Smartech;\nimport java.lang.ref.WeakReference;\nimport com.netcore.android.logger.SMTDebugLevel;\nimport com.smartechbasereactnative.SmartechBasePlugin;`, importStatementKotlin: `import com.netcore.android.Smartech\nimport java.lang.ref.WeakReference\nimport com.netcore.android.logger.SMTDebugLevel\nimport com.smartechbasereactnative.SmartechBasePlugin`, onCreateMethodRegexKotlin: /override\s+fun\s+onCreate\(\)\s*\{[^]*?}/g, onCreateMethodRegexJava: /@Override\s+public\s+void\s+onCreate\(\)\s*\{[^]*?}/g, newArchConditionRegexKotlin: /if\s*\(\s*BuildConfig\.IS_NEW_ARCHITECTURE_ENABLED\s*\)\s*\{[^]*?\n/g, newArchConditionRegexJava: /if\s*\(\s*BuildConfig\.IS_NEW_ARCHITECTURE_ENABLED\s*\)\s*\{\s*[^]*?\n/g, newArchCheckRegex: /if\s*\(BuildConfig\.IS_NEW_ARCHITECTURE_ENABLED\)\s*\{([\s\S]*?)\}/, superOnCreatePatternKotlin: 'super.onCreate()', superOnCreatePatternJava: 'super.onCreate();', // Function to conditionally create the import statement createImportStatementJava: function (props) { let imports = this.importStatementJava; // Conditionally add logging import let nudges = props.android.smartechNudges; if (nudges.smartechNudgesEnabled && nudges.isLogEnabled) { imports += `\nimport io.hansel.hanselsdk.Hansel;\n`; } return imports; }, createImportStatementKotlin: function (props) { let imports = this.importStatementKotlin; // Conditionally add logging import let nudges = props.android.smartechNudges; if (nudges.smartechNudgesEnabled && nudges.isLogEnabled) { imports += `\nimport io.hansel.hanselsdk.Hansel\n`; } return imports; } }; const hanselTestDeviceSnippet = (iskotlin) => { return { importStatement: iskotlin ? `import io.hansel.hanselsdk.Hansel` : `import io.hansel.hanselsdk.Hansel;`, testDeviceCode: iskotlin ? `Hansel.pairTestDevice(intent.dataString)` : `Hansel.pairTestDevice(getIntent().getDataString());`, superOnCreate: `super.onCreate` }; }; exports.hanselTestDeviceSnippet = hanselTestDeviceSnippet; const SDK_CONFIG = { hansel: { packageName: 'import io.hansel.hanselsdk.Hansel', kotlin: { testDeviceCode: `Hansel.pairTestDevice(intent.dataString)` }, java: { testDeviceCode: `Hansel.pairTestDevice(getIntent().getDataString());` } }, smartech: { packageName: `import com.netcore.android.Smartech\nimport android.content.Intent\nimport java.lang.ref.WeakReference`, kotlin: { testDeviceCode: ` val isSmartechHandledDeeplink = Smartech.getInstance(WeakReference(this)).isDeepLinkFromSmartech(intent) if (!isSmartechHandledDeeplink) { //Handle deeplink on app side } ` }, java: { testDeviceCode: ` boolean isSmartechHandledDeeplink = Smartech.getInstance(new WeakReference<>(this)).isDeepLinkFromSmartech(getIntent()); if (!isSmartechHandledDeeplink) { //Handle deeplink on app side } ` } } }; const generateTestDeviceSnippet = (sdk, isKotlin) => { const language = isKotlin ? 'kotlin' : 'java'; const config = SDK_CONFIG[sdk]; const config_lang = config[language]; return { importStatement: `${config.packageName}${isKotlin ? '' : ';'}`, methodStatement: config_lang.testDeviceCode, superOnCreateStatement: 'super.onCreate' }; }; const hanselTestDeviceUpdatedSnippet = (isKotlin) => generateTestDeviceSnippet('hansel', isKotlin); exports.hanselTestDeviceUpdatedSnippet = hanselTestDeviceUpdatedSnippet; const smartechTestDeviceSnippet = (isKotlin) => generateTestDeviceSnippet('smartech', isKotlin); exports.smartechTestDeviceSnippet = smartechTestDeviceSnippet; const smartechInitSnippetKotlin = (props) => ` val smartech = Smartech.getInstance(WeakReference(this)) val smartechBasePlugin = SmartechBasePlugin.getInstance() smartechBasePlugin.init(this) ${(props.android.isLogEnabled) ? 'smartech.setDebugLevel(SMTDebugLevel.Level.VERBOSE)' : ''} smartech.trackAppInstallUpdateBySmartech() ${(props.android.smartechNudges.smartechNudgesEnabled && props.android.smartechNudges.isLogEnabled) ? 'Hansel.enableDebugLogs()' : ''} `.replace(/\n\s*\n/g, '\n').trim(); exports.smartechInitSnippetKotlin = smartechInitSnippetKotlin; const smartechInitSnippetJava = (props) => ` Smartech smartech = Smartech.getInstance(new WeakReference(this)); SmartechBasePlugin smartechBasePlugin = SmartechBasePlugin.getInstance(); smartechBasePlugin.init(this); ${(props.android.isLogEnabled) ? 'smartech.setDebugLevel(SMTDebugLevel.Level.VERBOSE);' : ''} smartech.trackAppInstallUpdateBySmartech(); ${(props.android.smartechNudges.smartechNudgesEnabled && props.android.smartechNudges.isLogEnabled) ? ' Hansel.enableDebugLogs();' : ''} `.replace(/\n\s*\n/g, '\n').trim(); exports.smartechInitSnippetJava = smartechInitSnippetJava; exports.dependency = { smartechBase: "com.netcore.android:smartech-sdk", smartechNudge: "com.netcore.android:smartech-nudges" }; // SmartechNude encryption key exports.smartechHanselEncryptionKey = "SMT_USE_ENCRYPTION"; // TODO: Remove if not being used. exports.dependencyRegex = { smartechBase: /api\s+"com\.netcore\.android:smartech-sdk"/, smartechNudge: /api\s+"com\.netcore\.android:smartech-nudges"/ }; exports.AutoFetchLocationKey = "SMT_IS_AUTO_FETCHED_LOCATION";