Example #1
0
 const promises = this.plugins.map(p => {
     const debug = require('debug')([this.bin, p.name, 'hooks', event].join(':'));
     const context = {
         config: this,
         debug,
         exit(code = 0) { errors_1.exit(code); },
         log(message, ...args) {
             process.stdout.write(util_1.format(message, ...args) + '\n');
         },
         error(message, options = {}) {
             errors_1.error(message, options);
         },
         warn(message) { errors_1.warn(message); },
     };
     return Promise.all((p.hooks[event] || [])
         .map(async (hook) => {
         try {
             const f = ts_node_1.tsPath(p.root, hook);
             debug('start', f);
             const search = (m) => {
                 if (typeof m === 'function')
                     return m;
                 if (m.default && typeof m.default === 'function')
                     return m.default;
                 return Object.values(m).find((m) => typeof m === 'function');
             };
             await search(require(f)).call(context, Object.assign({}, opts, { config: this }));
             debug('done');
         }
         catch (err) {
             if (err && err.oclif && err.oclif.exit !== undefined)
                 throw err;
             this.warn(err, `runHook ${event}`);
         }
     }));
 });
Example #2
0
 exit(code = 0) { return Errors.exit(code); }