Skip to content

@dovenv/core - API documentation

Classes

Dovenv

Instance Dovenv.

This is the "dovenv" class that builds the command line interface.

It is similar to the cli tool but for use in js|ts projects.

Provides tools for managing configurations, constants, and path transformations etc. Supports custom configurations and predefined commands. Features:

  • Validate files or directories with custom rules.
  • Manage workspace constants efficiently.
  • Transform paths with configurable patterns.
  • Extend or override default behaviors with custom configurations.

See

https://dovenv.pigeonposse.com/guide/core

Example

ts
// Create an instance with custom configurations
const dovenv = new Dovenv({
  config: {
    check: {
      pkg: { include: ['src/**'], ... }
    },
  }
});

// Run a predefined action
await dovenv.run(['check', '-k', 'pkg']);

Constructors

new Dovenv()
ts
new Dovenv(params?: Params): Dovenv

Creates a new Dovenv instance.

Parameters
ParameterTypeDescription
params?ParamsOptional initialization parameters.
Returns

Dovenv

Methods

run()
ts
run(args: string[]): Promise<void>

Runs the build process with the given arguments.

Parameters
ParameterTypeDefault valueDescription
argsstring[][]Arguments to pass to the run process.
Returns

Promise<void>

Example
ts
const dovenv = new Dovenv({
  config: {
    check: {
      pkg: {...}
    },
    ...
  }
})
await dovenv.run(['check', '-k', 'pkg'])

Properties

PropertyTypeDescription
configundefined | ConfigConfiguration object for commands and options of the Dovenv instance.
dovenvConfigPathundefined | stringContains Dovenv config path. This property is used for user information purposes only. If the "config" option is added via the class constructor, this option will be undefined. In this case you can change its value, but this may alter the behavior of the class. Do so at your own risk.

PluginCore<Opts>

Plugin core class.

  • Contains the plugin utilities, styles etc.
  • Makes it easy to create plugins.

See

https://dovenv.pigeonposse.com/guide/plugin

Extends

  • CommandSuper<Opts>

Type Parameters

Type ParameterDefault type
Optsundefined

Constructors

new PluginCore()
ts
new PluginCore<Opts>(opts?: Opts, config?: Config): PluginCore<Opts>
Parameters
ParameterType
opts?Opts
config?Config
Returns

PluginCore<Opts>

Overrides

CommandSuper<Opts>.constructor

Properties

PropertyTypeDefault valueDescriptionOverridesInherited from
configundefined | ConfigundefinedThe dovenv configuration.-CommandSuper.config
optsundefined | OptsundefinedConfiguration options.-CommandSuper.opts
titlestring'plugin'The title of the application. Use in internal logs and functions.CommandSuper.title-

Functions

createPlugin()

ts
function createPlugin<Param>(fn: (data: {
  param: Param;
  utils: PluginCore<Param>;
 }) => Config, dovenvConfig?: Config): (param?: Param) => Config

Create a plugin function.

Type Parameters

Type ParameterDefault typeDescription
ParamunknownThe type of the arguments to be passed to the plugin.

Parameters

ParameterTypeDescription
fn(data: { param: Param; utils: PluginCore<Param>; }) => ConfigThe plugin function.
dovenvConfig?ConfigAdd a previous dovenv configuration if you need it.

Returns

Function

  • The plugin function that can be passed to the dovenv.
Parameters
ParameterType
param?Param
Returns

Config

Example

ts
import { createPlugin } from '@dovenv/core'

const plugin = createPlugin<{ title?: boolean }>( data => {
	 if ( data.param?.title ) {
		console.log( data.utils.style.title( 'Hello from plugin' ) )
	 }

	return {
		// Your dovenv configuration here.
	}
} )

defineConfig()

ts
function defineConfig(...config: (Config | Config[])[]): Config

Defines and returns the given configuration object.

Parameters

ParameterTypeDescription
...config(Config | Config[])[]The configuration object to define.

Returns

Config

  • The defined configuration object.

See

https://dovenv.pigeonposse.com/guide/core


Examples

ts
// Example 1: A single configuration object
export default defineConfig(config1);
ts
// Example 2: Multiple configurations as arguments
export default defineConfig(config1, config2);
ts
// Example 3: An array of configurations
export default defineConfig([config1, config2]);

run()

ts
function run(args: string[]): Promise<void>

Runs the build process with the given arguments.

Parameters

ParameterTypeDescription
argsstring[]Arguments to pass to the build process.

Returns

Promise<void>

Example

ts
import { run } from '@dovenv/core'

await run(['-c', 'my/config.js', 'check'])

Type Aliases

Config

ts
type Config: {
  alias: AliasesConfig;
  check: CheckConfig;
  const: ConstConfig;
  custom: CustomConfig;
  desc: string;
  name: string;
  transform: TransformConfig;
};

Type declaration

NameTypeDescription
alias?AliasesConfigConfiguration for the aliases
check?CheckConfigConfiguration for the check command
const?ConstConfigConfiguration for set the constants used in templates
custom?CustomConfigConfiguration for create custom commands
desc?stringDescription of the project
name?stringName of the project
transform?TransformConfigConfiguration for the transform command

Params

ts
type Params: {
  config: Config;
};

Type declaration

NameTypeDescription
config?ConfigConfiguration for dovenv See https://dovenv.pigeonposse.com/guide/core/api#config