foy: 轻量级的基于 nodejs 的通用 build 工具
npm 的 scripts 下写的命令太多就很容易很乱,各种第三方轮子都只能解决一部分问题,总感觉不是很好用,想找个类似 make 的工具只能找到 jake, 可是 jake 的 API 太老,居然很多都不支持 promise, 代码也不多,就干脆自己造轮子了, 感觉效果还行。
特点:
- 基于 promise 的任务和内置工具函数(fs/shell), 无缝支持 async/await
- 类似于 shelljs 的跨平台 shell dsl, 人人都会写 shell
- 易学易用,无需为写仅仅几个 build 命令而花费几个小时去寻找和学习第三方包
- 很小的安装成本
- 无缝和第三方支持 promise 的工具包整合,不需要封装成插件就能用
使用:
安装
yarn add -D foy # or npm i -D foy
# Or Install globally with
yarn add -g foy # or npm i -g foy
在项目根目录下增加一个 Foyfile.js (或者 Foyfile.ts, 需要安装 ts-node)
import { task, desc, option, strict, fs } from 'foy'
task('build', async ctx => {
await ctx.exec('tsc')
})
desc('Build ts files with tsc')
option('-w, --watch', 'watch file changes')
strict() // This will throw an error if you passed some options that doesn't defined via `option()`
task('build2', async ctx => {
await ctx.exec(`tsc ${ctx.options.watch ? '-w' : ''}`)
})
task('task', async ctx => {
await fs.rmrf('/some/dir/or/file') // Remove directory or file
await fs.copy('/src', '/dist') // Copy folder or file
let json = await fs.readJson('./xx.json')
await ctx.env('NODE_ENV', 'production')
await ctx.cd('./src')
await ctx.exec('some command') // Execute an command
let { stdout } = await ctx.exec('ls', { stdio: 'pipe' }) // Get the stdout, default is empty because it's redirected to current process via `stdio: 'inherit'`.
})
然后就可以运行任务了
# 安装在本地 node_modules 目录下
npx foy build
npx foy build1
npx foy task
# 安装在全局
foy build
foy build1
分类:
前端
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?