[英]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. 我仍然不清楚原因,但是无论如何,这里有两种方法可以满足您的需求。
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
可能是:
gh:user/project
, github:user/project
) gh:user/project
, github: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。
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的命令 ):
new
method scaffolds a new projects using init-skeleton
. new
方法使用init-skeleton
搭建新项目。 build
method runs Brunch for building project once. build
方法运行一次Brunch来构建项目。 watch
method runs Brunch watcher for incremental builds. watch
方法运行Brunch watcher以进行增量构建。 build
and watch
might be useful for you. build
和watch
可能对您有用。 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: 这里:
presistent
is a boolean value that indicates should project build once or watch for changes. presistent
是一个布尔值,指示应该构建项目一次还是监视更改。 arg2
is a path to the working directory (or undefined
if not present). arg2
是工作目录的路径(如果不存在,则为undefined
)。 It specified by build [path]
. build [path]
指定 。 arg3
is always a Command
object provided by commander.js . arg3
始终是 commander.js提供的Command
对象 。 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.