#!/usr/bin/env node
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var mPackage = require("./../../../package.json");

var Base = require("./../Module/Base");

var path = require("path");

var fs = require('fs');

var winston = require('winston');

var nodemon = require("nodemon");

var yargs = require("yargs");

var _require = require("commander"),
    Command = _require.Command;

var program = new Command();
program.version(mPackage.version).arguments("<file>").option('-d, --debug', 'Run Debug Mode').option('-w, --watch <dir>', 'directory watch changes').option('-n, --nodemon', 'Use Nodemon With Run').option('-b, --babel', 'Use Babel').action( /*#__PURE__*/function () {
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(file, options, command) {
    var configFilePath, watchOpt, babelOpt;
    return _regenerator["default"].wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            configFilePath = path.join(process.cwd(), "./node_modules/dkaframework/src/Framework/bin/babel.config.js");
            watchOpt = options.watch !== undefined ? "--watch ".concat(options.watch) : "";
            babelOpt = options.babel !== undefined ? "babel-node" : "node";
            _context3.next = 5;
            return Base["default"]().then( /*#__PURE__*/function () {
              var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(res) {
                return _regenerator["default"].wrap(function _callee$(_context) {
                  while (1) {
                    switch (_context.prev = _context.next) {
                      case 0:
                        if (!res.status) {
                          _context.next = 7;
                          break;
                        }

                        console.log(res);
                        _context.next = 4;
                        return nodemon("".concat(watchOpt, " --exec ").concat(babelOpt, " --config-file \"").concat(configFilePath, "\" ").concat(file));

                      case 4:
                        console.log("".concat(watchOpt, " --exec ").concat(babelOpt, " --config-file \"").concat(configFilePath, "\" ").concat(file));
                        _context.next = 9;
                        break;

                      case 7:
                        console.log(res);
                        process.exit(1);

                      case 9:
                      case "end":
                        return _context.stop();
                    }
                  }
                }, _callee);
              }));

              return function (_x4) {
                return _ref2.apply(this, arguments);
              };
            }())["catch"]( /*#__PURE__*/function () {
              var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(err) {
                return _regenerator["default"].wrap(function _callee2$(_context2) {
                  while (1) {
                    switch (_context2.prev = _context2.next) {
                      case 0:
                        console.log(err);
                        process.exit(1);

                      case 2:
                      case "end":
                        return _context2.stop();
                    }
                  }
                }, _callee2);
              }));

              return function (_x5) {
                return _ref3.apply(this, arguments);
              };
            }());

          case 5:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));

  return function (_x, _x2, _x3) {
    return _ref.apply(this, arguments);
  };
}());
program.parse(process.argv);
nodemon.once('start', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
  return _regenerator["default"].wrap(function _callee4$(_context4) {
    while (1) {
      switch (_context4.prev = _context4.next) {
        case 0:
          console.log("DKA Engine V.".concat(mPackage.version, ". Program Starting ..."));

        case 1:
        case "end":
          return _context4.stop();
      }
    }
  }, _callee4);
}))).on('quit', function () {
  console.log("DKA Program V.".concat(mPackage.version, " Has Terminating ..."));
  process.exit(1);
}).on('restart', function (files) {
  console.log("The DKA Program V.".concat(mPackage.version, " has Restarted."));
});
//# sourceMappingURL=dka.js.map