A template for a TypeScript app. To make it easier to start a new app without having to go through all the configuration.
- Example module.
- Example command line app (installable via npm install -g)
- Testing using Jest.
- Debugging setup for VS Code.
When you want to start a new TypeScript app:
- Copy this repo
- In
package.json
, changetypescript-template-cli
toyou-cmd-name
the name of the your cli program (once installed on a user's computer). - Across the whole repo, search and replace
typescript-template
toyour-module-name
. - Install your own custom dependencies
- Add your custom code.
- Comit it all to your own repo.
- If necessary, publish to npm using
npm publish
.
You now have a reusable code module and/or command line app that you can 'npm install' and share with your team mates.
Clone or download and unpack the repo.
Install local dependencies
cd your-module-name
npm install
Once you publish you can install via npm and use it from TypeScript or JavaScript or from the command line.
Import and use it (in a TypeScript file):
import { ExampleClass } from 'your-module-name';
var example = new ExampleClass();
console.log(example.returnsTrue());
Import and use it (from JavaScript):
var yourModule = require('your-module-name');
var ExampleClass = yourModule.ExampleClass;
var example = new ExampleClass();
console.log(example.returnsTrue());
You can also run your published module as a command line app.
For example, install it globally:
npm install -g your-module-name
Then run it:
your-module-name-cli [args]
Open folder in Visual Studio Code and hit Ctrl+Shift+B
Or
cd your-module-name
npm run compile
- Open in Visual Studio Code.
- Select 'Main' debug configuration.
- Select the 'Test All' or 'Test Current' debug configuration to debug all tests or the current test file.
- Set your breakpoints.
- Hit F5 to run.
Compile the application:
npm run build
The run the compiled JavaScript:
npm start
Run the command line app directly:
npm start:dev
Run tests directly:
npm test
Or:
npm run test:watch
See package.json for more scripts!