Skip to content

Instantly share code, notes, and snippets.

@poying
Last active August 29, 2015 14:23
Show Gist options
  • Save poying/638b3331dade4b051523 to your computer and use it in GitHub Desktop.
Save poying/638b3331dade4b051523 to your computer and use it in GitHub Desktop.
DUO := node_modules/.bin/duo
# 主要程式碼
SRC := $(shell find lib -type f -name '*.js')
# 所有 test 目錄下檔案,包含一些 util
TEST := $(shell find test -type f -name '*.js')
# 實際寫測試的檔案
TEST_SRC := $(shell find test -type f -name '*.test.js')
# Build 測試檔案
build-test: build/test/index.js
build/test/index.js: node_modules test/index.js $(SRC) $(TEST)
@$(DUO) test/index.js
# 建立 Entry Point
# 這個檔案需要加進 .gitignore
test/index.js: $(TEST_SRC)
# 覆蓋/建立檔案,並加入警告訊息
@echo "// 檔案是自動產生的,請勿修改" > $@
# test/settings.js 是 mocha 或其他測試 Framework 的設定檔
@echo "require('./settings');" >> $@
# require 所有測試檔案
@for fname in $(TEST_SRC); do \
# 將檔案路徑中的 test 目錄名稱拿掉
echo "require('./$${fname#test*/}');" >> $@; \
done
node_modules: package.json
@npm i
clean:
@-rm -rf node_modules build test/index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment