Skip to content

Neha/develop-your-first-CLI-workshop

Repository files navigation

💥 Develop your First CLI - Workshop 💥

This repo is the step-by-step guide to develop the CLI in Nodejs. This repo is the part of the GDG (Google Developer Groups), New Delhi/Gurgaon.

📆 Event Details

April

  • Event Name: Code-lab : Web Developers Day 3 by Google Developer Group, New Delhi
  • Date: 28th April 2019
  • Location: 91Springboard, Gurgaon
  • Event Link: GDG Event Page

May

  • Event Name: Code-lab : Develop your First CLI, Bangalore
  • Date: 12th May 2019
  • Location: Microsoft, Bangalore
  • Event Link: JSLovers

Introduction

My name is Neha Sharma. I am working as technical lead. I am the organizer of JSLovers community. I am tech and non-tech speaker. Apart form coding I enjoy doing calligraphy.

You can reach me :

❗ Pre-requists ❗

  • ✅ Knowledge of Javascript
  • ✅ Knowledge of nodejs
  • ✅ Comfortble working with CLI and IDE
  • ✅ Github account
  • ✅ NPM account

📝 Agenda

  1. What is nodejs & CLI [Theory]
  2. Project walkthrough [Theory]
  3. Folder structure [Theory]
  4. Installing package.json [Code]
  5. Create your data [Code]
  6. Code time [Code]
  7. Publish the npm [Code]

Content

  1. Walkthrough of Nodejs, CLI , and Project
  2. Setup your machine - nodejs, folder structure, package.json
  3. Create your data
  4. Install require package and print your first message
  5. Write the code
  6. Publish the NPM

🔔 How to use this repo?

This repo is step-by-step guide. You can clone the repo or follow along.Every folder is marked below with what is expected in it.

0️⃣ Walkthrough [Theory]

Introduction to nodejs and CLI.

Folder : session-1/intro.md

1️⃣ Setup your machine [Codelab]

Folder : session-1

  • Install nodejs

  • Create a folder - "myprofile"

  • Create package.json

      npm init
    

2️⃣ Create your Data [Codelab]

Folder : session-2

Go to folder session-2/myprofile/data. If you want to update the content you can edit it in data.js

3️⃣ Code Time [Codelab]

Folder : session-3

Go to folder session-3/myprofile. In this we will identify the commands and add it to the commands folder.

To sync with data.js we have following commands (user input) :

  • about me
  • contact me
  • experience
  • summary

To print the choices on the terminal we will use the npm package inquirer.

4️⃣ Beautification

Folder : session-4

This section is totally optional. To make the CLI' content more colorful and presentable. We will use two more packages:

  • chalk : Will let us provide the colors to the texts.
  • cfonts : Will let us write a big fancy welcome message.
  • inquirer : Common interactive command line user interfaces.
  • commander : Common interactive command line user interfaces.

5️⃣ Publish NPM [Codelab]

How to make it Executable?

  1. Add #!/usr/bin/env node on the top of index.js. Read about it here : https://en.wikipedia.org/wiki/Shebang_%28Unix%29

  2. In package.json, add section of bin

    "bin": {
        "myprofile": "./index.js"
    }
    
  3. Run the following command

     npm link
    
  4. Now go to the terminal and write

     myprofile
    

Publish to NPM

  1. Create an account in npmjs.com

  2. On terminal run the following command & enter the username and password.

    npm login
    
  3. To publish

    npm publish
    

    You can check your package after publishing : https://www.npmjs.com/~{username}/{package-name}

How to run it?

  1. Go to the desire folder. eg :

    cd session-2/myprofile
    
  2. Install the dependency

    npm install
    
  3. From the root of the myprofile run the following command to start the application

    node index.js
    

If you are only interested in the end code then clone the session-4 folder.

♥️ Collabrations

Collabrations are the awesome way to create small things better, and big. If you see anything which can be improved ? If you see something can be added here? Before telling to anyone else, raise the PR :) . If you are new to the collabrations and have no idea how to do it. Do not worry, reach to me [email protected]

About

develop-your-first-CLI-workshop

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published