npm install typescript -g
npm install typings -g
npm install mocha -g
npm init --force
typings install dt~node --global --save
typings install dt~mocha --global --save
- Modify
package.jsonusing template in this gist to define npmbuildandtestscripts. - Create
tsconfig.jsonusing template in this gist to allow runningtscto build all TypeScript files in the directory. - Create
.gitignorefrom template in this gist to avoid storing intermediate files produced by build in Git repository. - Create
.vscode/tasks.jsonusing template in this gist to define VSCodebuildandtesttasks. - Create
.vscode/launch.jsonusing template in this gist - Create
src\product.tsusing template in this gist - Create
test\product.tsusing template in this gist
- VSCode:
Ctrl+Shift+B - Shell:
tscornpm run build
How it works:
npmruns thebuildscript defined inpackage.jsonto invoketsccommand from thetypescriptmodule.tsclooks fortsconfig.jsonin the current directory and usesoutDirproperty to maketscgenerate.jsfiles in thebuildsubfolder,sourceMapsto generate.js.mapalong with them.
- VSCode:
Ctrl+Shift+PthenTasks: Run Test Task - Shell:
mocha build/testornpm test
node build/index.js
How it works:
tsccompilesindex.tstoindex.jsin thebuilddirectory based on thetsconfig.jsonsettingsnoderuns the JavaScript inindex.js
VS Code
Ctrl+Shift+Dto open Debugger view- select
Launchdebugger configuration F5
How it works:
.vsconfig/launch.jsondefinesLaunchconfigurationprogramproperty to indicate which.tsfile contains the application entry point,sourceMapsproperty to make debugger use.js.mapfiles,outDirproperty to specify where to find them.
- Shell
mocha build/test --debug-brk
- VS Code
Ctrl+Shift+Dto open Debugger view- select
Attachdebugger configuration F5
How it works:
mochatells node to stop as soon as it starts executing the test runner- Node starts listening on port 5858
- VS Code
Attachconfiguration supplies debugger settingsaddresstells debugger to connect tolocalhostwhere node is runningporttells debugger to connect to5858where node is listening