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

node-grid-cli

v1.0.2

Published

Grid' application generator.

Downloads

6

Readme

一个 nodejs 后端服务框架,具有自动生成文档,批量注册接口,自动记录日志等功能 ...

安装

npm i -g node-grid-cli

初始化

在当前目录下构建醒目

grid create <projectName>

在当前目录下初始化一个项目

文件夹必须为空

grid init

修改项目模板(自动打开模板目录)

以下命令效果相同

grid show
grid template
grid templates
grid change

使用

注册接口

统一在 ./src/routes 目录下的 index.js 中注册。

注册格式:

module.exports = {
    <接口地址>: {
        <方法>: <函数文件相对于 models 文件夹的路径>
        <二级接口>: {
            <方法>: <函数文件相对于 models 文件夹的路径>
        }
    }
}

配置文件

此配置文件不可删除,默认可以什么都不写

配置项解释:

module.exports = {
	basic: {
		// 多线程模式,默认关闭
		thread: true,
		// 设置 host 地址
		// host: '127.0.0.1',
		// 设置端口号,默认3000
		// port: 3000,
		// 解析 POST 请求的请求体,默认开启
		// bodyParser: true,
		// 解析请求携带的 cookie,默认开启
		// cookieParser: true,
	},
	staticResource: {
		// 是否启用静态资源托管,默认开启
		// enable: true,
		// 静态资源地址,默认为'/'
		// path: '/',
		// 静态资源所在目录,默认为'./public'
		// dirPath: './public',
	},
	log: {
		/**
		 * close: 关闭
		 * file: 写入文件
		 * console: 输出到控制台(默认)
		 */
		// mode: 'console',
		// 日志输出目录,默认为'./log'
		// filePath: './log',
		// 文件名中的日期部分格式
		// 默认值
		// dateFormat: 'YYYY-MM-DD',
		// 文件名格式
		// 默认值
		// fileName: 'Access-%DATE%.log',
	},
	// 响应头统一设置
	response: {
		// origin 为 * 时自动不接收 cookie
		origin: '*',
		credentials: false,
		ContentType: 'application/json;charset=utf-8',
		allow_methods: ['GET, POST, OPTIONS', 'PUT', 'DELETE'],
		allow_headers: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept'],
	},
	doc: {
		// 开启自动生成文档,默认关闭
		enable: true,
		// 文档输出目录
		// 默认值
		// dirPath: './doc',
		// 文档预览地址
		// 默认值
		// path: '/api-doc',
		// 文档名
		name: '自定义的文档标题',
		// 仓库地址
		// gitLine: 'https://gitee.com/ken200461/node-grid-cli',
		// 主题颜色,默认为绿色
		// themeColor: '#000',
		// 文档文字计数器设置
		// count: {
		// 	countable: true,
		// 语言,默认为英文
		// 	language: 'chinese',
		// },
		// 代码复制按钮
		// 默认值
		// copyCode: {
		// 	buttonText: 'copy',
		// 	errorText: '复制失败',
		// 	successText: '复制成功',
		// },
	},
}

关于日志

模式选择为 file 后,只会记录失败的请求。日志文件会按照天分开,避免文件过大。

生成文档

根据 models 下处理函数文件上的 JSDoc 注释生成,当 GET 和 POST 请求的处理函数都有注释时会优先解析 GET 请求处理函数上的注释

支持的 JSDoc 注释:

/**
 * // 接口是否过期
 * @deprecated
 * @description 接口解释文字
 * @group 接口分组
 * @name 接口名称
 * // 需要的参数
 * // 在参数名后加 * 代表必填
 * // 花括号中为参数类型
 * @apiParam {string} param1* 参数1说明
 * @apiParam {number} param2 参数2说明
 * // 接口返回值
 * @return {string} return1 返回值1说明
 * @return {number} return2 返回值2说明
 * // 请求示例
 * // GET 请求可以直接写地址
 * @example {url} /api/user/login?username=admin&password=123456
 * // json格式,写在json上的注释(不要有空格) json内容
 * @example {json} data {"key":"value","key2":"value2"}
 * // object 类型的键也需要加上双引号!!!
 * @example {object} object {"key":"value","key2":"value2"}
 * // 其余数据类型会被拼接为 axios 请求的代码后展示
 * @example {boolean} boolean true
 * @example {number} num 18
 * @example {string} str hello
 */