Home Manual Reference Source
public class | source

Targets

This service is in charge of loading and managing the project targets information.

Constructor Summary

Public Constructor
public

constructor(dotEnvUtils: DotEnvUtils, events: Events, environmentUtils: EnvironmentUtils, packageInfo: Object, pathUtils: PathUtils, projectConfiguration: ProjectConfigurationSettings, rootRequire: RootRequire, utils: Utils)

Member Summary

Public Members
public

The default type a target will be if it doesn't have a type property.

public

A local reference for the dotEnvUtils service.

public

A local reference for the environmentUtils service.

public

A local reference for the events service.

public

The information of the project's package.json.

public

A local reference for the pathUtils service.

public

All the project settings.

public

A local reference for the rootRequire function service.

public

A dictionary that will be filled with the targets information.

public

A simple regular expression to validate a target type.

public

A local reference for the utils service.

Method Summary

Public Methods
public

Find a target by a given filepath.

public

Gets an 'App Configuration' for a browser target.

public

Returns the target with the name of project (specified on the package.json) and if there's no target with that name, then the first one, using a list of the targets name on alphabetical order.

public

getFilesToCopy(target: Target, buildType: string): Array

Gets a list with the information for the files the target needs to copy during the bundling process.

public

Get a target information by its name.

public

Get all the registered targets information on a dictionary that uses their names as keys.

public

loadTargetDotEnvFile(target: Target, buildType: string, inject: boolean): Object

Loads the environment file(s) for a target and, if specified, inject their variables.

public

Loads and build the target information.

public

Validate whether a target exists or not.

Public Constructors

public constructor(dotEnvUtils: DotEnvUtils, events: Events, environmentUtils: EnvironmentUtils, packageInfo: Object, pathUtils: PathUtils, projectConfiguration: ProjectConfigurationSettings, rootRequire: RootRequire, utils: Utils) source

Params:

NameTypeAttributeDescription
dotEnvUtils DotEnvUtils

To read files with environment variables for the targets and inject them.

events Events

Used to reduce a target information after loading it.

environmentUtils EnvironmentUtils

To send to the configuration service used by the browser targets.

packageInfo Object

The project's package.json, necessary to get the project's name and use it as the name of the default target.

pathUtils PathUtils

Used to build the targets paths.

projectConfiguration ProjectConfigurationSettings

To read the targets and their templates.

rootRequire RootRequire

To send to the configuration service used by the browser targets.

utils Utils

To replace plaholders on the targets paths.

Public Members

public defaultType: string source

The default type a target will be if it doesn't have a type property.

public dotEnvUtils: DotEnvUtils source

A local reference for the dotEnvUtils service.

public environmentUtils: EnvironmentUtils source

A local reference for the environmentUtils service.

public events: Events source

A local reference for the events service.

public packageInfo: Object source

The information of the project's package.json.

public pathUtils: PathUtils source

A local reference for the pathUtils service.

public projectConfiguration: ProjectConfigurationSettings source

All the project settings.

public rootRequire: RootRequire source

A local reference for the rootRequire function service.

public targets: Object source

A dictionary that will be filled with the targets information.

public typesValidationRegex: RegExp source

A simple regular expression to validate a target type.

public utils: Utils source

A local reference for the utils service.

Public Methods

public findTargetForFile(file: string): Target source

Find a target by a given filepath.

Params:

NameTypeAttributeDescription
file string

The path of the file that should match with a target path.

Return:

Target

Throw:

Error

If no target is found.

public getBrowserTargetConfiguration(target: Target): Object source

Gets an 'App Configuration' for a browser target. This is a utility projext provides for browser targets as they can't load configuration files dynamically, so on the building process, projext uses this service to load the configuration and then injects it on the target bundle.

Params:

NameTypeAttributeDescription
target Target

The target information.

Return:

Object

Return Properties:

NameTypeAttributeDescription
configuration Object

The target 'App Configuration'.

files Array

The list of files loaded in order to create the configuration.

Throw:

Error

If the given target is not a browser target.

public getDefaultTarget(type: string): Target source

Returns the target with the name of project (specified on the package.json) and if there's no target with that name, then the first one, using a list of the targets name on alphabetical order.

Params:

NameTypeAttributeDescription
type string
  • optional
  • default: ''

A specific target type, node or browser.

Return:

Target

Throw:

Error

If the project has no targets

Error

If the project has no targets of the specified type.

Error

If a specified target type is invalid.

public getFilesToCopy(target: Target, buildType: string): Array source

Gets a list with the information for the files the target needs to copy during the bundling process. This method uses the target-copy-files reducer event, which receives the list of files to copy, the target information and the build type; it expects an updated list on return. The reducer event can be used to inject a TargetExtraFileTransform function.

Params:

NameTypeAttributeDescription
target Target

The target information.

buildType string
  • optional
  • default: 'development'

The type of bundle projext is generating.

Return:

Array

A list of TargetExtraFiles.

Throw:

Error

If the target type is node but bundling is disabled. There's no need to copy files on a target that doesn't require bundling.

Error

If one of the files to copy doesn't exist.

public getTarget(name: string): Target source

Get a target information by its name.

Params:

NameTypeAttributeDescription
name string

The target name.

Return:

Target

Throw:

Error

If there's no target with the given name.

public getTargets(): Object source

Get all the registered targets information on a dictionary that uses their names as keys.

Return:

Object

public loadTargetDotEnvFile(target: Target, buildType: string, inject: boolean): Object source

Loads the environment file(s) for a target and, if specified, inject their variables. This method uses the target-environment-variables reducer event, which receives the dictionary with the variables for the target, the target information and the build type; it expects an updated dictionary of variables in return.

Params:

NameTypeAttributeDescription
target Target

The target information.

buildType string
  • optional
  • default: 'development'

The type of bundle projext is generating or the environment a Node target is being executed for.

inject boolean
  • optional
  • default: true

Whether or not to inject the variables after loading them.

Return:

Object

A dictionary with the target variables that were injected in the environment.

public loadTargets() source

Loads and build the target information. This method emits the reducer event target-load with the information of a loaded target and expects an object with a target information on return.

Throw:

Error

If a target has a type but it doesn't match a supported type (node or browser).

Error

If a target requires bundling but there's no build engine installed.

public targetExists(name: string): boolean source

Validate whether a target exists or not.

Params:

NameTypeAttributeDescription
name string

The target name.

Return:

boolean