'use strict';

var chunkAF3E2D32_cjs = require('./chunk-AF3E2D32.cjs');
var types = require('@storm-software/config-tools/types');
var install = require('@stryke/fs/install');
var packageFns = require('@stryke/fs/package-fns');
var isNumber = require('@stryke/type-checks/is-number');

async function installPackage(log, context, packageName, dev = false) {
  const isInstalled = await packageFns.isPackageListed(packageName, context.options.projectRoot);
  if (!isInstalled) {
    if (context.options.skipInstalls !== true) {
      log(types.LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
      const result = await install.install(packageName, {
        cwd: context.options.projectRoot,
        dev
      });
      if (isNumber.isNumber(result.exitCode) && result.exitCode > 0) {
        log(types.LogLevelLabel.ERROR, result.stderr);
        throw new Error(`An error occurred while installing the package "${packageName}"`);
      }
    } else {
      log(types.LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
    }
  }
}
chunkAF3E2D32_cjs.__name(installPackage, "installPackage");
async function installPackages(log, context, packages) {
  return Promise.all(packages.map(async (pkg) => installPackage(log, context, pkg.name, pkg.dev)));
}
chunkAF3E2D32_cjs.__name(installPackages, "installPackages");

exports.installPackage = installPackage;
exports.installPackages = installPackages;
//# sourceMappingURL=chunk-3ZX4WMIX.cjs.map
//# sourceMappingURL=chunk-3ZX4WMIX.cjs.map