Prettier is an opinionated code formatter with support for several programming languages. More details can be found here.
For details on how to install Prettier and have it work with Zeus refer to this earlier link: viewtopic.php?p=13199
Using Prettier as a Zeus Auto-save Trigger
The installation from the earlier link details how to run Prettier as a tool using the menu or the keyboard.
However, Prettier can also be run as a Zeus trigger, meaning it will run every time the file is saved.
To make this happen, edit the document type and add the following line of code to the save and save as postfix triggers:
Code: Select all
$zud\zScript\prettier_fmt.lua
For example, the image below shows how the Options, Document Types menu was used to edit the TypeScript Document Type and in the Triggers panel the Prettier command lines were added to those events as shown below:
With those triggers in place, the Zeus Prettier macro is triggered every time the file is saved and that will then run the following command line:
Code: Select all
npx --quiet prettier --write --loglevel silent --no-config $fn
IMPORTANT: If the following error is produced, that means node.js has not been installed or the node.exe is not found in the system PATH:
Code: Select all
"node" is not recognized as an internal or external command,
operable program or batch file.
With the everything working as expected, and the following test.ts TypeScript file looking as follows: When this file is saved, it will be automatically reformatted by Prettier to look like this: Cheers Jussi