-
-
Save tranphuquy19/f1060366cba4c4c1959a6e1379a85abc to your computer and use it in GitHub Desktop.
Makefile for node.js application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Makefile for node application | |
# by @geta6 | |
# | |
NODE = node | |
NPM = npm | |
PM2 = ./node_modules/.bin/pm2 | |
BOWER = ./node_modules/.bin/bower | |
GRUNT = ./node_modules/.bin/grunt | |
MOCHA = ./node_modules/.bin/mocha | |
COVER = ./node_modules/.bin/coveralls | |
APP = ./config/app.coffee | |
APP_PORT = 3000 | |
APP_NAME = `$(NODE) -e 'require("util").print(require("./package.json").name)'` | |
APP_STDOUT = ./tmp/$(APP_NAME).out | |
APP_STDERR = ./tmp/$(APP_NAME).err | |
APP_PIDPATH = ./tmp/$(APP_NAME).pid | |
APP_INSTANCES = max | |
MOCHA_TARGET = test | |
MOCHA_REPORTER = spec | |
MOCHA_OPTIONS = --colors --growl --bail --check-leaks | |
# setup | |
setup: | |
@echo '---> install required components for development.' | |
@test -d tmp || mkdir tmp | |
@$(NPM) install | |
@$(BOWER) install | |
setup-production: | |
@echo '---> install required components for production.' | |
@test -d tmp || mkdir tmp | |
@$(NPM) install --production | |
@$(BOWER) install --production | |
# start-stop interface | |
debug: setup | |
@echo '---> launch development servers.' | |
@PORT=$(APP_PORT) NODE_ENV=development \ | |
$(PM2) start \ | |
-n $(APP_NAME) \ | |
-o $(APP_STDOUT) \ | |
-e $(APP_STDERR) \ | |
-p $(APP_PIDPATH) \ | |
-i $(APP_INSTANCES) \ | |
--watch $(APP) | |
@$(GRUNT) watch | |
start: setup-production build | |
@echo '---> launch production server.' | |
@PORT=$(APP_PORT) NODE_ENV=development \ | |
$(PM2) start \ | |
-n $(APP_NAME) \ | |
-o $(APP_STDOUT) \ | |
-e $(APP_STDERR) \ | |
-p $(APP_PIDPATH) \ | |
-i $(APP_INSTANCES) \ | |
$(APP) | |
stop: | |
@echo '---> kill all processes.' | |
@$(PM2) delete $(APP_NAME) | |
@$(PM2) kill | |
status: | |
@$(PM2) status | |
reload: | |
@echo '---> graceful reload child processes.' | |
@$(PM2) gracefulReload $(APP_NAME) | |
restart: | |
@echo '---> restart all processes.' | |
@$(PM2) restart $(APP_NAME) | |
force-restart: stop start | |
# asset | |
build: | |
@echo '---> build assets.' | |
@$(GRUNT) build | |
# utility | |
dump: | |
@$(PM2) dump | |
logs: | |
@$(PM2) logs $(APP_NAME) | |
monit: | |
@$(PM2) monit | |
# test | |
test: setup build | |
@echo '---> start test.' | |
@$(MOCHA) --compilers coffee:coffee-script/register \ | |
--reporter $(MOCHA_REPORTER) $(MOCHA_OPTIONS) $(MOCHA_TARGET) | |
coverage: setup lint build | |
@echo '---> test and measure coverage.' | |
@$(MOCHA) --compilers coffee:coffee-script/register \ | |
--reporter mocha-lcov-reporter \ | |
--require blanket \ | |
$(MOCHA_OPTIONS) $(MOCHA_TARGET) | $(COVER) | |
.PHONY: setup setup-production debug start stop status reload restart force-restart build dump logs monit test coverage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment