From 799c585ca41914de3517f8e5affe7947cb718e79 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sun, 10 Mar 2024 09:59:21 +0100 Subject: [PATCH] refactor --- .circleci/config.yml | 2 +- apps/remixdesktop/aftersign.js | 58 ++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 53d1f1b720..3660a23450 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -354,7 +354,7 @@ jobs: cd apps/remixdesktop yarn installRipGrepMacOXarm64 PUBLISH_FOR_PULL_REQUEST='false' USE_HARD_LINKS=false yarn dist --mac --arm64 - - run: + - run: command: | nvm use 20 cd apps/remixdesktop diff --git a/apps/remixdesktop/aftersign.js b/apps/remixdesktop/aftersign.js index 99017b42f8..08e00694b3 100644 --- a/apps/remixdesktop/aftersign.js +++ b/apps/remixdesktop/aftersign.js @@ -13,21 +13,34 @@ exports.default = async function notarizing(context) { const appName = context.packager.appInfo.productFilename const appPath = `${appOutDir}/${appName}.app` + // Function to promisify the exec command + function execShellCommand(cmd) { + return new Promise((resolve, reject) => { + exec(cmd, (error, stdout, stderr) => { + if (error) { + reject(new Error(`Error: ${error.message}`)); + return; + } + if (stderr) { + reject(new Error(`Stderr: ${stderr}`)); + return; + } + resolve(stdout); + }); + }); + } + // Function to check if the app is stapled - function checkStapleStatus() { - exec(`xcrun stapler validate "${appPath}"`, async (error, stdout, stderr) => { - if (error) { - console.log(`App is not stapled: ${error.message}`) - await runNotarize() - return - } - if (stderr) { - console.log(`App is not stapled: ${stderr}`) - await runNotarize() - return - } - console.log('App is already stapled. No action needed.') - }) + // Async function to check the stapling status + async function checkStapleStatus(appPath) { + try { + await execShellCommand(`xcrun stapler validate "${appPath}"`); + console.log('App is already stapled. No action needed.'); + return true + } catch (error) { + console.log(`App is not stapled: ${error.message}`); + return false + } } @@ -57,19 +70,18 @@ exports.default = async function notarizing(context) { // Stapling the app console.log('STAPLING') - exec(`xcrun stapler staple "${appPath}"`, (error, stdout, stderr) => { - if (error) { - console.error(`exec error: ${error}`) - return - } - console.log(`Stapling output: ${stdout}`) - console.error(`Stapling errors: ${stderr}`) - }) + await execShellCommand(`xcrun stapler staple "${appPath}"`) + } catch (error) { console.error('Error during notarization:', error) } } - checkStapleStatus() + if(!await checkStapleStatus()){ + await runNotarize() + await checkStapleStatus() + }else{ + return [] + } }