Skip to content

Commit

Permalink
add macos deps check as before-build hook
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Dec 14, 2024
1 parent 69ad832 commit f0517db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
59 changes: 32 additions & 27 deletions build-helpers/ensure-mac-dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,43 @@ const packages = [
// Add more packages here if needed
];

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

packages.forEach((packageName) => {
const packagePath = path.join(__dirname, '..', 'node_modules', packageName);
exports.default = function () {
console.log('Checking for macOS dependencies...');

if (isMac) {
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);
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 {
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);
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.`);
}
} else {
console.log(`Non-macOS platform detected and ${packageName} is not installed. No action needed.`);
}
}
});
});
};
2 changes: 2 additions & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ protocols:

asarUnpack:
- ./assets/images/taskbar

beforeBuild: ./build-helpers/ensure-mac-dependency.js
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 && node ./build-helpers/ensure-mac-dependency.js"
"postinstall": "npx lerna run prepare"
},
"keywords": [],
"author": "Stefan Malzner <[email protected]>",
Expand Down

0 comments on commit f0517db

Please sign in to comment.