## NPM

``` 

npm adduser

npm version

npm publish
```

``` 

npm run build
npm run lint
npm run format
```

# Notes

Setup package.json

``` 

# only file in /lib are included in npm package
  "files": [
    "lib/**/*" 
  ]
  ```

## Scripts

prepare will run both BEFORE the package is packed and published, and on local npm install. Perfect for running building the code. Add this script to package.json

``` 

"prepare" : "npm run build"

```

prepublishOnly will run BEFORE prepare and ONLY on npm publish. Here we will run our test and lint to make sure we don’t publish bad code:

``` 

"prepublishOnly" : "npm test && npm run lint"
```

preversion will run before bumping a new package version. To be extra sure that we’re not bumping a version with bad code, why not run lint here as well? 😃

``` 

"preversion" : "npm run lint"
```

Version will run after a new version has been bumped. If your package has a git repository, like in our case, a commit and a new version-tag will be made every time you bump a new version. This command will run BEFORE the commit is made. One idea is to run the formatter here and so no ugly code will pass into the new version:

``` 

"version" : "npm run format && git add -A src"
```

Postversion will run after the commit has been made. A perfect place for pushing the commit as well as the tag.

``` 

"postversion" : "git push && git push --tags"
```

## Bumping a new version

``` 

npm version patch
```

Our preversion, version, and postversion will run, create a new tag in git and push it to our remote repository. Now publish again:

``` 

npm publish
```

# Links

[Building and publishing an NPM Typescript package](https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c)
