text: 'use strict';
  
  Object.defineProperty(exports, '__esModule', {
    value: true
  });
  exports.default = void 0;
  
  function fs() {
    const data = _interopRequireWildcard(require('fs'));
  
    fs = function() {
      return data;
    };
  
    return data;
  }
  
  function path() {
    const data = _interopRequireWildcard(require('path'));
  
    path = function() {
      return data;
    };
  
    return data;
  }
  
  function _chalk() {
    const data = _interopRequireDefault(require('chalk'));
  
    _chalk = function() {
      return data;
    };
  
    return data;
  }
  
  function _prompts() {
    const data = _interopRequireDefault(require('prompts'));
  
    _prompts = function() {
      return data;
    };
  
    return data;
  }
  
  function _realpathNative() {
    const data = require('realpath-native');
  
    _realpathNative = function() {
      return data;
    };
  
    return data;
  }
  
  var _questions = _interopRequireWildcard(require('./questions'));
  
  var _errors = require('./errors');
  
  var _constants = require('./constants');
  
  var _generate_config_file = _interopRequireDefault(
    require('./generate_config_file')
  );
  
  var _modify_package_json = _interopRequireDefault(
    require('./modify_package_json')
  );
  
  function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {default: obj};
  }
  
  function _interopRequireWildcard(obj) {
    if (obj && obj.__esModule) {
      return obj;
    } else {
      var newObj = {};
      if (obj != null) {
        for (var key in obj) {
          if (Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc =
              Object.defineProperty && Object.getOwnPropertyDescriptor
                ? Object.getOwnPropertyDescriptor(obj, key)
                : {};
            if (desc.get || desc.set) {
              Object.defineProperty(newObj, key, desc);
            } else {
              newObj[key] = obj[key];
            }
          }
        }
      }
      newObj.default = obj;
      return newObj;
    }
  }
  
  /**
   * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
   *
   * This source code is licensed under the MIT license found in the
   * LICENSE file in the root directory of this source tree.
   */
  var _default = async (rootDir = (0, _realpathNative().sync)(process.cwd())) => {
    // prerequisite checks
    const projectPackageJsonPath = path().join(rootDir, _constants.PACKAGE_JSON);
    const jestConfigPath = path().join(rootDir, _constants.JEST_CONFIG);
  
    if (!fs().existsSync(projectPackageJsonPath)) {
      throw new _errors.NotFoundPackageJsonError(rootDir);
    }
  
    const questions = _questions.default.slice(0);
  
    let hasJestProperty = false;
    let hasJestConfig = false;
    let projectPackageJson;
  
    try {
      projectPackageJson = JSON.parse(
        fs().readFileSync(projectPackageJsonPath, 'utf-8')
      );
    } catch (error) {
      throw new _errors.MalformedPackageJsonError(projectPackageJsonPath);
    }
  
    if (projectPackageJson.jest) {
      hasJestProperty = true;
    }
  
    if (fs().existsSync(jestConfigPath)) {
      hasJestConfig = true;
    }
  
    if (hasJestProperty || hasJestConfig) {
      const result = await (0, _prompts().default)({
        initial: true,
        message:
          'It seems that you already have a jest configuration, do you want to override it?',
        name: 'continue',
        type: 'confirm'
      });
  
      if (!result.continue) {
        console.log();
        console.log('Aborting...');
        return;
      }
    } // Add test script installation only if needed
  
    if (
      !projectPackageJson.scripts ||
      projectPackageJson.scripts.test !== 'jest'
    ) {
      questions.unshift(_questions.testScriptQuestion);
    } // Start the init process
  
    console.log();
    console.log(
      _chalk().default.underline(
        `The following questions will help Jest to create a suitable configuration for your project\n`
      )
    );
    let promptAborted = false; // @ts-ignore: Return type cannot be object - faulty typings
  
    const results = await (0, _prompts().default)(questions, {
      onCancel: () => {
        promptAborted = true;
      }
    });
  
    if (promptAborted) {
      console.log();
      console.log('Aborting...');
      return;
    }
  
    const shouldModifyScripts = results.scripts;
  
    if (shouldModifyScripts || hasJestProperty) {
      const modifiedPackageJson = (0, _modify_package_json.default)({
        projectPackageJson,
        shouldModifyScripts
      });
      fs().writeFileSync(projectPackageJsonPath, modifiedPackageJson);
      console.log('');
      console.log(
        `✏️  Modified ${_chalk().default.cyan(projectPackageJsonPath)}`
      );
    }
  
    const generatedConfig = (0, _generate_config_file.default)(results);
    fs().writeFileSync(jestConfigPath, generatedConfig);
    console.log('');
    console.log(
      `📝  Configuration file created at ${_chalk().default.cyan(jestConfigPath)}`
    );
  };
  
  exports.default = _default;
  