Socket
Book a DemoInstallSign in
Socket

@renanlido/serverless-routes-generator

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@renanlido/serverless-routes-generator

Minimal package that automates routes creation for serverless applications with using serverless.ts config file

latest
Source
npmnpm
Version
2.2.4
Version published
Maintainers
1
Created
Source

@renanlido/serverless-routes-generator

GitHub Repo stars npm GitHub npm GitHub top language

Full starter stack to develop CJS/ESM compatible npm packages with TypeScript, Vitest, ESLint, Prettier, and GitHub Actions.

Introducing serverless-routes-generator – an npm package designed to simplify route creation for Serverless applications. With just a few commands, you can effortlessly generate and manage routes in your serverless.ts file, eliminating the need for manual configuration. Whether you’re building a small project or scaling a complex architecture, serverless-routes-generator streamlines your workflow, allowing you to focus on developing features instead of handling boilerplate setup. Enhance your Serverless development experience today with this intuitive and efficient tool!

Tools

  • TypeScript: TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
  • biome: Biome statically analyzes your code to quickly find problems.
  • GitHub Actions: Automate your workflow from idea to production.
  • tsup - Zero-config bundler for tiny TypeScript libraries.
  • glob - Match files using the patterns the shell uses, like stars and stuff.

Features

  • ESM/CJS ready - Write your code in TypeScript and publish it as ESM and CJS with 0 configuration.
  • Are The types wrong? ready - Passes all the checks for typings on https://arethetypeswrong.github.io/ by default.
  • ESM/CJS test apps setup - Test your package in both ESM and CJS environments already setup for you.
  • Test runner setup - Coming soon
  • Linting setup - Lint your code with ESLint and Prettier already setup for you.
  • GitHub Actions setup - Automate deployments to npm by using GitHub Actions.

Usage Setup

  • Install the package:

npm

npm install @renanlido/serverless-routes-generator

yarn

yarn add @renanlido/serverless-routes-generator

pnpm

pnpm add @renanlido/serverless-routes-generator
  • Create de configuration script run and customize the configuration for your project:
serverless-routes-generator init

ps: This command accept the following flags:

  • -t [type]: Type of the config file (js, ts, or json). Default is ts.

The generated config file will be created based on the specified type (js, ts, or json). Example:

import { type GeneratorConfigFileData } from '@renanlido/serverless-routes-generator'

export const config: GeneratorConfigFileData = {
  pathPattern: 'functions/**/handler.ts',
  projectRoot: 'src',
  generatedFileName: 'serverless-routes',
  generatedFileExtension: 'ts',
}
  • Integrate the functional decorator on your serverless handler:
import { createHandler } from "@renanlido/serverless-routes-generator";

export const generatePresignedLink = createHandler(
  {
    events: [
      // all lambda events
      {
        http: {
          method: 'POST',
          path: 'example/route',
          cors: true,
        },
      },
    ],
    layers: [
      'arn:aws:lambda:region:account-id:layer:layer-name:version'
    ]
  () => {
  // Any handler function here
    return {
      statusCode: 200,
      body: JSON.stringify({ message: 'Hello World' }),
    }
  },
)
  • Run the command to generate the routes:
{
  "scripts": {
    "generate-routes": "serverless-routes-generator generate"
  }
}

This command will create a file called serverless-routes.ts. Import it into your serverless.ts. That's it!

import { functions } from './serverless-routes'

// ...others configurations
functions: {
    ...functions,
  }
// ...other configurations

Development Setup

  • Clone the repository:
git clone git@github.com:renanlido/serverless-routes-generator.git
  • Install the dependencies:
pnpm install

Development Scripts

  • npm run generate:routes:bin - Generate the routes.
  • npm run generate:bin:init - Generate the bin.
  • npm run generate:bin - Generate the bin.
  • npm run generate:routes - Generate the routes.
  • npm run link:bin - Link the package to the global scope.
  • npm run build - Build the package.
  • npm run type-check - Check the types.
  • npm run check:fix - Check and fix the code.
  • npm run validate - Run the type-check and check:fix scripts.
  • npm run check:exports - Check the exports.
  • npm run local-release - Build the package, version it, and publish it locally.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

Acknowledgements

This project was inspired by the need to streamline route management in Serverless applications. Special thanks to the open-source community for their valuable contributions.

Keywords

serverless

FAQs

Package last updated on 04 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts