Skip to content

Custom actions

haskelt edited this page Mar 2, 2021 · 6 revisions

Salal is designed for one specific task, which is building websites. However, in the process of developing a site, you may want to perform various other utility actions. For example, you might want to deploy your site to a server. For convenience, Salal provides a way to define custom actions that will execute a set of external commands, or a mix of built-in and external commands.

Custom actions are configured by the use of System variables, specifically the variable action_commands. Here is an example of a profiles file defining an action deploy that uses the *nix tool rsync to copy the build directory to a server:

{
    "common": {
        "system": {
            "action_commands" : {
               "deploy" : [
	            { "type": "external",
	              "command": "rsync -e \"/usr/bin/ssh\" -av --exclude=/.well-known/ --delete {{paths.profile_build_dir}}/ {{deploy_destination}}"
	            }
	        ],
            }
        }
    }
}

The string specifying the command contains two variable references, indicated by text surrounded by {{ and }}. Variable references are replaced by the appropriate system variable values at the time the command is executed. You can include references to any system variable in the command string. In this case, profile_build_dir is a built-in system variable set internally by Salal itself (see System variables for more information on built-in variables). In contrast, deploy_destination is not a built-in variable, so its value would need to be specified in the build profiles file.

Here's another example illustrating how you could configure Salal to run a pre-build script before executing the built-in build action:

{
    "common" : {
	"system" : {
	    "action_commands": {
		"build" : [
		    { "type": "external", "command": "make -f {{paths.theme_root}}/theme.make" },
		    { "type": "internal", "command": "build" }
		]
	    }
        }
    }
}

If you need to reference a system variable that is more than one level under system in your profiles file, you can use the dot notation illustrated above with {{paths.theme_root}}. That reference corresponds to the theme_root variable shown below:

{
    "common" : {
	"system" : {
	    "paths": {
		"theme_root": "C:/Users/Plato/Documents/Courses/course_site_theme/"
	    }
        }
    }
}

Clone this wiki locally