2018-02-09 01:10:29 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-02-09 01:10:29 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-20 11:52:08 +00:00
|
|
|
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');
|
2018-01-31 00:04:04 +00:00
|
|
|
const getTargets = require('./getTargets');
|
2016-07-30 15:59:16 +00:00
|
|
|
const createGroupWithMessage = require('./createGroupWithMessage');
|
2016-05-20 11:52:08 +00:00
|
|
|
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();
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
const libraries = createGroupWithMessage(project, projectConfig.libraryFolder);
|
2016-05-20 11:52:08 +00:00
|
|
|
const file = addFileToProject(
|
|
|
|
project,
|
|
|
|
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath)
|
|
|
|
);
|
|
|
|
|
2018-01-31 00:04:04 +00:00
|
|
|
const targets = getTargets(project);
|
|
|
|
|
2016-05-20 11:52:08 +00:00
|
|
|
addProjectToLibraries(libraries, file);
|
|
|
|
|
2018-01-31 00:04:04 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
addSharedLibraries(project, dependencyConfig.sharedLibraries);
|
|
|
|
|
|
|
|
const headers = getHeadersInFolder(dependencyConfig.folder);
|
|
|
|
if (!isEmpty(headers)) {
|
|
|
|
addToHeaderSearchPaths(
|
|
|
|
project,
|
|
|
|
getHeaderSearchPath(projectConfig.sourceDir, headers)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
projectConfig.pbxprojPath,
|
|
|
|
project.writeSync()
|
|
|
|
);
|
|
|
|
};
|