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

@mongez/gnz

v6.0.0

Published

Generator Z, the next generation of scaffolding tools.

Downloads

587

Readme

GNZ

Your best solution for generating files and directories.

Features

  • Shipped with many built-in templates.
  • Allows you to create your own templates.

Installation

npm install @mongez/gnz

Using Yarn

yarn add @mongez/gnz

Using pnpm

pnpm add @mongez/gnz

Usage

There are many built-in templates that you may use.

Generate React Component

npx gnz react:component MyComponent --path src/components

This will create MyComponent component in src/components directory with the following structure:

src
└── components
    └── MyComponent
        ├── index.ts
        └── MyComponent.tsx

The output of the index.ts file is:

export { default } from "./MyComponent";

The output of the MyComponent.tsx file is:

import { memo } from "react";
function _MyComponent() {
  return (
    <>
      <h1>MyComponent</h1>
    </>
  );
}

const MyComponent = memo(_MyComponent);
export default MyComponent;

By default the component will be memoized, if you want to disable this, you can pass --memo option with false value.

npx gnz react:component MyComponent --path src/components --memo false

If you want to add a forward ref to the component, you can pass --ref option.

npx gnz react:component MyComponent --path src/components --ref

The output of the component file will be:

import { forwardRef, memo } from "react";
function _MyComponent(props: any, ref: any) {
  return (
    <>
      <h1>MyComponent</h1>
    </>
  );
}

const MyComponent = memo(forwardRef(_MyComponent));
export default MyComponent;

Generate Http Service files (Mongez Http)

By using Mongez Http, you can easily manage your endpoint services files.

There are two types of services: Single Service file, and restful service file.

Single Service File

This will generate a service file that contains two function, getXList where X is the name of the service, and getX which receives an id and returns the item with this id.

To create a service file run the following command:

npx gnz http:service users --path src/services

This will generate a users-service.ts file in src/services directory with the following structure:

import endpoint from "shared/endpoint";

export function getUsersList(params: any = {}) {
  return endpoint.get("/users", { params });
}

export function getUser(id: string | number) {
  return endpoint.get(`/users/${id}`);
}

If the endpoint instance is located in another location, path a endpoint option with the path to the endpoint instance.

npx gnz http:service users --path src/services --endpoint shared/endpoint

Restful Service File

This will generate a service file that contains all the restful method with a Restful Endpoint Class to manage list, get, create, update, and delete methods for a single resource.

To create a service file run the following command:

npx gnz http:restful users --path src/services

This will generate a users-service.ts file in src/services directory with the following structure:

import { RestfulEndpoint } from "mongez/http";

class UsersService extends RestfulEndpoint {
  /**
   * The resource route.
   */
  public route = "/users";
}

export const usersService = new UsersService();

If you want to manually change the route (which is taken from the service name) you can pass --route option.

npx gnz http:restful users --path src/services --route /users-list

MongoDB Model

You can easily generate A MongoDB Model using the following command:

npx gnz gn:model users --path src/models

This will create a user directory with the following structure:

src
└── models
    └── user
        ├── index.ts
        └── user.ts
        └── migration.ts

The output of the index.ts file is:

import { Casts, Document, Model } from "@mongez/monpulse";

export class User extends Model {
  /**
   * Collection name
   */
  public static collection = "users";

  /**
   * Default value for model data
   * Works only when creating new records
   */
  public defaultValue: Document = {};

  /**
   * Cast data types before saving documents into database
   */
  protected casts: Casts = {};

  /**
   * Define what columns should be used when model document is embedded in another document.
   * Make sure to set only the needed columns to reduce the document size.
   * This is useful for better performance when fetching data from database.
   */
  public embedded = ["id"];
}

And the migration file:

import { User } from "./user";

export const UserBluePrint = User.blueprint();

export async function userMigration() {
  await UserBluePrint.unique("id");
}

userMigration.blueprint = UserBluePrint;

userMigration.down = async () => {
  await UserBluePrint.dropUniqueIndex("id");
};

Generate a migration file

If you want to generate a migration file, you can use the following command:

npx gnz gn:migration users --path src/migrations

Generate Component Using Node Api

To generate it manually with more options, you can import the component generator manually and call it.

Create a file called gnz.ts in your root directory and add the following code:

import { gnz, generateReactComponent } from "@mongez/gnz";
import path from "path";

gnz.execute(
  generateReactComponent({
    saveTo: path.resolve(__dirname, "src/components"),
    name: "MyComponent",
  }),
);

Now execute this command:

npx gnz api

Generate Service File (Mongez)

This will generate a service file using Mongez Http

Vscode Extension

Lazy to do all of this? You can use the vscode extension to generate files and directories.

A note about generated templates

Any template that ends with (Mongez), it means the generated files will be using some of Mongez Packages.

TODO

  • [ ] Generate Nextjs Component.
  • [ ] Generate Nextjs Page.
  • [ ] Generate types file.
  • [ ] Generate scss module file.
  • [ ] Generate css module file.
  • [ ] Generate styled file.
  • [ ] Generate Mongez React Module
  • [ ] Generate Mongez Moonlight Module
    • [ ] Generate Mongez Moonlight Reactive Form
    • [ ] Generate Mongez Moonlight Super Table
    • [ ] Generate Mongez Moonlight Basic Table
  • [ ] Generate Mongez Warlock Module
    • [ ] Generate Mongez Warlock Controller/Action
    • [ ] Generate Mongez Warlock Route
    • [ ] Generate Mongez Warlock Output
    • [ ] Generate Mongez Warlock Locale
    • [ ] Generate Mongez Warlock flags
    • [ ] Generate Mongez Warlock events
  • [ ] Generate Mongez MongoDB Model
  • [ ] Generate Mongez Laravel Module
  • [ ] Complete Docs.