-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun.js
110 lines (73 loc) · 3.29 KB
/
run.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Export supported versions
exports.cliVersion = '>=3.X';
var TAG = 'TiFabric',
VERSION = '1.0',
API_KEY = 'YOUR_API_KEY',
API_SECRET = 'YOUR_API_SECRET',
fs = require('fs');
exports.init = function(logger, config, cli, appc) {
logger.info(TAG + ' : initiated');
var isProd = (cli.argv['deploy-type'] || cli.argv['deployment-type']) === 'production';
if (isProd || cli.argv['fabric-enabled'] === 'true') {
logger.info(TAG + ' : ' + ' initialization enabled');
var projectDir = cli.argv['project-dir'];
if (cli.argv['platform'] == 'ios' || cli.argv['platform'] == 'iphone' || cli.argv['platform'] == 'ipad') {
var modules = cli.tiapp.modules;
for (var i in modules) {
var module = modules[i];
if (module.id == 'ti.fabric' && module.version) {
VERSION = module.version;
break;
}
}
cli.on('build.ios.xcodebuild', {
pre : function(build, done) {
try {
logger.debug(TAG + ' : ' + ' processing fabric for ios - version ' + VERSION);
var pbxprojPath = projectDir + '/build/iphone/' + cli.tiapp.name + '.xcodeproj/project.pbxproj',
pbxprojStr = fs.readFileSync(pbxprojPath).toString(),
sectionName = 'Post-Compile',
shellScript = '\\nchmod 755 ../../modules/iphone/ti.fabric/' + VERSION + '/platform/Fabric.framework/run\\n../../modules/iphone/ti.fabric/' + VERSION + '/platform/Fabric.framework/run ' + (cli.argv['fabric-key'] || API_KEY) + ' ' + (cli.argv['fabric-secret'] || API_SECRET);
var p = 0;
while (p !== -1) {
p = pbxprojStr.indexOf('name = "' + sectionName + '"', p);
if (p !== -1) {
p = pbxprojStr.indexOf('shellScript = ', p);
if (p !== -1) {
pbxprojStr = pbxprojStr.substring(0, p) + 'shellScript = "' + pbxprojStr.substring(p + 'shellScript = '.length + 1, pbxprojStr.indexOf('\n', p) - 2) + shellScript + '";' + pbxprojStr.substring(pbxprojStr.indexOf('\n', p));
}
}
}
fs.writeFileSync(pbxprojPath, pbxprojStr);
done();
} catch(e) {
logger.error(TAG + ' : ' + e);
return;
}
}
});
} else if (cli.argv['platform'] == 'android') {
cli.on('build.android.writeAndroidManifest', {
post : function(build, done) {
try {
logger.debug(TAG + ' : ' + ' processing fabric for android');
var buildDir = projectDir + '/build/android/',
srcFabricProperties = projectDir + '/plugins/ti.fabric/android/fabric.properties',
srcKitsProperties = projectDir + '/plugins/ti.fabric/android/kits.properties',
srcCustomRules = projectDir + '/plugins/ti.fabric/android/custom_rules.xml',
srcCrashlyticsFld = projectDir + '/plugins/ti.fabric/android/crashlytics';
fs.writeFileSync(buildDir + 'fabric.properties', fs.readFileSync(srcFabricProperties).toString().replace("API_SECRET", (cli.argv['fabric-secret'] || API_SECRET)));
fs.writeFileSync(buildDir + 'custom_rules.xml', fs.readFileSync(srcCustomRules).toString().replace("PROJECT_NAME", cli.tiapp.name));
var fse = require('fs-extra');
fse.copySync(srcKitsProperties, buildDir + 'kits.properties');
fse.copySync(srcCrashlyticsFld, buildDir + 'crashlytics');
done();
} catch(e) {
logger.error(TAG + ' : ' + e);
return;
}
}
});
}
}
};