import {ProjextPlugin} from 'projext-plugin-runner/src/services/utils/projextPlugin.js'
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 |
|
public |
A local reference for the |
Private Members | ||
private |
The name of the option flag the service will add on the build commands. |
Method Summary
Public Methods | ||
public |
Get a service from projext. |
|
public |
getBuildCommand(args: Object, environmentVariables: string): string Generate a projext build command. |
|
public |
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:
|
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 |
_updateCopyList(list: Array): Array This method gets called when projext is copying the project files to the distribution directory. |
|
private |
_updateFileVersion(version: string) 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:
Name | Type | Attribute | Description |
info | Object | The plugin's |
|
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.
Private Members
Public Methods
public get(service: string): * source
Get a service from projext.
Params:
Name | Type | Attribute | Description |
service | string | The service name. |
Return:
* |
Throw:
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.
Throw:
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:
Name | Type | Attribute | Description |
target | string | Array | A target name or a list of them. |
|
args | Object |
|
A dictionary of arguments and their values to
send on the command. If this dictionary
contains a |
environmentVariables | string |
|
Environment variables to prefix the command
with. For example: |
Return:
Array | No matter if you used a single ( |
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:
Name | Type | Attribute | Description |
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.
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 |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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 |