Skip to content

Commit 6249f69

Browse files
authored
Fix react-native-macos-init to not break react-native-windows-init (#317)
* Update scripts to publish react-native-macos-init * Clean up merge markers * Restored ios:macos RNTester parity except for InputAccessoryView. * Revert "Restored ios:macos RNTester parity except for InputAccessoryView." This reverts commit 5a67ae0. * Make react-native.config.js be appended to existing file.
1 parent 77927fe commit 6249f69

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

local-cli/generator-common/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ function upgradeFileContentChangedCallback(
125125
);
126126
}
127127

128+
/**
129+
* @param {string} srcPath
130+
* @param {string} relativeDestDir
131+
* @param {Record<string, string>} replacements
132+
*/
133+
function appendToExistingFile(srcPath, relativeDestDir, replacements) {
134+
walk(srcPath).forEach(absoluteSrcFilePath => {
135+
const filename = path.relative(srcPath, absoluteSrcFilePath);
136+
const relativeDestPath = path.join(relativeDestDir, replaceInPath(filename, replacements));
137+
138+
const templateFileContents = fs.readFileSync(absoluteSrcFilePath, { encoding: 'UTF8' });
139+
fs.appendFileSync(relativeDestPath, templateFileContents);
140+
});
141+
}
142+
128143
module.exports = {
129-
createDir, copyAndReplaceWithChangedCallback, copyAndReplaceAll,
144+
appendToExistingFile, createDir, copyAndReplaceWithChangedCallback, copyAndReplaceAll,
130145
};

local-cli/generator-macos/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const path = require('path');
77
const childProcess = require('child_process');
88
const fs = require('fs');
99
const {
10+
appendToExistingFile,
1011
createDir,
1112
copyAndReplaceAll,
1213
copyAndReplaceWithChangedCallback,
@@ -60,6 +61,9 @@ function copyProjectTemplateAndReplace(
6061

6162
[
6263
{ from: path.join(srcRootPath, 'react-native.config.js'), to: 'react-native.config.js' },
64+
].forEach((mapping) => appendToExistingFile(mapping.from, mapping.to, templateVars));
65+
66+
[
6367
{ from: path.join(srcRootPath, 'metro.config.macos.js'), to: 'metro.config.macos.js' },
6468
].forEach((mapping) => copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite));
6569

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1-
/**
2-
* This cli config is needed for the coexistance of react-native and other
3-
* out-of-tree implementations such react-native-macos.
4-
* The following issue is tracked by
5-
* https://github.com/react-native-community/discussions-and-proposals/issues/182
6-
*
7-
* The work-around involves having a metro.config.js for each out-of-tree
8-
* platform, i.e. metro.config.js for react-native and
9-
* metro.config.macos.js for react-native-macos.
10-
* This react-native.config.js looks for a --use-react-native-macos
11-
* switch and when present pushes --config=metro.config.macos.js
12-
* and specifies reactNativePath: 'node_modules/react-native-macos'.
13-
* The metro.config.js has to blacklist 'node_modules/react-native-macos',
14-
* and conversely metro.config.macos.js has to blacklist 'node_modules/react-native'.
15-
*/
16-
'use strict';
17-
181
const macSwitch = '--use-react-native-macos';
19-
const windowsSwitch = '--use-react-native-windows';
202

213
if (process.argv.includes(macSwitch)) {
224
process.argv = process.argv.filter(arg => arg !== macSwitch);
235
process.argv.push('--config=metro.config.macos.js');
246
module.exports = {
257
reactNativePath: 'node_modules/react-native-macos',
268
};
27-
} else if (process.argv.includes(windowsSwitch)) {
28-
process.argv = process.argv.filter(arg => arg !== windowsSwitch);
29-
process.argv.push('--config=metro.config.windows.js');
30-
module.exports = {
31-
reactNativePath: 'node_modules/react-native-windows',
32-
};
339
}

0 commit comments

Comments
 (0)