iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🗿

Improve Development Efficiency and Prevent Forgotten Commands with a Personal Makefile Without Affecting the Team

に公開

*This is a life-hack style post intended for beginners to intermediate developers.

Recently, I have been involved in the development of various products, and I find that the required procedures during development often differ from one product to another.
In particular, when I first joined a project, I often wasted time by forgetting to run necessary commands, which prevented the application from starting, or by submitting pull requests without running auto-generation scripts.
If you are working on side projects, juggling multiple companies as a freelancer, or handling multiple products within a single company, perhaps you have had similar experiences?

In this article, I would like to briefly introduce what I personally do to solve these kinds of problems.

Procedures

1. Create a personal Makefile in your working directory

As you read on, you will see that you should keep the filename of the Makefile you create here fixed.
Be careful to ensure it doesn't conflict with other Makefiles in different directories or files that might be generated in the future.
To ensure it never conflicts, I use the first two letters of my last name (e.g., Yamafile.mk).

2. Register the filename in your global gitignore file

If you leave it as is after creating it, git management becomes cumbersome, so let's exclude it in your global gitignore file.
Reference: docs.github.com

~/.gitignore_global
Yamafile.mk

3. Set a command alias

Change the file you modify depending on the shell you use.
Setting the command using your last name or nickname should help avoid conflicts with other commands.

~/.zshrc
alias yama='make -f ./Yamafile.mk'

4. Edit the file to make it easy to use!

This is how I personally set it up.
It is especially convenient when accessing RDBs like MySQL!

Working directory/Yamafile.mk
.PHONY: mysql
mysql:
	docker exec -it [mysql container name] mysql -u[user] -p[password]

.PHONY: run
run:
	# e.g., when preparation is needed before the start command

.PHONY: before-commit
before-commit:
	# e.g., auto-generation commands, linters, or tests

Now, you can execute it in the directory where you created the file like this:

pwd
=> .../Working directory

yama mysql
mysql> // The familiar prompt

Summary

How was that?
This method is very useful, especially when you need to be involved in multiple products on a single PC.

I hope you find this helpful.

Discussion