Skip to content

Commit

Permalink
add script for optional mac dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Dec 13, 2024
1 parent 90f4053 commit 829424a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
46 changes: 46 additions & 0 deletions build-helpers/ensure-mac-dependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const os = require('os');
const fs = require('fs');
const { execSync } = require('child_process');
const path = require('path');

// Configuration: Array of packages to handle conditionally
const packages = [
'node-mac-permissions',
// Add more packages here if needed
];

const isMac = os.platform() === 'darwin';

packages.forEach((packageName) => {
const packagePath = path.join(__dirname, '..', 'node_modules', packageName);

if (isMac) {
// On macOS, ensure that the package is installed
if (!fs.existsSync(packagePath)) {
console.log(`macOS detected and ${packageName} is not installed. Installing...`);
try {
execSync(`npm install ${packageName}`, { stdio: 'inherit' });
console.log(`${packageName} installed successfully.`);
} catch (error) {
console.error(`Failed to install ${packageName} on macOS:`, error);
process.exit(1);
}
} else {
console.log(`macOS detected and ${packageName} is already installed. No action needed.`);
}
} else {
// On non-macOS platforms, ensure that the package is not present
if (fs.existsSync(packagePath)) {
console.log(`Non-macOS platform detected and ${packageName} is present. Removing...`);
try {
execSync(`npm uninstall ${packageName}`, { stdio: 'inherit' });
console.log(`${packageName} removed successfully.`);
} catch (error) {
console.error(`Failed to uninstall ${packageName} on non-mac platform:`, error);
process.exit(1);
}
} else {
console.log(`Non-macOS platform detected and ${packageName} is not installed. No action needed.`);
}
}
});
20 changes: 15 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"buildPackges": "npx lerna run build",
"packages": "npx lerna publish --no-git-tag-version",
"uidev": "cd uidev && webpack-dev-server",
"postinstall": "npx lerna run prepare"
"postinstall": "npx lerna run prepare && node ./build-helpers/ensure-mac-dependency.js"
},
"keywords": [],
"author": "Stefan Malzner <[email protected]>",
Expand Down

0 comments on commit 829424a

Please sign in to comment.