diff --git a/apps/generator/lib/hooksRegistry.js b/apps/generator/lib/hooksRegistry.js index 2c21389fb..9c2aa5212 100644 --- a/apps/generator/lib/hooksRegistry.js +++ b/apps/generator/lib/hooksRegistry.js @@ -25,40 +25,45 @@ module.exports.registerHooks = async (hooks, templateConfig, templateDir, hooksD * @param {String} hooksDir Directory where local hooks are located. */ async function registerLocalHooks(hooks, templateDir, hooksDir) { - return new Promise(async (resolve, reject) => { - const localHooks = path.resolve(templateDir, hooksDir); + const localHooks = path.resolve(templateDir, hooksDir); - if (!await exists(localHooks)) return resolve(hooks); + try { + const localHooksExist = await exists(localHooks); + if (!localHooksExist) return hooks; - const walker = xfs.walk(localHooks, { - followLinks: false - }); + return new Promise((resolve, reject) => { + const walker = xfs.walk(localHooks, { + followLinks: false + }); - walker.on('file', async (root, stats, next) => { - try { - const filePath = path.resolve(templateDir, path.resolve(root, stats.name)); + walker.on('file', async (root, stats, next) => { + try { + const filePath = path.resolve(templateDir, path.resolve(root, stats.name)); - registerTypeScript(filePath); + await registerTypeScript(filePath); - delete require.cache[require.resolve(filePath)]; - const mod = require(filePath); + delete require.cache[require.resolve(filePath)]; + const mod = require(filePath); - addHook(hooks, mod); + addHook(hooks, mod); - next(); - } catch (e) { - reject(e); - } - }); + next(); + } catch (e) { + reject(e); + } + }); - walker.on('errors', (root, nodeStatsArray) => { - reject(nodeStatsArray); - }); + walker.on('errors', (root, nodeStatsArray) => { + reject(nodeStatsArray); + }); - walker.on('end', async () => { - resolve(hooks); + walker.on('end', () => { + resolve(hooks); + }); }); - }); + } catch (error) { + throw error; + } } /**