// This file is generated by codegen/index.ts
// Do not edit this file manually
import { Command, Option } from 'clipanion'

export abstract class BaseBuildCommand extends Command {
  static paths = [['build']]

  static usage = Command.Usage({
    description: 'Build the NAPI-RS project',
  })

  target?: string = Option.String('--target,-t', {
    description:
      'Build for the target triple, bypassed to `cargo build --target`',
  })

  cwd?: string = Option.String('--cwd', {
    description:
      'The working directory of where napi command will be executed in, all other paths options are relative to this path',
  })

  manifestPath?: string = Option.String('--manifest-path', {
    description: 'Path to `Cargo.toml`',
  })

  configPath?: string = Option.String('--config-path,-c', {
    description: 'Path to `napi` config json file',
  })

  packageJsonPath?: string = Option.String('--package-json-path', {
    description: 'Path to `package.json`',
  })

  targetDir?: string = Option.String('--target-dir', {
    description:
      'Directory for all crate generated artifacts, see `cargo build --target-dir`',
  })

  outputDir?: string = Option.String('--output-dir,-o', {
    description:
      'Path to where all the built files would be put. Default to the crate folder',
  })

  platform?: boolean = Option.Boolean('--platform', {
    description:
      'Add platform triple to the generated nodejs binding file, eg: `[name].linux-x64-gnu.node`',
  })

  jsPackageName?: string = Option.String('--js-package-name', {
    description:
      'Package name in generated js binding file. Only works with `--platform` flag',
  })

  constEnum?: boolean = Option.Boolean('--const-enum', {
    description: 'Whether generate const enum for typescript bindings',
  })

  runtimeStringEnum?: boolean = Option.Boolean('--runtime-string-enum', {
    description:
      'Emit `#[napi(string_enum)]` enums as runtime enums (`export declare enum`) under `--no-const-enum`. Default: type-only union.',
  })

  jsBinding?: string = Option.String('--js', {
    description:
      'Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output-dir`.',
  })

  noJsBinding?: boolean = Option.Boolean('--no-js', {
    description:
      'Whether to disable the generation JS binding file. Only works with `--platform` flag.',
  })

  dts?: string = Option.String('--dts', {
    description:
      'Path and filename of generated type def file. Relative to `--output-dir`',
  })

  dtsHeader?: string = Option.String('--dts-header', {
    description:
      'Custom file header for generated type def file. Only works when `typedef` feature enabled.',
  })

  noDtsHeader?: boolean = Option.Boolean('--no-dts-header', {
    description:
      'Whether to disable the default file header for generated type def file. Only works when `typedef` feature enabled.',
  })

  dtsCache = Option.Boolean('--dts-cache', true, {
    description: 'Whether to enable the dts cache, default to true',
  })

  esm?: boolean = Option.Boolean('--esm', {
    description:
      'Whether to emit an ESM JS binding file instead of CJS format. Only works with `--platform` flag.',
  })

  strip?: boolean = Option.Boolean('--strip,-s', {
    description: 'Whether strip the library to achieve the minimum file size',
  })

  release?: boolean = Option.Boolean('--release,-r', {
    description: 'Build in release mode',
  })

  verbose?: boolean = Option.Boolean('--verbose,-v', {
    description: 'Verbosely log build command trace',
  })

  bin?: string = Option.String('--bin', {
    description: 'Build only the specified binary',
  })

  package?: string = Option.String('--package,-p', {
    description: 'Build the specified library or the one at cwd',
  })

  profile?: string = Option.String('--profile', {
    description: 'Build artifacts with the specified profile',
  })

  crossCompile?: boolean = Option.Boolean('--cross-compile,-x', {
    description:
      '[experimental] cross compile by replacing the cargo subcommand: Windows MSVC targets from a non-Windows host build with `cargo-xwin` (`windows-gnu` targets are rejected, `cargo-xwin` cannot handle them), non-Windows targets build with `cargo-zigbuild` (requires `zig` on PATH). The selected subcommand is auto-installed on first use. Cannot be combined with `--use-cross`, `--use-napi-cross` or `--watch`',
  })

  useCross?: boolean = Option.Boolean('--use-cross', {
    description:
      '[experimental] not recommended, prefer `--cross-compile` or `--use-napi-cross`: build in a Docker or Podman container with [cross](https://github.com/cross-rs/cross), which must be installed manually and needs a running container engine. Cannot be combined with `--cross-compile`, `--use-napi-cross` or `--watch`',
  })

  useNapiCross?: boolean = Option.Boolean('--use-napi-cross', {
    description:
      '[experimental] download a prebuilt gcc cross toolchain from `@napi-rs/cross-toolchain` (glibc 2.17) and set linker and C compiler environment variables. Linux glibc targets only (x64, arm64, armv7, ppc64le, s390x) on a Linux x64 or arm64 host, any other target or host errors. Cannot be combined with `--cross-compile` or `--use-cross`',
  })

  watch?: boolean = Option.Boolean('--watch,-w', {
    description:
      'watch the crate changes and build continuously with `cargo-watch` crates',
  })

  features?: string[] = Option.Array('--features,-F', {
    description: 'Space-separated list of features to activate',
  })

  allFeatures?: boolean = Option.Boolean('--all-features', {
    description: 'Activate all available features',
  })

  noDefaultFeatures?: boolean = Option.Boolean('--no-default-features', {
    description: 'Do not activate the `default` feature',
  })

  getOptions() {
    return {
      target: this.target,
      cwd: this.cwd,
      manifestPath: this.manifestPath,
      configPath: this.configPath,
      packageJsonPath: this.packageJsonPath,
      targetDir: this.targetDir,
      outputDir: this.outputDir,
      platform: this.platform,
      jsPackageName: this.jsPackageName,
      constEnum: this.constEnum,
      runtimeStringEnum: this.runtimeStringEnum,
      jsBinding: this.jsBinding,
      noJsBinding: this.noJsBinding,
      dts: this.dts,
      dtsHeader: this.dtsHeader,
      noDtsHeader: this.noDtsHeader,
      dtsCache: this.dtsCache,
      esm: this.esm,
      strip: this.strip,
      release: this.release,
      verbose: this.verbose,
      bin: this.bin,
      package: this.package,
      profile: this.profile,
      crossCompile: this.crossCompile,
      useCross: this.useCross,
      useNapiCross: this.useNapiCross,
      watch: this.watch,
      features: this.features,
      allFeatures: this.allFeatures,
      noDefaultFeatures: this.noDefaultFeatures,
    }
  }
}

/**
 * Build the NAPI-RS project
 */
export interface BuildOptions {
  /**
   * Build for the target triple, bypassed to `cargo build --target`
   */
  target?: string
  /**
   * The working directory of where napi command will be executed in, all other paths options are relative to this path
   */
  cwd?: string
  /**
   * Path to `Cargo.toml`
   */
  manifestPath?: string
  /**
   * Path to `napi` config json file
   */
  configPath?: string
  /**
   * Path to `package.json`
   */
  packageJsonPath?: string
  /**
   * Directory for all crate generated artifacts, see `cargo build --target-dir`
   */
  targetDir?: string
  /**
   * Path to where all the built files would be put. Default to the crate folder
   */
  outputDir?: string
  /**
   * Add platform triple to the generated nodejs binding file, eg: `[name].linux-x64-gnu.node`
   */
  platform?: boolean
  /**
   * Package name in generated js binding file. Only works with `--platform` flag
   */
  jsPackageName?: string
  /**
   * Whether generate const enum for typescript bindings
   */
  constEnum?: boolean
  /**
   * Emit `#[napi(string_enum)]` enums as runtime enums (`export declare enum`) under `--no-const-enum`. Default: type-only union.
   */
  runtimeStringEnum?: boolean
  /**
   * Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output-dir`.
   */
  jsBinding?: string
  /**
   * Whether to disable the generation JS binding file. Only works with `--platform` flag.
   */
  noJsBinding?: boolean
  /**
   * Path and filename of generated type def file. Relative to `--output-dir`
   */
  dts?: string
  /**
   * Custom file header for generated type def file. Only works when `typedef` feature enabled.
   */
  dtsHeader?: string
  /**
   * Whether to disable the default file header for generated type def file. Only works when `typedef` feature enabled.
   */
  noDtsHeader?: boolean
  /**
   * Whether to enable the dts cache, default to true
   *
   * @default true
   */
  dtsCache?: boolean
  /**
   * Whether to emit an ESM JS binding file instead of CJS format. Only works with `--platform` flag.
   */
  esm?: boolean
  /**
   * Whether strip the library to achieve the minimum file size
   */
  strip?: boolean
  /**
   * Build in release mode
   */
  release?: boolean
  /**
   * Verbosely log build command trace
   */
  verbose?: boolean
  /**
   * Build only the specified binary
   */
  bin?: string
  /**
   * Build the specified library or the one at cwd
   */
  package?: string
  /**
   * Build artifacts with the specified profile
   */
  profile?: string
  /**
   * [experimental] cross compile by replacing the cargo subcommand: Windows MSVC targets from a non-Windows host build with `cargo-xwin` (`windows-gnu` targets are rejected, `cargo-xwin` cannot handle them), non-Windows targets build with `cargo-zigbuild` (requires `zig` on PATH). The selected subcommand is auto-installed on first use. Cannot be combined with `--use-cross`, `--use-napi-cross` or `--watch`
   */
  crossCompile?: boolean
  /**
   * [experimental] not recommended, prefer `--cross-compile` or `--use-napi-cross`: build in a Docker or Podman container with [cross](https://github.com/cross-rs/cross), which must be installed manually and needs a running container engine. Cannot be combined with `--cross-compile`, `--use-napi-cross` or `--watch`
   */
  useCross?: boolean
  /**
   * [experimental] download a prebuilt gcc cross toolchain from `@napi-rs/cross-toolchain` (glibc 2.17) and set linker and C compiler environment variables. Linux glibc targets only (x64, arm64, armv7, ppc64le, s390x) on a Linux x64 or arm64 host, any other target or host errors. Cannot be combined with `--cross-compile` or `--use-cross`
   */
  useNapiCross?: boolean
  /**
   * watch the crate changes and build continuously with `cargo-watch` crates
   */
  watch?: boolean
  /**
   * Space-separated list of features to activate
   */
  features?: string[]
  /**
   * Activate all available features
   */
  allFeatures?: boolean
  /**
   * Do not activate the `default` feature
   */
  noDefaultFeatures?: boolean
}

export function applyDefaultBuildOptions(options: BuildOptions) {
  return {
    dtsCache: true,
    ...options,
  }
}
