Commit c246405e authored by coconux's avatar coconux
Browse files

Update gulp job and documentation

parent 0843bb1d
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
## Objective

This job installs `npm` dependencies listed in your `package.json` and installs
also gulp to run your tasks.
This job installs `npm` or `yarn` dependencies listed in your `package.json` and installs
 gulp to run your tasks.
It exposes `node_modules` as cache to other jobs of your pipeline. It allows you to run
`npm install` only once in your pipeline.

@@ -11,7 +11,7 @@ It exposes `node_modules` as cache to other jobs of your pipeline. It allows you
   [`package.json`](https://docs.npmjs.com/cli/v6/configuring-npm/package-json){:target="_blank"}
   file which contains the requirements
1. Ensure that your project have
  [`gulpfile.js`](https://gulpjs.com/docs/en/getting-started/javascript-and-gulpfiles/#gulpfile-explained){:target="_blank"} file which contains your tasks
  [`gulpfile.js`](https://gulpjs.com/docs/en/getting-started/javascript-and-gulpfiles/#gulpfile-explained){:target="_blank"} or [`gulpfile.ts`](https://gulpjs.com/docs/en/getting-started/javascript-and-gulpfiles/#transpilation){:target="_blank"} file which contains your tasks
1. Add the corresponding URL to your `.gitlab-ci.yml` file (see [Getting
   started](/use-the-hub)). Example:
    ```yaml
@@ -44,11 +44,11 @@ It exposes `node_modules` as cache to other jobs of your pipeline. It allows you

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PROJECT_ROOT` | Path to the directory containing `package.json`  | `.` |
| `NPM_INSTALL_OPTIONS` | Additional options for `npm install` | ` ` |
| `GULPFILE_PATH` | Path (from `PROJECT_ROOT`) to your  gulpfile `gulpfile.js` or `gulpfile.ts` or `gulpfile.babel.js`| ` ` |
| `GULP_TASKS` | List of your tasks to run with `gulp` (separated by ; ). *Ex: "minify-css; minify-js;"* | ` ` |

| `PROJECT_ROOT` <img width=70/>| Path to the directory containing `package.json`  | `.` |
| `PACKAGE_MANAGER` | Package manager to install your dependencies `npm` or `yarn`  | `npm` |
| `INSTALL_OPTIONS` | Additional options for the installation of `PACKAGE_MANAGER` <br/> *Ex: For npm `--save-dev`*  | ` ` |
| `GULPFILE_PATH` | Path (from `PROJECT_ROOT`) to your  gulpfile `gulpfile.js` or `gulpfile.ts`| ` ` |
| `GULP_TASKS` | List of your tasks to run with `gulp` (separated by ; ). <br/> *Ex: "minify-css; minify-js;"* | ` ` |


### Cache
@@ -58,7 +58,7 @@ applied, cache behavior is the following:

* Shared between all jobs and pipelines on the same branch
* Contains folder `$PROJECT_ROOT/node_modules`
* If `npm install` produces different result than the cached content
* If `npm install` or `yarn install` produces different result than the cached content

More information on Gitlab caching mechanism in [Gitlab CI/CD caching
documentation](https://docs.gitlab.com/ee/ci/caching/index.html).
+16 −8
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ cache:
  key:
    files:
      - "${PROJECT_ROOT}/package.json"
    prefix: "npm-${CI_COMMIT_REF_SLUG}"
    prefix: "$PACKAGE_MANAGER-${CI_COMMIT_REF_SLUG}"
  paths:
    - "${PROJECT_ROOT}/node_modules"
  when: "on_success"
@@ -16,7 +16,8 @@ gulp:
  stage: others
  variables:
    PROJECT_ROOT: "."
    NPM_INSTALL_OPTIONS: ""
    PACKAGE_MANAGER: "npm"
    INSTALL_OPTIONS: ""
    GULPFILE_PATH: "."
    GULP_TASKS: ""
    OUTPUT_FOLDER: "./build/"
@@ -29,12 +30,19 @@ gulp:
  script:
    # Working directory
    - cd $PROJECT_ROOT
    # Run npm install
    - npm install $NPM_INSTALL_OPTIONS
    # Install gulp
    - npm install -g gulp-cli
    # Install alternative of gulpfile.js .ts .babel.js
    - npm install -D ts-node typescript @types/gulp
    # Run npm or yarn install
    -   $PACKAGE_MANAGER install $INSTALL_OPTIONS

    # Install global gulp for npm
    -   if [ $PACKAGE_MANAGER == "npm" ]; then
    -     $PACKAGE_MANAGER add --global gulp-cli
    -   fi

    # Install global gulp for yarn
    -   if [ $PACKAGE_MANAGER == "yarn" ]; then
    -     $PACKAGE_MANAGER global add gulp-cli
    -   fi

    # Get and run all the tasks
    - echo "Begin run tasks"
    - TASKS_LIST=$(echo $GULP_TASKS | tr ";" "\n")