antikythera v0.2.0 mix antikythera.prepare_assets View Source

Prepares static assets for your gear.

This mix task is called right before compilations of the gear in antikythera’s auto-deploy script. It ensures all static assets of your gear reside in priv/static/ directory before compilations of YourGear.Asset module. Assets in priv/static/ directory will then be uploaded to cloud storage for serving via CDN. See Antikythera.Asset for details.

If your gear uses some kind of preprocessing tools to generate asset files (JS, CSS, etc.), you have to set up any of the supported asset preparation methods described in the next section.

This mix task detects available asset preparation methods in your gear repository, then executes them in sequence. If any part of the preparation resulted in failure (non-zero exit code), the whole task will abort and thus auto-deploy will fail.

Normally you do not have to invoke this mix task when you locally develop your assets. Though you may do so in order to confirm asset preparation is working as you intended.

This mix task invokes the chosen preprocessing tools with ANTIKYTHERA_COMPILE_ENV environment variable (see also Antikythera.Env). You can use this environment variable to distinguish for which environment current script is running.

Supported Asset Preparation Methods

Asset preparation process is split into two steps: package installation step and build step.

Any combinations of available methods are acceptable.

Note that if none of prerequisites for build steps are present, the whole asset preparation process will be skipped since package installation is unnecessary.

Package Installation

1. Using yarn

  • Prerequisite: yarn.lock file
  • Command: yarn
  • This method takes precedance over npm install.

2. Using npm install

  • Prerequisite: package.json file
  • Command: npm install

Build

1. Using npm-scripts

  • Prerequisite: antikythera_prepare_assets script in package.json file
  • Command: npm run antikythera_prepare_assets
  • This is the recommended method.
  • This method takes precedance over gulp.
  • Within antikythera_prepare_assets script, you may execute any asset-related actions such as:

    • Linting
    • Type Checking
    • Testing
    • Compiling/Transpiling
    • Uglifying/Minifying
    • etc…
  • How to organize these actions is up to you. You may use whatever tools available in npm, such as webpack or browserify.

    • You can even call gulp tasks from the script.

2. Using gulp (Deprecated)

  • Prerequisite: gulpfile.js file
  • Command: node_modules/.bin/gulp

    • default gulp task will be executed.
  • This is the old and deprecated method, kept for backward compatibility. Use npm-scripts method for new gears.
  • As is the case in npm-scripts, you may execute any asset-related actions in your default gulp task.
  • You can safely migrate to npm-scripts by putting antikythera_prepare_assets script in your package.json file like this:
{
  ...
  "scripts": {
    ...
    "antikythera_prepare_assets": "gulp"
  }
}

Note on implementation

This step is responsible for placing finalized static assets into priv/static/ directory.

In old versions of gear_generator, Node.js packages that depend on compass was used by default in generated gear. compass gem was (and is) globally installed on antikythera jenkins server to enable them.

However, compass is no longer maintained. We recommend you to consider using alternative SASS/SCSS processor. compass gem will be kept installed for backward compatibility.

Link to this section Summary

Link to this section Functions

Link to this function run_command!(cmd, args, env) View Source
run_command!(String.t(), [String.t()], String.t()) :: String.t()