diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ddf104c --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b4a82e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +.DS_Store \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..c483022 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +shamefully-hoist=true \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c577b0 --- /dev/null +++ b/LICENSE @@ -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 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8a75a57 --- /dev/null +++ b/README.md @@ -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` \ No newline at end of file diff --git a/build.mjs b/build.mjs new file mode 100644 index 0000000..021f763 --- /dev/null +++ b/build.mjs @@ -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); +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..7ae52d5 --- /dev/null +++ b/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.ts", + "vendetta": { + "icon": "ic_badge_staff" + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..189b00e --- /dev/null +++ b/package.json @@ -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" + ] + } + } +} diff --git a/src/Settings.tsx b/src/Settings.tsx new file mode 100644 index 0000000..004df79 --- /dev/null +++ b/src/Settings.tsx @@ -0,0 +1,8 @@ +import { Forms } from "@vendetta/ui/components"; +const { FormText } = Forms; + +export default () => ( + + Hello, world! + +) \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..03bd39a --- /dev/null +++ b/src/index.ts @@ -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/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..253439d --- /dev/null +++ b/tsconfig.json @@ -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"] +}