Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cynosphere authored Dec 5, 2023
0 parents commit 2b9ede2
Show file tree
Hide file tree
Showing 15 changed files with 1,352 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main

permissions:
contents: read
pages: write
id-token: write

jobs:
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build extensions
env:
NODE_ENV: production
run: pnpm run build
- name: Pack extensions
env:
REPO_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
run: pnpm run repo

- name: Setup GitHub Pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./repo

- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dist
/repo
/node_modules
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "moonlight"]
path = moonlight
url = https://github.com/moonlight-mod/moonlight.git
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 80,
"trailingComma": "none",
"tabWidth": 2,
"singleQuote": false
}
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# moonlight sample extension

This is a sample extension for the [moonlight](https://github.com/moonlight-mod/moonlight) Discord mod.

## Getting started

- Make sure you have [Node.js](https://nodejs.org/en) and [pnpm](https://pnpm.io) installed.
- Click "Use this template".
- In the repository settings, make sure GitHub Actions are enabled for this repository, and that the GitHub Pages source is set to GitHub Actions.

Then, clone and start hacking away:

- Install dependencies (`pnpm i`).
- Build the project (`pnpm run build`).
- If you'd prefer to run in watch mode, do `pnpm run dev` instead.

Add the following to your moonlight config:

```json
{
"devSearchPaths": [
"/path/to/sample-extension/dist"
]
}
```

where `/path/to/sample-extension` is the folder you cloned the repository into. After restarting your client, the extension will load.

## Project structure

This sample extension uses [esbuild](https://esbuild.github.io) as its build system. The two entrypoints (`index` and `node`) get loaded on the web and Node.js side respectively. Code exported from the Node.js side can be called from the web side. Each side is optional, in case you only need to run in a specific context (usually web only).

## Publishing to GitHub Pages

Your repository will be published to `https://<username>.github.io/<repository>/repo.json`. Every time a commit is made to the main branch, the extensions will be built on GitHub Actions and published automatically.
57 changes: 57 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as esbuild from "esbuild";
import copyStaticFiles from "esbuild-copy-static-files";
import fs from "fs";

const prod = process.env.NODE_ENV === "production";
const watch = process.argv.includes("--watch");

function makeConfig(ext, name) {
const entryPoints = [];
const fileExts = ["js", "jsx", "ts", "tsx"];
for (const fileExt of fileExts) {
const path = `./src/${ext}/${name}.${fileExt}`;
if (fs.existsSync(path)) entryPoints.push(path);
}

if (entryPoints.length === 0) return null;

return {
entryPoints,
outfile: `./dist/${ext}/${name}.js`,

format: "cjs",
platform: "node",

treeShaking: true,
bundle: true,
minify: prod,
sourcemap: "inline",

plugins: [
copyStaticFiles({
src: `./src/${ext}/manifest.json`,
dest: `./dist/${ext}/manifest.json`
})
]
};
}

const exts = fs.readdirSync("./src");

const config = exts
.map((x) => [makeConfig(x, "index"), makeConfig(x, "node")])
.flat()
.filter((c) => c !== null);

if (watch) {
await Promise.all(
config.map(async (c) => {
const ctx = await esbuild.context(c);
await ctx.watch();
})
);
} else {
for (const c of config) {
await esbuild.build(c);
}
}
1 change: 1 addition & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@moonlight-mod/types" />
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "sample-extension",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"build": "node build.mjs",
"dev": "node build.mjs --watch",
"repo": "node repo.mjs"
},
"devDependencies": {
"@electron/asar": "^3.2.8",
"esbuild": "^0.19.3",
"esbuild-copy-static-files": "^0.1.0"
},
"dependencies": {
"@moonlight-mod/types": "^1.0.0"
}
}
Loading

0 comments on commit 2b9ede2

Please sign in to comment.