1.0.0 • Published 2 years ago

tiny-npm-deploy-swap v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Publish the project to NPM: cli --> NPM Registry(cli) local-api --> NPM Registry(local-api) local-client --> NPM Registry(local-client)

--> npm install -g jbook

--> User' machine
    cli -- uses
        local-api -- uses
            local-client

Note the dependency here between the modules.

tiny-npm-deploy -- this package should start up an express server listening on port 3005 index.ts --> Typescript complier --> index.js

Create directory: D:\Self-Learning\TypeScript-Redux\react\big-project>mkdir tiny-npm-deploy D:\Self-Learning\TypeScript-Redux\react\big-project>cd tiny-npm-deploy

Create package.json: D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npm init -y Wrote to D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy\package.json:

{
"name": "tiny-npm-deploy",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

Install typescript and express: D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npm install typescript express npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/ npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN tiny-npm-deploy@1.0.0 No description npm WARN tiny-npm-deploy@1.0.0 No repository field.

+ express@4.18.1
+ typescript@4.7.4
added 58 packages from 43 contributors in 13.954s

7 packages are looking for funding
run `npm fund` for details

Install Express @types: D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npm install @types/express npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/ npm WARN tiny-npm-deploy@1.0.0 No repository field.

+ @types/express@4.17.13
added 9 packages from 72 contributors in 48.819s

7 packages are looking for funding
run `npm fund` for details

Create tsconfig file:

D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npx tsc --init
Created a new tsconfig.json with:
target: es2016
module: commonjs
strict: true
esModuleInterop: true
skipLibCheck: true
forceConsistentCasingInFileNames: true

Enable properties in tsconfig file: "declaration": true, "outDir": "./dist",

Create dist directory for generating JS of relevant TS: D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npm run build

> tiny-npm-deploy@1.0.0 build D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy
> tsc

Changes needed in package.json: 1. Remove from scripts object: "test": "echo \"Error: no test specified\" && exit 1" 2. Add to scripts object: "build": "tsc" 3. Change the name to something unique which is not already present on NPM 4. Add following piece to specify what files needs to ge to NPM: "files": "dist" , 5. Move "@types/express": "^4.17.13" and "typescript": "^4.7.4" from dependencies to devDependencies: Since, we don't want User to download those dependecies on his/her machine as we are using it internally and already generating required JS "dependencies": {
"express": "^4.18.1" }, "devDependencies": { "@types/express": "^4.17.13", "typescript": "^4.7.4" } 6. Add section to publish project publicly: "publishConfig": { "access": "public" }, 7. Specify which file to load on server start: "bin": "dist/index.js", 8. Add in scripts by default to run npm build: "scripts": { "build": "tsc", "prepublishOnly": "npm run build" },

Add in index.ts file: This will allow to directly execute this file from terminal #!/usr/bin/env node

Commit to GIT: 1. D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>git init Initialized empty Git repository in D:/Self-Learning/TypeScript-Redux/react/big-project/tiny-npm-deploy/.git/

2. Note: We should not commit the node_modules and dist directory to GIT as they are not part of source code.
    To do so create .gitignore file with contents of both directory names: dist and node_modules

3. D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>git status
    On branch master
    No commits yet
    Untracked files:
    (use "git add <file>..." to include in what will be committed)
            .gitignore
            package-lock.json
            package.json
            readMe.txt
            src/
            tsconfig.json
    nothing added to commit but untracked files present (use "git add" to track)

4. D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>git add .
    warning: LF will be replaced by CRLF in package-lock.json.
    The file will have its original line endings in your working directory
    warning: LF will be replaced by CRLF in package.json.
    The file will have its original line endings in your working directory

5. D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>git commit -m "initial commit"
    [master (root-commit) 1cf4623] initial commit
    6 files changed, 764 insertions(+)
    create mode 100644 .gitignore
    create mode 100644 package-lock.json
    create mode 100644 package.json
    create mode 100644 readMe.txt
    create mode 100644 src/index.ts
    create mode 100644 tsconfig.json

NPM Publish: 1. To publish you need to be logged into NPM a. Create your account on NPM JS (https://www.npmjs.com/) Remember the credentials used while login

    b. D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npm login
        npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
        Username: <username>
        Password: <password>
        Email: (this IS public) swapneil99@gmail.com
        npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
        npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
        npm ERR! code E426
        npm ERR! 426 Upgrade Required - PUT http://registry.npmjs.org/-/user/org.couchdb.user:swapneil99

        npm ERR! A complete log of this run can be found in:
        npm ERR!     C:\Users\work\AppData\Roaming\npm-cache\_logs\2022-06-26T14_20_45_649Z-debug.log
    
    You might see this nasty error here. This is error is basically related to https. By default http is used in our app which is causing the issue.
    We need to set the registry to use https instead as provided in next step.

    c. To get rid of above error hit following command:
        D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npm config set registry https://registry.npmjs.org/

    d. D:\Self-Learning\TypeScript-Redux\react\big-project\tiny-npm-deploy>npm login
        Username: <username>
        Password: <password>
        Email: (this IS public) swapneil99@gmail.com
        npm notice Please check your email for a one-time password (OTP)
        Enter one-time password from your authenticator app: <otp goes here>
        Logged in as swapneil99 on https://registry.npmjs.org/.

    OTP will be sent to your registered email ID. You should now be successfully logged into NPM on your terminal.