react-native-macos/React/Modules
Ramanpreet Nara f37093319b Start using getConstants
Summary:
TurboModules depend on a getConstants method. Existing ObjectiveC modules do not have this method. Therefore, I moved the contents of `constantsToExport` to `getConstants` and then had `constantsToExports` call `getConstants`.

facebook
Since all NativeModules will eventually need to be migrated to the TurboModule system, I didn't restrict this to just the NativeModules in Marketplace.

```
const fs = require('fs');

if (process.argv.length < 3) {
    throw new Error('Expected a file containing a list of native modules as the third param');
}

function read(filename) {
    return fs.readFileSync(filename, 'utf8');
}

const nativeModuleFilenames = read(process.argv[2]).split('\n').filter(Boolean);

nativeModuleFilenames.forEach((fileName) => {
    if (fileName.endsWith('.h')) {
        return;
    }

    const absPath = `${process.env.HOME}/${fileName}`;
    const fileSource = read(absPath);

    if (/(\n|^)-\s*\((.+)\)getConstants/.test(fileSource)) {
        return;
    }

    const constantsToExportRegex = /(\n|^)-\s*\((.+)\)constantsToExport/;
    const result = constantsToExportRegex.exec(fileSource);

    if (result == null) {
        throw new Error(`Didn't find a constantsToExport function inside NativeModule ${fileName}`);
    }

    const returnType = result[2];

    const newFileSource = fileSource.replace(
        constantsToExportRegex,
        '$1- ($2)constantsToExport\n' +
        '{\n' +
        `  return ${returnType.includes('ModuleConstants') ? '($2)' : ''}[self getConstants];\n` +
        '}\n' +
        '\n' +
        '- ($2)getConstants'
    );

    fs.writeFileSync(absPath, newFileSource);
});
```

```
> xbgs -l ')constantsToExport'
```

Reviewed By: fkgozali

Differential Revision: D13951197

fbshipit-source-id: 394a319d42aff466c56a3d748e17c335307a8f47
2019-02-04 17:46:56 -08:00
..
RCTAccessibilityManager.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTAccessibilityManager.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTAlertManager.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTAlertManager.m Fixes alert view block first responder (#23240) 2019-02-01 03:51:24 -08:00
RCTAppState.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTAppState.m Start using getConstants 2019-02-04 17:46:56 -08:00
RCTAsyncLocalStorage.h Expose AsyncLocalStorage get/set methods (#18454) 2019-01-29 08:54:16 -08:00
RCTAsyncLocalStorage.m Always write the manifest in multiRemove (#18613) 2019-01-29 09:15:30 -08:00
RCTClipboard.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTClipboard.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTDevSettings.h iOS changes to switch to JSI 2018-10-18 01:06:24 -07:00
RCTDevSettings.mm iOS changes to switch to JSI 2018-10-18 01:06:24 -07:00
RCTDeviceInfo.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTDeviceInfo.m Start using getConstants 2019-02-04 17:46:56 -08:00
RCTEventEmitter.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTEventEmitter.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTExceptionsManager.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTExceptionsManager.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTI18nManager.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTI18nManager.m Start using getConstants 2019-02-04 17:46:56 -08:00
RCTI18nUtil.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTI18nUtil.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTKeyboardObserver.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTKeyboardObserver.m Expose isLocalUserInfoKey to keyboard event notifications (#23245) 2019-02-01 14:32:19 -08:00
RCTLayoutAnimation.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTLayoutAnimation.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTLayoutAnimationGroup.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTLayoutAnimationGroup.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRedBox.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRedBox.m Updated RedBox screen (#22242) 2019-01-15 06:29:49 -08:00
RCTRedBoxExtraDataViewController.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTRedBoxExtraDataViewController.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTSourceCode.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTSourceCode.m Start using getConstants 2019-02-04 17:46:56 -08:00
RCTStatusBarManager.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTStatusBarManager.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTVNavigationEventEmitter.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTVNavigationEventEmitter.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTiming.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTTiming.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTUIManager.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTUIManager.m Start using getConstants 2019-02-04 17:46:56 -08:00
RCTUIManagerObserverCoordinator.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTUIManagerObserverCoordinator.mm Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTUIManagerUtils.h Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
RCTUIManagerUtils.m Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00