# dricup-cli

> A CLI to quickly create Express JS Api's

Latest version **0.0.1** (published 2020-12-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install dricup-cli
pnpm add dricup-cli
yarn add dricup-cli
bun add dricup-cli
```

Provides the command `dricup`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2020-12-21 |
| First published | 2020-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=13.x |
| Dependencies | 13 |
| Unpacked size | 74.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Faraz Ahmad |
| Maintainers | farazahmad759 |
| Keywords | dricup, dricup-cli, mern, mean, mevn, express-generator, node app-generator |

## Links

- npm: https://www.npmjs.com/package/dricup-cli
- Repository: https://github.com/farazahmad759/dricup-cli
- Homepage: https://github.com/farazahmad759/dricup-cli#readme
- Issues: https://github.com/farazahmad759/dricup-cli/issues
- npm.io page: https://npm.io/package/dricup-cli

## Dependencies (13)

- [arg](https://npm.io/package/arg.md) ^5.0.0
- [esm](https://npm.io/package/esm.md) ^3.2.18
- [ncp](https://npm.io/package/ncp.md) ^2.0.0
- [rxjs](https://npm.io/package/rxjs.md) ^6.6.3
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [execa](https://npm.io/package/execa.md) ^4.1.0
- [listr](https://npm.io/package/listr.md) ^0.14.3
- [npmview](https://npm.io/package/npmview.md) ^0.0.4
- [inquirer](https://npm.io/package/inquirer.md) ^7.3.3
- [pluralize](https://npm.io/package/pluralize.md) ^8.0.0
- [pkg-install](https://npm.io/package/pkg-install.md) ^1.0.0
- [edit-json-file](https://npm.io/package/edit-json-file.md) ^1.5.0
- [get-installed-path](https://npm.io/package/get-installed-path.md) ^4.0.8

## Recent versions

- 0.0.1 (latest) — 2020-12-21

## README

<header>

<h1 style="font-weight:200; font-size:80px">Dricup CLI (beta)</h1>

</header>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
![node-current (scoped with tag)](https://img.shields.io/node/v/@dricup/dricup-cli/latest?color=green)
![Dependencies](https://img.shields.io/badge/dependencies-up%20to%20date-brightgreen.svg)
[![GitHub Issues](https://img.shields.io/github/issues/farazahmad759/dricup-cli)](https://github.com/farazahmad759/dricup-cli/issues)
![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

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](https://vercel.com/).

## Table of Contents

- [Installation](#Installation)
- [Features](#Features)
- [Quickstart](#Quickstart)
- [Supported Commands](#Supported-commands)
- [Documentation](./documentation/features.md)
- [Acknowledgements](#Acknowledgements)
- [Authors](#Authors)
- [Support](#Support)
- [Use cases](#Use-cases)
- [License](#License)

## 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](https://vercel.com/).
- Clean directory structure, taken from [express-generator](https://github.com/expressjs/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](http://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](http://localhost:3000/app-1), you will see another web page coming to you via Client Side Rendering.

**Database configuration**<br>
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.

2. Run the following command

```
knex migrate:up
```

3. 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 <br> 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](./documentation/documentation.md)

| Action             | Command                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Create Project     | `dricup --create:project` <br> Creates a new project in the current working directory (CWD)                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Create Migrations  | **Single**<br>`dricup --create:migrations --file="file_name.json"` <br> Reads `file_name.json` from _dricup/schemas_ directory and creates a database migration file in _migrations_ directory. <br><br> **Bulk**<br>`dricup --create:migrations --all` <br> Reads all `.json` files from _dricup/schemas_ directory and creates database migration files for all of them in _migrations_ directory                                                                                                                                           |
| Create Models      | **Single**<br>`dricup --create:models --file="file_name.json"` <br> Reads `file_name.json` from _dricup/schemas_ directory and creates a _Model_ file in _models_ directory.<br><br> **Bulk**<br>`dricup --create:models --all` <br> Reads all `.json` files from _dricup/schemas_ directory and creates database Models for all of them in _models_ directory.                                                                                                                                                                               |
| Create Controllers | **Single**<br>`dricup --create:controllers --file="file_name.json"` <br> Reads `file_name.json` from _dricup/schemas_ directory and creates a _Controller_ file in _controllers_ directory.<br><br> **Bulk**<br>`dricup --create:controllers --all` <br> Reads all `.json` files from _dricup/schemas_ directory and creates _Controllers_ for all of them in _controllers_ directory.                                                                                                                                                        |
| Create Routes      | **Single**<br>`dricup --create:routes --file="file_name.json"` <br> Reads `file_name.json` from _dricup/schemas_ directory and creates a _Route_ file in _routes_ directory.<br><br> **Bulk**<br>`dricup --create:routes --all` <br> Reads all `.json` files from _dricup/schemas_ directory and creates _Routes_ for all of them in _routes_ directory. <hr> Note: The routes commands above will also create/update an additional file `routes.js` in _routes_ directory.                                                                   |
| Create CRUD APIs   | **Single**<br>`dricup --create:crud --file="file_name.json"` <br> Reads `file_name.json` from _dricup/schemas_ directory and creates Migration, Model, Controller and Route files in respective directories.<br><br> **Bulk**<br>`dricup --create:crud --all` <br> Reads all `.json` files from _dricup/schemas_ directory and creates Migrations, Models, Controllers and Routes for all of them in respective directories. <hr> 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](./documentation/documentation.md), 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](https://github.com/appzcoder/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](https://expressjs.com/) framework to create the MERN, MEAN and MEVN stack apps quickly.
- The basic boilerplate code and directory structure has been taken from [express-generator](https://github.com/expressjs/generator)
- Database migrations are handled using [knex](http://knexjs.org/)
- [Objection Js](https://vincit.github.io/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](https://github.com/remy/nodemon)

## Authors

- Faraz Ahmad (https://github.com/farazahmad759)

## 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](https://www.patreon.com/farazahmad759)

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

## License

[MIT](https://github.com/farazahmad759/dricup-cli/blob/main/LICENSE)

## 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](https://sequelize.org/).

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

---
_Source: https://npm.io/package/dricup-cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
