-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreact-native-start-with-link.js
More file actions
executable file
·83 lines (73 loc) · 2.09 KB
/
react-native-start-with-link.js
File metadata and controls
executable file
·83 lines (73 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Original gist by GingerBear: https://gist.github.com/GingerBear/485f922a1e403739dc56d279925b216d
* I've removed runBundlerWithConfig
* - check symlink in depencency and devDepency
* - if found, generate rn-cli-config.js
* - react-native start with rn-cli-config
*/
const packageJson = require('./package.json');
const fs = require('fs');
const exec = require('child_process').execSync;
const RN_CLI_CONFIG_NAME = `rn-cli.config.js`;
main();
function main() {
const deps = Object.keys(
Object.assign({}, packageJson.dependencies, packageJson.devDependencies)
);
const symlinkPathes = getSymlinkPathes(deps);
generateRnCliConfig(symlinkPathes, RN_CLI_CONFIG_NAME);
}
function getSymlinkPathes(deps) {
const depLinks = [];
const depPathes = [];
deps.forEach(dep => {
const stat = fs.lstatSync('node_modules/' + dep);
if (stat.isSymbolicLink()) {
depLinks.push(dep);
depPathes.push(fs.realpathSync('node_modules/' + dep));
}
});
console.log('Starting react native with symlink modules:');
console.log(
depLinks.map((link, i) => ' ' + link + ' -> ' + depPathes[i]).join('\n')
);
return depPathes;
}
function generateRnCliConfig(symlinkPathes, configName) {
const fileBody =
`
var path = require('path');
var blacklist;
try {
blacklist = require('metro-bundler/src/blacklist');
} catch(e) {
blacklist = require('metro/src/blacklist');
}
var config = {
extraNodeModules: {
'react-native': path.resolve(__dirname, 'node_modules/react-native')
},
getBlacklistRE() {
return blacklist([
${symlinkPathes.map(
path =>
`/${path.replace(
/\//g,
'[/\\\\]'
)}[/\\\\]node_modules[/\\\\]react-native[/\\\\].*/`
)}
]);
},
getProjectRoots() {
return [
// Keep your project directory.
path.resolve(__dirname),
// Include your forked package as a new root.
${symlinkPathes.map(path => `path.resolve('${path}')`)}
];
}
};
module.exports = config;
`;
fs.writeFileSync(configName, fileBody);
}