-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.js
More file actions
91 lines (82 loc) · 3.32 KB
/
postinstall.js
File metadata and controls
91 lines (82 loc) · 3.32 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
84
85
86
87
88
89
90
91
const fs = require('fs');
const https = require('https');
const path = require('path');
const rimraf = require('./rimraf');
const PROJECT_ROOT_RELATIVE_PATH = '../../../..';
const FIREBASE_URL = 'https://cd.smartface.io/repository/smartfacefirebase/ios/3.0.4/firebaseios.zip';
async function getIOSFirebasePlugin() {
const projectPluginPath = path.normalize(path.join(__dirname, `${PROJECT_ROOT_RELATIVE_PATH}/plugins/iOS/firebaseios.zip`));
return new Promise((resolve, reject) => {
https.get(FIREBASE_URL, (res) => {
const filePath = fs.createWriteStream(projectPluginPath);
res.pipe(filePath);
filePath.on('finish', () => {
filePath.close();
resolve();
});
filePath.on('error', (err) => reject(err));
});
});
}
async function getAndroidFirebasePlugin() {
const androidFirebasePath = path.normalize(path.join(__dirname, 'Native/Android/firebaseplugin'));
const projectPluginPath = path.normalize(path.join(__dirname, `${PROJECT_ROOT_RELATIVE_PATH}/plugins/Android/firebaseplugin`));
rimraf.sync(projectPluginPath, { recursive: true, force: true, disableGlob: true });
return new Promise((resolve, reject) => {
fs.rename(androidFirebasePath, projectPluginPath, (err) => {
if (err) {
reject(err);
}
resolve();
});
});
}
function addDefaultConfigToProjectJSON() {
const projectJSONPath = path.normalize(path.join(__dirname, `${PROJECT_ROOT_RELATIVE_PATH}/config/project.json`));
const project = require(projectJSONPath);
if (!project.build.input.ios.plugins.firebaseios) {
project.build.input.ios.plugins.firebaseios = {
path: 'plugins/iOS/firebaseios.zip',
active: true,
crashlytics: true
};
}
if (!project.build.input.android.plugins.modules || !project.build.input.android.plugins.modules.firebaseandroid) {
project.build.input.android.plugins.modules = project.build.input.android.plugins.modules
? project.build.input.android.plugins.modules
: {};
project.build.input.android.plugins.modules.firebaseplugin = {
path: 'plugins/Android/firebaseplugin',
active: true
};
}
const output = JSON.stringify(project, null, '\t');
fs.writeFileSync(projectJSONPath, output, 'utf8');
}
function deleteRemainders() {
const nativePath = path.normalize(path.join(__dirname, 'Native'));
rimraf.sync(nativePath, { recursive: true, force: true, disableGlob: true });
}
function isSmartfaceProject() {
const projectJSONPath = path.normalize(path.join(__dirname, `${PROJECT_ROOT_RELATIVE_PATH}/config/project.json`));
return fs.existsSync(projectJSONPath);
}
function isAppcircleBuild() {
return !!process.env.AC_APPCIRCLE;
}
/**
* This check is here to enable installation on development environment.
* If we are not building or in smartface environment, don't try to get plugins.
*/
if (!isAppcircleBuild() || !isSmartfaceProject()) {
return;
}
Promise.all([getAndroidFirebasePlugin(), getIOSFirebasePlugin()])
.then(() => {
addDefaultConfigToProjectJSON();
deleteRemainders();
})
.catch((err) => {
console.error('An error occurred : ', err);
process.exit(1);
});