foy輕量級的項目 build 工具
福伊(foy) 是一個輕量級的基于 nodejs 和 promise 的通用 build 工具
特點:
基于 promise 的任務和內置工具函數(shù)(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
評論
圖片
表情
