-
Notifications
You must be signed in to change notification settings - Fork 24k
/
registerNativeModule.js
90 lines (79 loc) · 2.56 KB
/
registerNativeModule.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
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
const xcode = require('xcode');
const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const addToHeaderSearchPaths = require('./addToHeaderSearchPaths');
const getHeadersInFolder = require('./getHeadersInFolder');
const getHeaderSearchPath = require('./getHeaderSearchPath');
const getProducts = require('./getProducts');
const getTargets = require('./getTargets');
const createGroupWithMessage = require('./createGroupWithMessage');
const addFileToProject = require('./addFileToProject');
const addProjectToLibraries = require('./addProjectToLibraries');
const addSharedLibraries = require('./addSharedLibraries');
const isEmpty = require('lodash').isEmpty;
const getGroup = require('./getGroup');
/**
* Register native module IOS adds given dependency to project by adding
* its xcodeproj to project libraries as well as attaching static library
* to the first target (the main one)
*
* If library is already linked, this action is a no-op.
*/
module.exports = function registerNativeModuleIOS(
dependencyConfig,
projectConfig,
) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const dependencyProject = xcode
.project(dependencyConfig.pbxprojPath)
.parseSync();
const libraries = createGroupWithMessage(
project,
projectConfig.libraryFolder,
);
const file = addFileToProject(
project,
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath),
);
const targets = getTargets(project);
addProjectToLibraries(libraries, file);
getTargets(dependencyProject).forEach(product => {
var i;
if (!product.isTVOS) {
for (i = 0; i < targets.length; i++) {
if (!targets[i].isTVOS) {
project.addStaticLibrary(product.name, {
target: targets[i].uuid,
});
}
}
}
if (product.isTVOS) {
for (i = 0; i < targets.length; i++) {
if (targets[i].isTVOS) {
project.addStaticLibrary(product.name, {
target: targets[i].uuid,
});
}
}
}
});
addSharedLibraries(project, dependencyConfig.sharedLibraries);
const headers = getHeadersInFolder(dependencyConfig.folder);
if (!isEmpty(headers)) {
addToHeaderSearchPaths(
project,
getHeaderSearchPath(projectConfig.sourceDir, headers),
);
}
fs.writeFileSync(projectConfig.pbxprojPath, project.writeSync());
};