From 32c221f150b22ca9f37506eb6167dc8a452b7cc2 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Tue, 5 Feb 2019 12:16:52 -0500 Subject: [PATCH] automatic module name in examples_postinstall.js (and log the cleanup path) --- lib.js | 3 +-- templates/example.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib.js b/lib.js index f790e80..6d8d734 100644 --- a/lib.js +++ b/lib.js @@ -119,10 +119,9 @@ module.exports = ({ return new Promise((resolve, reject) => { // Add postinstall script to example package.json const pathExampleApp = `./${rootFolderName}/example`; - const moduleName = `${modulePrefix}-${paramCase(name)}`; npmAddScriptSync(`${pathExampleApp}/package.json`, { key: 'postinstall', - value: `node ../scripts/examples_postinstall.js node_modules/${moduleName}` + value: `node ../scripts/examples_postinstall.js` }); // Add and link the new library diff --git a/templates/example.js b/templates/example.js index e6e984b..04066eb 100644 --- a/templates/example.js +++ b/templates/example.js @@ -22,7 +22,9 @@ module.exports = [{ * * It is expected this scripts lives in the libraries root folder within a * scripts folder. As first parameter the relative path to the libraries - * folder within the examples node_modules folder should be provided. + * folder within the example's node_modules folder may be provided. + * This script will determine the path from this project's package.json file + * if no such relative path is provided. * An example's package.json entry could look like: * "postinstall": "node ../scripts/examples_postinstall.js node_modules/react-native-library-name/" */ @@ -98,10 +100,14 @@ module.exports = [{ // Read out dir of example project const exampleDir = process.cwd(); - // Relative libraries path within the examples node_modules directory - const relativeLibraryNodeModulesPath = process.argv[2]; - const libraryNodeModulesPath = path.resolve(exampleDir, relativeLibraryNodeModulesPath); + console.log(\`Starting postinstall cleanup for \${exampleDir}\`); + // Resolve the React Native library's path within the example's node_modules directory + const libraryNodeModulesPath = process.argv.length > 2 + ? path.resolve(exampleDir, process.argv[2]) + : path.resolve(exampleDir, 'node_modules', require('../package.json').name); + + console.log(\`Removing unwanted artifacts for \${libraryNodeModulesPath}\`); removeLibraryNodeModulesPath(libraryNodeModulesPath);