Home Manual Reference Source Test
import InitCommand from 'atscm-cli/src/cli/commands/Init.js'
public class | source

InitCommand

Extends:

Command → InitCommand

The command invoked when running "init".

Test:

Constructor Summary

Public Constructor
public

constructor(name: string, description: string)

Creates a new InitCommand with the specified name and description.

Method Summary

Public Methods
public

Checks the version of this package against the "engines > atscm-cli" field of the newly installed atscm module's package file.

public

Checks if the given path contains an empty directory.

public

Creates a an empty package file at the given path.

public

getDefaultOptions(options: Object[]): *

Returns the default values for the given init options.

public

getOptions(modulePath: string, options: Object): Promise<Object, Error>

Resolves the needed options from the local atscm module and asks for them.

public

install(path: string, packages: string | string[]): Promise<undefined, Error>

Runs npm install --save-dev {packages} at the given path.

public

Installs any additional dependencies needed after writing files.

public

async installLocal(path: string, options: Object): Promise<undefined, Error>

Installs the local atscm module at the given path.

public

This command never requires an Liftoff.Environment.

public

run(cli: AtSCMCli): *

Creates a new atscm project.

public

runNpm(args: string[], options: Object): *

Runs npm with the given args.

public

writeFiles(modulePath: string, options: Object): Promise<{install: string[]}, Error>

Runs the local atscm module's init script. This script is stored in the atscm module inside out/init/init.

Inherited Summary

From class Command
public get

The minimum and maximum number of (non-option) arguments the command handles.

public get

The options available for the command.

public get

If an error should be thrown for unknown arguments.

public get

Returns the usage string for the command.

public

The command descriptions.

public

The command's name.

private

The command's raw options.

public

Returns true if the command requires a Liftoff.Environment before it can be run.

public

run(cli: AtSCMCli)

Runs the command with the current Cli instance.

Public Constructors

public constructor(name: string, description: string) source

Creates a new InitCommand with the specified name and description.

Override:

Command#constructor

Params:

NameTypeAttributeDescription
name string

The command's name.

description string

The command's description.

Public Methods

public checkCliVersion(env: Liftoff.Environment): Liftoff.Environment source

Checks the version of this package against the "engines > atscm-cli" field of the newly installed atscm module's package file.

Params:

NameTypeAttributeDescription
env Liftoff.Environment

The environment to check.

Return:

Liftoff.Environment

The environment to check.

Throw:

Error

Throws an error if the atscm-cli version does not match.

Test:

public checkDirectory(path: string, overwrite: boolean): Promise<string, Error> source

Checks if the given path contains an empty directory. OS specific temporary files (.DS_Store under macOS, thumbs under Windows) are ignored.

Params:

NameTypeAttributeDescription
path string

The path to check.

overwrite boolean
  • optional
  • default: false

If existing files should be overwritten.

Return:

Promise<string, Error>

Fulfilled with the valid directory's path, rejected if path contains no or a non-empty directory.

Test:

public createEmptyPackage(path: string): Promise<undefined, Error> source

Creates a an empty package file at the given path.

Params:

NameTypeAttributeDescription
path string

The location to create the package at.

Return:

Promise<undefined, Error>

Rejected if an error occurred while writing the file.

Test:

public getDefaultOptions(options: Object[]): * source

Returns the default values for the given init options.

Params:

NameTypeAttributeDescription
options Object[]

An array of init options to check.

Return:

*

public getOptions(modulePath: string, options: Object): Promise<Object, Error> source

Resolves the needed options from the local atscm module and asks for them. These options are stored in the atscm module inside out/init/options.

Params:

NameTypeAttributeDescription
modulePath string

The path to the local module to use.

options Object
  • optional

The options to use.

options.useDefaults boolean
  • optional
  • default: false

Use default values.

Return:

Promise<Object, Error>

Resolved with the chosen options.

Test:

public install(path: string, packages: string | string[]): Promise<undefined, Error> source

Runs npm install --save-dev {packages} at the given path.

Params:

NameTypeAttributeDescription
path string

The path to install packages at.

packages string | string[]

Names of the packages to install.

Return:

Promise<undefined, Error>

Rejected if installing failed, resolved otherwise.

Test:

public installDependencies(path: string, deps: string[]): Promise<undefined, Error> source

Installs any additional dependencies needed after writing files.

Params:

NameTypeAttributeDescription
path string

The path to install the dependencies at.

deps string[]

Names of the packages to install.

Return:

Promise<undefined, Error>

Rejected if installing failed, resolved otherwise.

Test:

public async installLocal(path: string, options: Object): Promise<undefined, Error> source

Installs the local atscm module at the given path.

Params:

NameTypeAttributeDescription
path string

The path to install the module at.

options Object

The options to use.

options.useBetaRelease boolean
  • optional
  • default: false

If beta versions should be used.

options.link boolean
  • optional
  • default: false

Link instead of installing.

Return:

Promise<undefined, Error>

Rejected if installing failed, resolved otherwise.

Test:

public requiresEnvironment(): boolean source

This command never requires an Liftoff.Environment.

Override:

Command#requiresEnvironment

Return:

boolean

Always false.

Test:

public run(cli: AtSCMCli): * source

Creates a new atscm project.

Override:

Command#run

Params:

NameTypeAttributeDescription
cli AtSCMCli

The current Cli instance.

Return:

*

Test:

public runNpm(args: string[], options: Object): * source

Runs npm with the given args.

Params:

NameTypeAttributeDescription
args string[]

The arguments to call npm with.

options Object

Options applied to the spawn call.

Return:

*

public writeFiles(modulePath: string, options: Object): Promise<{install: string[]}, Error> source

Runs the local atscm module's init script. This script is stored in the atscm module inside out/init/init.

Params:

NameTypeAttributeDescription
modulePath string

The path to the local module to use.

options Object

The options to apply (Received by calling InitCommand#getOptions).

Return:

Promise<{install: string[]}, Error>

Resolved with information on the further init steps (which dependencies are needed), rejected with an error if running the init script failed.

Test: