Problem: Verbose Tooling Commands
Tools like Goose and SQLC require long, repetitive command-line arguments for paths, configurations, and database settings. This makes workflows tedious and error-prone.
Introduction to Just (Justfile)
Just is presented as a modern alternative to Makefiles that simplifies command execution. It allows developers to define named commands that group complex shell instructions into short, reusable tasks.
Environment Variable Loading
The set .env-load configuration automatically loads environment variables across platforms. This avoids manual exports, reduces debugging time, and ensures consistency between Unix and Windows systems.
Command Abstractions for Common Tasks
Just commands encapsulate repetitive tasks such as migrations, query compilation, code generation, and view fixes. Instead of writing full command syntax, developers can execute concise commands like just up migration or just compile queries.
Application Run and Watch Workflow
A run app command integrates build and watch behavior using a file-watching tool. It recompiles the application on relevant file changes while excluding large directories like node_modules.
Parallel Execution and View Compilation
Parallel tasks run template watchers and the application simultaneously. Template changes trigger recompilation, and the application automatically rebuilds to reflect updates in real time.
Aliases and Workflow Optimization
Aliases provide shorter command names for frequently used tasks. Overall, the Justfile centralizes and streamlines development commands, preparing the project for efficient application development.
Okay, so we have added our tools now, but these tools can be quite verbose to call.
For example, when we want to generate a new migration file and apply the generation file,
we need to point Goose to where our migration lives.
And we also need to point it where they should output it.
And the same with SQL C.
We need to point it where the SQL files are, where everything should be placed.
So this can become quite tedious.
To solve this, we are going to be using a tool called Just, or Just Files.
And Just is simply a modern version of Make Files.
And if you don't know about Make Files, they are pretty much what we see here.
It's just a way to group or make calling certain commands easier.
For example, the test all builds that you see right here.
It combines two commands to one.
So we first build and then we test.
This makes our life a lot easier when dealing with these commands.
So go ahead, install Just, and then we are going to jump into the Just file for this project.
I'm not going to type it out.
I'm just going to walk through it so you get an idea of these Just commands and how they work and why they make our life that much easier.
I will link the file in the episode notes, or the file, but the commands, so you can copy paste them, or you can just grab it from the repository.
Right.
So the first command we have here is set .env-load.
And if you're not familiar with the .env, how you load .env into a shell is that normally we would have to either export them manually one by one,
or we would in our .env file, add, export, and then we could source it.
This works on Unix based system.
It doesn't work on Windows based systems.
So doing this all the time can be a little bit tedious.
And you might also forget and spend time debugging it right.
And also, if you have some people on the Unix based system and others on Windows, it will work different for each one.
So by doing this set .env-load, we automatically load our .env file into our session, into our terminal, and we can start using the .env variables.
Next, we have a bunch of aliases, but we're not going to touch upon them now.
I want to jump down here and show you the fix views command.
So this is what we would have to type out ourselves if we did not have this command.
The same here with generate, with watch, with compile.
With compile queries, you can see like gotool sqlc compile-f, and then the path to the sqlc config file.
And then we could do the same thing down here, and then we read queries.
And then we get to migrations here, where we specify the path to the migrations.
We specify the type of the database engine.
We specify the database connection URI, right?
And then we also have to provide it with what we want to do, and the name, and so on and so forth.
So you can see how these commands just--
makes it so much easier to just have to write just up migration, just down migration, just compile queries, just generate queries, so on and so forth.
We can also see we have this run app that uses the tool error that we added.
And we specify our build command, where to put it, what to exclude, what to include, what to do when there's an error, and also what to do when we stop.
So this run app will run our application.
It will watch for changes, but not in node modules.
It will ignore that.
It will look for file changes, including Go and CSS and JavaScript files.
Now, this we technically don't need.
It's kind of-- because we don't have node modules, I just want to add it there so you know you can exclude certain things.
You might want to add node modules.
So we're going to add node modules to this project at one point.
And it's really good to have this exclude directory for node modules so we don't watch for folder changes in that, because it's going to be a huge folder.
Finally, we have this parallel.
And this just runs watch views and run app.
And watch views, we saw it maybe quickly here, where we just call go tool template generate.
And then we pass the watch.
Watch flag.
So this will just continuously watch for changes in the dot temple files.
And then it will compile every time you make a change.
And then once we make a change, the run app command here will pick up that some Go files has been changed.
And then that will recompile so we get the latest version of the views in or can see the latest changes, right?
And these two runs in parallel.
Okay, this is a very quick rundown of the just commands, but it's literally a way where we can give a command a name and then have it do something and we can group them together here, we could say, whenever we compile views, you know, we also want to add fixed views.
So they will first run fixed views, and then the compile views, we can add, we can do multiple things here, go to red and then do something else.
So this is really powerful.
And you can add a lot of things.
You can add a lot of commands to this, to these files that will make your life a lot easier.
Finally, we have the aliases that should be kind of self explanatory, right?
We have, for example, have fixed views that have alias to FV.
So we can actually go out and say just FV, which will run the fixed views command.
We can also say just the fixed views, and then it runs the same command, right?
Just think of the just file here as a way to make your life easier and put commands in a place.
So so we don't have to write all of this tedious syntax whenever we use the tools.
Great. Now we basically have all we all we need to to start building out the application.
So in the next part, we will actually begin building our our block.
Our our app and start to use all of these tools as well as start to add on to the application structure that we have created.