'use strict';

var chunkLP4HYSF4_cjs = require('./chunk-LP4HYSF4.cjs');
var chunk2ITILIBC_cjs = require('./chunk-2ITILIBC.cjs');
var chunk3MH6X7IX_cjs = require('./chunk-3MH6X7IX.cjs');
var chunkUJJENY47_cjs = require('./chunk-UJJENY47.cjs');
var chunkAF3E2D32_cjs = require('./chunk-AF3E2D32.cjs');
var types = require('@storm-software/config-tools/types');
var unbuild = require('@storm-software/unbuild');
var defu = require('defu');

var Plugin = class {
  static {
    chunkAF3E2D32_cjs.__name(this, "Plugin");
  }
  /**
  * The name of the plugin
  */
  name;
  /**
  * The name of the plugin
  */
  installPath;
  /**
  * The logger function to use
  */
  log;
  /**
  * 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.endsWith("plugin")) {
      this.name = this.name.replace(/plugin$/, "").trim();
    }
    this.log = chunk3MH6X7IX_cjs.createLog(`${this.name}-plugin`);
    this.installPath = installPath || `@storm-stack/plugin-${this.name}`;
    if (!installPath) {
      this.log(types.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(types.LogLevelLabel.TRACE, `Writing file ${filepath} to disk`);
    return chunkUJJENY47_cjs.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 chunk2ITILIBC_cjs.installPackage(this.log, context, packageName, dev);
  }
  /**
  * Builds the Storm Stack project
  *
  * @param context - The resolved Storm Stack context
  */
  async build(context) {
    this.log(types.LogLevelLabel.TRACE, "Building Storm Stack project");
    if (context.projectType === "library" || context.projectType === "adapter") {
      await this.buildLib(context);
    } else {
      await this.buildApp(context);
    }
  }
  /**
  * Run the build process for application projects
  *
  * @param _context - The resolved Storm Stack context
  */
  async buildApp(_context) {
    this.log(types.LogLevelLabel.WARN, "Skipping build for project - this plugin does not support application builds");
  }
  /**
  * Run the unbuild process for library builds
  *
  * @param context - The unbuild context
  */
  async buildLib(context) {
    return unbuild.build(defu.defu(context.override, {
      projectRoot: context.projectRoot,
      outputPath: context.outputPath || "dist",
      platform: context.platform,
      generatePackageJson: true,
      minify: Boolean(context.minify),
      sourcemap: context.mode === "production",
      loaders: [
        chunkLP4HYSF4_cjs.getUnbuildLoader(context)
      ],
      env: context.resolvedDotenv.values
    }));
  }
};

exports.Plugin = Plugin;
//# sourceMappingURL=chunk-7IMBVNN5.cjs.map
//# sourceMappingURL=chunk-7IMBVNN5.cjs.map