Skip to content

Commit

Permalink
Update unlink interface (#79)
Browse files Browse the repository at this point in the history
* Initial commit

* Fix errors

* Resolve

* Fixes
  • Loading branch information
grabbou committed May 3, 2016
1 parent bd8edc1 commit fa1d6a7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/android/registerNativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ module.exports = function registerNativeAndroidModule(
projectConfig.mainActivityPath,
makeImportPatch(androidConfig.packageImportPath)
);

return true;
};
2 changes: 0 additions & 2 deletions src/android/unregisterNativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ module.exports = function unregisterNativeAndroidModule(
projectConfig.mainActivityPath,
makeImportPatch(androidConfig.packageImportPath)
);

return true;
};
6 changes: 0 additions & 6 deletions src/ios/unregisterNativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const getProducts = require('./getProducts');
const getHeadersInFolder = require('./getHeadersInFolder');
const isEmpty = require('lodash').isEmpty;
const getHeaderSearchPath = require('./getHeaderSearchPath');
const hasLibraryImported = require('./hasLibraryImported');
const removeProjectFromProject = require('./removeProjectFromProject');
const removeProjectFromLibraries = require('./removeProjectFromLibraries');
const removeFromStaticLibraries = require('./removeFromStaticLibraries');
Expand All @@ -24,9 +23,6 @@ module.exports = function unregisterNativeModule(dependencyConfig, projectConfig
const dependencyProject = xcode.project(dependencyConfig.pbxprojPath).parseSync();

const libraries = getGroup(project, projectConfig.libraryFolder);
if (!libraries || !hasLibraryImported(libraries, dependencyConfig.projectName)) {
return false;
}

const file = removeProjectFromProject(
project,
Expand Down Expand Up @@ -55,6 +51,4 @@ module.exports = function unregisterNativeModule(dependencyConfig, projectConfig
projectConfig.pbxprojPath,
project.writeSync()
);

return true;
};
89 changes: 55 additions & 34 deletions src/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const log = require('npmlog');
const getProjectDependencies = require('./getProjectDependencies');
const unregisterDependencyAndroid = require('./android/unregisterNativeModule');
const unregisterDependencyIOS = require('./ios/unregisterNativeModule');
const isInstalledAndroid = require('./android/isInstalled');
const isInstalledIOS = require('./ios/isInstalled');
const unlinkAssetsAndroid = require('./android/unlinkAssets');
const unlinkAssetsIOS = require('./ios/unlinkAssets');
const getDependencyConfig = require('./getDependencyConfig');
Expand All @@ -13,14 +15,58 @@ const flatten = require('lodash').flatten;

log.heading = 'rnpm-link';

const unlinkDependencyAndroid = (androidProject, dependency, packageName) => {
if (!androidProject || !dependency.android) {
return;
}

const isInstalled = isInstalledAndroid(androidProject, packageName);

if (!isInstalled) {
log.info(`Android module ${packageName} is not installed`);
return;
}

log.info(`Unlinking ${packageName} android dependency`);

unregisterDependencyAndroid(packageName, dependency.android, androidProject);

log.info(`Android module ${packageName} has been successfully unlinked`);
};

const unlinkDependencyIOS = (iOSProject, dependency, packageName) => {
if (!iOSProject || !dependency.ios) {
return;
}

const isInstalled = isInstalledIOS(iOSProject, dependency.ios);

if (!isInstalled) {
log.info(`iOS module ${packageName} is not installed`);
return;
}

log.info(`Unlinking ${packageName} ios dependency`);

unregisterDependencyIOS(dependency.ios, iOSProject);

log.info(`iOS module ${packageName} has been successfully unlinked`);
};

/**
* Updates project and unlink specific dependency
*
* If optional argument [packageName] is provided, it's the only one that's checked
* If optional argument [packageName] is provided, it's the only one
* that's checked
*/
module.exports = function unlink(config, args) {
const packageName = args[0];

var project;
var dependency;

try {
const project = config.getProjectConfig();
project = config.getProjectConfig();
} catch (err) {
log.error(
'ERRPACKAGEJSON',
Expand All @@ -29,10 +75,8 @@ module.exports = function unlink(config, args) {
return Promise.reject(err);
}

const packageName = args[0];

try {
const dependency = config.getDependencyConfig(packageName);
dependency = config.getDependencyConfig(packageName);
} catch (err) {
log.warn(
'ERRINVALIDPROJ',
Expand All @@ -41,35 +85,10 @@ module.exports = function unlink(config, args) {
return Promise.reject(err);
}

const allDependencies = getDependencyConfig(config, getProjectDependencies());

if (project.android && dependency.android) {
log.info(`Unlinking ${packageName} android dependency`);
unlinkDependencyAndroid(project.android, dependency, packageName);
unlinkDependencyIOS(project.ios, dependency, packageName);

const didUnlinkAndroid = unregisterDependencyAndroid(
packageName,
dependency.android,
project.android
);

if (didUnlinkAndroid) {
log.info(`Android module ${packageName} has been successfully unlinked`);
} else {
log.info(`Android module ${packageName} is not linked yet`);
}
}

if (project.ios && dependency.ios) {
log.info(`Unlinking ${packageName} ios dependency`);

const didUnlinkIOS = unregisterDependencyIOS(dependency.ios, project.ios);

if (didUnlinkIOS) {
log.info(`iOS module ${packageName} has been successfully unlinked`);
} else {
log.info(`iOS module ${packageName} is not linked yet`);
}
}
const allDependencies = getDependencyConfig(config, getProjectDependencies());

const assets = difference(
dependency.assets,
Expand All @@ -90,7 +109,9 @@ module.exports = function unlink(config, args) {
unlinkAssetsAndroid(assets, project.android.assetsPath);
}

log.info(`${packageName} assets has been successfully unlinked from your project`);
log.info(
`${packageName} assets has been successfully unlinked from your project`
);

return Promise.resolve();
};

0 comments on commit fa1d6a7

Please sign in to comment.