@aaronhayes/hasura-cli 中文文档教程

发布于 3年前 浏览 30 项目主页 更新于 3年前

hasura-cli

Fork

这是来自 jjangga0214 的一个分支,我维护这个 repo 以更快地发布新版本。 我经常发布得更快,但有时 Jjangga0214 会这样。

一个 npm 包,以隔离方式自动安装和包装 Hasura CLI 二进制文件

license 测试 code style:airbnb 代码风格:更漂亮  .nvmrc yarn:required 常规提交 Commitizen friendly pr welcome

Why?

Original Hasura CLI,不是这个包,是一个编译后的binary,原来是用go写的。 但是仅仅将它安装在您的系统上可能会导致一些问题。

  1. Difficult to use different hasura versions on multiple projects.
  2. Inconvenient to ensure every colleagues having same version installed.
  3. Manual installation not specified as npm devDependency.

hasura-cli 解决了它们。 它会自动下载 CLI 并公开命令 hasura。 下载的 CLI 将被隔离,使其仅专用于安装它的“项目”。 当然,您也可以将其安装为全局包。

Installation

你可以简单地通过 npm 或 yarn 安装 hasura-cli。 请注意,此包遵循 Original Hasura CLI 的版本。 如果您想查看其版本,请转到此处

目前有2个npm标签(npm标签与版本不同),latestbetalatest 标签是指 Hasura 最新的稳定版本(例如 v1.1.1 as of writing),而 beta 是 beta 版本(例如 v1.2.0-beta.3 as of writing) .

当然,你可以全局安装,也可以安装

npm install --global @aaronhayes/hasura-cli[@tag|@version]

在一个项目中。

# latest version from latest tag
npm install --save-dev @aaronhayes/hasura-cli@latest

# latest version from beta tag
npm install --save-dev @aaronhayes/hasura-cli@beta

# or specific version
npm install --save-dev @aaronhayes/hasura-cli@1.0.0

# latest version regardless of tag
npm install --save-dev @aaronhayes/hasura-cli

然后你就可以运行 hasura 命令了。

例如,

# print hasura version
npx hasura version

或者以您想要的方式在 package.json 上配置 npm 脚本。 (提示。提供诸如 $HASURA_GRAPHQL_ENDPOINT$HASURA_GRAPHQL_ADMIN_SECRET 之类的环境变量)

{
  "scripts": {
    "hasura": "hasura --project hasura --skip-update-check",
    "hasura:console": "npm run hasura console",
    "hasura:apply": "npm run hasura migrate apply"
  }
}

Support

通常,它适用于 node@>=8 的任何 Linux、macOS 和 Windows 的 64 位架构.

Development (Contribution)

Note

请在开始之前阅读 NOTE.md

Environment variables

环境变量旨在仅用于开发环境。

首先,创建 .env 文件,并根据需要进行配置。

cp .env.example .env

您可以通过执行 yarn devyarn dev:no-respawn 简单地填充变量。 否则,您必须手动喂养它们(例如 dotenv -- )。 那是因为这个项目没有使用dotenv,但是dotenv-cli。 因此,应用程序不会自行读取 .env

HASURA_CLI_INSTALL (boolean)

src/index.ts 是否会安装 cli。 您可以将其设置为 false 以防止不需要的下载。

HASURA_CLI_DEST_DIR (string)

应安装 Hasura CLI 的目录。

HASURA_CLI_DEST_FILENAME (string)

Hasura CLI 的文件名。

Getting started

安装依赖项。 生命周期脚本 postinstall 仅适用于想要安装二进制文件的客户。 因此,使用 --ignore-scripts 选项忽略它。 它也应该用在 CI 上。

yarn install --ignore-scripts

在开发中,您可以运行

yarn dev
# or
yarn dev:no-respawn
# or
yarn dev:build

yarn dev 观察源代码并在文件更改时重新启动进程。 它不会将编译后的 js 写入文件系统。 ts-node-dev 进行监视、编译和重启。

yarn dev:no-respawn 做同样的事情,只是它不重启。

yarn dev:build 在逻辑上从高角度做同样的工作。 但是它编译(tsc -w) ts,在文件系统上写js,然后运行(nodemon) js。 同时同时运行tscnodemon

要手动测试编译的js,你可以运行

yarn build # compiles ts to js
yarn start # runs dist/index.js

Other scripts

yarn test # runs all tests (against "*.test.ts")
yarn test:coverage # runs all tests and measures coverage
yarn lint # lint
yarn format # format(fix)

How does this work?

这里是一个简短的文件系统树。

hasura-cli
├── dist // to be generated by build process (e.g. `yarn build`), and ignored by git
├── hasura
├── package.json
└── src
    ├── asset.ts
    ├── index.ts
    └── install.ts

package.json 将命令 hasura 公开为文件 hasura 的符号链接。 只有目录 dist 和文件 hasura 被打包为一个包。

{
  "bin": {
    "hasura": "./hasura"
  },
  "files": ["dist", "hasura"]
}

但是,当发布(npm publish 在开发环境中)包时,文件 hasura 只是一个虚拟的“文本”文件,而不是二进制文件。 只有当客户端在 Linux 或 MacOS 上安装包时,该文件才会被替换为二进制文件。 在 Windows 上,与 linux 和 macOS 不同,文件 hasura 将被删除,并且将创建一个新文件 hasura.exepostinstall 生命周期挂钩执行 dist/index.js,这将安装平台特定的二进制文件。

二进制文件作为发布资产托管在 GitHub 上。 src/asset.ts 暴露了“获取 GitHub 资产 url”“从 url 下载资产” 的功能。 src/install.ts 公开了一个函数“组合它们并处理应该如何处理安装”src/index.ts 使用该函数通过一些额外的控制来实际安装资产。

License

麻省理工学院许可证。 版权所有 © 2019,GIL B. Chan <bnbcmindnpass@gmail.com>

hasura-cli

Fork

This is a fork from jjangga0214, I maintain this repo to release new versions faster. I often release faster, but sometimes Jjangga0214 does.

An npm package that automatically installs and wraps Hasura CLI binary in isolated manner

license test code style:airbnb code style:prettier .nvmrc yarn:required Conventional Commits Commitizen friendly pr welcome

Why?

The Original Hasura CLI, which is not this package, is a compiled binary originally written in go. But just installing it on your system could cause some problems.

  1. Difficult to use different hasura versions on multiple projects.
  2. Inconvenient to ensure every colleagues having same version installed.
  3. Manual installation not specified as npm devDependency.

hasura-cli solves them. It automatically downloads the CLI and exposes the command hasura. Downloaded CLI would be isolated, making it only dedicated to the "project" that installed it. Of course, you can install it as global package as well.

Installation

You can just simply install hasura-cli through npm or yarn. Note that this package follows version of the Original Hasura CLI. If you want to check its releases, go here.

Currently there are 2 npm tags (npm tags are different from versions), latest and beta. latest tag refers to Hasura's latest stable version(e.g. v1.1.1 as of writing), while beta, beta version(e.g. v1.2.0-beta.3 as of writing).

Of course, you can install it globally,

npm install --global @aaronhayes/hasura-cli[@tag|@version]

or in a project.

# latest version from latest tag
npm install --save-dev @aaronhayes/hasura-cli@latest

# latest version from beta tag
npm install --save-dev @aaronhayes/hasura-cli@beta

# or specific version
npm install --save-dev @aaronhayes/hasura-cli@1.0.0

# latest version regardless of tag
npm install --save-dev @aaronhayes/hasura-cli

Then you will be able to run hasura command.

For example,

# print hasura version
npx hasura version

Or configure npm scripts on package.json in the way you want. (tip. provide env vars like $HASURA_GRAPHQL_ENDPOINT or $HASURA_GRAPHQL_ADMIN_SECRET)

{
  "scripts": {
    "hasura": "hasura --project hasura --skip-update-check",
    "hasura:console": "npm run hasura console",
    "hasura:apply": "npm run hasura migrate apply"
  }
}

Support

Generally, it works on 64 bits architecture of any Linux, macOS, and Windows with node@>=8.

Development (Contribution)

Note

Please read NOTE.md, before getting started.

Environment variables

Environment variables are intended to be only used on development environment.

First, create .env file, and configure it as you want.

cp .env.example .env

You can simply populate the variables by executing yarn dev or yarn dev:no-respawn. Otherwise, you have to manually feed them (e.g. dotenv -- <your command>). That's because this project doesn't use dotenv, but dotenv-cli. So, the application does not read .env by itself.

HASURA_CLI_INSTALL (boolean)

Whether src/index.ts would install the cli. You can set it false to prevent unwanted downloads.

HASURA_CLI_DEST_DIR (string)

A directory where Hasura CLI should be installed.

HASURA_CLI_DEST_FILENAME (string)

A file name of Hasura CLI.

Getting started

Install dependencies. Lifecycle script postinstall is only for clients who want to install the binary. So, ignore it with --ignore-scripts option. It should also be used on CI.

yarn install --ignore-scripts

On development, you can run

yarn dev
# or
yarn dev:no-respawn
# or
yarn dev:build

yarn dev watches source code and restarts a process when file changes. It does not write compiled js to the file system. ts-node-dev does watching, compiling and restarting.

yarn dev:no-respawn does the same thing except it does not restart.

yarn dev:build logically does the identical job at the high viewpoint. But it compiles (tsc -w) ts, writes js on file system, and run (nodemon) js. concurrently runs tsc and nodemon simualtaneously.

To manually test compiled js, you can run

yarn build # compiles ts to js
yarn start # runs dist/index.js

Other scripts

yarn test # runs all tests (against "*.test.ts")
yarn test:coverage # runs all tests and measures coverage
yarn lint # lint
yarn format # format(fix)

How does this work?

Here is a brief file system tree.

hasura-cli
├── dist // to be generated by build process (e.g. `yarn build`), and ignored by git
├── hasura
├── package.json
└── src
 &nbsp;&nbsp; ├── asset.ts
 &nbsp;&nbsp; ├── index.ts
 &nbsp;&nbsp; └── install.ts

package.json exposes the command hasura as a symlink to the flie hasura. Only the directory dist and file hasura are packed as a package.

{
  "bin": {
    "hasura": "./hasura"
  },
  "files": ["dist", "hasura"]
}

However, when publishing (npm publish on development environment) the package, the file hasura is just a dummy 'text' file, not a binary flie. The file will be replaced to a binary only when a client installs the package on Linux or MacOS. On windows, unlike linux and macOS, the file hasura is to be removed, and a new file hasura.exe will be created. postinstall lifecycle hook executes dist/index.js, which would install the platform-specfic binary.

The binaries are hosted on GitHub as release assets. src/asset.ts exposes functions of "getting GitHub asset url" and "downloading the asset from the url". src/install.ts exposes a function of "composing them and handling how installation should be processed". src/index.ts uses the function to actually install the asset with some additional control.

License

MIT License. Copyright © 2019, GIL B. Chan <bnbcmindnpass@gmail.com>

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文