npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

generator-tsoa-bootstrap

v1.0.3

Published

TSOA, Sequelize, and Jasmine scaffolding including model, test, controller, and migration creation

Downloads

31

Readme

generator-tsoa-bootstrap NPM version Dependency Status

TSOA, Sequelize, and Jasmine project generator

Installation

First, install Yeoman and generator-tsoa-bootstrap using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-tsoa-bootstrap

Then generate your new project:

yo tsoa-bootstrap

Usage

Once you have the app installed, there's a few things you'll want to do.

Sequelize Config

First, in /app/sequelize/config/config.ts, you'll want to configure your database settings. The test settings are already set up to connect to an in-memory sqlite database.

See The Sequelize Docs for more information.

Generators

The following generators are available to you:

model

You can run yo tsoa-bootstrap:model <modelName> to generate a new model. The model name will automatically be singularized for you.

/sequelize/models/ModelName.ts

This is where you'll define what you want your model to look like and it's associations. The model defined in here will automatically be added to the default export in /sequelize/models/index so it can be imported as:

import db from './models';

db.YourModel.findById(id);

/sequelize/dao/ModelName.ts

The DAO (Data Access Object) will be a class containing methods for accessing data from your model. This class will automatically be instantiated and added to your model with the DAO property.

import db from './models';

db.YourModel.DAO.createModelWithData(data);

/spec/dao/ModelName.spec.ts

This will be the test file for your DAO. Before every test, a sqlite database will be created in memory and all migrations will be run. This ensures that you start with a fresh environment for every test that's as close to production as possible.

controller

Controllers are where you define your routes and the logic behind your routes.

You can generate a new controller with:

yo tsoa-bootstrap:controller <name>

See https://github.com/lukeautry/tsoa for more information on how to set your controller up.

association

The association generator will allow you to associate two tables together. The syntax is like:

yo tsoa-bootstrap:assocaition <from> <type> <to> <through>
  • from is the model to add the association to
  • type is the type of association. It must be one of the following
    • hasOne
    • hasMany
    • belongsTo
    • belongsToMany (must provide a through model)

This will automatically add the association to the model and add all of the supporting methods to the models instance interface.

crud

The crud generator will take a controller and model as input and create the standard CRUD methods in the model's DAO, and the standard CRUD routes in the controller, along with tests to support them.

The syntax is like so:

yo tsoa-bootstrap:crud <controller> [<model>]

If you do not provide a model, the model will be inferred from the controller name (i.e., the controller singularized).

migration

Migration scripts are used to create and modify your database tables. You create a new migration with:

yo tsoa-bootstrap:migration

In the up method, you will place all methods you want to use to alter your database in the migration. In the down method, you will place all methods to rollback the migration.

To run the migration (and all pending migrations), run npm run sequelize:migrate.

To undo the last migration, run npm run :sequelize:migrate:undo.

See The Sequelize Migration Docs for more information.

sqlite-scaffold

The sqlite-scaffold generator allows you to take an input sqlite create script and auto generate a migration and models using the script. It will automatically determine the columns and types, primary/foreign keys, unique constraints, and default values for you and them both to the migration script and model.

The syntax is as follows:

yo tsoa-bootstrap:sqlite-scaffold <path-to-sql> [--initial]

If you pass the --initial flag, the script will automatically undo all migrations, delete all migrations, then create a new migration. The normal workflow for starting an app would be to use the --initial flag until you get to a point where you release your app. Once released, you should stop using the flag and start adding new migrations to support release rollback.

Tip: You can use MySQL Workbench to create models and use the mysql-wb-exportsqlite script to convert the models to sqlite automatically for you. Then, you can use this generator to generate your migration and models for you based on your MySQL Workbench model.

Building and Running the Server

Build the server using npm run build. This will do a few things for you:

  • Compile the typescript
  • Create a swagger file with tsoa swagger
  • Create your routes with tsoa routes
  • Copy all of this over to dist/

Once you have your projet built, you can run it using npm start. Visiting localhost:3000/docs will load the Swagger UI where you can see your swagger documentation and manually test your routes.

Running npm test will run all of your Jasmine tests in the spec/ folder.

Getting To Know Yeoman

  • Yeoman has a heart of gold.
  • Yeoman is a person with feelings and opinions, but is very easy to work with.
  • Yeoman can be too opinionated at times but is easily convinced not to be.
  • Feel free to learn more about Yeoman.

License

Apache-2.0 © Jeremy Overman