const { cleanPath } = require("../utilities/utils");



async function loadTasks(config) {
    var Path = cleanPath(process.cwd() + "/extensions/tasks/**/index.js")
    return new Promise(function (resolve, reject) {
        glob(Path, {}, function (er, files) {
          // register all endpoints
         // consola.success(`${files.length} Tasks charged`);

          files.map((file) => {
            let register = require("" + file);
            register({
              router: config.app,
              api: config.api,
              services: config.service,
              task:cron,
              state:config.state
            });
          });
          // files is an array of filenames.
          // If the `nonull` option is set, and nothing
          // was found, then files is ["**/*.js"]
          // er is an error object or null.
            resolve()
        });
    })

}

module.exports = {
  loadTasks
};
