Have ideas to improve npm?Join in the discussion! »

    dricup-cli

    0.0.1 • Public • Published

    Dricup CLI (beta)

                        node-current (scoped with tag) Dependencies GitHub Issues Contributions welcome License

    A simple straightforward package to bootstrap your MERN and MEVN stack projects. The projects generated through dricup-cli are pre-configured for deployment to vercel.

    Table of Contents

    Installation

    npm install -g @dricup/dricup-cli
    

    Features

    • Bootstraps your MERN/MEVN stack projects.
    • From your_schema_file.json, you can instantly create CRUD API's with a single command by generating the following
      • Database Migrations
      • Models
      • Controllers
      • Routes
    • Supports handlebars templating engine for server-side-rendering (SSR)
    • Supports the generation of client-side-rendered (CSR) apps
    • Your projects are pre-configured for instant deployment to Vercel.
    • Clean directory structure, taken from express-generator

    Quickstart

    First of all open the terminal if you are using MacOS or Linux, or command_prompt for windows. Then run npm install -g @dricup-dricup-cli to install dricup-cli globally.

    Create and navigate to a new directory for your project

    mkdir dricup_project && cd dricup_project
    

    Create the project

    dricup --create:project
    

    Install the packages

    npm install
    

    Run the project

    npm run server
    

    Open localhost:3000 and see your MERN app up and running :) This page comes to you via Server Side Rendering. Now, if you type localhost:3000/app-1, you will see another web page coming to you via Client Side Rendering.

    Database configuration
    Uptill now we have only viewed static web pages that do not show any content coming from the database. In order to involve database, you need to provide credentials for your database. Don't worry, it's very easy. Just follow along.

    1. Open knexfile.js in the root of your project. You will see a knexConfig object in it that has several database configurations for different environments (development, staging, production). For testing on local machine, we need to update development credentials. The default credentials are
      development: {
        client: "mysql",
        connection: {
          host: "127.0.0.1",
          database: "express-test-app",
          user: "root",
          password: "",
        },
        migrations: {
          directory: __dirname + "/migrations",
        },
        seeds: {
          directory: __dirname + "/seeds/development",
        }
      }
    

    Just update host, database, user and password fields in the above object.

    1. Run the following command
    knex migrate:up
    
    1. Congratulations! Now you have access to users Api and you can call the following endpoints
    HTTP Method URL Function
    POST http://localhost:3000/users Create new user in database
    GET http://localhost:3000/users/:id Find a user by Id
    PUT http://localhost:3000/users/:id Update a user by Id
    DELETE http://localhost:3000/users/:id Delete a user by Id
    GET http://localhost:3000/users Finds all users
    Users can be filtered by providing the query paramaters in the URL. Like, http://localhost:3000/users?email=faraz will fetch all users whose email contains the string 'faraz'

    Supported-commands

    Dricup CLI provides several helpful commands for creating database migrations, Models, Controllers, and Routes, which are listed below. Detailed in-depth description is provided in documentation

    Action Command
    Create Project dricup --create:project
    Creates a new project in the current working directory (CWD)
    Create Migrations Single
    dricup --create:migrations --file="file_name.json"
    Reads file_name.json from dricup/schemas directory and creates a database migration file in migrations directory.

    Bulk
    dricup --create:migrations --all
    Reads all .json files from dricup/schemas directory and creates database migration files for all of them in migrations directory
    Create Models Single
    dricup --create:models --file="file_name.json"
    Reads file_name.json from dricup/schemas directory and creates a Model file in models directory.

    Bulk
    dricup --create:models --all
    Reads all .json files from dricup/schemas directory and creates database Models for all of them in models directory.
    Create Controllers Single
    dricup --create:controllers --file="file_name.json"
    Reads file_name.json from dricup/schemas directory and creates a Controller file in controllers directory.

    Bulk
    dricup --create:controllers --all
    Reads all .json files from dricup/schemas directory and creates Controllers for all of them in controllers directory.
    Create Routes Single
    dricup --create:routes --file="file_name.json"
    Reads file_name.json from dricup/schemas directory and creates a Route file in routes directory.

    Bulk
    dricup --create:routes --all
    Reads all .json files from dricup/schemas directory and creates Routes for all of them in routes directory.
    Note: The routes commands above will also create/update an additional file routes.js in routes directory.
    Create CRUD APIs Single
    dricup --create:crud --file="file_name.json"
    Reads file_name.json from dricup/schemas directory and creates Migration, Model, Controller and Route files in respective directories.

    Bulk
    dricup --create:crud --all
    Reads all .json files from dricup/schemas directory and creates Migrations, Models, Controllers and Routes for all of them in respective directories.
    Note: The crud commands above will also create/update an additional file routes.js in routes directory.

    Documentation

    You can view in-depth documentation here, but let's get an overview here. When you first run dricup --create:project command, it will create the following file structure.

    .
    ├── client                  # CSR rendered apps will be stored here
    │   └── app-1
    │   │   └── build
    │   │       └── index.html  # it will be rendered at localhost:3000/app-1
    │   └── `client.js`         # IMPORTANT: contains names and routes of all the client apps
    ├── controllers             # API files should be placed in this directory
    ├── dricup                  # all schemas files should be placed in dricup/schemas directory
    │   └── schemas
    │       └── users.json
    ├── migrations              # database migration files are stored here
    ├── models                  # Models in MVC are created in this directory
    ├── public                  # images, stylesheets and javascript files can be placed here
    ├── routes                  # contains application routes
    │   └── index.js
    │   └── `routes.js`         # IMPORTANT: stores information about all other files in the directory
    │   └── users.js
    ├── views                   # Views (in MVC) are stored here
    ├── app.js
    ├── dricup.config.json      # IMPORTANT: do not delete/modify it
    ├── index.js                # IMPORTANT: entry file of the app
    ├── knexfile.js             # IMPORTANT: database configurations are stored here
    ├── now.json                # IMPORTANT: config file for deployment to Vercel
    └── README.md
    

    Notes

    Client Apps

    • Client-side rendered apps should be stored "directly" inside /client directory.
    • Each app should have a "build" directory containing an index.html at the minimum. Otherwise it won't work. This applies to HTML as well as Js-framework'ed apps. If your CSR rendered app is React/Vue/Angular app, the npm build command should output an index.html file in "build" directory.
    • Each app should be registered in client/client.js file, otherwise it won't be displayed. The route where this app will be displayed, is also configured in client/client.js file.

    CRUD Api

    Whether you want Migrations, Models, Controllers or Routes (or even full API creation), all you have to do is provide a some_schema.json file for every database table. The Schema files should be of the following format.

    {
        "tableName": "users",
        "fields": [
            {
                "title": "name",
                "type": "string"
            },
            {
                "title": "username",
                "type": "string"
            },
            {
                "title": "email",
                "type": "string"
            },
            {
                "title": "password",
                "type": "string"
            }
        ]
    }
    

    Acknowledgements

    • Inspired by Laravel CRUD generator that speeds up the app development process by minimizing the redundancy.
    • Dricup CLI is not a framework, rather it makes use of Express JS framework to create the MERN, MEAN and MEVN stack apps quickly.
    • The basic boilerplate code and directory structure has been taken from express-generator
    • Database migrations are handled using knex
    • Objection Js is used to created Models and Controllers (CRUD Api). This is the only supported ORM as of now. Support for other ORM's will be added soon.
    • Nodemon

    Authors

    Support

    This package has been created to save the precious time that each developer spends while setting up every project. It is still in beta. I am actively working to make it robust. If you find this helpful and want to support me, there are two ways you can do this.

    1. Become a Patreon

    2. Work with me (Contact: farazahmad759@gmail.com)

    License

    MIT

    Use-cases

    Coming soon

    What is more?

    This is just the beginning. Several options will be added very soon to configure libraries such as Sequelize.

    Feel free to request features, and I will be delighted to assist you in the issues that you experience while using this package.

    Install

    npm i dricup-cli

    DownloadsWeekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    76 kB

    Total Files

    35

    Last publish

    Collaborators

    • avatar