Initial Setup
Create a package.json file:
npm init -y
Update name of the package to: @cfntickets/common.
In order to publish a package, it has to be initialized and commited to git
git init && git add . && git commit -m "initial commit"
Login to npm:
npm login
Publish package to the organization:
npm publish --access public
Generate a TS config file:
tsc --init
Install initial dependencies (just for dev):
npm i typescript del-cli --save-dev
Add follow-up scripts to package.json to compile typescript code into JS and to clean build folder when trying to rebuild the project:
{
"clean": "del ./build/*",
"build": "tsc"
}
Uncomment and update these lines in tsconfig.json file:
- "declaration": true,
- "outDir": "./build"
Update package.json to set main file source, main def type file and what files should be included in the final published version of the package:
{
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"build/**/*"
],
}
Add .gitignore file to avoid commiting to git folders:
- build
- node_modules
To publish a change, commit the changes:
git add . && git commit -m \"Updates\"
And update the package version (check semantic versioning for details):
npm version patch
Then, rebuild the project:
npm run build
And finally we can publish:
npm publish
NOTE: Don't forget to install the rest of the dependencies needed for the package to work.
npm i express express-validator cookie-session jsonwebtoken @types/cookie-session @types/express @types/jsonwebtoken