'use strict';

var BRSAP7LG_cjs = require('./BRSAP7LG.cjs');
var U7VZULNU_cjs = require('./U7VZULNU.cjs');

// src/commands/utility/sui-like.ts
U7VZULNU_cjs.init_cjs_shims();
var permissionFixScripts = [
  "chmod -R 777 build",
  "find build -type f -exec chmod 644 {} +",
  "chmod 644 Move.lock"
];
var SuiWrapper = class {
  static {
    U7VZULNU_cjs.__name(this, "SuiWrapper");
  }
  command;
  configScript;
  defaultVolumes;
  constructor(command, configScript, defaultVolumes) {
    this.command = command;
    this.configScript = configScript;
    this.defaultVolumes = defaultVolumes;
  }
  async run(subcommand, args, options) {
    if (options.volumes.length) {
      throw new Error(`Volume option is not supported by the \`${this.command}\` wrapper`);
    }
    await this.initializeConfig(options);
    await this.downloadDependencies(subcommand, options);
    await BRSAP7LG_cjs.executeToolCommand(this.command, [
      "move",
      subcommand,
      "--skip-fetch-latest-git-deps",
      ...args
    ], {
      ...options,
      volumes: this.defaultVolumes
    });
    await this.fixArtifactPermissions(options);
  }
  // Initialize config in the Docker volume if it doesn't exist.
  async initializeConfig(options) {
    await BRSAP7LG_cjs.executeToolCommand(this.command, [
      "-c",
      this.configScript
    ], {
      ...options,
      volumes: this.defaultVolumes.map((volume) => ({
        ...volume,
        locked: true
      })),
      customEntrypoint: "/bin/sh"
    });
  }
  // Fetch dependencies into the shared Docker volume with a lock.
  // TODO Fetch dependencies with a read write lock.
  async downloadDependencies(subcommand, options) {
    await BRSAP7LG_cjs.executeToolCommand(this.command, [
      "move",
      subcommand,
      "--fetch-deps-only"
    ], {
      ...options,
      volumes: this.defaultVolumes.map((volume) => ({
        ...volume,
        locked: true
      }))
    });
  }
  async fixArtifactPermissions(options) {
    for (const script of permissionFixScripts) {
      await BRSAP7LG_cjs.executeToolCommand(this.command, [
        "-c",
        script
      ], {
        ...options,
        customEntrypoint: "/bin/sh"
      });
    }
  }
};

exports.SuiWrapper = SuiWrapper;
//# sourceMappingURL=L2LY6RIT.cjs.map
//# sourceMappingURL=L2LY6RIT.cjs.map