generated from Fierdetta/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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 8fd45c0
Showing
11 changed files
with
240 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: Build and deploy | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Prepare environment | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "16" | ||
|
||
- run: npm install --global pnpm | ||
|
||
- name: Install deps | ||
run: pnpm m i | ||
|
||
- name: Build plugin(s) | ||
run: node ./build.mjs | ||
|
||
# Foolproof feature: | ||
# - Copies over README so that the root of the deployed website shows it | ||
# - Changes 404 page to README so that you don't get lost while clicking links | ||
# If you remove this step then you should probably remove the enable_jekyll option in the next one | ||
- name: Copy additional files | ||
run: | | ||
cp README.md dist/README.md | ||
printf -- "---\npermalink: /404.html\n---\n" > dist/404.md | ||
printf -- "> **Note:** You accessed a link that returned a 404. How did you end up here!?!\n\n" >> dist/404.md | ||
cat README.md >> dist/404.md | ||
# Documentation: https://github.com/peaceiris/actions-gh-pages | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./dist | ||
# Makes it so the md files in the previous step get processed by GitHub Pages | ||
enable_jekyll: true | ||
# This creates the CNAME file required to host GitHub Pages on a custom domain | ||
# cname: example.com |
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 @@ | ||
node_modules/ | ||
dist/ | ||
.DS_Store |
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 @@ | ||
shamefully-hoist=true |
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,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <https://unlicense.org> |
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,7 @@ | ||
# Vendetta Plugin Template | ||
This repo contains a template for creating a [Vendetta](https://github.com/vendetta-mod/Vendetta) plugin. | ||
|
||
# How to install? | ||
Paste this plugin's URL into the Plugins page of Vendetta, following a basic format of: | ||
|
||
https://`YOUR_GITHUB_USERNAME`.github.io/`REPO_NAME` |
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,84 @@ | ||
import { readFile, writeFile, readdir } from "fs/promises"; | ||
import { extname } from "path"; | ||
import { createHash } from "crypto"; | ||
|
||
import { rollup } from "rollup"; | ||
import esbuild from "rollup-plugin-esbuild"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
import nodeResolve from "@rollup/plugin-node-resolve"; | ||
import swc from "@swc/core"; | ||
|
||
const extensions = [".js", ".jsx", ".mjs", ".ts", ".tsx", ".cts", ".mts"]; | ||
|
||
/** @type import("rollup").InputPluginOption */ | ||
const plugins = [ | ||
nodeResolve(), | ||
commonjs(), | ||
{ | ||
name: "swc", | ||
async transform(code, id) { | ||
const ext = extname(id); | ||
if (!extensions.includes(ext)) return null; | ||
|
||
const ts = ext.includes("ts"); | ||
const tsx = ts ? ext.endsWith("x") : undefined; | ||
const jsx = !ts ? ext.endsWith("x") : undefined; | ||
|
||
const result = await swc.transform(code, { | ||
filename: id, | ||
jsc: { | ||
externalHelpers: true, | ||
parser: { | ||
syntax: ts ? "typescript" : "ecmascript", | ||
tsx, | ||
jsx, | ||
}, | ||
}, | ||
env: { | ||
targets: "defaults", | ||
include: ["transform-classes", "transform-arrow-functions"], | ||
}, | ||
}); | ||
return result.code; | ||
}, | ||
}, | ||
esbuild({ minify: true }), | ||
]; | ||
|
||
const manifest = JSON.parse(await readFile(`./manifest.json`)); | ||
const outPath = `./dist/index.js`; | ||
|
||
try { | ||
const bundle = await rollup({ | ||
input: `./${manifest.main}`, | ||
onwarn: () => { }, | ||
plugins, | ||
}); | ||
|
||
await bundle.write({ | ||
file: outPath, | ||
globals(id) { | ||
if (id.startsWith("@vendetta")) | ||
return id.substring(1).replace(/\//g, "."); | ||
const map = { | ||
react: "window.React", | ||
}; | ||
|
||
return map[id] || null; | ||
}, | ||
format: "iife", | ||
compact: true, | ||
exports: "named", | ||
}); | ||
await bundle.close(); | ||
|
||
const toHash = await readFile(outPath); | ||
manifest.hash = createHash("sha256").update(toHash).digest("hex"); | ||
manifest.main = "index.js"; | ||
await writeFile(`./dist/manifest.json`, JSON.stringify(manifest)); | ||
|
||
console.log(`Successfully built ${manifest.name}!`); | ||
} catch (e) { | ||
console.error("Failed to build plugin...", e); | ||
process.exit(1); | ||
} |
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,14 @@ | ||
{ | ||
"name": "Template Plugin", | ||
"description": "A plugin for use as a template.", | ||
"authors": [ | ||
{ | ||
"name": "You!", | ||
"id": "YOUR_ID_HERE" | ||
} | ||
], | ||
"main": "src/index.ts", | ||
"vendetta": { | ||
"icon": "ic_badge_staff" | ||
} | ||
} |
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,26 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"build": "node build.mjs" | ||
}, | ||
"dependencies": { | ||
"@swc/helpers": "^0.4.14" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^24.0.0", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@swc/core": "^1.3.35", | ||
"esbuild": "^0.16.14", | ||
"rollup": "^3.9.1", | ||
"rollup-plugin-esbuild": "^5.0.0", | ||
"vendetta-types": "latest" | ||
}, | ||
"pnpm": { | ||
"peerDependencyRules": { | ||
"ignoreMissing": [ | ||
"react", | ||
"react-native" | ||
] | ||
} | ||
} | ||
} |
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,8 @@ | ||
import { Forms } from "@vendetta/ui/components"; | ||
const { FormText } = Forms; | ||
|
||
export default () => ( | ||
<FormText> | ||
Hello, world! | ||
</FormText> | ||
) |
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,12 @@ | ||
import { logger } from "@vendetta"; | ||
import Settings from "./Settings"; | ||
|
||
export default { | ||
onLoad: () => { | ||
logger.log("Hello world!"); | ||
}, | ||
onUnload: () => { | ||
logger.log("Goodbye, world."); | ||
}, | ||
settings: Settings, | ||
} |
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,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"jsx": "react-native", | ||
"allowJs": true | ||
}, | ||
"include": ["node_modules/vendetta-types", "src"] | ||
} |