Skip to content

Commit

Permalink
feat(firebase-hosting): Added documentation and improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 14, 2021
1 parent 6da87b4 commit 7dfbfb8
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 81 deletions.
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"singleQuote": true
"singleQuote": true,
"semi": false,
"trailingComma": "none"
}
58 changes: 15 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,30 @@
# Nx-extend
# NX-extend

<p align="center"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="450"></p>

🔎 **Nx-extend is a set of Extensible Dev Tools for Monorepos.**
🔎 **NX-extend is a set of tools to help your NX project.**

## Nx-extend adds the following capabilities to your workspace

- [GCP Cloud Run](https://cloud.google.com/)
- [GCP Cloud Run](./packages/gcp-cloud-run/README.md)
- `npm install --save-dev @nx-extend/gcp-cloud-run`
- [GCP Deployment Manager](https://cloud.google.com/)
- [GCP Deployment Manager](./packages/gcp-deployment-manager/README.md)
- `npm install --save-dev @nx-extend/gcp-deployment-manager`
- [GCP Functions](https://cloud.google.com/)
- [GCP Functions](./packages/gcp-functions/README.md)
- `npm install --save-dev @nx-extend/gcp-functions`
- [GCP Secrets](https://cloud.google.com/)
- [GCP Secrets](./packages/gcp-secrets/README.md)
- `npm install --save-dev @nx-extend/gcp-secrets`
- [GCP Storage](https://cloud.google.com/)
- [GCP Storage](./packages/gcp-storage/README.md)
- `npm install --save-dev @nx-extend/gcp-storage`
- [Firebase Hosting](https://firebase.google.com/products/hosting)
- [Firebase Hosting](./packages/firebase-hosting/README.md)
- `npm install --save-dev @nx-extend/firebase-hosting`
- [Translations](#)
- [Translations](./packages/translations/README.md)
- `npm install --save-dev @nx-extend/translations`
- [Strapi](./packages/strapi/README.md)
- `npm install --save-dev @nx-extend/strapi`

## [License](./LICENSE)

## GCP Cloud Run
> TODO
Build and deploy your application to Cloud Run.

## GCP Deployment Manager
> TODO
Manage your Google Cloud resources create, update and delete them.

## GCP Functions
> TODO
Build and deploy Google Cloud Functions, includes a runner generator to run http / pub-sub functions locally.

## GCP Secrets
> TODO
Manage your Google Cloud secrets through easy to use JSON files, you can encrypt, decrypt and deploy secrets.

## GCP Storage
> TODO
Upload your app / files to Google Cloud Storage

## Firebase Hosting
> TODO
Upload your app to Firebase Hosting.
Conventional Changelog Action is [MIT licensed](./LICENSE).

## Translations
> TODO
## Collaboration

Translate your apps, extracts translations and uploads them (Transifex and Traduora supported).
If you have questions or [issues](https://github.com/TriPSs/nx-extend/issues), please [open an issue](https://github.com/TriPSs/nx-extend/issues/new)!
61 changes: 59 additions & 2 deletions packages/firebase-hosting/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
# NX - Firebase Hosting
# @nx-extend/firebase-hosting

Upload your project to Firebase Hosting
<a href="https://www.npmjs.com/package/@nx-extend/firebase-hosting" rel="nofollow">
<img src="https://badgen.net/npm/v/@nx-extend/firebase-hosting" alt="@nx-extend/firebase-hosting NPM package">
</a>

**Nx plugin for deploy your app to [Firebase Hosting](https://firebase.google.com/products/hosting)**.

## Setup

### Install

```sh
npm install -D @nx-extend/firebase-hosting
nx g @nx-extend/firebase-hosting:add
```

This will add the following to the target:

```json
{
...other targets
"deploy": {
"executor": "@nx-extend/firebase-hosting:deploy",
"options": {
"site": "<site provided in setup>"
}
}
}
```

And create a `.firebase.json` file if it does not exist already, if it exists it will
add this target to the hosting section:

```json
{
...other firebase config
"hosting": [
{
"target": "<provided site name>",
"public": "<target dist directory>",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
]
}
```

## Usage

### Deploy

#### Available options:

| name | type | default | description |
| ------------ | -------- | ------- | ---------------------------------------------------- |
| **`--site`** | `string` | `null` | specify the site to deploy from the `.firebase.json` |
17 changes: 9 additions & 8 deletions packages/firebase-hosting/src/executors/deploy/deploy.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { ExecutorSchema } from './schema'

export default async function runExecutor(options: ExecutorSchema) {
// Make sure the deployment target is defined
await execCommand(buildCommand([
'npx firebase target:apply',
`hosting ${options.site} ${options.site}`
]))
execCommand(
buildCommand([
'npx firebase target:apply',
`hosting ${options.site} ${options.site}`
])
)

return execCommand(buildCommand([
'npx firebase deploy',
`--only=hosting:${options.site}`
]))
execCommand(
buildCommand(['npx firebase deploy', `--only=hosting:${options.site}`])
)
}
5 changes: 2 additions & 3 deletions packages/firebase-hosting/src/executors/deploy/schema.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"$schema": "http://json-schema.org/schema",
"cli": "nx",
"title": "Deploy executor",
"description": "",
"type": "object",
"properties": {
"site": {
"type": "string"
"type": "string",
"description": "Site name in Firebase Hosting"
}
}
}
44 changes: 27 additions & 17 deletions packages/firebase-hosting/src/generators/add/add.impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { readProjectConfiguration, updateProjectConfiguration, Tree } from '@nrwl/devkit'
import {
readProjectConfiguration,
updateProjectConfiguration,
writeJsonFile,
readJsonFile,
Tree
} from '@nrwl/devkit'
import { ProjectConfiguration } from '@nrwl/tao/src/shared/workspace'

import { FirebaseHostingGeneratorSchema } from './schema'
Expand All @@ -9,6 +15,12 @@ export default async function (
) {
const app = readProjectConfiguration(host, options.target)

if (!app) {
return {
success: false
}
}

addToFirebaseJson(host, app, options.site)

updateProjectConfiguration(host, options.target, {
Expand All @@ -25,23 +37,25 @@ export default async function (
})
}

export function addToFirebaseJson(host: Tree, app: ProjectConfiguration, site: string) {
export function addToFirebaseJson(
host: Tree,
app: ProjectConfiguration,
site: string
) {
const firebaseJsonLocation = 'firebase.json'

let firebaseJson = {
hosting: [{
target: site,
public: app?.targets?.build?.options?.outputPath || null,
ignore: [
'firebase.json',
'**/.*',
'**/node_modules/**'
]
}]
hosting: [
{
target: site,
public: app?.targets?.build?.options?.outputPath || null,
ignore: ['firebase.json', '**/.*', '**/node_modules/**']
}
]
}

if (host.exists(firebaseJsonLocation)) {
const existingFirebaseJson = JSON.parse(host.read(firebaseJsonLocation).toString('utf8'))
const existingFirebaseJson = readJsonFile(firebaseJsonLocation)

firebaseJson = {
...existingFirebaseJson,
Expand All @@ -54,7 +68,6 @@ export function addToFirebaseJson(host: Tree, app: ProjectConfiguration, site: s
...existingFirebaseJson.hosting,
...firebaseJson.hosting
]

} else {
firebaseJson.hosting = [
existingFirebaseJson.hosting,
Expand All @@ -64,8 +77,5 @@ export function addToFirebaseJson(host: Tree, app: ProjectConfiguration, site: s
}
}

host.write(
firebaseJsonLocation,
Buffer.from(JSON.stringify(firebaseJson, null, 2))
)
writeJsonFile(firebaseJsonLocation, firebaseJson)
}
11 changes: 4 additions & 7 deletions packages/firebase-hosting/src/generators/add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@
"properties": {
"target": {
"type": "string",
"description": "",
"description": "Target to add Firebase Hosting to",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "To what app would you like to add Firebase hosting?"
"x-prompt": "To what target would you like to add Firebase hosting?"
},
"site": {
"type": "string",
"description": "",
"description": "Site name in Firebase Hosting",
"$default": {
"$source": "argv",
"index": 1
},
"x-prompt": "What is the Firebase site name?"
}
},
"required": [
"target",
"site"
]
"required": ["target", "site"]
}

0 comments on commit 7dfbfb8

Please sign in to comment.