Skip to content

automatic module name in examples_postinstall.js #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions templates/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
*/
Expand Down Expand Up @@ -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);

Expand Down