@crisptickets/common
v1.0.10
Published
To publish a package to NPM, follow the steps below in the folder of the package: 1) npm init -y 2) change the "name" to "@<organization_name>/<package_name>" 3) git init -> git add . -> git commit -m "..." 4) npm login 5) npm publish --access public
Downloads
453
Readme
To publish a package to NPM, follow the steps below in the folder of the package:
- npm init -y
- change the "name" to "@<organization_name>/<package_name>"
- git init -> git add . -> git commit -m "..."
- npm login
- npm publish --access public
Since the shared libraries will be written in Typescript (and converted in JS before publishing them), you have to setup typescript with: tsc --init Then install typescript (install this dependencies only in DEV mode): npm install typescript del-cli --save-dev
--> Then you can create the typescript files of this library. Before publishing it, you need convert typescript files into javascript. Modify the 'scripts' in package.json as: "scripts": { "build": tsc // this will compile typescript to js } And you need to tell where to place the compiled js file obtained by the typescript source code. In the 'tsconfig.json', uncomment this properties: 1) declaration: true --> this will ensure to generate a type definition file while c converting typescript to js 2) outDir: ... --> set the js generated file in the 'build' directory
--> Whenever a change is made to the typescript file, you have to clean the "build" directory. Instead of doing it manually, you can use the "del-cli" package installed before. Add the "clean" script in package.json and specify the directory to remove when this command is run. Add that command to the "build" one
--> You have to make sure to specify the right file that is imported by the users that install this package. Since the typescript file is converted to js in the "build" directory, you have to change the "main" property (in 'package.json') to point to the file obtained while converting typescript to js (this is in the build/index.js) Then you also need to specify the TYPE DEFINITION file obtained by typescript. Do this in the "types" property (always in package.json). Then, the "files" property tells NPM to make sure to include the specified files inside the final publish version of this package.
Then add the .gitignore.
BEFORE PUBLISHING
- Add the changes to git + commit
- Increment the version of the package (manually or wih 'npm version patch')
- npm run build
- npm publish (just for this course a new script command is made to automate (1)->(4)) => DON'T DO THIS
FILES IN THIS PACKAGE All the custom errors and middleware (to check for authentication) are published in this file. In order for the user to be able to import a specific file from this package as: import { BadRequestError } from "@crispticket/common"
and not with the command: import { BadRequestError } from "@crispticket/common/error/bad-request-errors" you have to export all the files inside the 'index.ts'.
Then, since each of this file needs some libraries (like express, json-web-token) and so on, you have to install in this package all the libraries used by each of these files.