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

create-omni-func

v0.0.28

Published

A scaffold for initialing EF omni serverless app.

Downloads

275

Readme

create-omni-func Usage Guide

create-omni-func is a command-line tool for creating Serverless Cloud Functions (SCF) or adding new entry points in omni-serverless or omni-web projects.

Scaffolding

Creating a New Function

To create a new function in omni-serverless, run the following command in the project root:

npx create-omni-func@latest

This command will prompt you for the following information:

  1. App Name: Application name (defaults to the target directory name).
  2. Remove existing files and continue?: If the target directory is not empty, decide whether to remove existing files and continue.
  3. Package Name: Package name (if the target directory name is not a valid npm package name).
  4. Description: Project description.
  5. Add TypeScript?: Whether to add TypeScript support.
  6. Template: Choose a template (e.g., scf-webpack).

You will need to input the function name and description, and choose the template type. If you attempt to create a function that already exists, the command will ask whether you'd like to override it.

Since pnpm is used as the package manager, after creating a new function, simply run pnpm i to install the dependencies. To add a new dependency, use pnpm add <dependency>.

Creating a New Entry Point

After creating the function, you can run the command again in the function's directory:

npx create-omni-func@latest

This command will prompt you to choose the entry point type:

  1. API: API Gateway handlers.
  2. Kafka: Kafka handlers.
  3. Batch: Batch handlers.
  4. Custom: Custom handlers.

Based on your selection, the appropriate handler scheme will be generated and injected into the eventHandler.

You can code in the handler folders, but you can remove them if you prefer to code in your own way.

Testing

Unit Testing

The scaffolder utilizes vitest to enable unit testing. Basic testing settings are configured in vitest.config.js.

All tests should be coded in the tests folder, with filenames ending in test.ts or test.js.

For a coding guide or usage information for unit testing, visit: Vitest Guide.

Test UI

Testing can be automatically detected by VSCode or WebStorm, and can be found in the test tab.

Additionally, there is a vitest UI which can be started with the command pnpm test-ui. This will launch a web UI for managing and reporting tests.

Deployment

Use the following commands to deploy your function:

  • pnpm deploy:stg to deploy to the omni-stg namespace.
  • pnpm deploy:live to deploy to the omni-live namespace.

Environment Variables

During deployment, the scripts will load environment variables first from the function root and then from the project root. This means you only need to set variables specific to the function.

create-omni-func 使用指南

create-omni-func 是一个命令行工具,用于创建无服务器云函数(SCF)或在 omni-serverlessomni-web 项目中添加新的入口点。

脚手架

创建新函数

要在 omni-serverless 中创建一个新函数,请在项目根目录运行以下命令:

npx create-omni-func@latest

该命令会提示您输入以下信息:

  1. 应用名称:应用名称(默认为目标目录名)。
  2. 移除现有文件并继续?:如果目标目录不为空,决定是否移除现有文件并继续。
  3. 包名:包名(如果目标目录名不是有效的 npm 包名)。
  4. 描述:项目描述。
  5. 添加 TypeScript?:是否添加 TypeScript 支持。
  6. 模板:选择一个模板(例如 scf-webpack)。

您需要输入函数名称和描述,并选择模板类型。如果您尝试创建已存在的函数,命令会询问是否覆盖。

由于使用 pnpm 作为包管理器,创建新函数后,只需运行 pnpm i 安装依赖项。要添加新依赖项,请使用 pnpm add <dependency>

创建新入口点

在创建函数后,您可以在该函数的目录中再次运行该命令:

npx create-omni-func@latest

该命令会提示您选择入口点类型:

  1. API:API 网关处理器。
  2. Kafka:Kafka 处理器。
  3. Batch:批处理器。
  4. Custom:自定义处理器。

根据您的选择,适当的处理器方案将生成并注入到 eventHandler 中。

您可以在处理器文件夹中编写代码,但如果您更喜欢以自己的方式编写代码,可以删除这些文件夹。

测试

单元测试

脚手架使用 vitest 来实现单元测试。基本的测试设置已配置在 vitest.config.js 中。

所有测试应编写在 tests 文件夹中,文件名应以 test.tstest.js 结尾。

有关单元测试的编写指南或使用信息,请访问:Vitest 指南

测试 UI

VSCodeWebStorm 可以自动检测测试,并在测试选项卡中显示。

此外,还有一个 vitest UI,可以通过命令 pnpm test-ui 启动。该命令将启动一个用于管理和报告测试的 Web UI。

部署

使用以下命令来部署您的函数:

  • pnpm deploy:stg 部署到 omni-stg 命名空间。
  • pnpm deploy:live 部署到 omni-live 命名空间。

环境变量

在部署期间,脚本将首先从函数根目录加载环境变量,然后从项目根目录加载。这意味着您只需要设置函数特定的变量。