我正在尝试清理我的构建系统,并且我希望使用firebase-tools(Firebase-hosted docs)模块来执行此操作。在CLI中使用软件包的文档已经足够了,但是将其用作节点模块的文档很少(并且通过软件包的源代码也不是很简单)。
在撰写本文时,这里是相关文档(它只出现在GH库中):
Firebase CLI也可以编程方式用作标准节点模块。这只能在您的计算机上完成,并且无法在云功能中完成。每个命令都作为一个函数公开,它接受一个options对象并返回一个Promise。例如:
var client = require('firebase-tools');
client.list().then(function(data) {
console.log(data);
}).catch(function(err) {
// handle error
});
client.deploy({
project: 'myfirebase',
token: process.env.FIREBASE_TOKEN,
cwd: '/path/to/project/folder'
}).then(function() {
console.log('Rules have been deployed!')
}).catch(function(err) {
// handle error
});
如您所见,仅包含两个非常基本的示例,并且没有可以为每个命令提供的各种选项的描述。
例如,CLI使用--only
标记(例如--only database
,如果只想推送新规则)。如果我只想部署规则,是否在选项中包含only: "database"
?
示例中的输出夸耀"规则已经部署!"成功消息,但没有提供给deploy
的选项似乎表明这只会推动规则(而不是没有--only
选项的完整部署)!
奖金问题:如果我的规则文件与我希望托管的文件有不同的路径,该怎么办?我看到示例中只提供了一个cwd
选项。
这里有一些更清晰的文档会有很长的路要走:)
答案 0 :(得分:0)
一般准则:
示例:
firebase --project my-firebase-project database:get /user/setting --output /tmp/out.json
成为:
var util = require('util'),
client = require('firebase-tools');
client.database.get('/user/setting', {
project: 'my-firebase-project', // global option
output: '/tmp/out.json', // global option
shallow: true // database:get option
}).then(
x => console.log(util.inspect(x))
).catch(
e => console.log(util.inspect(e))
);
答案 1 :(得分:0)
如果目标为deploy
,则可以使用选项键only
或except
。
您可以指定用逗号分隔的目标列表(例如“主机,功能”),不接受数组。对于函数,可以指定带有冒号的过滤器以将函数部署范围仅限制到那些函数(例如“ functions:func1,functions:func2”)。
这是我在gulpfile中使用的:
const fbTools = require('firebase-tools');
function deployProdTask() {
return fbTools.deploy({
project: 'abc',
only: 'functions',
token: '123',
force: true
});
}
令牌必须按照here的说明生成。