|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # bin/detect <build-dir> |
3 | 3 |
|
| 4 | +error() { |
| 5 | + local c="2,999 s/^/ ! /" |
| 6 | + # send all of our output to stderr |
| 7 | + exec 1>&2 |
| 8 | + |
| 9 | + echo -e "\033[1;31m" # bold; red |
| 10 | + echo -n " ! ERROR: " |
| 11 | + # this will be fed from stdin |
| 12 | + case $(uname) in |
| 13 | + Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries |
| 14 | + *) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data |
| 15 | + esac |
| 16 | + echo -e "\033[0m" # reset style |
| 17 | + exit 1 |
| 18 | +} |
| 19 | + |
4 | 20 | if [ -f $1/package.json ]; then |
5 | 21 | echo 'Node.js' |
6 | 22 | exit 0 |
7 | 23 | fi |
8 | 24 |
|
9 | | ->&2 echo 'Node.js: package.json not found in application root' |
| 25 | +if [[ -f "$1/.slugignore" ]] && grep -Fxq "package.json" "$1/.slugignore"; then |
| 26 | + error << EOF |
| 27 | +'package.json' listed in '.slugignore' file |
| 28 | +
|
| 29 | +The 'heroku/nodejs' buildpack is set on this application, but was |
| 30 | +unable to detect a 'package.json' file. This is likely because |
| 31 | +the '.slugignore' file is removing it before the build begins. |
| 32 | +
|
| 33 | +For more information, refer to the following documentation: |
| 34 | +https://devcenter.heroku.com/articles/slug-compiler#ignoring-files-with-slugignore |
| 35 | +EOF |
| 36 | +elif [[ -f "$1/.gitignore" ]] && grep -Fxq "package.json" "$1/.gitignore"; then |
| 37 | + error << EOF |
| 38 | +'package.json' listed in '.gitignore' file |
| 39 | +
|
| 40 | +The 'heroku/nodejs' buildpack is set on this application, but was |
| 41 | +unable to detect a 'package.json' file. This is likely because |
| 42 | +the '.gitignore' file is preventing it from being checked in to |
| 43 | +the git repo. |
| 44 | +
|
| 45 | +For more information, refer to the following documentation: |
| 46 | +https://devcenter.heroku.com/articles/gitignore |
| 47 | +EOF |
| 48 | +else |
| 49 | + error <<- EOF |
| 50 | +Application not supported by 'heroku/nodejs' buildpack |
| 51 | +
|
| 52 | +The 'heroku/nodejs' buildpack is set on this application, but was |
| 53 | +unable to detect a Node.js codebase. |
| 54 | + |
| 55 | +A Node.js app on Heroku requires a 'package.json' at the root of |
| 56 | +the directory structure. |
| 57 | +
|
| 58 | +If you are trying to deploy a Node.js application, ensure that this |
| 59 | +file is present at the top level directory. This directory has the |
| 60 | +following files: |
| 61 | +
|
| 62 | +$(ls -1p $1) |
| 63 | + |
| 64 | +If you are trying to deploy an application written in another |
| 65 | +language, you need to change the list of buildpacks set on your |
| 66 | +Heroku app using the 'heroku buildpacks' command. |
| 67 | + |
| 68 | +For more information, refer to the following documentation: |
| 69 | +https://devcenter.heroku.com/articles/buildpacks |
| 70 | +https://devcenter.heroku.com/articles/nodejs-support#activation |
| 71 | +EOF |
| 72 | +fi |
| 73 | + |
10 | 74 | exit 1 |
0 commit comments