generated from moonlight-mod/sample-extension
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2b9ede2
Showing
15 changed files
with
1,352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/dist | ||
/repo | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 80, | ||
"trailingComma": "none", | ||
"tabWidth": 2, | ||
"singleQuote": false | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="@moonlight-mod/types" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.