Starter: Create new (typescript enabled) NPM package from scratch

Date: 2018-02-07

1. Or create a folder with the name of the package you want to use

mkdir <package-name>

2. Generate a package.json file (answering the questions on de cli)

npm init -y

3. Install the latest typescript version globally

npm i -g typescript@latest

3. Install typescript as development dependency (saving to package.json)

npm install  typescript --save-dev

4. Generate a .tsconfig file

.\node_modules\.bin\tsc --init
or
./node_modules/.bin/tsc --init
or
tsc --init

5. in .tsconfig set:

"declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true,  /* Generates corresponding '.map' file. */

6. In package.json set:

{ 
"bin" : { "my-executable" : "./dist/index.js" } }, /* when exporting an executable*/
"main": "dist/index.js", /* when exporting a library */
"types": "dist/index.d.ts", /* typescript type definition file */
"scripts": {
"build": "tsc --listEmittedFiles",
"install": "tsc --listEmittedFiles", /* optional: when installing build project  */
"test": "jasmine --config=jasmine.json",
}
}

7. Install dependencies for unit-tests

npm install --save-dev jasmine
./node_modules/.bin/jasmine init
Add a .gitignore file
# compiled output
/dist
/tmp
/out-tsc
# dependencies
/node_modules

.project
*.launch
.settings/
.vscode/
# misc
npm-debug.log
/typings

# e2e
/e2e/*.js
/e2e/*.map

Add an .npmignore file

src/
# Maak een nieuwe map voor het project
mkdir MyProject
cd MyProject

# Maak een nieuw TypeScript-project
npm init -y
npm install typescript --save-dev
npx tsc --init

# Maak .gitignore en .npmignore bestanden
New-Item -ItemType File -Path .\.gitignore -Value "node_modules/"
New-Item -ItemType File -Path .\.npmignore -Value "node_modules/"

# Add jasmine
npm install --save-dev jasmine
npx jasmine init
10150cookie-checkStarter: Create new (typescript enabled) NPM package from scratch