1.7.0 • Published 1 year ago

@arameau/cli v1.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

IGS CLI

IGS CLI - The CLI tool for IGS projects

Instalation

npm install git+ssh://git@github.com:IvanAram1107/igs-cli.git --save-dev
# or
npm install IvanAram1107/igs-cli --save-dev

JSON Definition

The JSON filename must be igs.db.json for the db admin tool and the db models generator tool and igs.routes.json for the routes model generator tool.

  • db

The json file should have the projects as the keys, and their values should be an object decribing the database used in that project. The database description should be an object with its keys being the filenames / tablenames, and the values should be the field definition. The filenames should be kebab-case while the tablenames are in snake-case; both are the same, the only difference is that the tablenames have the project name prepended. Also the generated DB model is the same as the filename but in pascal-case.

  • routes

The keys of the JSON should be the projects and the values should be objects, these objects should have the endpoints as keys and the required CRUD operations as values, see below to understand better. If post or patch should not be created for a specific endpoint then the value should be null, while for get and delete it should be false. If other sub-endpoint has to be added, another key should be added to the endpoint (see below). If a post or patch field is a file, then the field name should be prepended with file: so that the generator knows that it will receive a file.

// DB JSON
{
  "<project>": {
    "<filename>": {
      "<field>": {
        "datatype": "ID | INTEGER | TINYINT | DECIMAL | VARCHAR | JSON | DATETIME | DATE | TIME | BLOB | TEXT",
        "size (optional)": "number",
        "decimal (optional)": "number",
        "nullable (optional)": "boolean (defaults to true)",
        "defaultValue (optional)": "any",
        "foreign-table (optional)": "<project>.<filename>"
      }
    }
  } 
}
// Routes JSON
{
  "<project>": {
    "[file:]<db_model_name>": {
      "get (optional)": "boolean (defaults to true)",
      "post (optional)": "string[] | null (defaults to null)",
      "patch (optional)": "string[] | null (defaults to post)",
      "delete (optional)": "boolean (defaults to true)",
      // The key below would match <api>/<endpoint>/<other_url>[.../:<params>]
      "<other_url> (optional)": {
        "method": "string (any http method recognized by express)",
        // The controller class method should be static!
        "function": "<controller-class-method>",
        // The controller class should be in the path <root>/controllers/<controllerFile> 
        "controller": "<controller-class>",
        "controllerFile (optional)": "<controller-filename> (defaults to controller but all lowercase and ending with '.controller.js')",
        "body (optional)": "string[] | null (defaults to null)",
        "params (optional)": "string[] | null (defaults to null)"
      }
    }
  }
}

IGS DB Admin

CLI Tool used to generate the database migrations and apply them. Is the database admin tool.

# Usage (if installed locally):
npx igs-db init [-v | --verbose]
npx igs-db migrate (-n | --name <migration_name>) [-v | --verbose] 
npx igs-db apply [-v | --verbose] 
npx igs-db reset [-v | --verbose]
npx igs-db list
npx igs-db revert [-v | --verbose]

These environment variables have to be set in order for this tool to work:

  • dbuser = Database user
  • dbpwd = Database user password
  • dbport = Database port
  • dbhost = Database host
  • dbname = Database name

The init command initializes the migrations on the database, meaning that it will create the migrations table and store the first schema found on the input json file. If the table already exists this command will fail.

The migrate command saves the schema found on the igs.db.json file into the migrations table.

The apply command applies any pending migrations to the database.

The reset command re-applies all migrations to the database.

The list command lists all migrations registered in the database.

The revert command deletes the last unapplied migration from the database.

IGS Generator

CLI Tool used to generate files used by IGS projects.

  • db
    • Generates the database models used in the IGS server.
  • routes
    • Generates the NodeJS router files.
# Usage (if installed locally):
npx igs-generator all --output .\\src\\ --verbose
npx igs-generator db --output .\\src\\ --verbose
npx igs-generator routes --output .\\src\\ --verbose
# output path defaults to .\\
1.7.0

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago