Skip to content
This repository was archived by the owner on Feb 20, 2021. It is now read-only.

Commit 0b97088

Browse files
authored
chore: Improve the way a npm build script is found. (#150)
* chore: Improve the way a npm build script is found. * This commit will first install just the production-only dependencies. Then a script will check the package.json for a build script. If non is found, it just continues, but if there is a build script, `npm install` will be called again to install the dev dependencies. Then `npm run build` is execute. * This reason for doing this way was so we weren't installing all dependecies if we didn't need them * need to set the NODE_ENV to development to install dev deps when on in debug mode. * Also don't do npm install twice, since this could trigger postinstall scripts twice
1 parent e2a6ea3 commit 0b97088

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

s2i/assemble

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,25 @@ else
4949
if [ "$DEV_MODE" == true ]; then
5050
echo "---> Using 'npm install'"
5151
npm install
52-
else
53-
echo "---> Installing all dependencies"
54-
NODE_ENV=development npm install
5552

5653
#do not fail when there is no build script
57-
echo "---> Building in production mode"
54+
echo "---> Building in development mode"
5855
npm run build --if-present
56+
else
57+
HAS_BUILD=$(node -e "console.log(require('./package.json').scripts.build ? true : false)")
58+
59+
# check to see if there is a build script by inspecting the package.json
60+
if [ "$HAS_BUILD" == true ]; then
61+
# Do a npm install to get the dev depdencies
62+
echo "---> Installing dev dependencies"
63+
NODE_ENV=development npm install
64+
#do not fail when there is no build script
65+
echo "---> Building in production mode"
66+
npm run build --if-present
67+
else
68+
echo "---> Using 'npm install -s --only=production'"
69+
npm install -s --only=production
70+
fi
5971

6072
echo "---> Pruning the development dependencies"
6173
npm prune

0 commit comments

Comments
 (0)