redbadger/website-honestly

View on GitHub
Makefile

Summary

Maintainability
Test Coverage
#!/bin/sh

SHELL=/bin/bash
BIN=./bin
LOAD_ENV=source bin/load-dotenv.sh && source bin/construct-additional-env.sh
WEBPACK=yarn webpack --bail
JEST=yarn jest
PRETTIER=yarn prettier --write --parser babel '{!(dist)/,!(dist)/**/}*.js'
PRETTIER_FAIL=yarn prettier --list-different --parser babel './**/*.js'
ESLINT=yarn eslint
SERVERLESS=cd services && ../node_modules/.bin/sls
WEBPACK_DEV_SERVER=yarn webpack-dev-server
NPM_CHECK_UPDATES=yarn ncu


# color output
NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m

OK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)
ERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)
WARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)

AWK_CMD = awk '{ printf "%-30s %-10s\n",$$1, $$2; }'
PRINT_LINE = printf "%0.s*" {1..50} && printf "\n"
PRINT_ERROR = printf "$(ERROR_COLOR)$@ $(ERROR_STRING)\n" | $(AWK_CMD) && printf "$(CMD)\n$$LOG\n" && false && $(PRINT_LINE)
PRINT_WARNING = printf "$(WARN_COLOR)$@ $(WARN_STRING)\n" | $(AWK_CMD) && printf "$(CMD)\n$$LOG\n" && $(PRINT_LINE)
PRINT_OK = printf "$(OK_COLOR)$@ $(OK_STRING)\n" | $(AWK_CMD) && $(PRINT_LINE)

help:
    @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

badger: ## Red Badger 4 lyfe!
    npm run badger > /dev/null

clean: ## Remove compiled files
    rm -rf dist
    @$(PRINT_OK)

clean/services:
    rm -rf dist/services
    rm -f dist/services.zip
    @$(PRINT_OK)

check-deps: ## Check deps for updates
    $(NPM_CHECK_UPDATES)
    @$(PRINT_OK)

dev: badger ## Run the frontend dev server
    $(LOAD_ENV) && $(WEBPACK_DEV_SERVER) --color --hot --config webpack.dev.browser.config.js
    @$(PRINT_OK)

fetch:
    $(LOAD_ENV) && node dev/content-fetcher

generate-sitemap:
    $(LOAD_ENV) && node dev/generate-sitemap

dev-static: dist/static-site dist/dev-static/index.js ## Compile the site to HTML locally and serve
    ln -fs ../assets-honestly dist/static-site/assets-honestly
    node dist/dev-static/index.js
    ./node_modules/.bin/http-server ./dist/static-site -p 8000
    @$(PRINT_OK)

dev-commit: dist/static-site dist/dev-static/index.js ## Compile the site to HTML locally
    node dist/dev-static/index.js
    @$(PRINT_OK)

test: ## Run the tests
    FORCE_COLOR=1 $(JEST)
    @$(PRINT_OK)

flow: ## Run the type checker
    yarn flow
    @$(PRINT_OK)

prettier: ## Run the prettifier
    $(PRETTIER)
    @$(PRINT_OK)

prettier-fail: ## Run the prettifier, but fail if changes need to be made
    $(PRETTIER_FAIL)
    @$(PRINT_OK)

test-watch: ## Run the tests and watch for changes
    $(JEST) --watch
    @$(PRINT_OK)

test-coverage: ## Run the tests and coverage for changes
    $(JEST) --coverage --runInBand
    @$(PRINT_OK)

build: dist/services.zip ## Compile project used in CI deploy
    @$(PRINT_OK)

build-all: dist/services.zip dist/dev-static/index.js ## Compile project
    @$(PRINT_OK)

lint: ## Lint Javascript files
    FORCE_COLOR=1 $(ESLINT) . --ext .js --ext .jsx --ignore-path .eslintignore --cache
    @$(PRINT_OK)

services-info: ## Check serverless installed correctly and detects the correct service
    $(LOAD_ENV) \
    && $(SERVERLESS) info
    @$(PRINT_OK)

services-deploy: dist/services.zip ## Upload the publish service to AWS Lambda
    $(LOAD_ENV) \
    && $(SERVERLESS) deploy
    @$(PRINT_OK)

services-invoke-publish:
    $(LOAD_ENV) \
    && $(SERVERLESS) invoke -f publish
    @$(PRINT_OK)

publish-service-invoke: ## Invoke the publish service
    $(LOAD_ENV) \
    && curl -XPOST --fail $$PUBLISH_ENDPOINT
    @$(PRINT_OK)

keyrings: ## Initialize blackbox secrets in the keyrings folder (required to get .env file)
    git clone git@github.com:redbadger/blackbox-secrets.git keyrings -b website-honestly
    @echo ""
    @echo "*************************************************************"
    @echo "* Follow the instructions to get added to the blackbox admins:"
    @echo "* https://github.com/redbadger/blackbox-secrets/blob/master/README.md"
    @echo "*************************************************************"
    @echo ""
    @read -p "Press any key to continue."
    @$(PRINT_OK)

update-secrets: keyrings ## Update .env file to latest version
    cd keyrings \
    && git pull
    blackbox_edit_start keyrings/files/.env
    mv keyrings/files/.env .env
    @$(PRINT_OK)

edit-secrets: keyrings update-secrets ## Edit .env file (get latest -> decrypt -> edit -> encrypt -> push)
    blackbox_edit keyrings/files/.env
    cd keyrings \
    && git commit -m "files/.env.gpg updated" "files/.env.gpg" \
    && git push origin website-honestly
    blackbox_edit_start keyrings/files/.env
    mv keyrings/files/.env .env
    @$(PRINT_OK)

dist/services.zip: dist/services
    cd dist/services \
    && zip -r ../services.zip *
    @$(PRINT_OK)

dist/services:
    export NODE_ENV=production \
    && $(LOAD_ENV) \
    && $(WEBPACK) --config webpack.lambda.config.js \
    && $(WEBPACK) --config webpack.browser.config.js \
    && rm -rf dist/services/assets-honestly
    @$(PRINT_OK)

dist/dev-static/index.js:
    export NODE_ENV=production \
    && $(LOAD_ENV) \
    && $(WEBPACK) --config webpack.dev.static.config.js
    @$(PRINT_OK)

dist/static-site:
    mkdir -p ./dist/static-site
    @$(PRINT_OK)

scanner: ## Initialize git secrets in the scanner folder
    git clone git@github.com:redbadger/secrets-scanner.git scanner
    @echo ""
    @echo "*************************************************************"
    @echo "* Follow the instructions below to setup the scanner:"
    @echo "* https://github.com/redbadger/secrets-scanner/blob/master/README.md"
    @echo "*************************************************************"
    @echo ""
    @read -p "Press any key to continue."

setup-scanner: scanner ## Setup git secrets with stored configuration
    @cd scanner && git pull
    @cd scanner && $(MAKE) full-setup
    @$(PRINT_OK)

scan-secrets: scanner ## Scan for secrets
    @git secrets --scan
    @$(PRINT_OK)

.PHONY: \
    dev \
    dev-static \
    install \
    check-deps \
    flow \
    prettier \
    lint \
    help \
    clear \
    build \
    badger \
    services-info \
    services-deploy \
    services-invoke \
    fetch \
    test \
    test-watch \
    sw \
    update-secrets \
    edit-secrets \
    setup-scanner \
    scan-secrets