Commit c56d1dd0 authored by totara-thib's avatar totara-thib
Browse files

Resolve reviews

parent 19f97059
Loading
Loading
Loading
Loading
+32 −5
Original line number Diff line number Diff line
## Objective

This job will permits users to run several scripts from their `package.json` file using `npm`. Scripts can be used with args.
This job allows users to run several scripts from their `package.json` file using `npm`. Scripts can be used with args.


## How to use it
@@ -8,14 +8,16 @@ This job will permits users to run several scripts from their `package.json` fil
1. Make sure that your project has 
   [`package.json`](https://docs.npmjs.com/cli/v6/configuring-npm/package-json){:target="_blank"}
   file which contains predefined command in the `scripts` object
2. If you want the job to run scripts make sure to add them inside the `variable` `NPM_SCRIPTS` and separate every command with `;`
3. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
1. If you want the job to run scripts make sure to add them inside the `variable` `NPM_SCRIPTS` and separate every command with `;`
1. The default stage is `others`, if you want to customize this stage depending of the scripts that you run, check the [stage
   customization](/use-the-hub/#use-custom-stage)
1. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/npm_scripts.yml'
    ```
4. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
1. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
5. You are done, the job is ready to use ! 😉
1. You are done, the job is ready to use ! 😉


## Job details
@@ -35,9 +37,34 @@ This job will permits users to run several scripts from their `package.json` fil
| Name | Description | Default |
| ---- | ----------- | ------- |
| `PROJECT_ROOT` | Path to the directory containing `package.json`  | `.` |
| `NPM_INSTALL_OPTIONS` | Additional options for `npm install` | ` ` |
| `NPM_SCRIPTS` | Value of several scripts specified in `package.json` that can be separated by `;` | ` ` |
| `NPM_OUTPUT` | Path to the output send by script specified in `package.json` | ` ` |

### Example to use several scripts

Following example of `.gitlab-ci.yml` file describes how to enable Gitlab pages
deployment using this job:

#### Scripts in Package.json
```yaml
  "scripts": {
    "build": "ng build",
    "lint": "ng lint"
  }
```
#### .gitlab-ci.yml
```yaml
stages:
  - others

include:
  - remote: 'https://jobs.r2devops.io/npm_scripts.yml'

npm_scripts:
  variables:
    NPM_SCRIPTS: "build;lint"
```

### Cache

+3 −0
Original line number Diff line number Diff line
@@ -12,11 +12,14 @@ npm_scripts:
    entrypoint: [""]
  variables:
    PROJECT_ROOT: "."
    NPM_INSTALL_OPTIONS: ""
    NPM_SCRIPTS: ""
    NPM_OUTPUT: ""
  script:
    # Working directory
    - cd $PROJECT_ROOT
    # install project dependencies
    - npm install $NPM_INSTALL_OPTIONS
    # Save default IFS
    - oldIFS=$IFS
    # Modifying IFS