Skip to content

Commit

Permalink
feat: project setup and complete migration
Browse files Browse the repository at this point in the history
  • Loading branch information
t0bst4r committed Oct 26, 2024
1 parent 4a1cb40 commit 54a622f
Show file tree
Hide file tree
Showing 175 changed files with 20,773 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pull Request

on:
pull_request:

permissions:
contents: read

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: nx cache
uses: actions/cache@v4
with:
path: .nx
key: ${{ runner.os }}-nx

- run: npm ci
- run: npm run pull-request
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release

on:
push:
branches:
- main

permissions:
contents: write
packages: write

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: nx cache
uses: actions/cache@v4
with:
path: .nx
key: ${{ runner.os }}-nx

- run: npm ci
- run: npx nx release version
- name: Extract new Version
run: PACKAGE_VERSION=$(node -p "require('home-assistant-matter-hub/package.json').version")
- run: npx nx release changelog --version $PACKAGE_VERSION
- run: npm run pull-request
- name: Commit, tag and push
run: |
git commit -m "chore: release v$PACKAGE_VERSION"
git tag -a v$PACKAGE_VERSION -m "Release v$PACKAGE_VERSION" -m "[skip ci]"
git push --follow-tags
- run: npx nx release publish
- run: |
gh release create v$PACKAGE_VERSION \
--latest \
--notes-file CHANGELOG.md \
--title "v$PACKAGE_VERSION" \
--verify-tag
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Personal Configs
.env
.local-storage/

# Dependencies
node_modules/
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Empty file added CHANGELOG.md
Empty file.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# HomeAssistantMatterHub

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>

✨ Your new, shiny [Nx workspace](https://nx.dev) is almost ready ✨.

[Learn more about this workspace setup and its capabilities](https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) or run `npx nx graph` to visually explore what was created. Now, let's get you up to speed!

## Finish your CI setup

[Click here to finish setting up your workspace!](https://cloud.nx.app/connect/aCpc1b2IhO)

## Run tasks

To run tasks with Nx use:

```sh
npx nx <target> <project-name>
```

For example:

```sh
npx nx build myproject
```

These targets are either [inferred automatically](https://nx.dev/concepts/inferred-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) or defined in the `project.json` or `package.json` files.

[More about running tasks in the docs &raquo;](https://nx.dev/features/run-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Versioning and releasing

To version and release the library use

```
npx nx release
```

Pass `--dry-run` to see what would happen without actually releasing the library.

[Learn more about Nx release &raquo;](hhttps://nx.dev/features/manage-releases?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Add new projects

While you could add new projects to your workspace manually, you might want to leverage [Nx plugins](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) and their [code generation](https://nx.dev/features/generate-code?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) feature.

To install a new plugin you can use the `nx add` command. Here's an example of adding the React plugin:

```sh
npx nx add @nx/react
```

Use the plugin's generator to create new projects. For example, to create a new React app or library:

```sh
# Genenerate an app
npx nx g @nx/react:app demo

# Generate a library
npx nx g @nx/react:lib some-lib
```

You can use `npx nx list` to get a list of installed plugins. Then, run `npx nx list <plugin-name>` to learn about more specific capabilities of a particular plugin. Alternatively, [install Nx Console](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) to browse plugins and generators in your IDE.

[Learn more about Nx plugins &raquo;](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) | [Browse the plugin registry &raquo;](https://nx.dev/plugin-registry?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

[Learn more about Nx on CI](https://nx.dev/ci/intro/ci-with-nx#ready-get-started-with-your-provider?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Install Nx Console

Nx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ.

[Install Nx Console &raquo;](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Useful links

Learn more:

- [Learn more about this workspace setup](https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Learn about Nx on CI](https://nx.dev/ci/intro/ci-with-nx?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Releasing Packages with Nx release](https://nx.dev/features/manage-releases?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [What are Nx plugins?](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

And join the Nx community:

- [Discord](https://go.nx.dev/community)
- [Follow us on X](https://twitter.com/nxdevtools) or [LinkedIn](https://www.linkedin.com/company/nrwl)
- [Our Youtube channel](https://www.youtube.com/@nxdevtools)
- [Our blog](https://nx.dev/blog?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
1 change: 1 addition & 0 deletions apps/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.tgz
17 changes: 17 additions & 0 deletions apps/docker/addon.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:20-slim

ENV SUPERVISOR_TOKEN ""
VOLUME /config

RUN mkdir /install
COPY package.tgz /install/app.tgz
RUN npm install -g /install/app.tgz
RUN rm -rf /install

CMD home-assistant-matter-hub \
--log-level=$(bashio::config 'log_level') \
--disable-log-colors=$(bashio::config 'disable_log_colors') \
--storage-location=/config/data \
--web-port=$(bashio::config 'web_port') \
--home-assistant-url='http://supervisor/core' \
--home-assistant-access-token="$SUPERVISOR_TOKEN"
53 changes: 53 additions & 0 deletions apps/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

PACKAGE_VERSION=$(tar xfO package.tgz package/package.json | jq -r ".version")
IMAGE_NAME="ghcr.io/t0bst4r/home-assistant-matter-hub"

SIMPLE_DOCKERFILE="simple.Dockerfile"
SIMPLE_PACKAGE_VERSION="$PACKAGE_VERSION"

ADDON_DOCKERFILE="addon.Dockerfile"
ADDON_PACKAGE_VERSION="$PACKAGE_VERSION-addon"

BUILD="simple"
DOCKER_PUSH="false"
TAG_LATEST="false"
while test $# -gt 0
do
case "$1" in
--addon) BUILD="addon"
;;
--push) DOCKER_PUSH="true"
;;
--latest) TAG_LATEST="true"
;;
esac
shift
done

if [ "$BUILD" = "addon" ]; then
DOCKERFILE="$ADDON_DOCKERFILE"
IMAGE_VERSION="$ADDON_PACKAGE_VERSION"
else
DOCKERFILE="$SIMPLE_DOCKERFILE"
IMAGE_VERSION="$SIMPLE_PACKAGE_VERSION"
fi

TAGS=("$IMAGE_NAME:$IMAGE_VERSION")
if [ "$TAG_LATEST" = "true" ]; then
TAGS+=("$IMAGE_NAME:latest")
fi

DOCKER_BUILD_ARGS=()
for TAG in "${TAGS[@]}"; do
DOCKER_BUILD_ARGS+=("-t" "$TAG")
done

if [ "$DOCKER_PUSH" = "true" ]; then
DOCKER_BUILD_ARGS+=("--push")
fi

docker buildx build \
"${DOCKER_BUILD_ARGS[@]}" \
-f "$DOCKERFILE" \
.
51 changes: 51 additions & 0 deletions apps/docker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@home-assistant-matter-hub/docker",
"version": "dev",
"private": true,
"type": "module",
"scripts": {
"build": "",
"build:simple": "./build.sh --latest",
"build:addon": "./build.sh --addon",
"retrieve-package": "node retrieve-package.js",
"nx-release-publish": "./build.sh --latest --push && ./build.sh --addon --push"
},
"dependencies": {
"home-assistant-matter-hub": "*"
},
"devDependencies": {
"@home-assistant-matter-hub/build-utils": "*"
},
"nx": {
"targets": {
"retrieve-package": {
"cache": true,
"dependsOn": [
"^pack"
],
"outputs": [
"{projectRoot}/package.tgz"
]
},
"build": {
"cache": true,
"dependsOn": [
"build:simple",
"build:addon"
]
},
"build:simple": {
"cache": true,
"dependsOn": [
"retrieve-package"
]
},
"build:addon": {
"cache": true,
"dependsOn": [
"retrieve-package"
]
}
}
}
}
14 changes: 14 additions & 0 deletions apps/docker/retrieve-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { distDir } from "@home-assistant-matter-hub/build-utils";
import * as fs from "node:fs";
import * as path from "node:path";

const packageDist = distDir("home-assistant-matter-hub");
const filename = fs
.readFileSync(path.join(packageDist, "package-name.txt"), "utf-8")
.trim();

const packagePath = path.join(packageDist, filename);
const destination = path.join(import.meta.dirname, "package.tgz");

fs.copyFileSync(packagePath, destination);
console.log(`Copied ${packagePath} to ${destination}`);
20 changes: 20 additions & 0 deletions apps/docker/simple.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:20-slim

ENV HAMH_LOG_LEVEL "info"
ENV HAMH_DISABLE_LOG_COLORS "false"

ENV HAMH_STORAGE_LOCATION "/data"
VOLUME /data

ENV HAMH_WEB_PORT 8080
EXPOSE 8080

ENV HAMH_HOME_ASSISTANT_URL "http://x.x.x.x:yyyy"
ENV HAMH_HOME_ASSISTANT_ACCESS_TOKEN "access-token"

RUN mkdir /install
COPY package.tgz /install/app.tgz
RUN npm install -g /install/app.tgz
RUN rm -rf /install

CMD home-assistant-matter-hub
3 changes: 3 additions & 0 deletions apps/home-assistant-matter-hub/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
HAMH_HOME_ASSISTANT_URL="http://192.168.178.111:8123/"
HAMH_HOME_ASSISTANT_ACCESS_TOKEN="long-lived-access-token"
HAMH_STORAGE_LOCATION=$PWD/.local-storage
1 change: 1 addition & 0 deletions apps/home-assistant-matter-hub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pack/
10 changes: 10 additions & 0 deletions apps/home-assistant-matter-hub/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules/
test/
.env*
build.js
tsconfig.json

pack/

!dist/
!package.json
29 changes: 29 additions & 0 deletions apps/home-assistant-matter-hub/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as path from "node:path";
import * as fs from "node:fs";

import { rimraf } from "rimraf";
import { distDir } from "@home-assistant-matter-hub/build-utils";

const dist = path.resolve(import.meta.dirname, "dist");

await rimraf(dist);

await copyDist(
distDir("@home-assistant-matter-hub/frontend"),
path.join(dist, "frontend"),
);

await copyDist(
distDir("@home-assistant-matter-hub/backend"),
path.join(dist, "backend"),
);

async function copyDist(source, destination) {
process.stdout.write(
`Copy ${path.relative(import.meta.dirname, source)} to ${path.relative(import.meta.dirname, destination)}... `,
);
fs.cpSync(source, destination, {
recursive: true,
});
process.stdout.write("Done\n");
}
Loading

0 comments on commit 54a622f

Please sign in to comment.