Add pre/postunlink
Summary: An attempt to address https://github.com/facebook/react-native/issues/9156. cc grabbou Kureev **Test plan (required)** 1. Added the following to the `package.json` of a `react-native-plugin` ``` "rnpm": { "commands": { "preunlink": "node node_modules/react-native-plugin/scripts/preunlink" "postunlink": "node node_modules/react-native-plugin/scripts/postunlink" } } ``` 2. Added files, `scripts/preunlink.js` and `scripts/postunlink.js` to the plugin. Each of them simply logs a string to the console. 3. Ran `react-native unlink react-native-plugin` to verify that those logs get printed. Closes https://github.com/facebook/react-native/pull/9157 Differential Revision: D3749434 fbshipit-source-id: 40b94c9026db4f11e8f5be4a417a0670e8069be6
This commit is contained in:
parent
d943e28bc6
commit
e7521a114f
|
@ -0,0 +1 @@
|
|||
module.exports = (cb) => cb();
|
|
@ -14,15 +14,13 @@ const copyAssetsIOS = require('./ios/copyAssets');
|
|||
const getProjectDependencies = require('./getProjectDependencies');
|
||||
const getDependencyConfig = require('./getDependencyConfig');
|
||||
const pollParams = require('./pollParams');
|
||||
const commandStub = require('./commandStub');
|
||||
const promisify = require('./promisify');
|
||||
|
||||
log.heading = 'rnpm-link';
|
||||
|
||||
const commandStub = (cb) => cb();
|
||||
const dedupeAssets = (assets) => uniq(assets, asset => path.basename(asset));
|
||||
|
||||
const promisify = (func) => new Promise((resolve, reject) =>
|
||||
func((err, res) => err ? reject(err) : resolve(res))
|
||||
);
|
||||
|
||||
const linkDependencyAndroid = (androidProject, dependency) => {
|
||||
if (!androidProject || !dependency.config.android) {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (func) => new Promise((resolve, reject) =>
|
||||
func((err, res) => err ? reject(err) : resolve(res))
|
||||
);
|
|
@ -11,8 +11,12 @@ const getDependencyConfig = require('./getDependencyConfig');
|
|||
const compact = require('lodash').compact;
|
||||
const difference = require('lodash').difference;
|
||||
const filter = require('lodash').filter;
|
||||
const isEmpty = require('lodash').isEmpty;
|
||||
const find = require('lodash').find;
|
||||
const flatten = require('lodash').flatten;
|
||||
const isEmpty = require('lodash').isEmpty;
|
||||
const promiseWaterfall = require('./promiseWaterfall');
|
||||
const commandStub = require('./commandStub');
|
||||
const promisify = require('./promisify');
|
||||
|
||||
log.heading = 'rnpm-link';
|
||||
|
||||
|
@ -88,35 +92,47 @@ function unlink(args, config) {
|
|||
|
||||
const allDependencies = getDependencyConfig(config, getProjectDependencies());
|
||||
const otherDependencies = filter(allDependencies, d => d.name !== packageName);
|
||||
const thisDependency = find(allDependencies, d => d.name === packageName);
|
||||
const iOSDependencies = compact(otherDependencies.map(d => d.config.ios));
|
||||
|
||||
unlinkDependencyAndroid(project.android, dependency, packageName);
|
||||
unlinkDependencyIOS(project.ios, dependency, packageName, iOSDependencies);
|
||||
const tasks = [
|
||||
() => promisify(thisDependency.config.commands.preunlink || commandStub),
|
||||
() => unlinkDependencyAndroid(project.android, dependency, packageName),
|
||||
() => unlinkDependencyIOS(project.ios, dependency, packageName, iOSDependencies),
|
||||
() => promisify(thisDependency.config.commands.postunlink || commandStub)
|
||||
];
|
||||
|
||||
const assets = difference(
|
||||
dependency.assets,
|
||||
flatten(allDependencies, d => d.assets)
|
||||
);
|
||||
return promiseWaterfall(tasks)
|
||||
.then(() => {
|
||||
const assets = difference(
|
||||
dependency.assets,
|
||||
flatten(allDependencies, d => d.assets)
|
||||
);
|
||||
|
||||
if (isEmpty(assets)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (isEmpty(assets)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (project.ios) {
|
||||
log.info('Unlinking assets from ios project');
|
||||
unlinkAssetsIOS(assets, project.ios);
|
||||
}
|
||||
if (project.ios) {
|
||||
log.info('Unlinking assets from ios project');
|
||||
unlinkAssetsIOS(assets, project.ios);
|
||||
}
|
||||
|
||||
if (project.android) {
|
||||
log.info('Unlinking assets from android project');
|
||||
unlinkAssetsAndroid(assets, project.android.assetsPath);
|
||||
}
|
||||
if (project.android) {
|
||||
log.info('Unlinking assets from android project');
|
||||
unlinkAssetsAndroid(assets, project.android.assetsPath);
|
||||
}
|
||||
|
||||
log.info(
|
||||
`${packageName} assets has been successfully unlinked from your project`
|
||||
);
|
||||
|
||||
return Promise.resolve();
|
||||
log.info(
|
||||
`${packageName} assets has been successfully unlinked from your project`
|
||||
);
|
||||
})
|
||||
.catch(err => {
|
||||
log.error(
|
||||
`It seems something went wrong while unlinking. Error: ${err.message}`
|
||||
);
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Reference in New Issue