简体   繁体   English

如何以编程方式部署到 Firebase 托管?

[英]How to programatically deploy to Firebase Hosting?

The problem问题

I have configured a project that currently is possible to deploy to Firebase Hosting multi sites by using the Firebase CLI.我已经配置了一个项目,目前可以使用 Firebase CLI 部署到 Firebase 托管多站点。

The problem is that currently I am doing this manually.问题是目前我正在手动执行此操作。 And I want to programatically do this, and if possible, using NodeJS.我想以编程方式执行此操作,如果可能的话,使用 NodeJS。

The steps of my system:我的系统步骤:

  • User uploads a.zip file with a index.html用户上传带有索引 .html 的.zip 文件
  • I extract and check the.zip file with NodeJS我用 NodeJS 提取并检查 .zip 文件
  • I deploy the files to Firebase Hosting我将文件部署到 Firebase 托管

Currently I am doing like this:目前我这样做:

  1. First create the site page with, where game-project-id-unique should be unique:首先创建站点页面,其中 game-project-id-unique 应该是唯一的:

firebase hosting:sites:create game-project-id-unique

  1. Then, add the target/project ID linked to the game, where game-id is defined by us:然后,添加链接到游戏的目标/项目 ID,其中 game-id 由我们定义:

firebase target:apply hosting game-id game-project-id-unique

  1. Add to the firebase.json the configuration of the file (array):添加到firebase.json文件(数组)的配置:
 {
      "target": "game-id",
      "public": "games/game-id",
      "ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
 }
  1. Then, to publish:然后,发布:

firebase deploy --only hosting

Possible solutions?可能的解决方案?

I have researched here, I have found out that is possible to use the API-DEPLOY or the CLOUD BUILD , but this is not enough to guide me into the programatically approach, without the need of a human in-between.我在这里进行了研究,发现可以使用API-DEPLOYCLOUD BUILD ,但这不足以指导我采用编程方法,而无需中间人。

Is there a way of doing this?有没有办法做到这一点? Is it even possible?有可能吗?

You can certainly just write a script that invokes the CLI.您当然可以只编写调用 CLI 的脚本。 This is very common.这很常见。

You can also use the Firebase Hosting REST API , but in my opinion that is going to be a lot more work.您也可以使用Firebase Hosting REST API ,但我认为这需要做更多的工作。

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

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