foy: 基于 nodejs 的轻量级通用 build 东西

npm 的 scripts 下写的敕令太多就很轻易很乱,种种第三方轮子都只能处理一部分题目,总觉得不是很好用,想找个相似 make 的东西只能找到 jake, 但是 jake 的 API 太老,竟然许多都不支撑 promise, 代码也不多,就痛快本身造轮子了, 觉得结果还行。

项目地点: https://github.com/zaaack/foy

特性:

  • 基于 promise 的使命和内置东西函数(fs/shell), 无缝支撑 async/await
  • 相似于 shelljs 的跨平台 shell dsl, 大家都会写 shell
  • 易学易用,无需为写仅仅几个 build 敕令而消费几个小时去寻觅和进修第三方包
  • 很小的装置本钱

    • foy: 《foy: 基于 nodejs 的轻量级通用 build 东西》
    • gulp: 《foy: 基于 nodejs 的轻量级通用 build 东西》
    • grunt: 《foy: 基于 nodejs 的轻量级通用 build 东西》
  • 无缝和第三方支撑 promise 的东西包整合,不须要封装成插件就能用

《foy: 基于 nodejs 的轻量级通用 build 东西》

运用:

装置

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
    原文作者:zaaack
    原文地址: https://segmentfault.com/a/1190000017271433
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞