Scenario
For our prototyping work we want a Typescript starter project preconfigured with Jest, Typedoc, and NPM Workflow Scripts.
Cloning it like this creates the project <project_name>
:
git clone git@github.com:fireflysemantics/typescript-starter.git <project_name>
This is the final repository in case you want to get right to it:
Approach
First create a new Node
project:
mkdir typescript-starter
cd typescript-starter
npm init -y
This initializes package.json
for us.
NPM Workflow Scripts
The below install-devdeps
will install the latest development dependencies needed:
"install-devdeps": "npm i -D typescript typedoc ts-node ts-jest source-map-support @types/node jest @types/jest"
The types/node
package from provides access to types for the node APIs like file
, process
and so on.
The script install-tools
install the latest development workflow packages:
"install-tools": "npm i -g del-cli npm-install-peers npm-check-updates @jsdevtools/version-bump-prompt http-server"
The script update
will update the dependency versions and install them and the newer versions of peer dependencies:
"update": "ncu -u && npm i && npm-install-peers"
The pub
script bumps the patch version and publishes the project to NPM:
"pub": "npm t && bump patch && npm run update && npm run build && npm publish"
The test script runs Jest:
"test": "jest"
The build script runs the build:
"build": "del-cli dist && tsc"
The doc
script runs Typedoc:
"doc": "del-cli doc && typedoc --entryPointStrategy expand ./src/ --out doc --exclude **/*.spec.ts"
And the sdoc
script runs Typedoc and serves up the results:
"sdoc": "npm run doc && http-server -o doc"
Typescript files are written to the doc
directory.
Jest Configuration
We will be using this Jest configuration (jest.config.js
):
Typescript Configuration
Our Typescript configuration is as follows:
Commit to Github
Create the Github repository fireflysemantics/typescript-starter
.
Then add, commit, and push the files.
git add .
git commit -m "First Commit"
git remote add origin git@github.com:fireflysemantics/typescript-starter.git
git push --set-upstream origin master
Test Project Creation
We can now tryout the README.md
instructions for the project:
git clone git@github.com:fireflysemantics/typescript-starter.git <project_name>cd <project_name>npm run install-allnpm test