Skip to content

Commit

Permalink
docs: Add Firebase Hosting and Vercel publishing support.
Browse files Browse the repository at this point in the history
- Add documentation and examples for using Firebase Hosting target in `docs/zh/publishers/firebase-hosting.md` and `docs/en/publishers/firebase-hosting.md`
- Implement new `AppPackagePublisherFirebaseHosting` class in `packages/flutter_app_publisher/lib/src/publishers/firebase_hosting/app_package_publisher_firebase_hosting.dart` with support for `web` platform and configuration files creation
- Update instructions and fix typo in `docs/en/publishers/vercel.md` for using `vercel` target
- Update imports and functions in `website/utils/rehypeExtractHeadings.ts`
- Add `firebase-hosting` and `vercel` to the list of publishers in Navbar.tsx
- Add new file `packages/flutter_app_publisher/lib/src/publishers/firebase_hosting/publish_firebase_hosting_config.dart` with new `PublishFirebaseHostingConfig` class and required `project-id` argument
- Add `AppPackagePublisherFirebaseHosting()` to the list of publishers used in `FlutterAppPublisher` in `packages/flutter_app_publisher/lib/src/flutter_app_publisher.dart`
- Add specifier for Firebase Hosting project ID in `publishArguments` map in `packages/flutter_distributor/bin/command_publish.dart`
- Update parameter names in `docs/zh/publishers/vercel.md` and add new dependency to `website/package.json`: `unist-util-visit`
  • Loading branch information
lijy91 committed Apr 8, 2023
1 parent 8b73049 commit ee89718
Show file tree
Hide file tree
Showing 14 changed files with 4,301 additions and 3,958 deletions.
47 changes: 47 additions & 0 deletions docs/en/publishers/firebase-hosting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: firebase-hosting
---

The firebase-hosting target publishes your web artifacts to the [firebase hosting](https://firebase.google.com/docs/hosting).

## Get publishing arguments

Open [https://firebase.google.com](https://firebase.google.com/) And log in

### Get `project-id`

Select the project you want to deploy, Open the Project Settings page and find `Project ID`.

## Usage

Run:

```
flutter_distributor publish \
--path dist/1.0.0+1/hello_world-1.0.0+1-web \
--targets firebase-hosting \
--firebase-hosting-project-id your-project-id
```

### Configure `distribute_options.yaml`

```yaml
output: dist/
releases:
- name: dev
jobs:
- name: web-direct
package:
platform: web
target: direct
publish:
target: firebase-hosting
args:
project-id: your-project-id
```
Run:
```
flutter_distributor release --name dev
```
8 changes: 4 additions & 4 deletions docs/en/publishers/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ The vercel target publishes your web artifacts to the [vercel.com](https://verce

## Get publishing arguments

打开 [vercel.com](https://vercel.com) 并登录
Open [vercel.com](https://vercel.com) And log in

### Get `org-id`

Open the Account Settings page and find `Your ID`.

### Get `project-id`

Open the Project Settings page and find `Project ID`.
Select the project you want to deploy, Open the Project Settings page and find `Project ID`.

## Usage

Expand All @@ -24,8 +24,8 @@ Run:
flutter_distributor publish \
--path dist/1.0.0+1/hello_world-1.0.0+1-web \
--targets vercel \
--org-id your-org-id \
--project-id your-project-id
--vercel-org-id your-org-id \
--vercel-project-id your-project-id
```

### Configure `distribute_options.yaml`
Expand Down
47 changes: 47 additions & 0 deletions docs/zh/publishers/firebase-hosting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: firebase-hosting
---

The firebase-hosting target publishes your web artifacts to the [firebase hosting](https://firebase.google.com/docs/hosting).

## 获取发布参数

打开 [https://firebase.google.com](https://firebase.google.com/) 并登录

### 获取 `project-id`

选择你要部署的项目,打开项目设置页面,并找到 `Project ID`

## 用法

运行:

```
flutter_distributor publish \
--path dist/1.0.0+1/hello_world-1.0.0+1-web \
--targets firebase-hosting \
--firebase-hosting-project-id your-project-id
```

### 配置 `distribute_options.yaml`

```yaml
output: dist/
releases:
- name: dev
jobs:
- name: web-direct
package:
platform: web
target: direct
publish:
target: firebase-hosting
args:
project-id: your-project-id
```
运行:
```
flutter_distributor release --name dev
```
6 changes: 3 additions & 3 deletions docs/zh/publishers/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The vercel target publishes your web artifacts to the [vercel.com](https://verce

### 获取 `project-id`

打开项目设置页面,并找到 `Project ID`
选择你要部署的项目,打开项目设置页面,并找到 `Project ID`

## 用法

Expand All @@ -24,8 +24,8 @@ The vercel target publishes your web artifacts to the [vercel.com](https://verce
flutter_distributor publish \
--path dist/1.0.0+1/hello_world-1.0.0+1-web \
--targets vercel \
--org-id your-org-id \
--project-id your-project-id
--vercel-org-id your-org-id \
--vercel-project-id your-project-id
```

### 配置 `distribute_options.yaml`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FlutterAppPublisher {
AppPackagePublisherAppStore(),
AppPackagePublisherFir(),
AppPackagePublisherFirebase(),
AppPackagePublisherFirebaseHosting(),
AppPackagePublisherGithub(),
AppPackagePublisherPgyer(),
AppPackagePublisherPlayStore(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'dart:convert';
import 'dart:io';

import 'package:app_package_publisher/app_package_publisher.dart';
import 'package:flutter_app_publisher/src/publishers/firebase_hosting/publish_firebase_hosting_config.dart';
import 'package:shell_executor/shell_executor.dart';

class AppPackagePublisherFirebaseHosting extends AppPackagePublisher {
@override
String get name => 'firebase-hosting';

@override
List<String> get supportedPlatforms => ['web'];

@override
Future<PublishResult> publish(
FileSystemEntity fileSystemEntity, {
Map<String, String>? environment,
Map<String, dynamic>? publishArguments,
PublishProgressCallback? onPublishProgress,
}) async {
Directory directory = fileSystemEntity as Directory;

PublishFirebaseHostingConfig publishConfig =
PublishFirebaseHostingConfig.parse(
environment,
publishArguments,
);

try {
File firebaseRcFile = File('${directory.path}/.firebaserc');
firebaseRcFile.createSync(recursive: true);
firebaseRcFile.writeAsStringSync(json.encode({
'projects': {'default': publishConfig.projectId}
}));
File firebaseJsonFile = File('${directory.path}/firebase.json');
firebaseJsonFile.createSync(recursive: true);
firebaseJsonFile.writeAsStringSync(json.encode({
'hosting': {
'public': '.',
'ignore': ['firebase.json']
}
}));
ProcessResult r = await $(
'firebase',
['deploy'],
workingDirectory: directory.path,
);

String log = r.stdout.toString();
RegExpMatch? match =
RegExp(r'(?<=Hosting URL: )\bhttps?:\/\/\S+\b').firstMatch(log);

return PublishResult(
url: match != null ? match.group(0)! : '',
);
} catch (error) {
rethrow;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:app_package_publisher/app_package_publisher.dart';

class PublishFirebaseHostingConfig extends PublishConfig {
PublishFirebaseHostingConfig({
required this.projectId,
});

factory PublishFirebaseHostingConfig.parse(
Map<String, String>? environment,
Map<String, dynamic>? publishArguments,
) {
String? projectId = publishArguments?['project-id'];
if ((projectId ?? '').isEmpty) {
throw PublishError('Missing `project-id` config.');
}

PublishFirebaseHostingConfig publishConfig = PublishFirebaseHostingConfig(
projectId: projectId!,
);
return publishConfig;
}

String projectId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export 'appcenter/app_package_publisher_appcenter.dart';
export 'appstore/app_package_publisher_appstore.dart';
export 'fir/app_package_publisher_fir.dart';
export 'firebase/app_package_publisher_firebase.dart';
export 'firebase_hosting/app_package_publisher_firebase_hosting.dart';
export 'github/app_package_publisher_github.dart';
export 'pgyer/app_package_publisher_pgyer.dart';
export 'playstore/app_package_publisher_playstore.dart';
Expand Down
5 changes: 5 additions & 0 deletions packages/flutter_distributor/bin/command_publish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ class CommandPublish extends Command {
].join('\n'),
);

// Firebase Hosting
argParser.addSeparator('firebase-hosting');
argParser.addOption('firebase-hosting-project-id', valueHelp: '');

// Github
argParser.addSeparator('github');

Expand Down Expand Up @@ -198,6 +202,7 @@ class CommandPublish extends Command {
'firebase-testers-file': argResults?['firebase-testers-file'],
'firebase-groups': argResults?['firebase-groups'],
'firebase-groups-file': argResults?['firebase-groups-file'],
'firebase-hosting-project-id': argResults?['firebase-hosting-project-id'],
'github-repo-owner': argResults?['github-repo-owner'],
'github-repo-name': argResults?['github-repo-name'],
'github-release-title': argResults?['github-release-title'],
Expand Down
14 changes: 6 additions & 8 deletions website/components/MdxPage/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ const mockdata = [
{
label: "Getting Started",
icon: Notes,
link: "/docs/getting-started"
link: "/docs/getting-started",
},
{
label: "Distribute Options",
icon: Notes,
link: "/docs/distribute-options"
link: "/docs/distribute-options",
},
{
label: "CLI",
icon: Notes,
link: "/docs/cli"
link: "/docs/cli",
},
{
label: "Makers",
Expand All @@ -45,9 +45,11 @@ const mockdata = [
{ label: "appstore", link: "/docs/publishers/appstore" },
{ label: "fir", link: "/docs/publishers/fir" },
{ label: "firebase", link: "/docs/publishers/firebase" },
{ label: "firebase-hosting", link: "/docs/publishers/firebase-hosting" },
{ label: "github", link: "/docs/publishers/github" },
{ label: "pgyer", link: "/docs/publishers/pgyer" },
{ label: "qiniu", link: "/docs/publishers/qiniu" },
{ label: "vercel", link: "/docs/publishers/vercel" },
],
},
{
Expand All @@ -66,11 +68,7 @@ export function Navbar() {
));

return (
<NavbarComp
height={800}
width={{ sm: 260 }}
className={classes.navbar}
>
<NavbarComp height={800} width={{ sm: 260 }} className={classes.navbar}>
<NavbarComp.Section grow className={classes.links} component={ScrollArea}>
<div className={classes.linksInner}>{links}</div>
</NavbarComp.Section>
Expand Down
3 changes: 2 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"redux-devtools-extension": "^2.13.2",
"redux-persist": "6.0.0",
"remark-gfm": "^3.0.1",
"tabler-icons-react": "^1.43.0"
"tabler-icons-react": "^1.43.0",
"unist-util-visit": "^4.1.2"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
Expand Down
Loading

0 comments on commit ee89718

Please sign in to comment.