# Usage summary

There are following lifecycle steps for `window-pain`-enabled application:
* on build machine:
** checkout application repository to local directory
** build the application into `nupkg`
* on target machine: 
** install `nupkg`
** install the application
** install additional configuration if needed
** uninstall installed application
** remove installed `nupkg`  


# Main methods

`window-pain` provides 3 main scripts:
- `install.cmd`       - installs the application 
- `installConfig.cmd` - installs application config from Git repository
- `uninstall.cms`     - uninstalls the application


# `install.cmd`


## Description

`install.cmd` installs the application from installed nupkg.
It takes following actions:
- copy files from installed nupkg to target directory for 32 and 64 systems (`c:\Program Files (x86)\apps\approot\code` or `c:\Program Files\apps\approot\code` )
- copy binaries (`node.exe`, `nssm.exe`, `winsw.exe`) required to run the application from `dist/` to application root directory (same as target).
- run `*.js` scripts located in application's `tools/scripts/preinstall/` directory
- install application as windows service using `winsw.exe` or `nssm.exe` (according to command line switches `-winsw` / `-nssm`)
- start the service (according to command line `-Start`/`-NoStart` switches)   
- run `*.js` scripts located in application's `tools/scripts/postinstall/` directory

`install.cmd` is dynamically generated during `npm run build` for the application.
Target path (and some other parameters) for the installation are hardcoded in it.


## Usage: 

`install.cmd` must be started from same directory in which `nuget install` command was run.
```
<installed_nupkg>\content\tools\install.cmd [<switches>] [<parameters>]
```

```
<installed_nupkg>\content\tools\install.cmd [-NoStart |-Start ][-winsw |-nssm ][-robocopy |-xcopy ] [<domain> <username> <password>]
```

Switches:

`-NoStart`  - disable automatic start of the service after install
`-Start`    - enable automatic start of the service after install (default)   
`-winsw`    - use `winsw.exe` tool to handle windows service (default)   
`-nssm`     - use `nssm.exe` tool to handle windows service
`-robocopy` - use `robocopy` utility to copy files (default)
`-xcopy`    - use `xcopy` to copy files   
All switches are case insensitive

Parameters:

`domain`    - domain name for the user to run the service (`.` for local user)
`username`  - user name to run the service (default is 'LocalSystem')
`password`  - password


Example:

```
appname\content\tools\install.cmd -NoStart . test test
```


# `installConfig.cmd`


## Description

`installConfig.cmd` allows to overwrite application default config after the installation with the config taken from Git repository.
`install.cmd` must run with `-NoStart` switch and started after `installConfig.cmd` finish in order to apply the config before the service started.


## Usage

`installConfig.cmd` must be started from the directory from which `nuget install` command was run.

```
<installed_nupkg>\content\tools\installConfig.cmd <env_name>\<app_name> <repo_name> <git_hostname_path> <branch> <username> <password>  
```

<env_name>          - config env name (example: `aaa`) 
<app_name>          - application name (example: `awl-client`)
<repo_name>         - Git repository name
<git_hostname_path> - hostname and path for Git repository
<branch>            - Git branch name
<username>          - Git username (required only to clone repository; not required if repository is already cloned)  
<password>          - Git password (required only to clone repository; not required if repository is already cloned) 

Example:

```
appname\content\tools\installConfig.cmd aaa\awl-data config github.com/orgname/config.git master username password                        
```


# `uninstall.cmd`

## Description

`uninstall.cmd` allows to uninstall the application (it does not touches installed nupkg and it must be deleted separately)
 
## Usage

`uninstall.cmd` must be started from the directory from which `nuget install` command was run.

```
<installed_nupkg>\content\tools\uninstall.cmd
```

`uninstall.cmd` has no parameters.
 
