Skip to content

Instantly share code, notes, and snippets.

@benosman
Created March 30, 2017 12:33
Show Gist options
  • Select an option

  • Save benosman/c80653779f90a5d6fb0b95ad2654dc96 to your computer and use it in GitHub Desktop.

Select an option

Save benosman/c80653779f90a5d6fb0b95ad2654dc96 to your computer and use it in GitHub Desktop.
post deployment script to build nuxt based on deploy.cmd - place in deployment subfolder
[config]
SCM_POST_DEPLOYMENT_ACTIONS_PATH=deployment
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
:: ----------------------
:: Post Deployment Script
:: Version: 1.0.13
:: ----------------------
:: Prerequisites
:: -------------
:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
goto error
)
:: Setup
:: -----
setlocal enabledelayedexpansion
SET SITES=%~dp0%..\..\..
IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%~dp0%..
)
IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%SITES%\wwwroot
)
goto Build
:: Utility Functions
:: -----------------
:SelectNodeVersion
IF DEFINED KUDU_SELECT_NODE_VERSION_CMD (
:: The following are done only on Windows Azure Websites environment
call %KUDU_SELECT_NODE_VERSION_CMD% "%DEPLOYMENT_SOURCE%" "%DEPLOYMENT_TARGET%" "%DEPLOYMENT_TEMP%"
IF !ERRORLEVEL! NEQ 0 goto error
IF EXIST "%DEPLOYMENT_TEMP%\__nodeVersion.tmp" (
SET /p NODE_EXE=<"%DEPLOYMENT_TEMP%\__nodeVersion.tmp"
IF !ERRORLEVEL! NEQ 0 goto error
)
IF EXIST "%DEPLOYMENT_TEMP%\__npmVersion.tmp" (
SET /p NPM_JS_PATH=<"%DEPLOYMENT_TEMP%\__npmVersion.tmp"
IF !ERRORLEVEL! NEQ 0 goto error
)
IF NOT DEFINED NODE_EXE (
SET NODE_EXE=node
)
SET NPM_CMD="!NODE_EXE!" "!NPM_JS_PATH!"
) ELSE (
SET NPM_CMD=npm
SET NODE_EXE=node
)
goto :EOF
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Build
:: ----------
:Build
echo Building nuxt.
:: 1. Select node version
call :SelectNodeVersion
:: 2. Build nuxt
IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd !NPM_CMD! run build
IF !ERRORLEVEL! NEQ 0 goto error
popd
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end
:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%
:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul
:exitSetErrorLevel
exit /b 1
:exitFromFunction
()
:end
endlocal
echo Finished successfully.
@benmccallum
Copy link
Copy Markdown

Thanks mate. Saved me a bit of time doing another one of these. I thought about whether I could use kuduSync to only copy over into wwwroot the bare essentials (.nuxt folder and nuxt.config.js) but not being a node guy I was hesitant to waste time trying in case there was other things it needed. At the end of the day it doesn't matter a whole lot!

@benmccallum
Copy link
Copy Markdown

Also worth noting that if you've got "devDependencies" required during the build, they aren't installed by Azure's standard kudu script, so you may need to add a line between step 1 and 2 that does an npm install --only:dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment