"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _fs = require("fs");
var _path = require("path");
var _fsExtra = _interopRequireDefault(require("../../compiled/fs-extra"));
var _Generator = _interopRequireDefault(require("../Generator/Generator"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class BaseGenerator extends _Generator.default {
  constructor({
    path,
    target,
    data,
    questions,
    baseDir
  }) {
    super({
      baseDir: baseDir || target,
      args: data
    });
    this.path = path;
    this.target = target;
    this.data = data;
    this.questions = questions || [];
  }
  prompting() {
    return this.questions;
  }
  async writing() {
    const context = {
      ...this.data,
      ...this.prompts
    };
    if ((0, _fs.statSync)(this.path).isDirectory()) {
      this.copyDirectory({
        context,
        path: this.path,
        target: this.target
      });
    } else {
      if (this.path.endsWith('.tpl')) {
        this.copyTpl({
          templatePath: this.path,
          target: this.target,
          context
        });
      } else {
        const absTarget = this.target;
        _fsExtra.default.mkdirpSync((0, _path.dirname)(absTarget));
        (0, _fs.copyFileSync)(this.path, absTarget);
      }
    }
  }
}
exports.default = BaseGenerator;