Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FieryFlames authored Jul 18, 2023
0 parents commit 8fd45c0
Show file tree
Hide file tree
Showing 11 changed files with 240 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: 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
.DS_Store
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
24 changes: 24 additions & 0 deletions LICENSE
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>
7 changes: 7 additions & 0 deletions README.md
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`
84 changes: 84 additions & 0 deletions build.mjs
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);
}
14 changes: 14 additions & 0 deletions manifest.json
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"
}
}
26 changes: 26 additions & 0 deletions package.json
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"
]
}
}
}
8 changes: 8 additions & 0 deletions src/Settings.tsx
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>
)
12 changes: 12 additions & 0 deletions src/index.ts
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,
}
12 changes: 12 additions & 0 deletions tsconfig.json
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"]
}

0 comments on commit 8fd45c0

Please sign in to comment.