summaryrefslogtreecommitdiffhomepage
path: root/gui/packages/mobile/postinstall.js
blob: 6b5c80664ba80911d85f4c53029a4dba65ec43bd (plain)
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
//
// React-native CLI doesn't function properly in workspace configuration.
//
// Symlinking `/gui/node_modules/react-native` to `/gui/packages/mobile/node_modules/react-native`
// solves this. See rn-cli.config.js for project roots override.
//

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

const sourcePath = path.resolve(path.join(__dirname, '../../node_modules/react-native'));
const symlinkPath = path.join(__dirname, 'node_modules/react-native');

try {
  console.log('Removing a symlink to react-native');
  fs.unlinkSync(symlinkPath);
} catch (error) {
  if (error.code !== 'ENOENT') {
    throw error;
  }
}

try {
  console.log('Adding a symlink to react-native');

  // Symlinks require elevated permissions on Windows. Use junction instead.
  const type = process.platform === 'win32' ? 'junction' : undefined;

  fs.symlinkSync(sourcePath, symlinkPath, type);
  console.log('Done');
} catch (error) {
  console.error('Cannot symlink react-native: ' + error.message);
}