import { installPackage } from './chunk-QZAEKS7V.js';
import { createLog } from './chunk-5S5JGJML.js';
import { writeFile } from './chunk-4SEZDGHZ.js';
import { __name } from './chunk-6AXVLTU5.js';
import { LogLevelLabel } from '@storm-software/config-tools/types';

var Plugin = class {
  static {
    __name(this, "Plugin");
  }
  /**
  * The name of the plugin
  */
  name;
  /**
  * The name of the plugin
  */
  installPath;
  /**
  * The logger function to use
  */
  log;
  /**
  * A list of plugin modules required as dependencies by the current Preset.
  *
  * @remarks
  * These plugins will be called prior to the current Preset.
  */
  dependencies = [];
  /**
  * The constructor for the plugin
  *
  * @param name - The name of the plugin
  * @param installPath - The path to install the plugin
  */
  constructor(name, installPath) {
    this.name = name.toLowerCase();
    if (this.name.startsWith("plugin-")) {
      this.name = this.name.replace(/^plugin-/, "").trim();
    } else if (this.name.endsWith("-plugin")) {
      this.name = this.name.replace(/-plugin$/, "").trim();
    }
    this.log = createLog(`${this.name}-plugin`);
    this.installPath = installPath || `@storm-stack/plugin-${this.name}`;
    if (!installPath) {
      this.log(LogLevelLabel.WARN, `No install path parameter provided to constructor for ${this.name} plugin. Will attempt to use "${this.installPath}".`);
    }
  }
  /**
  * Writes a file to the file system
  *
  * @param filepath - The file path to write the file
  * @param content - The content to write to the file
  * @param skipFormat - Should the plugin skip formatting the `content` string with Prettier
  */
  async writeFile(filepath, content, skipFormat = false) {
    this.log(LogLevelLabel.TRACE, `Writing file ${filepath} to disk`);
    return writeFile(this.log, filepath, content, skipFormat);
  }
  /**
  * Installs a package if it is not already installed.
  *
  * @param context - The resolved Storm Stack context
  * @param packageName - The name of the package to install
  * @param dev - Whether to install the package as a dev dependency
  */
  async install(context, packageName, dev = false) {
    return installPackage(this.log, context, packageName, dev);
  }
};

export { Plugin };
//# sourceMappingURL=chunk-7FL63SBR.js.map
//# sourceMappingURL=chunk-7FL63SBR.js.map