在内存中以编程方式运行gulp [英] Run gulp programmatically in memory

查看:119
本文介绍了在内存中以编程方式运行gulp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

特定问题

我可以从node运行gulp并从中获取return var而不处理任何文件,而只是从文件中读取吗?

Can I run gulp from node and get a return var from it without manipulating any files, just reading from them?

更多背景

我正在尝试构建与 Modernizr的构建工具类似的东西.我的磁盘上有几个文件,想让访问者有机会选择表单中的一部分并将其提交.

I am trying to build something not unlike Modernizr's build tool. I have several files on disk and want to give the visitor the chance to select a subset of those in a form and submit it.

然后应该发生的事情是,访问者将获得下载,作为提交内容(一个zip文件)的返回,其中包含他/她选择并策划和处理的那些文件(最小化,串联和其他魔术).

What should happen then is the visitor will get a download as an return of the submission (a zip file) with those files he/she selected curated and processed (minifying, concatenation and some other magic).

现在,我狂热地创建了一个POC,它是一个NodeJS应用程序,它侦听端口并严重依赖于回调来遍历每组魔术,然后构建所有文件并将其压缩到内存中,然后将其返回为结果到请求.

Now in my craze I created a POC that is a NodeJS app, listening to a port and relies heavily on callbacks to go through each set of the magic to then build all files and zip them up in memory and return it as the result to the request.

那感觉很脏.我认为应该将所有流整齐地组合在一起以进行即插即用,但是我不确定如何实现.我从没用过gulp,给我的印象是它只会在磁盘上处理文件?

That feels dirty though. I think it should all be streams neatly put together for plug and play action BUT I am not sure how. I have never used gulp and I am under the impression it would manipulate files only on disk?

我要在内存中创建所有内容的原因是因为我不想担心垃圾回收器和多个会话会相互覆盖.

The reason I want to create everything in memory is because I don't want to worry about a garbage collector and multiple sessions overwriting each other.

推荐答案

Gulp适用于全局选择.据我所知,目前还没有其他方法(以gulp格式)来传递特定文件,然后再对其进行硬编码.

Gulp works on glob selections. As far as i know there is no existing way (in gulp) to pass specific files other then to hardcode them.

我可以想到的唯一可以使文件选择参数化的方法是:

The only way i can concieve of to paramaterize file selection is to either:

a.创建您的任务,以便您可以在CLI中将其作为标志传递给该对象,例如 yargs 有用

a. Create your task so you can pass them in as flags in the CLI for this something like yargs would be useful

b.设置基本目录并创建将自动显示文件的内容,检查 inquirer 这样的插件应该会有所帮助

b. Set the base dir and create something that will automatically display the files, examining a plugin like inquirer should help

这篇关于在内存中以编程方式运行gulp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆