简体   繁体   English

直接从node.js而不是CLI运行Brunch.io

[英]Running Brunch.io directly from node.js rather than CLI

I'm looking for an more efficient build-tool like gulp for huge Projects. 我正在为大型项目寻找像gulp这样更有效的构建工具。

Brunch seems to be the thing for that, but I was wondering if I could run Brunch from an Node.js script, rather than the CLI. 早午餐似乎就是解决这个问题的方法,但是我想知道是否可以从Node.js脚本而不是CLI运行早午餐。 The docs doesn't seem to have any detail on that…. 文档似乎对此没有任何详细信息。

Are there any plans or undocumented ways to archive this? 是否有任何计划或未记录的方式对此进行存档?

The reasons are still unclear for me, but anyway, here are two approaches that could fit your needs. 我仍然不清楚原因,但是无论如何,这里有两种方法可以满足您的需求。

init-skeleton 初始骨架

We have awesome package that is used in Brunch internally. 我们有一个很棒的软件包,内部在Brunch中使用。 It's called init-skeleton . 它称为init-skeleton You can write a skeleton for your needs and use that package for scaffolding. 您可以根据需要编写框架,并使用该软件包进行脚手架。

This package has init method that could help you. 该软件包具有可以帮助您的init方法。 It has this signature init(skeleton[, options]) . 它具有此签名init(skeleton[, options]) The skeleton might be: skeleton可能是:

  • Path to the skeleton in your file system 文件系统中框架的路径
  • Git URI Git URI
  • GitHub URI (such as gh:user/project , github:user/project ) GitHub URI(例如gh:user/projectgithub:user/project

options are optional. options是可选的。 There are these ones: 这些有:

  • rootPath — a string which is a root path of the result directory rootPath —一个字符串,它是结果目录的根路径
  • commandName — a string which is a command that will be used in printBanner function . commandName —一个字符串,它是将在printBanner函数中使用的命令。
  • logger — a function that will be used for logging purposes. logger -用于记录目的的功能。

For example: 例如:

const initSkeleton = require('init-skeleton').init

initSkeleton('path/to/skeleton')
  .then(() => {
    console.log('Done!')

    // do something else
    // ...
  })

If that's not you're looking for, then there is another solution — use Brunch JavaScript API. 如果您不是要找的人,那么还有另一种解决方案-使用Brunch JavaScript API。

Brunch JavaScript API 早午餐JavaScript API

Yeah, probably that's what you're looking for. 是的,可能正是您要找的东西。 Brunch has internal JavaScript API. 早午餐具有内部JavaScript API。 This API isn't documented. 该API未记录。 This API could be changed (and apparently wile be), so be careful using this. 该API可能会更改(而且显然是可以更改的),因此请谨慎使用。

Probably, you've already noticed that Brunch's package.json have main field that corresponds to ./lib/index . 可能您已经注意到,Brunch的package.json具有./lib/index对应的main字段 This exports three methods (which actually correspond to Brunch's commands ): 这将导出三种方法(实际上对应于Brunch的命令 ):

  1. new method scaffolds a new projects using init-skeleton . new方法使用init-skeleton搭建新项目。
  2. build method runs Brunch for building project once. build方法运行一次Brunch来构建项目。
  3. watch method runs Brunch watcher for incremental builds. watch方法运行Brunch watcher以进行增量构建。

build and watch might be useful for you. buildwatch可能对您有用。 Both of them uses start function . 他们两个都使用start功能 This function is encapsulated for internal usage and has following signature: start(persistent, arg2, arg3) . 该函数被封装以供内部使用,并具有以下签名: start(persistent, arg2, arg3) Here: 这里:

Moreover, you can also require a brunch/lib/cli module. 此外,您还可以要求使用brunch/lib/cli模块。 This module exports a run method . 此模块导出run方法 This method doesn't take any argument. 此方法不带任何参数。 It just parses process.argv and runs the Brunch properly. 它只是解析process.argv并正确运行Brunch。

That's it. 而已。 It may look like a hack, it does and it is. 它看起来确实像黑客一样,确实如此。 Be careful using it, because we are going to change that API in future. 请谨慎使用它,因为将来我们将更改该API。 Keep in mind that these possibilities aren't documented , so we won't warn you before changes . 请记住,这些可能性并未记录在案 ,因此我们不会在更改之前警告您

Try to find another solution for you problem. 尝试为您的问题找到另一种解决方案。 Sometimes problem appears not because of problem itself, but because of bad understanding of approach you use. 有时出现问题的原因不是因为问题本身,而是因为对您使用的方法的了解不足。

Hope this would help you. 希望这对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM