Jake 是 NodeJS 的 JavaScript 构建工具。Jake 自 Node 的早期就开始存在,功能齐全,经过充分测试。对我来说,JakeJS 最令人着迷的地方在于它拥有类似于 GNU Make、CMake 或 Ruby 社区的 Rake 的功能,但现在让我们将 Jake 整合到 Travis 中,看看它是如何工作的!
Jakefile
好的,所以我们需要一个 Jakefile
,以便在 Travis 中调用 Jake,所以让我们在根目录中创建一个 Jakefile
let { task, desc } = require('jake');
desc('This is the default task.');
task('default', function () {
console.log('This is the default task.');
console.log('Jake will run this task if you run `jake` with no task specified.');
});
desc('This is some other task. It depends on the default task');
task('otherTask', ['default'], function () {
console.log('Some other task');
});
好的,我的 Jakefile 看起来不错,现在让我们构建我们的 .travis.yml
。
这是我配置 .travis.yml
的方式,使其可以与 Jake 整合
dist: jammy
language: node_js
node_js:
- "12"
before_install:
- npm update -g npm
- npm install -g jake
script:
- jake -v
如你所见,我们使用最新的 Ubuntu 镜像,通过 dist: jammy
,你可以看到我安装 Jake 的位置,然后我想打印出在 Travis 中运行的 Jake 版本,以确保整合成功。
现在,在我们将此示例部署到 Travis 之前,让我们创建一个名为 bin
的目录,并在 bin
中创建一个名为 cli.js
的 JavaScript 文件,这是我的文件外观
#!/usr/bin/env node
// Load `jake` global
require('../lib/jake');
var args = process.argv.slice(2);
jake.run.apply(jake, args);
我们使用经典的 JavaScript 函数,比如 slice
,你也可以使用 pop
,随你喜欢!这仅仅是我的示例。
你刚刚将 Jake 与 Travis 整合在一起!与往常一样,这是我的 仓库,所以你可以关注它,并查看构建结果,如果你遇到任何问题。
像往常一样,如果你对整合 Jake 和 Travis 有任何疑问,请给我发邮件 [email protected],我会在这个教程中帮助你。
祝你构建愉快!