I have been trying to get in the habit of using th...
# box-products
r
I have been trying to get in the habit of using the cfformat plugin on personal projects. I was wondering if there was preferred method of running cfformat on save in VSC. It shouldn’t be rocket surgery, I just didn’t want to reinvent the wheel if there was already something out there.
b
There is a watcher command you can run in the background
you point it to your files with a file globbing pattern and it reformats as you save
But there's nothing built into VSCode directly
The overhead of spinning up CommandBox itself (and the lack of an LSP) makes that difficult.
r
Thanks Brad, usually I run
watch
in another terminal, I was just being lazy and trying to save that extra 3 seconds or so
b
Yeah, not one I know of
A lot of our ortus projects have it built into our CI process to just fix it automatically when you commit too
r
I see several “run on save” packages, but I cannot use it all the time.
b
The only annoying thing there is the extra commits you have to always make sure to pull
r
lol Yeah, but that happens any time more than 1 person uses a repo. I will look in to that
b
@mborn Do we have a Github Action created yet for running CFFormat and committing back the changes?
m
@bdw429s an action to format CFCs? Sure. Does it include a
git commit
command? No. See • my ITB talk on github actions - https://cfcasts.com/series/into-the-box-2021/videos/automate-all-things-with-github-actions-michael-born • our "CommandBox GitHub Action" docs - https://github.com/marketplace/actions/box-command#cfformat-usage
b
Ahh, that's why I couldn't find it
I was searching the Ortus repos and I found the commandbox action and I wasn't sure if we had a repo specific for the cfformat
👍
r
I see commandbox-actions repo
b
@Robert Zehnder You can start with that example above for running CFFormat in github actions pretty easy
👍 1
r
But I was just briefly going through the repos.
b
Copy code
steps:
- uses: Ortus-Solutions/commandbox-action@v1.0.2
  with:
    cmd: cfformat run models,handlers,interceptors,tests/specs --overwrite
m
I looked into creating a CFFormat-specific action, but a lot of Ortus CFFormat steps use
box task run cfformat
. This wa devs can specify the
cfformat
script inside
box.json
and use it within VS Code as well.
r
Good stuff! Thank you guys for your help. I appreciate it.
m
@Robert Zehnder yepper! There are a lot of CI stuff you can look at for inspiration. I'd take a look at the ColdBox module template we use for bootstrapping new modules. It's got Luis' preferred github actions already configured.
r
Thank you, I will definitely check that out
b
I just use command runner in vscode, setup a cfformat command for the current file and then just set that command to a shortcut key combo. It's not on save but it's pretty quick and easy to do once you set it up .
Copy code
"command-runner.terminal.name": "runCommand",
"command-runner.terminal.autoClear": true,
"command-runner.terminal.autoFocus": true,
"command-runner.commands": {
    "cfformat file": "box fmt ${file} --overwrite"
}
b
Yep, that will work. You just have to deal with a delay of 5-10 seconds for it to spin up box.
👍 1
b
Followup: Just open a terminal in vscode and start box to avoid the spin up wait time every time you run the cfformat shortcut