Home Reference Source
public class | source

ProjextPlugin

This service handles all interaction between the plugin and projext. It takes care of validating if projext is installed, registering the necessary events and generating the build commands for when the plugin is used on a development environment.

Constructor Summary

Public Constructor
public

constructor(info: Object, runnerFile: RunnerFile)

Class constructor.

Member Summary

Public Members
public

The name of the plugin as it's defined on the package.json. It's used on the generated build command(s) as the --plugin option.

public

A local reference for the runnerFile service.

Private Members
private

The name of the option flag the service will add on the build commands.

Method Summary

Public Methods
public

get(service: string): *

Get a service from projext.

public

getBuildCommand(args: Object, environmentVariables: string): string

Generate a projext build command.

public

getBuildCommandForTarget(target: string | Array, args: Object, environmentVariables: string): Array

Generate a projext build command for one or more targets.

public

Check whether projext is installed or not.

public

registerPlugin(instance: Projext)

Register all the necessary events for the plugin to work:

  • Update the target information on the runner file when the target build command is generated.
Private Methods
private

Detect whether or not projext is installed on the current environment.

private

Get an instance of projext by requiring the module.

private

If projext is installed but the plugin wasn't registerd (probably because the plugin was executed from its own CLI), this method will try to set the instance by requiring the module.

private

_setInstance(instance: Projext)

Set the projext instance.

private

_updateBuildCommands(commands: Array, params: CLIBuildCommandParams, unknownOptions: Object): Array

This method gets called when projext is creating the build commands for a target.

private

This method gets called when projext is copying the project files to the distribution directory.

private

This method gets called when projext is generating a revision file and it takes care of updating the runner file with the generated version.

Public Constructors

public constructor(info: Object, runnerFile: RunnerFile) source

Class constructor.

Params:

NameTypeAttributeDescription
info Object

The plugin's package.json. The service uses it to get the name and send it on the build commands as the --plugin flag.

runnerFile RunnerFile

To be able to update the runner file when a target is built.

Public Members

public pluginName: string source

The name of the plugin as it's defined on the package.json. It's used on the generated build command(s) as the --plugin option. The flag is verified by the plugin in order to building dependencies (other targets) when a target is running on a development environment.

public runnerFile: RunnerFile source

A local reference for the runnerFile service.

Private Members

private _pluginFlagName: string source

The name of the option flag the service will add on the build commands.

Public Methods

public get(service: string): * source

Get a service from projext.

Params:

NameTypeAttributeDescription
service string

The service name.

Return:

*

Throw:

Error

If the plugin hasn't been registered.

public getBuildCommand(args: Object, environmentVariables: string): string source

Generate a projext build command. If not overwritten by the args parameter, this method sends an empty target and a plugin argument with the value of the pluginName property.

Params:

NameTypeAttributeDescription
args Object

A dictionary of arguments and their values to send on the command.

environmentVariables string
  • optional
  • default: ''

Environment variables to prefix the command with. For example: NODE_ENV=production

Return:

string

Throw:

Error

If projext is not installed and/or it couldn't access is instance.

public getBuildCommandForTarget(target: string | Array, args: Object, environmentVariables: string): Array source

Generate a projext build command for one or more targets.

Params:

NameTypeAttributeDescription
target string | Array

A target name or a list of them.

args Object
  • optional
  • default: {}

A dictionary of arguments and their values to send on the command. If this dictionary contains a target key, it will be ignored and removed, since it's the one used to send the target name this method uses as parameter.

environmentVariables string
  • optional
  • default: ''

Environment variables to prefix the command with. For example: NODE_ENV=production.

Return:

Array

No matter if you used a single (string) target or a list (Array), it will always return a list (Array) of commands.

public isInstalled(): boolean source

Check whether projext is installed or not.

Return:

boolean

public registerPlugin(instance: Projext) source

Register all the necessary events for the plugin to work:

  • Update the target information on the runner file when the target build command is generated.
  • Add the runner file to the list of files projext copies.
  • Update the runner file version when the revision file is created.

Params:

NameTypeAttributeDescription
instance Projext

The projext instance that is registering the plugin.

Private Methods

private _detectInstallation(): boolean source

Detect whether or not projext is installed on the current environment.

Return:

boolean

private _getInstalledInstance(): Projext source

Get an instance of projext by requiring the module.

Return:

Projext (nullable: true)

If something is wrong with the module or projext is not installed, it will return null.

private _loadInstalledInstanceIfNeeded() source

If projext is installed but the plugin wasn't registerd (probably because the plugin was executed from its own CLI), this method will try to set the instance by requiring the module.

private _setInstance(instance: Projext) source

Set the projext instance.

Params:

NameTypeAttributeDescription
instance Projext

The projext instance accessed either from registering the plugin or by requiring the module directly.

private _updateBuildCommands(commands: Array, params: CLIBuildCommandParams, unknownOptions: Object): Array source

This method gets called when projext is creating the build commands for a target. It takes care of updating the runner file with the target information and, if the target needs other targes to be built first in order to run, injecting the commands for building those targets.

Params:

NameTypeAttributeDescription
commands Array

The list of commands projext uses to build and run the target.

params CLIBuildCommandParams

A dictionary with all the required information the service needs to run the command: The target information, the build type, whether or not the target will be executed, etc.

unknownOptions Object

Like options, this is also a dictionary of options the original command received, the difference is that these ones are unknown by the command, as they were probably injected by an event. In this case, the method checks if the plugin option the getBuildCommand method adds is present in order to determine whether it should add the build commands for the dependencies or not.

Return:

Array

The updated list of commands.

private _updateCopyList(list: Array): Array source

This method gets called when projext is copying the project files to the distribution directory. It just adds the runner file to the list and returns it.

Params:

NameTypeAttributeDescription
list Array

The list of files projext is going to copy.

Return:

Array

An updated list of files, with the runner file on it.

private _updateFileVersion(version: string) source

This method gets called when projext is generating a revision file and it takes care of updating the runner file with the generated version.

Params:

NameTypeAttributeDescription
version string

The new version for the revision file.