10

I would like to avoid adding the generated JavaScript files to the git source control repository. Does the Azure Git Deploy support running addition commands to run the build before deploying the files?

Joe Wood
  • 1,321
  • 2
  • 13
  • 25

5 Answers5

3

Yes, you can run arbitrary logic using a custom deployment script. You'll need to either include the tools you need in your repo, or preferably download them as needed (to avoid commiting binaries).

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • I tried this but it seems like the custom deployment script generated from the azure site tool ignores the node engine specification in the package.json. I need to upgrade to 8.x to support the TypeScript compiler. – Joe Wood Feb 28 '13 at 02:37
  • Hmmm, that shouldn't be the case I think. We'd need to look at a repro repository to make sense of it. – David Ebbo Feb 28 '13 at 02:56
  • Actually, you're right, it doesn't work today but it soon will :) – David Ebbo Feb 28 '13 at 08:36
  • Great, does "soon will" mean a new release of Azure WebSites, the 'azure site' tool or just a back-end fix? – Joe Wood Feb 28 '13 at 12:08
  • Or, if you could just publish the magic command to scan and update the engine - that would work too :-) – Joe Wood Feb 28 '13 at 12:09
  • Please see Amit's new answer (he works on this with me). And feel free to accept it as the answer instead of this one! :) – David Ebbo Feb 28 '13 at 19:57
3

For now you can generate a custom deployment script custom deployment script

Then edit the npm command to use the newer node.exe version (0.8.2) with the following command:

call "D:\Program Files (x86)\nodejs\0.8.2\node.exe" "D:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" install --production

Amit Apple
  • 9,034
  • 41
  • 50
  • OK, I got it to work by explicitly calling this version of node for both npm and the tsc compiler. The TS module was installed into %appdata%\npm\node_modules\typescript. – Joe Wood Feb 28 '13 at 22:48
  • as azure-cli was updated you can now generate a custom deployment script as described by David and the %NODE_EXE% environment variable will contain the correct node.exe version according to the package.json file (and what's available on Azure). – Amit Apple Apr 08 '13 at 17:01
2

Just in case somebody else is looking, this is what I needed to do to get this working.

First, I make sure that TypeScript is installed where the Kudu build server can reach it, by adding these lines somewhere towards the top of my deploy.cmd file:

call npm install typescript
IF %ERRORLEVEL% NEQ 0 (
  echo Unable to install TypeScript
  goto error
)

This places the Node-callable version of TypeScript in .\node_modules\.bin\tsc.cmd.

The batch file that actually performs the build (callable in various ways, but primarily as a post-build event) looks like this:

@echo off
if (%1%=="") goto settsc
cd %1%

:settsc
if exist ".\node_modules\.bin\tsc.cmd" (
    set tsc=call ".\node_modules\.bin\tsc.cmd"
    goto build
)
if exist "%ProgramFiles(x86)%\Microsoft Sdks\Typescript\0.9\tsc.exe" (
    set tsc="%ProgramFiles(x86)%\Microsoft Sdks\Typescript\0.9\tsc.exe"
    goto build
)
if exist "%ProgramFiles%\Microsoft Sdks\Typescript\0.9\tsc.exe" (
    set tsc="%ProgramFiles%\Microsoft Sdks\Typescript\0.9\tsc.exe"  
    goto build
)
echo TypeScript compiler not found
exit 999

:build
echo Building TypeScript: Payboard.Site.js (using %tsc%)
%tsc% --sourcemap --out Scripts\Payboard\Payboard.Site.js @tsbuild_Site.txt
echo Building TypeScript: Payboard Widget (using %tsc%)
%tsc% --sourcemap --out Widget\v1.0\Payboard.js @tsbuild_Widget_v10.txt
echo Building TypeScript: App\Payboard.App.js (using %tsc%)
%tsc% --sourcemap --out App\Payboard.App.js @tsbuild_App.txt

Hope this helps someone else out.

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
1

And here is another option for a workaround that doesn't require custom deploy scripts, no batch files and only minimal changes to the project file.

The blog post with details is available at http://manfredlange.blogspot.co.nz/2014/01/aspnet-mvc-typescript-azure-website-and.html. The source code for the example project referred to in the blog post is available at https://bitbucket.org/ml_agileutilities/typescript-sample. There is a branch that reproduces the issue and there is a second branch that includes the workaround.

Please be aware that as far as I know Microsoft is working on a proper solution. At the time you are reading this the workaround may no longer be required.

Manfred
  • 5,320
  • 3
  • 35
  • 29
0

Typescript can now be used without any scripting. Just make sure TypeScript works from VS, then it will also work in the Kudu build. Note that you may have TypeScript version clashes, see e.g. this question .

Community
  • 1
  • 1
theDmi
  • 17,546
  • 6
  • 71
  • 138