smartech-base-expo-plugin
Version:
Smartech Base Expo SDK's React Native Plugin For React Native Projects.
64 lines (63 loc) • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepLinkHandlerSwiftSnippet = exports.deepLinkHandlerSnippet = exports.smartechBaseSwiftSnippet = exports.smartechBaseSnippet = exports.swiftImports = exports.appdelegateSnippet = exports.appdelegate_header_snippet = void 0;
exports.appdelegate_header_snippet = `#import <Smartech/Smartech.h>`;
exports.appdelegateSnippet = {
fileName: 'AppDelegate.h',
smartechHeaderSnippet: '#import <Smartech/Smartech.h>',
hanselHeaderSnippet: '#import <SmartechNudges/Hansel.h>'
};
exports.swiftImports = {
smartechImport: 'import Smartech',
hanselImport: 'import SmartechNudges'
};
exports.smartechBaseSnippet = {
smartechInit: `[[Smartech sharedInstance] initSDKWithDelegate:self withLaunchOptions:launchOptions];`,
debugLevel: `[[Smartech sharedInstance] setDebugLevel:SMTLogLevelVerbose];`,
trackAppInstallUpdateBySmartech: `[[Smartech sharedInstance] trackAppInstallUpdateBySmartech];`,
hanselLogSnippet: `[Hansel enableDebugLogs];`,
didfinishRegex: /\(\s*BOOL\s*\)\s*application:(UIApplication\s*)application\s*didFinishLaunchingWithOptions:\s*\(NSDictionary\s*\*\)\s*launchOptions/,
regexPattern: /application\s*:\s*\(UIApplication\s*\*\)\s*application\s*didFinishLaunchingWithOptions\s*:\s*\(NSDictionary\s*\*\)\s*launchOptions/
// // didfinishRegex: /\[super application:application didFinishLaunchingWithOptions/
};
exports.smartechBaseSwiftSnippet = {
smartechInit: `Smartech.sharedInstance().initSDK(with: self, withLaunchOptions: launchOptions)`,
debugLevel: `Smartech.sharedInstance().setDebugLevel(.verbose)`,
trackAppInstallUpdateBySmartech: `Smartech.sharedInstance().trackAppInstallUpdateBySmartech()`,
hanselLogSnippet: `Hansel.enableDebugLogs()`,
// Updated regex to handle multiline method signatures and optional keywords
didFinishLaunchingRegex: /(?:public\s+)?(?:override\s+)?func\s+application\s*\(/,
openURLRegex: /(?:public\s+)?(?:override\s+)?func\s+application\s*\(\s*_\s+app:/
};
const deepLinkHandlerSnippet = (delayInSeconds) => {
const delayValue = typeof delayInSeconds === 'number' && delayInSeconds > 0
? delayInSeconds
: 1.5;
return [
"#pragma mark - SmartechDelegate Method",
"- (void)handleDeeplinkActionWithURLString:(NSString *)deeplinkURLString andNotificationPayload:(NSDictionary *_Nullable)notificationPayload {",
`dispatch_after(dispatch_time(DISPATCH_TIME_NOW, ${delayValue} * NSEC_PER_SEC), dispatch_get_main_queue(), ^{`,
'NSLog(@"SMTLOGGER DEEPLINK: %@",deeplinkURLString);',
'[[NSNotificationCenter defaultCenter] postNotificationName:kSMTDeeplinkNotificationIdentifier object:nil userInfo:notificationPayload];',
"});",
"}",
"\n",
].join("\n");
};
exports.deepLinkHandlerSnippet = deepLinkHandlerSnippet;
const deepLinkHandlerSwiftSnippet = (delayInSeconds) => {
const delayValue = typeof delayInSeconds === 'number' && delayInSeconds > 0
? delayInSeconds
: 1.5;
return [
" // MARK: - SmartechDelegate Method",
" public func handleDeeplinkAction(withURLString deeplinkURLString: String, andNotificationPayload notificationPayload: [AnyHashable : Any]?) {",
` DispatchQueue.main.asyncAfter(deadline: .now() + ${delayValue}) {`,
' print("SMTLOGGER DEEPLINK: \\(deeplinkURLString)")',
' NotificationCenter.default.post(name: NSNotification.Name("SmartechDeeplink"), object: nil, userInfo: notificationPayload)',
" }",
" }",
"",
].join("\n");
};
exports.deepLinkHandlerSwiftSnippet = deepLinkHandlerSwiftSnippet;