Skip to content

Latest commit

 

History

History
185 lines (131 loc) · 4.05 KB

05_modules.md

File metadata and controls

185 lines (131 loc) · 4.05 KB

Modules

About modules

b5 provides some common modules to allow for easy usage of generic tasks, helper functions and more. All modules are defined inside the config.yml. Each module may be used multiple times using different parameters, so you may for example use one virtualenv for your build/ and one for your web/ path.

Loading modules

Inside your config.yml you may just put the desired modules inside the "modules" key. Example:

modules:
  examplemodule:
  modulewithparams:
    param1: value1
    param2: value2

Naming schema

Example module: "example"

# The functions provided by the modules will be prefixed by it's name
examplemodule:function() {
    echo "Did something"
}

This is important when calling module functions and for understanding how to write your own modules.

Provided environment

All parameters passed to the module will be available in the bash environment using the following schema: {MODULE_NAME}_{variable_key}

The example above will generate the following environment for modulewithparams:

MODULEWITHPARAMS_param1="value1"
MODULEWITHPARAMS_param2="value2"

Please note, that the provided environment will represent the internal values of the module. This means that in most cases some preprocessing/cleanup of values might have happened. For paths like this in the example, it means that paths are converted to absolute paths. Example:

modules:
  example:
    some_path: ../web

Will most certainly become:

EXAMPLE_some_path="/absolute/path/to/project/web"

Using modules

Some generic tasks may need to call the used modules. This is currently used for the following tasks:

  • install
  • update
  • clean

Your install task may look like:

task:install() {
    virtualenv:install
    npm:install
}

Using modules multiple times

If you need to use the same module twice or more (for example when needing multiple virtualenv directories) you may need to instantiate the same module twice. This may be done using the "class" key inside the module parameters:

modules:
  virtualenv_build:
    class: virtualenv
    base_path: .
  virtualenv_web:
    class: virtualenv
    base_path: ../web

The Taskfile will then look like this:

task:install() {
    virtualenv_build:install
    virtualenv_web:install
}

The following environment will be provided in this case:

VIRTUALENV_BUILD_base_path="/path/to/project/build"
VIRTUALENV_BUILD_...="more variables of virtualenv module"
VIRTUALENV_WEB_base_path="/path/to/project/web"
VIRTUALENV_WEB_...="more variables of virtualenv module"

Example

config.yml

modules:
  npm:
  virtualenv_build:
    class: virtualenv
    base_path: .
  virtualenv_web:
    class: virtualenv
    base_path: ../web
#!/usr/bin/env bash
# b5 Taskfile, see https://git.team23.de/build/b5 for details

task:install() {
    npm:install
    virtualenv_build:install
    virtualenv_web:install
}

task:update() {
    npm:update
    virtualenv_build:update
    virtualenv_web:update
}

task:example() {
    echo "This is a minimal example task"
}

You may now use b5 install to install your npm and python packages, b5 update for updating the installed packages.

Existing modules

Note: See source of module for details, beyond documentation.

legacy

Reenables legacy module loading using b5:module_load. Do not use.

npm

Use npm to install JS dependencies. See documentation.

comlipy

Use comlipy to lint your commit messages by adding a git commit-msg hook. See documentation.

composer

Use composer to install PHP dependencies. See documentation.

docker

Allow simple usage of docker. See documentation.

pipenv

Handling of your virtualenv's using pipenv. See documentation.

virtualenv

Handling of your virtualenv's. See documentation.

template

Allows for easy template rendering using Jinja2. See documentation.