掌声
(原始内容存档于2019-03-31) (英语). hopi pal CLI
主维护者 - 变形常春藤
hpal 是为了帮助你,
- : sparkles: 从 创建新的 hopi 项目 锅炉板
- :花序:为路由,扩展生成文件, 模型, (中文(简体) ), 服务等通过 高考成绩
- :书:搜索 临时文件 来自命令行的 - 加上许多其他例如: 乔伊 财务报告和审定财务报表 玩具
- : honeybee: 运行您服务器的 hopi 插件定义的自定义命令
安装
建议在您的项目中安装 hpal CLI 作为 dev 依赖, 然后引用它 npx 数据。 。 。 .
npm install --save-dev @hapipal/hpal
npx hpal --help
但是,如果你现在想尝试 Hpal CLI, 只要复制和粘贴这个右 在你的终端!
npx @hapipal/hpal docs --ver 20.0.0 h.response
使用量
Hpal CLI的用法为:hapi v19+和nodejs v12+(下级支持请参见 v2) (中文(简体) ).
Usage: hpal <command> <options>
Commands:
hpal new <new-project-directory>
e.g. hpal new ~/node-projects/new-pal-project
hpal make [--asDir|--asFile] <haute-couture-item> [<item-name>]
e.g. hpal make route create-user
hpal docs[:<package-name>] [--ver x.y.z|ref] <docs-section> [<config-item>]
e.g. hpal docs --ver 20.0.0 h.continue
hpal run [--list] <cmd> [<cmd-options>]
e.g. hpal run plugin-name:command-name
Options:
-h, --help show usage options
-v, --version show version information
-d, --asDir [make] creates new haute-couture item in a directory index file
-f, --asFile [make] creates new haute-couture item in a file
-V, --ver [docs] specifies the version/ref of the API docs to search for the given package
-l, --list [run] lists all available commands on your server
图标
hpal new
hpal new <new-project-directory> e.g. hpal new ~/node-projects/new-pal-project
克隆人们 锅炉板,帮助您填写初始细节 npm init,拉下来 伙伴口味,并离开你准备 第一次承诺你的新项目.
hpal make
hpal make [--asDir|--asFile] <haute-couture-item> [<item-name>] e.g. hpal make route create-user
为 a 创建新文件 高考项目 详细情况准备就绪 这是在任何使用高精度的项目中添加一个路由,插件,模型,服务等的最佳方式.
在出现时使用 .hc.js 在工程中的文件,即使它是空的,以便确定用于写入文件的插件的基础目录。 若为 .hc.js 包含修正案,然后这些修正案将得到尊重,这样您就可以自定义行为 hpal make 每个项目。 创建项目 hpal new 已配置用于工作 hpal make。 。 。 .
这个 --asDir 财务报告和审定财务报表 --asFile 标记可以用来确定文件的写地。 对于一个列表项目,如 routes,指定 --asFile (单位:千美元)hpal make route --asFile将创建 routes.js 而不是说 routes/index.js。对于像 auth/default,指定 --asDir (单位:千美元)hpal make auth/default --asDir将创建 auth/default/index.js 而不是说 auth/default.js当可选时 <item-name> 然后指定将总是将一个文件放在相关目录中并带有名称 <item-name>.js。例如, hpal make route create-user 将写入文件 routes/create-user.js。 。 。 .
要省去语句以启用 严格模式 到生成文件的顶部(每向页样式指南),您可以指定 exampleUseStrict 作为 false 内部 meta 有关高压修正的财产.
hpal docs
hpal docs[:<package-name>] [--ver x.y.z|ref] <docs-section> [<config-item>] e.g. hpal docs --ver 20.0.0 h.continue
搜索 hopi API 参考文献 然后打印出格式化到控制台.
: dizzzy : 此命令还可以通过指定在 pal 和 hapijs 生态系统中搜索任何软件包的 API 引用 <package-name>,比如说. hpal docs:toys noop 或者说 hpal docs:joi any.strip。 。 。 .
<docs-section> 可能会是,
- 任何高考项目的名称(例如:.
route, (中文(简体) ),plugins, (中文(简体) ),auth/default当在高考项目中 - 任何服务器的名称、请求、工具包等方法
- 文档中任何标题的子串
- 譬如说.
hpal docs router
- 譬如说.
- 在文档中可以看到的锚
何时 <config-item> 中的第一个列表项 <docs-section> 匹配文本从 <config-item> 将自动显示。 譬如说, hpal docs request.setUrl 是一个很长的文档部分,但是 hpal docs request.setUrl stripTrailingSlash 仅包含与 stripTrailingSlash 参数.
所有搜索都是对大小写不敏感.
何时 --ver 指定为 semver 版本或 git ref (分支、标签或承诺),然后查找该版本的文档。 否则,当项目内部搜索当前已安装的给定软件包版本的文档时。 当不是在一个项目和 --ver 未指定,将搜索软件包文件的主分支.
hpal run
hpal run [--list] <cmd> [<cmd-options>] e.g. hpal run plugin-name:command-name
运行命令 <cmd> 由您的 hopi 服务器上的插件定义 。 如果插件 my-plugin 定义命令 do-the-thing,然后该命令可以运行 hpal run my-plugin:do-the-thing。如果插件名称的前缀为 hpal-,则 hpal- 可以在运行命令时省略。 插件也可能有一个“ 默认” 命令, 可以运行为 hpal run my-plugin。 。 。 .
服务器上可用的命令列表及其描述可用 hpal run --list。 。 。 .
在运行一个命令 hpal时,如果服务器尚未初始化,则会初始化,然后在命令成功退出时停止服务器.
所需资源
为了使用 hpal runHpal一定能找到你的Happi服务器 它会看着 server.js 财务报告和审定财务报表 server/index.js 相对您的项目的根。 该文件应该导出一个属性 deployment 它包含返回 hopi 服务器的函数,或者对 hopi 服务器的保证(例如 async 函数).
如果你正在使用这个 锅炉板 那你应该已经准备好了!
下面是一个非常基本的例子,
// server/index.js
const Hapi = require('hapi');
const AppPlugin = require('../app');
exports.deployment = async ({ start } = {}) => {
const server = Hapi.server();
await server.register(AppPlugin);
if (start) {
await server.start();
}
return server;
};
// Start the server only when this file is
// run directly from the CLI, i.e. "node ./server"
if (!module.parent) {
exports.deployment({ start: true });
}
创建自己的命令
任何 happi 插件都可以创建可运行的命令 hpal run命令会用HPAL的 server.expose()在您的插件内 my-plugin 简单的呼叫 server.expose('commands', commands)时 commands 是一个对象,
- 其密钥为命令名 。 名称
default保留给命令hpal run my-plugin。骆驼案的命令名称被转换为kebab case,所以如果密钥是someCommand然后使用hpal run my-plugin:some-command。 。 。 . - 其值为对象
{ command, description }或函数command在哪里,command- 带有签名的函数async function(server, args, root, ctx)。 。 。 .server- 初始化的 hopi 服务器 .args- 一系列命令的 CLI 参数。 例如,运行hpal run my-plugin --custom-flag value将会导致args状态['--custom-flag', 'value']。 。 。 .root- 项目根目录的绝对路径.ctx- 包含一些hpal内饰的上下文对象,在测试中可能有用,另外还有一些公共帮助者. 现公布如下:colors- 具有基本格式化具有颜色和样式的CLI输出功能的对象:colors.green(str), (中文(简体) ),colors.yellow(str), (中文(简体) ),colors.red(str), (中文(简体) ),colors.grey(str),以及colors.bold(str)。当 CLI 不支持颜色时,这些函数不起作用.DisplayError- 可以用来表示hpal的"安全"失败的类. 扔一个DisplayError将输出错误message并用代码退出进程1,但不会显示堆栈跟踪,因为会出现出乎意料的错误.
description- 显示命令的字符串描述hpal run --list。也可以是带有签名的函数function (ctx)接收ctx并返回字符串描述.
例如,这里的插件创建了显示服务器路由表的命令,
// hpal run route-table:show
module.exports = {
name: 'hpal-route-table', // The hpal- prefix is ignored when running the command
register(server) {
server.expose('commands', {
show(srv) {
console.log('Route table:');
srv.table().forEach(({ method, path }) => {
console.log(` ${method} ${path}`);
});
}
});
}
};