Недавно я нашел this article online, в котором объясняется, как настроить цель make help
, которая автоматически проанализирует Makefile для комментариев и отобразит красиво отформатированную справочную команду.Как автоматически сгенерировать команду справки Makefile
Он разбирает:
install: ## Install npm dependencies for the api, admin, and frontend apps
@echo "Installing Node dependencies"
@npm install
install-dev: install ## Install dependencies and prepared development configuration
@./node_modules/.bin/selenium-standalone install
@cp -n ./config/development.js-dist ./config/development.js | true
run-frontend-dev: webpack.PID ## Run the frontend and admin apps in dev (using webpack-dev-server)
В:
install Install npm dependencies for the api, admin, and frontend apps
install-dev Install dependencies and prepared development configuration
run-frontend-dev Run the frontend and admin apps in dev (using webpack-dev-server)
Но по какой-то причине я не могу заставить его работать (на OSX по крайней мере). С этой целью:
help: ## Show the help prompt.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Когда я бегу:
make help
Я просто:
$ make help
make: Nothing to be done for `help'.
Я пробовал все различные решения от комментариев в статье тоже но ничего не работает. Что я делаю не так?
Кроме того, какова будет вариация скрипта, которая позволит размещать комментарии по строке до цели, а не после нее. Как так:
# Build the source files with Babel.
build: $(shell find lib)
@rm -rf build
@mkdir -p build
@$(babel) lib $(babel_options)
# Seed the database with fake data.
db-fake:
@$(run) node bin/run-sql fake
Вот полный Makefile в вопросе:
# Options.
DEBUG ?=
SOURCEMAPS ?= true
WATCH ?=
# Variables.
bin = ./node_modules/.bin
tests = $(shell find test/routes -depth 1)
shorthand-tests = $(patsubst test/routes/%.js,test-%,$(tests))
# Binaries.
babel = $(bin)/babel
mocha = $(bin)/mocha
node = node
nodemon = $(bin)/nodemon
run = heroku local:run
# Babel options.
babel_options = \
--out-dir build \
--copy-files
# Sourcemaps?
ifneq ($(SOURCEMAPS),false)
babel_options += --source-maps
endif
# Watch?
ifdef WATCH
babel_options += --watch
endif
# Development?
ifneq ($(NODE_ENV),production)
node = $(nodemon)
endif
# Debug?
ifdef DEBUG
node += debug
mocha += debug
endif
# Default.
default: help ## Default.
# Build the source files with Babel.
build: $(shell find lib) ## Build the source files with Babel.
@rm -rf build
@mkdir -p build
@$(babel) lib $(babel_options)
# Seed the database with fake data.
db-fake: ## Seed the database with fake data.
@$(run) node bin/run-sql fake
# Reset the database, dropping everything and the creating again.
db-reset: ## Reset the database, dropping everything and the creating again.
@$(run) node bin/run-sql drop
@$(run) node bin/run-sql create
# Seed the database with test data.
db-seed: ## Seed the database with test data.
@$(run) node bin/run-sql seed
# Show the help prompt.
help: ## Show the help prompt.
@awk '/^#/{c=substr($0,3);next}c&&/^[[:alpha:]][[:alnum:]_-]+:/{print substr($1,1,index($1,":")),c}1{c=0}' mm.mk | column -s: -t
# Open the PSQL interface.
psql: ## Open the PSQL interface.
@psql contentshq
# Run the development server.
server: ## Run the development server.
@$(run) $(node) bin/api
# Start the local postgres server.
start: ## Start the local postgres server.
@pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# Stop the local postgres server.
stop: ## Stop the local postgres server.
@pg_ctl -D /usr/local/var/postgres stop -s -m fast
# Run all of the tests.
test: ## Run all of the tests.
@$(run) $(mocha) $(tests)
# Run specific route tests.
$(shorthand-tests): ## Run specific route tests.
@$(run) $(mocha) test/routes/$(subst test-,,[email protected]).js
# Watch the source files with Babel.
watch: ## Watch the source files with Babel.
@WATCH=true $(MAKE) build
# Phony targets.
.PHONY: help
.PHONY: test
.PHONY: watch
достаточно Жутко, если я ударил забой три раза начинаются в начале '@ awk' линии, которая удаляет' 'символов, и перепечатайте их. Кажется, что это работает. Есть ли что-то делать с Makefiles, которые действуют странно с некоторыми символами новой строки? –
Вы не случайно имеете '\' в конце строки, начиная 'help:', не так ли? Кроме того, следующая строка должна начинаться с вкладки, но в вашем разрезе и вставке это выглядит как два пробела. Это должно вызвать ошибку. – rici
Ах, стреляй, это его полностью, по какой-то причине я думал, что для Makefile нужны пробелы, но им нужны вкладки. Вместо того, чтобы ошибаться, это просто дает мне результат «ничего не делать». –