commit f7f29d2b049137fb0dc85beeb3fe64169b2194ca Author: Amsyar Rasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Tue Jan 24 15:56:43 2023 +0000 Initial commit diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..4e05eb4 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,47 @@ +name: Build and deploy + +on: + push: + branches: [master] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Prepare environment + uses: actions/setup-node@v2 + 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, probably by clicking one of the plugin links. You're supposed to copy the link address and add it into Vendetta.\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 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adc4bff --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +dist/ +pnpm-lock.yaml +yarn.lock +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b3e2a25 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Vendetta Plugins Template +This repo contains a template for creating [Vendetta](https://github.com/vendetta-mod/Vendetta) plugins. + +# How to install? +Paste a plugin URL into the Plugins page of Vendetta, following a basic format of: + +https://`YOUR_GITHUB_USERNAME`.github.io/`REPO_NAME`/`PLUGIN_NAME` \ No newline at end of file diff --git a/build.mjs b/build.mjs new file mode 100644 index 0000000..dd44f89 --- /dev/null +++ b/build.mjs @@ -0,0 +1,53 @@ +import { rollup } from "rollup"; +import { readFile, writeFile, readdir } from "fs/promises"; +import { createHash } from "crypto"; +import esbuild from "rollup-plugin-esbuild"; +import nodeResolve from "@rollup/plugin-node-resolve"; +import commonjs from "@rollup/plugin-commonjs"; + +for (let plug of await readdir("./plugins")) { + const manifest = JSON.parse(await readFile(`./plugins/${plug}/manifest.json`)); + const outName = manifest.main.split("/").reverse()[0]; + const outPath = `./dist/${plug}/${outName}`; + + try { + const bundle = await rollup({ + input: `./plugins/${plug}/${manifest.main}`, + onwarn: () => {}, + plugins: [ + nodeResolve(), + commonjs(), + esbuild({ + target: "esnext", + minify: true, + }) + ], + }); + + 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 = outName; + await writeFile(`./dist/${plug}/manifest.json`, JSON.stringify(manifest)); + + console.log(`Successfully built ${manifest.name}!`); + } catch (e) { + console.error("Failed to build plugin...", e); + process.exit(1); + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..f878cfb --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "scripts": { + "build": "node build.mjs" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^24.0.0", + "@rollup/plugin-node-resolve": "^15.0.1", + "esbuild": "^0.16.14", + "rollup": "^3.9.1", + "rollup-plugin-esbuild": "^5.0.0" + } +} diff --git a/plugins/template/manifest.json b/plugins/template/manifest.json new file mode 100644 index 0000000..8db2c78 --- /dev/null +++ b/plugins/template/manifest.json @@ -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.js", + "vendetta": { + "icon": "ic_badge_staff" + } +} \ No newline at end of file diff --git a/plugins/template/src/Settings.jsx b/plugins/template/src/Settings.jsx new file mode 100644 index 0000000..a4056da --- /dev/null +++ b/plugins/template/src/Settings.jsx @@ -0,0 +1,7 @@ +import { FormText } from "@vendetta/ui/components/Forms"; + +export default () => ( + + Hello, world! + +) \ No newline at end of file diff --git a/plugins/template/src/index.js b/plugins/template/src/index.js new file mode 100644 index 0000000..03bd39a --- /dev/null +++ b/plugins/template/src/index.js @@ -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, +} \ No newline at end of file diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..2a603e8 --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - plugins/* \ No newline at end of file