From 5f97739d21a69f5fccba3aad589f2c8f6350512a Mon Sep 17 00:00:00 2001 From: Tom De Nies Date: Fri, 7 May 2021 11:37:16 +0200 Subject: [PATCH 1/2] Added gitattributes and editorconfig to ensure windows devs check out lf endings --- .editorconfig | 13 +++++++++++++ .gitattributes | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..977e762 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true + +[*.{diff,md}] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..96c4e7d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,31 @@ +# Handle line endings automatically for files detected as text +# and leave all files detected as binary untouched. +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Force the following filetypes to have unix eols, so Windows does not break them +*.* text eol=lf + +# Denote all files that are truly binary and should not be modified. (bit overkill for this project, but better safe than sorry) +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.ico binary +*.mov binary +*.mp4 binary +*.mp3 binary +*.flv binary +*.fla binary +*.swf binary +*.gz binary +*.zip binary +*.7z binary +*.ttf binary +*.eot binary +*.woff binary +*.pyc binary +*.pdf binary +*.ez binary +*.bz2 binary +*.swp binary \ No newline at end of file From 74089a94a431267b5ec11e900fd36a7b21601556 Mon Sep 17 00:00:00 2001 From: Tom De Nies Date: Fri, 7 May 2021 12:41:14 +0200 Subject: [PATCH 2/2] Added DEV_OS option to enable -watch-legacy for windows users --- README.md | 18 ++++++++++++++++++ boot.sh | 14 +++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9900bdc..773c16b 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,24 @@ docker run --link virtuoso:database \ semtech/mu-javascript-template ``` +#### On Windows: +You might notice that code reloading doesn't work when you mount your code from a Windows host machine. + +It turns out nodemon --watch won't work if your code resides on Windows, but --legacy-watch should. +It's less efficient and more error-prone than --watch, but at least it works. + +Set the `DEV_OS` environment variable to `windows` so `boot.sh` will use --legacy-watch, and you should have live-reload. + +``` +docker run --link virtuoso:database \ + -v `pwd`:/app \ + -p 8888:80 \ + -e NODE_ENV=development \ + -e DEV_OS=windows \ + --name my-js-test \ + semtech/mu-javascript-template +``` + ### Develop in mu.semte.ch stack When developing inside an existing mu.semte.ch stack, it is easiest to set the development mode and mount the sources directly. This makes it easy to setup links to the database and the dispatcher. diff --git a/boot.sh b/boot.sh index 244263d..0fbe67c 100755 --- a/boot.sh +++ b/boot.sh @@ -1,4 +1,16 @@ -if [ "$NODE_ENV" == "development" ] +if [ "$NODE_ENV" == "development" -a "$DEV_OS" == "windows" ] +then + # Run live-reload development with legacy-watch + # It's important to go to the right directory first, and to ignore the /usr/src/app/ and /tmp/ directories, since legacy-watch will match any file matching the **.* pattern + # not ignoring these paths will result in an infinite restart loop, as run-development.sh writes to these directories + cd /app/ + exec /usr/src/app/node_modules/.bin/nodemon \ + --legacy-watch /app \ + --ignore /usr/src/app/ \ + --ignore /tmp/ \ + --ext js,mjs,cjs,json \ + --exec /usr/src/app/run-development.sh +elif [ "$NODE_ENV" == "development" ] then # Run live-reload development exec /usr/src/app/node_modules/.bin/nodemon \