虚拟机声音沙哑
I've been contributing to the amazing A-Frame project, a library with allows you to create VR experiences using web technologies, and it's been a blast. The JavaScript code is very concise and uniform, making contribution a joy while keeping the code standards strict. Why is it so concise? The A-Frame project uses a combination of JSHint, which we're all familiar with, but another package I was unfamiliar with: . Husky builds precommit
and other git hooks to run commands within your package.json
before a commit is allowed.
我一直在为令人惊叹的A-Frame项目做出贡献,该库可让您使用Web技术创建VR体验,这是一个爆炸。 JavaScript代码非常简洁和统一,在保持严格的代码标准的同时,做出了令人高兴的贡献。 为什么这么简洁? A-Frame项目使用了我们都熟悉的JSHint的组合,但是我不熟悉的另一个包是: 。 在允许提交之前,Husky会构建precommit
和其他git钩子以在package.json
运行命令。
package.json (package.json)
You'll add husky
to the devDependencies
object within package.json
to gain access to the utility during npm install
. Within your scripts
object, you'll create a key, precommit
for instance, to run JSHint or any other routines you desire. Here's a reduced sample:
您将添加husky
的devDependencies
内对象package.json
来获得期间进入实用npm install
。 在scripts
对象内,您将创建一个键(例如, precommit
提交)以运行JSHint或所需的任何其他例程。 这是一个简化的示例:
{ /* ... */ "scripts": { "lint": "semistandard -v | snazzy", "precommit": "npm run lint" }, /* ... */ "devDependencies": { /* ... */ "husky": "^0.10.1", "semistandard": "^7.0.2", "snazzy": "^3.0.0" } /* ... */}
钩子 (The Hook)
A hook is generated that looks as follows (.git/hooks/pre-commit
as an example):
生成一个如下所示的.git/hooks/pre-commit
(以.git/hooks/pre-commit
为例):
#!/bin/sh# huskyPATH="/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/YOURUSER/Projects/aframe/node_modules/husky/node_modules/.bin:/Users/YOURUSER/Projects/aframe/node_modules/.bin:/usr/local/bin:/Users/YOURUSER/.rvm/gems/ruby-2.1.1/bin:/Users/YOURUSER/.rvm/gems/ruby-2.1.1@global/bin:/Users/YOURUSER/.rvm/rubies/ruby-2.1.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/YOURUSER/.rvm/bin"cd .[ -f package.json ] && cat package.json | grep -q '"precommit"\s*:'[ $? -ne 0 ] && exit 0npm run precommitif [ $? -ne 0 ]; then echo echo "husky - pre-commit hook failed (add --no-verify to bypass)" echo exit 1fi
The hook checks for a package.json
file, then checks to see if there's a scripts
key for the hook file it's in; if so, the scripts
key command is executed and only if it returns 0
allows the commit to be completed; if there are any lint errors, for example, the commit is not executed and you'll have to fix the nits presented by JSHint.
钩子检查package.json
文件,然后检查钩子文件所在的位置是否有scripts
键; 如果是,则执行scripts
key命令,并且只有返回0
才可以完成提交。 例如,如果存在任何皮棉错误,则不会执行提交,您必须修复JSHint提出的问题。
Using husky for JSHint is just an example usage; you can use husky to run any command you like, like spellchecking or security vulnerability checks, to ensure the commit meets your standards. I wish I knew about husky long ago -- it makes setting up hooks structured and easy!
将husky用于JSHint只是一个例子。 您可以使用husky运行任何您喜欢的命令,例如拼写检查或安全漏洞检查,以确保提交符合您的标准。 我希望我很早以前就知道哈士奇犬-它使设置钩子变得结构化且容易!
翻译自:
虚拟机声音沙哑