Skip to content
Permalink
Browse files

refactor(packager): resolve hook files in a common function

  • Loading branch information
malept committed Sep 24, 2017
1 parent 38f9a3d commit 08d5577245e80dd707fc328e161189c5d2ca6500
Showing with 13 additions and 6 deletions.
  1. +13 −6 src/api/package.js
@@ -28,6 +28,17 @@ const d = debug('electron-forge:packager');
* @property {string} [outDir=`${dir}/out`] The path to the output directory for packaged apps
*/

/**
* Resolves hooks if they are a path to a file (instead of a `Function`).
*/
function resolveHooks(hooks, dir) {
if (hooks) {
return hooks.map(hook => (typeof hook === 'string' ? requireSearch(dir, [hook]) : hook));
}

return [];
}

/**
* Package an Electron application into an platform dependent format.
*
@@ -94,12 +105,8 @@ export default async (providedOptions = {}) => {
}
await fs.writeFile(path.resolve(buildPath, 'package.json'), JSON.stringify(copiedPackageJSON, null, 2));
done();
}].concat(forgeConfig.electronPackagerConfig.afterCopy ? forgeConfig.electronPackagerConfig.afterCopy.map(item =>
(typeof item === 'string' ? requireSearch(dir, [item]) : item)
) : []),
afterExtract: forgeConfig.electronPackagerConfig.afterExtract ? forgeConfig.electronPackagerConfig.afterExtract.map(item =>
(typeof item === 'string' ? requireSearch(dir, [item]) : item)
) : [],
}].concat(resolveHooks(forgeConfig.electronPackagerConfig.afterCopy, dir)),
afterExtract: resolveHooks(forgeConfig.electronPackagerConfig.afterExtract, dir),
dir,
arch,
platform,

0 comments on commit 08d5577

Please sign in to comment.
You can’t perform that action at this time.