Tasks

Tasks are what define which skill should be used when a specific subcommand is called. For example, when alfred run build is called, Alfred needs to decide which skill to run build with (either @alfred/skill-rollup, @alfred/skill-parcel, or @alfred/skill-webpack).

Skill with Tasks

This is an example of a skill for parcel which supports both the build and start subcommands:

const skill = {
name: 'parcel',
tasks: [
'@alfred/task-build',
'@alfred/task-start'
],
// ...
};
export default skill;

Skill with Tasks and Configs

Skills can support different platforms and projects. When adding a task to a skill, the task config takes an optional supports property, which is an object containing the projectss, platforms, and environments the skill supports for th given task.

const supports = {
envs: ['production', 'development', 'test'],
platforms: ['browser', 'node'],
projects: ['app']
};
const skill = {
name: 'parcel',
tasks: [
['@alfred/task-build', { supports }],
['@alfred/task-start', { supports }]
],
// ...
};

If supports is not passed, Alfred will assume the task supports all platforms, projects, and environments.

Running once for each target

Certain tasks need to be run once for each target. One example of this is the @alfred/task-build task, which need to build each target it supports. The @alfred/task-lint task only needs to be run once for all targets.

Running once for each target

module.exports = {
subcommand: 'build',
description: 'Build, optimize, and bundle assets in your app',
runForEachTarget: true,
resolveSkill(skills, target) {
// return whichever skill you want to resolve...
}
};

Running once for all targets

module.exports = {
subcommand: 'lint',
description: 'Lint your app',
runForEachTarget: false,
resolveSkill(skills) {
// return whichever skill you want to resolve...
}
};

Resolving a Skill

resolveSkill takes an array of Skills and returns the skill to be resolved. If runForEachTarget is true, a target paramater is passed to resolveSkill.