diff --git a/scripts/src/main/resources/scripts/command/npm b/scripts/src/main/resources/scripts/command/npm index f43791046..ebfb87be5 100755 --- a/scripts/src/main/resources/scripts/command/npm +++ b/scripts/src/main/resources/scripts/command/npm @@ -49,17 +49,20 @@ function doCheckTopLevelProject() { function doRunBuild() { doSetup - local extra_arg="" - if [ ! -d node_modules ] && [[ "${*}" != *install* ]] - then - extra_arg="install" - fi - doEcho "Running: npm ${extra_arg} ${*}" + doEcho "Running: npm ${*}" if doIsQuiet then - npm --quiet ${extra_arg} "${@}" + npm --quiet "${@}" else - npm ${extra_arg} "${@}" + npm "${@}" + fi +} + +function doBuild() { + doRunBuild install + if doIsPackageJsonContainingScript build + then + doRunBuild run build fi } @@ -76,30 +79,38 @@ then echo "Options:" exit fi -if [ -z "${1}" ] +if [ -z "${1}" ] || [ "${1}" = "build" ] then - # shellcheck disable=SC2086 - doRunBuild ${NPM_BUILD_OPTS:-build} -elif [ "${1}" = "setup" ] -then - doSetup setup -else - if [ "${1}" = "get-version" ] - then - doGetProjectVersion - elif [ "${1}" = "set-version" ] && [ -n "${2}" ] - then - shift - doSetProjectVersion "${@}" - elif [ "${1}" = "check-top-level-project" ] - then - shift - doCheckTopLevelProject "${@}" - elif [ "${1}" = "release" ] + if [ -n "${NPM_BUILD_OPTS}" ] then # shellcheck disable=SC2086 - doRunBuild ${NPM_RELEASE_OPTS:-release} + doRunBuild ${NPM_BUILD_OPTS} else + doBuild + fi + shift + if [ -n "${1}" ] + then doRunBuild "${@}" fi +elif [ "${1}" = "setup" ] +then + doSetup setup +elif [ "${1}" = "get-version" ] +then + doGetProjectVersion +elif [ "${1}" = "set-version" ] && [ -n "${2}" ] +then + shift + doSetProjectVersion "${@}" +elif [ "${1}" = "check-top-level-project" ] +then + shift + doCheckTopLevelProject "${@}" +elif [ "${1}" = "release" ] +then + # shellcheck disable=SC2086 + doRunBuild ${NPM_RELEASE_OPTS:-release} +else + doRunBuild "${@}" fi diff --git a/scripts/src/main/resources/scripts/command/yarn b/scripts/src/main/resources/scripts/command/yarn index 14a3084f6..51945533b 100755 --- a/scripts/src/main/resources/scripts/command/yarn +++ b/scripts/src/main/resources/scripts/command/yarn @@ -55,17 +55,20 @@ function doCheckTopLevelProject() { function doRunBuild() { doSetup - local extra_arg="" - if [ ! -d node_modules ] && [[ "${*}" != *install* ]] - then - extra_arg="install" - fi - doEcho "Running: yarn ${extra_arg} ${*}" + doEcho "Running: yarn ${*}" if doIsQuiet then - yarn --silent ${extra_arg} "${@}" + yarn --silent "${@}" else - yarn ${extra_arg} "${@}" + yarn "${@}" + fi +} + +function doBuild() { + doRunBuild install + if doIsPackageJsonContainingScript build + then + doRunBuild run build fi } @@ -86,30 +89,38 @@ then echo "Options:" exit fi -if [ -z "${1}" ] +if [ -z "${1}" ] || [ "${1}" = "build" ] then - # shellcheck disable=SC2086 - doRunBuild ${YARN_BUILD_OPTS:-build} -elif [ "${1}" = "setup" ] -then - doSetup setup -else - if [ "${1}" = "get-version" ] - then - doGetProjectVersion - elif [ "${1}" = "set-version" ] && [ -n "${2}" ] - then - shift - doSetProjectVersion "${@}" - elif [ "${1}" = "check-top-level-project" ] - then - shift - doCheckTopLevelProject "${@}" - elif [ "${1}" = "release" ] + if [ -n "${YARN_BUILD_OPTS}" ] then # shellcheck disable=SC2086 - doRunBuild ${YARN_RELEASE_OPTS:-release} + doRunBuild ${YARN_BUILD_OPTS} else + doBuild + fi + shift + if [ -n "${1}" ] + then doRunBuild "${@}" fi +elif [ "${1}" = "setup" ] +then + doSetup setup +elif [ "${1}" = "get-version" ] +then + doGetProjectVersion +elif [ "${1}" = "set-version" ] && [ -n "${2}" ] +then + shift + doSetProjectVersion "${@}" +elif [ "${1}" = "check-top-level-project" ] +then + shift + doCheckTopLevelProject "${@}" +elif [ "${1}" = "release" ] +then + # shellcheck disable=SC2086 + doRunBuild ${YARN_RELEASE_OPTS:-release} +else + doRunBuild "${@}" fi diff --git a/scripts/src/main/resources/scripts/functions b/scripts/src/main/resources/scripts/functions index 2c6d23551..7d1e87597 100755 --- a/scripts/src/main/resources/scripts/functions +++ b/scripts/src/main/resources/scripts/functions @@ -328,7 +328,7 @@ function doDevonCommandAndReturn() { fi shift # shellcheck disable=SC2086 - "${command}" ${force} ${quiet} ${batch} "${@}" + "${command}" ${force} ${quiet} ${debug} ${batch} "${@}" result=${?} if [ ${result} != 0 ] then @@ -1127,6 +1127,17 @@ function doIsWindows() { return 255 } +function doIsPackageJsonContainingScript() { + doDebug "checking if package.json contains script section named $1" + if sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/§/g' package.json | tr -d '\r' | grep -q "[\"']scripts[\"']\s*:\s*{\s*§.*[\"']${1}[\"']\s*:" + then + return 0 + else + doEcho "no build script is present in package.json - skipping to run build script." + return 255 + fi +} + # $1: single CLI arg # returns 0 if a standard option was detected and handled, 255 otherwise (regular argument to be handeled by CLI parser) function doParseOption() {