'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _fsExtra = require('fs-extra');

var _fsExtra2 = _interopRequireDefault(_fsExtra);

var _session = require('../session');

var _session2 = _interopRequireDefault(_session);

var _debug = require('../debug');

var _debug2 = _interopRequireDefault(_debug);

var _printTools = require('../print-tools');

var _Constants = require('../../constants/Constants');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const { debug } = (0, _debug2.default)('utils-init');

class Init {
  constructor() {
    this.session = _session2.default;

    this.templates = [{ name: 'empty', description: 'Empty project' }, { name: 'hello', description: 'Hello World template (recommended)' }];
  }

  createFilesAndFolders() {
    debug('createFilesAndFolders()');

    try {
      debug('Template name:', this.templateName);
      debug('Project path:', this.session.projectPath);
      _fsExtra2.default.copySync((0, _Constants.getInitTemplate)(this.templateName), this.session.projectPath);
      (0, _printTools.echo)(4)(_chalk2.default.dim(`Project has been created from ${_chalk2.default.green(this.templateName)} template.`));
      (0, _printTools.echo)();
    } catch (err) {
      (0, _printTools.echo)(err);
      throw err;
    }
  }

  getTemplatesChoices() {
    return this.templates.map(template => `${template.name} - ${template.description}`);
  }

  checkConfigFiles() {
    return !_fsExtra2.default.existsSync(this.session.projectPath);
  }

  checkIfInitiated() {
    return _fsExtra2.default.existsSync(this.session.projectPath) && this.session.project;
  }

  addConfigFiles(projectParams = {}, projectPath) {
    if (projectPath) {
      this.session.settings.account.addProject(projectPath, projectParams);
    } else {
      this.session.settings.account.addProject(_path2.default.join(process.cwd(), 'syncano'), projectParams);
    }

    (0, _printTools.echo)(4)(`Your project is attached to ${_chalk2.default.green(projectParams.instance)} instance now!`);
  }

  noConfigFiles() {
    debug('noConfigFiles()');
    this.createFilesAndFolders();
  }

}

exports.default = Init;
module.exports = exports['default'];
//# sourceMappingURL=init.js.map