View Source mix antikythera.prepare_assets (antikythera v0.5.0)

Prepares static assets for your gear.

This mix task must be called before compilations of the gear if you need asset preparation. It ensures all static assets of your gear reside in priv/static/ directory before compilations of YourGear.Asset module. Assets in priv/static/ directory must be uploaded to cloud storage by mix antikythera_core.upload_new_asset_versions for serving via CDN if you run the gear on cloud. See Antikythera.Asset and Mix.Tasks.AntikytheraCore.UploadNewAssetVersions for details.

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

This mix task invokes the 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 Method

Asset preparation process is split into 3 steps: package installation step, auditing step and build step. If any part of the preparation process resulted in failure (non-zero exit code), the whole task will abort and thus auto-deploy will fail.

  • Prerequisite: package.json file and antikythera_prepare_assets script in it

Note that if the above prerequisite is not present, the whole asset preparation process will be skipped since package installation is unnecessary.

Package Installation

Use yarn if yarn.lock file exists, otherwise use npm install.

Auditing the packages

Run yarn audit or npm audit and abort if one or more critical packages found.

Build using npm-scripts

  • Command: npm run antikythera_prepare_assets
  • 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.

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.

Summary

Functions

Link to this function

run_command(cmd, args, env)

View Source
@spec run_command(String.t(), [String.t()], String.t()) ::
  {String.t(), non_neg_integer(), String.t()}
Link to this function

run_command!(cmd, args, env)

View Source
@spec run_command!(String.t(), [String.t()], String.t()) :: String.t()