Export scripts are executable scripts or programs that the app runs every time you export your design. You can use them to rename files, move images, run things like eslint or even upload your site automatically to your server.
To do any of this, though, you need to be comfortable with writing code. This is why the feature is hidden in the Advanced area in Export Settings:
You point it to an executable file somewhere on your disk. This can be a shell script or a compiled program. The only requirement is that it can be run from a terminal and doesn't wait for user input.
For macOS and Linux, shell scripts are a simple yet powerful option for writing export scripts. The export destination path is passed as arg 1, so you need to
cd $1 in order to navigate to the folder with the exported files.
Here is an example, written in bash, which changes the extension of your index file to php:
#!/bin/bash cd $1 mv index.html index.php
Remember to mark the script as executable, so that the OS can start it as a program:
chmod +x yourscript.sh
For more complex tasks, you can write your scripts in Node, Python, Ruby, PHP or anything else that you feel comfortable with. Just make sure that the script is marked as executable, and that the
#! row is added, so that the interpreter can be located by the os.
For Windows, regular batch files or compiled programs would work. The export destination path is passed as arg 1, so you need to
cd %1 in order to navigate to the folder with the exported files.
Here is an example of a batch file which renames your index.html file to php:
@ECHO OFF cd %1 mv index.html index.php
Save this as a text file with the bat extension. This is needed so that Windows knows to execute this file as a program.
Important: A lot of Windows batch examples you can find online add a
PAUSEcommand at the end of the script. Don't add this to your export scripts, as it will case the script to hang and take up memory when it's started by Bootstrap Studio.
An alternative for writing your scripts is to use Python and py2exe to compile your script as an executable.
Setting the Script to Run
All that remains is to tell Bootstrap Studio to run your script upon export. With your design loaded, open the Settings dialog and select the Export entry on the left. Then, expand the Advanced section, click the Browse button and locate your export script.
If your script throws any errors or log messages, they will be written to an error.log file in the export folder. You can use it to debug potential issues.
You can check out a more complex example for publishing your website to Github Pages automatically after an export.