npm 的 scripts 下写的命令太多就很容易很乱,各种第三方轮子都只能解决一部分问题,总感觉不是很好用,想找个类似 make 的工具只能找到 jake, 可是 jake 的 API 太老,居然很多都不支持 promise, 代码也不多,就干脆自己造轮子了, 感觉效果还行。

特点:

  • 基于 promise 的任务和内置工具函数(fs/shell), 无缝支持 async/await
  • 类似于 shelljs 的跨平台 shell dsl, 人人都会写 shell
  • 易学易用,无需为写仅仅几个 build 命令而花费几个小时去寻找和学习第三方包
  • 很小的安装成本
    • foy:
    • gulp:
    • grunt:
  • 无缝和第三方支持 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

最新文章

  1. 将List下载到本地保存为Excel
  2. andorid lint
  3. C#-DataTable分页代码
  4. Apache 的启动/重启/停止
  5. Qt 学习第一步 做计划和确定目标
  6. [Effective C++ --010]令赋值操作符返回一个reference to *this
  7. [转]SharePoint 2010/2013 使用Javascript来判断权限的三种方法
  8. Codeforces Round #322 (Div. 2) —— F. Zublicanes and Mumocrates
  9. 《Android内核剖析》读书笔记 第13章 View工作原理【View树遍历】
  10. ovs+dpdk numa感知特性验证
  11. 《31天成为IT服务达人》最新文件夹
  12. 初学cdq分治学习笔记(可能有第二次的学习笔记)
  13. Autofac之依赖注入
  14. 【转】MySQL sql_mode 说明(及处理一起 sql_mode 引发的问题)
  15. p4n 今天与朋友沟通支付云服务普及以及跨境电子商务的光辉前景
  16. 隐藏UITableView当没有数据或数据不够的时候出现的分割线.
  17. git mv与直接mv的区别
  18. C# Timer 用法
  19. python3爬取全站美眉图片
  20. acm1217教训

热门文章

  1. JavaScprit30-6 学习笔记
  2. 【Unity3D】点击交互——简单工厂
  3. 兼容IE9以下的获取兄弟节点
  4. springmvc学习经验
  5. MySQL连表Update修改数据
  6. telegraf1.8+influxdb1.6+grafana5.2 环境搭建 结合JMeter3.2
  7. Vue.js-this详解
  8. IM云服务领域,融云因何得以登上浪潮之巅?
  9. 【UML】类图Class diagram(转)
  10. UVA1607 Gates 与非门电路 (二分)