Repository: jiahaog/nativefier
File: src/build/buildNativefierApp.ts (TypeScript)

Code before:
        'Building an app with a target platform of Mac on a Windows machine requires admin priveleges to perform. Please rerun this command in an admin command prompt.',
      );
    }
  }

  log.info('\nPreparing Electron app...');
  const tmpPath = getTempDir('app', 0o755);
  await prepareElectronApp(options.packager.dir, tmpPath, options);

  log.info('\nConverting icons...');
  options.packager.dir = tmpPath; // const optionsWithTmpPath = { ...options, dir: tmpPath };
  convertIconIfNecessary(options);
  await copyIconsIfNecessary(options, tmpPath);

  log.info(
    "\nPackaging... This will take a few seconds, maybe minutes if the requested Electron isn't cached yet...",
  );
  trimUnprocessableOptions(options);
  electronGet.initializeProxy(); // https://github.com/electron/get#proxies
  const appPathArray = await electronPackager(options.packager);

  log.info('\nFinalizing build...');
  const appPaths =
    options.packager.arch === 'all' ? appPathArray : [getAppPath(appPathArray)];

  if (appPaths) {
    let osRunHelp = '';
    if (options.packager.platform === 'win32') {
      osRunHelp = `the contained .exe file.`;
    } else if (options.packager.platform === 'linux') {
      osRunHelp = `the contained executable file (prefixing with ./ if necessary)\nMenu/desktop shortcuts are up to you, because Nativefier cannot know where you're going to move the app. Search for "linux .desktop file" for help, or see https://wiki.archlinux.org/index.php/Desktop_entries`;
    } else if (options.packager.platform === 'darwin') {
      osRunHelp = `the app bundle.`;
    }
    log.info(
      `App(s) built to ${appPaths.join(
        ',\n',
      )}, move to wherever it makes sense for you and run ${osRunHelp}`,
    );
  }
  return appPaths;
}


Review comment (suggestion):
`appPaths` is now an array and an array is always true-ish, this condition is bogusly always true. You probably want

```suggestion
  if (appPaths.length > 0) {
```

Code after:
    // https://github.com/electron/electron-packager/issues/933
    // https://github.com/electron/electron-packager/issues/1194
    // https://github.com/electron/electron/issues/11094
    if (!isWindowsAdmin()) {
      throw new Error(
        'Building an app with a target platform of Mac on a Windows machine requires admin priveleges to perform. Please rerun this command in an admin command prompt.',
      );
    }
  }

  log.info('\nPreparing Electron app...');
  const tmpPath = getTempDir('app', 0o755);
  await prepareElectronApp(options.packager.dir, tmpPath, options);

  log.info('\nConverting icons...');
  options.packager.dir = tmpPath; // const optionsWithTmpPath = { ...options, dir: tmpPath };
  convertIconIfNecessary(options);
  await copyIconsIfNecessary(options, tmpPath);

  log.info(
    "\nPackaging... This will take a few seconds, maybe minutes if the requested Electron isn't cached yet...",
  );
  trimUnprocessableOptions(options);
  electronGet.initializeProxy(); // https://github.com/electron/get#proxies
  const appPathArray = await electronPackager(options.packager);

  log.info('\nFinalizing build...');
  const appPath = getAppPath(appPathArray);

  if (appPath) {
    let osRunHelp = '';
    if (options.packager.platform === 'win32') {
      osRunHelp = `the contained .exe file.`;
    } else if (options.packager.platform === 'linux') {
      osRunHelp = `the contained executable file (prefixing with ./ if necessary)\nMenu/desktop shortcuts are up to you, because Nativefier cannot know where you're going to move the app. Search for "linux .desktop file" for help, or see https://wiki.archlinux.org/index.php/Desktop_entries`;
    } else if (options.packager.platform === 'darwin') {
      osRunHelp = `the app bundle.`;
    }
    log.info(
      `App built to ${appPath}, move to wherever it makes sense for you and run ${osRunHelp}`,
    );
  }
  return appPath;
}