-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.js
82 lines (69 loc) · 2.29 KB
/
setup.js
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
const fs = require('fs');
const path = require('path');
const os = require('os');
const { execSync } = require('child_process');
const EMPTY_LINE = '';
const deleteFile = filename => {
try {
return fs.unlinkSync(path.join(__dirname, filename));
} catch (error) {}
}
const deleteFolder = path => {
try {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function(file, index) {
const currentPath = `${path}/${file}`;
if (fs.lstatSync(currentPath).isDirectory()) {
deleteFolder(currentPath);
} else {
deleteFile(currentPath);
}
});
fs.rmdirSync(path);
}
} catch (error) {}
}
const packagePath = path.join(__dirname, 'package.json');
const packageJSON = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
const versionString = packageJSON.dependencies['react-native'];
const versionNumber = parseInt(versionString.replace(/\./g, ''));
if (versionNumber >= 570 && versionNumber < 575) {
console.log('🛠 Fix [email protected] installation...');
console.log(' -> Cleaning React Native cache...');
execSync('rm -Rf .rncache', {
cwd: os.homedir()
});
console.log(' -> Downloading third-party...');
execSync('sh ./scripts/ios-install-third-party.sh', {
cwd: 'node_modules/react-native',
stdio: 'ignore'
});
console.log(' -> Setup Glog...');
execSync('../../scripts/ios-configure-glog.sh', {
cwd: 'node_modules/react-native/third-party/glog-0.3.5',
stdio: 'ignore'
});
}
console.log(EMPTY_LINE);
console.log('📝 Extending package.json...');
// Inject config in package.json
const scripts = require('./scripts.json');
const extension = require('./extension.json');
const updatedPackageJSON = Object.assign({}, packageJSON, scripts, extension);
fs.writeFileSync(packagePath, JSON.stringify(updatedPackageJSON, null, 2));
console.log('⚙️ Resolve Enzyme dependencies...');
const reactVersion = updatedPackageJSON.dependencies['react'];
execSync(`yarn add --dev react-dom@${reactVersion}`, {
stdio: 'ignore'
});
console.log('🧹 Clean...');
// Remove files
deleteFolder('__tests__');
deleteFile('LICENSE');
deleteFile('README.md');
deleteFile('.npmignore');
deleteFile('extension.json');
deleteFile('scripts.json');
deleteFile('setup.js');
deleteFile('App.js');
console.log('✅ Finished!');