Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # make build the entire site (all languages)
  2. # make test run internal tests such as linting the source
  3. # make all test and build the entire site (all languages)
  4. # make init just install NPM dependencies
  5. # make en build just the English edition (replace 'en' with 'fr' for French, etc.)
  6. # make clean destroy built files
  7. # make reset destroy built files and build all languages from scratch
  8. # make watch [...] watch for any source changes and rebuild everything
  9. # make watch_css watch for stylus changes and rebuild just CSS
  10. #----------------------------------------------------------------------
  11. # CONFIGURATION
  12. #----------------------------------------------------------------------
  13. # Collect list of languages based on available locale files
  14. LANGUAGES := $(notdir $(basename $(wildcard source/locales/*.json)))
  15. # Collect list of static assets that get copied over
  16. ASSETS := $(notdir $(wildcard source/assets/*))
  17. # Turn on expansion so we can reference target patterns in our dependencies list
  18. .SECONDEXPANSION:
  19. # Don’t delete intermediary targets after building
  20. .SECONDARY:
  21. # Figure out the absolute path to the directory where this Makefile is
  22. BASE := $(shell cd "$(shell dirname $(lastword $(MAKEFILE_LIST)))" && pwd)
  23. # This is a hack for the ‘watch’ targets later on. It has to be
  24. # early to nullify any targets that might otherwise run, but in
  25. # the end allows extra parameters to be passed on to the next make
  26. ifeq (watch,$(firstword $(MAKECMDGOALS)))
  27. WATCH_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
  28. $(eval $(WATCH_ARGS):;@:)
  29. endif
  30. #----------------------------------------------------------------------
  31. # COMMANDS
  32. #----------------------------------------------------------------------
  33. # Explicitly set the default target that does the minimum possible
  34. .PHONY: default
  35. default: assets full
  36. # This is the kitchen-sink build that does everything
  37. .PHONY: all
  38. all: lint assets full
  39. # Run anything that needs doing post-checkout to make this buildable
  40. .PHONY: init
  41. init: node_modules
  42. # Use building English language as a check to see if everything works
  43. .PHONY: test
  44. test: lint en
  45. .PHONY: lint
  46. lint: $(foreach SOURCE,$(shell find source -type f -name '*.json'),$(SOURCE).lint)
  47. %.lint: %
  48. npx jsonlint -q $<
  49. touch $@
  50. # Start fresh and rebuild everything
  51. .PHONY: reset
  52. reset: clean default
  53. # Targets to build all the dynamically generated stuff for all languages
  54. .PHONY: full
  55. full: css html public/index.html
  56. # Targets for rebuilding only single language and only what isn’t already done
  57. .PHONY: $(LANGUAGES)
  58. $(LANGUAGES): assets css html_$$@
  59. #----------------------------------------------------------------------
  60. # CONVENIENCE ALIASES
  61. #----------------------------------------------------------------------
  62. .PHONY: assets
  63. assets: init $(foreach ASSET,$(ASSETS),public/assets/$(ASSET))
  64. .PHONY: css
  65. css: init public/assets/css/screen.css
  66. .PHONY: html
  67. html: init $(foreach LANGUAGE,$(LANGUAGES),html_$(LANGUAGE))
  68. HTMLLANGS = $(foreach LANGUAGE,$(LANGUAGES),html_$(LANGUAGE))
  69. .PHONY: $(HTMLLANGS)
  70. $(HTMLLANGS): html_%: public/%/index.html
  71. #----------------------------------------------------------------------
  72. # FUNCTIONS
  73. #----------------------------------------------------------------------
  74. node_modules package-lock.json: package.json
  75. npm install
  76. # Copy fixed assets from the source tree (if newer files exist)
  77. public/assets/%: source/assets/% $$(shell find source/assets/$$* -type f)
  78. mkdir -p $(dir $@)
  79. rsync -r $</ $@/
  80. # Rebuild stylesheet if any of the input templates change
  81. public/assets/css/%.css: source/stylesheets/%.styl $(shell git ls-files *.styl)
  82. mkdir -p $(dir $@)
  83. npx stylus -c -u nib $< -o $@
  84. public/index.html: source/index.html
  85. cp $< $@
  86. # Use script to rebuild index if index is older than any files with this locale in the name
  87. public/%/index.html: source/functions/build/site-%.ls $$(shell git ls-files | grep '\b$$*\b')
  88. npx lsc $<
  89. .PHONY: clean
  90. clean:
  91. rm -rf public/*
  92. find -type f -name '*.json.lint' -delete
  93. # Localizations
  94. LOCALLANGS = $(foreach LANGUAGE,$(LANGUAGES),localize_$(LANGUAGE))
  95. .PHONY: $(LOCALLANGS)
  96. $(LOCALLANGS): localize_%:
  97. npx lsc ./source/functions/find-missing-localizations.ls $*
  98. #----------------------------------------------------------------------
  99. # CONVENIENCE FUNCTIONS
  100. #----------------------------------------------------------------------
  101. .PHONY: watch
  102. watch:
  103. git ls-files | entr -p make $(WATCH_ARGS)
  104. .PHONY: serve
  105. serve:
  106. npx http-server
  107. # Rebuild CSS live on input changes
  108. .PHONY: watch_css
  109. watch_css:
  110. npx stylus -c -u nib -w source/stylesheets/screen.styl -o public/assets/css/