Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Corb3nik committed Oct 27, 2024
0 parents commit 2ad9a8c
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 🚀 Release

on:
workflow_dispatch:

env:
NODE_VERSION: 20
PNPM_VERSION: 9

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout project
uses: actions/checkout@v4

- name: Check version
id: meta
run: |
VERSION=$(jq -r .version manifest.json)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
run_install: true

- name: Build package
run: pnpm build

- name: Sign package
working-directory: dist
run: |
if [[ -z "${{ secrets.PRIVATE_KEY }}" ]]; then
echo "Set an ed25519 key as PRIVATE_KEY in GitHub Action secret to sign."
else
echo "${{ secrets.PRIVATE_KEY }}" > private_key.pem
openssl pkeyutl -sign -inkey private_key.pem -out plugin_package.zip.sig -rawin -in plugin_package.zip
rm private_key.pem
fi
- name: Create release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.meta.outputs.version }}
commit: ${{ github.sha }}
body: 'Release ${{ steps.meta.outputs.version }}'
artifacts: 'dist/plugin_package.zip,dist/plugin_package.zip.sig'
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2024 [Author]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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 OR COPYRIGHT HOLDERS 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.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Vanilla JS Frontend Template

This template should be used as a starting point for creating a new plugin with a vanilla JS frontend.

## Features

- [pnpm](https://pnpm.io/) as package manager
- [TypeScript](https://www.typescriptlang.org/)
18 changes: 18 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "pwnfox",
"name": "PwnFox",
"version": "0.0.1",
"description": "Integration with the PwnFox browser extension",
"author": {
"name": "SyzikSecu",
"email": "[email protected]",
"url": "https://x.com/SyzikSecu"
},
"plugins": [
{
"kind": "workflow",
"id": "pwnfox-passive",
"name": "Passive Workflow"
}
]
}
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "no-frontend",
"version": "0.0.1",
"description": "Plugin package template with no frontend",
"author": "Caido Labs Inc. <[email protected]>",
"license": "CC0-1.0",
"type": "module",
"scripts": {
"typecheck": "pnpm -r typecheck",
"build": "node scripts/clean.js && pnpm -r build && node scripts/pack.js"
},
"devDependencies": {
"@caido/plugin-manifest": "0.1.3",
"jszip": "3.10.1",
"typescript": "5.5.4",
"vite": "5.2.7"
}
}
13 changes: 13 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "backend",
"version": "0.0.0",
"type": "module",
"types": "src/index.ts",
"scripts": {
"typecheck": "tsc --noEmit",
"build": "vite build"
},
"devDependencies": {
"@caido/sdk-backend": "0.42.0"
}
}
15 changes: 15 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { DefineAPI, SDK } from "caido:plugin";

const generateRandomString = (sdk: SDK, length: number) => {
const randomString = Math.random().toString(36).substring(2, length + 2);
sdk.console.log(`Generating random string: ${randomString}`);
return randomString;
}

export type API = DefineAPI<{
generateRandomString: typeof generateRandomString;
}>;

export function init(sdk: SDK<API>) {
sdk.api.register("generateRandomString", generateRandomString);
}
7 changes: 7 additions & 0 deletions packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["@caido/sdk-backend"]
},
"include": ["./src/**/*.ts"]
}
21 changes: 21 additions & 0 deletions packages/backend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from "vite";
import { resolve } from "path";
import { builtinModules } from "module";

export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, "src/index.ts"),
name: "plugin-template-backend",
fileName: (format) => "script.js",
formats: ["es"],
},
outDir: "../../dist/backend",
rollupOptions: {
external: [/caido:.+/, ...builtinModules],
output: {
manualChunks: undefined,
},
},
},
});
2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- 'packages/*'
8 changes: 8 additions & 0 deletions scripts/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const DIST = path.join(__dirname, "../dist");

fs.rmSync(DIST, { recursive: true, force: true });
55 changes: 55 additions & 0 deletions scripts/pack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import JSZip from "jszip";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { validateManifest } from "@caido/plugin-manifest";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const DIST = path.resolve(__dirname, "../dist");

/**
* @param {string} dirPath
* @param {JSZip} zipFolder
*/
function addDirToZip(dirPath, zipFolder) {
const files = fs.readdirSync(dirPath);
files.forEach((file) => {
const filePath = path.join(dirPath, file);
const fileStat = fs.statSync(filePath);
if (fileStat.isDirectory()) {
const newZipFolder = zipFolder.folder(file);
addDirToZip(filePath, newZipFolder);
} else {
const fileContents = fs.readFileSync(filePath);
zipFolder.file(file, fileContents);
}
});
}

console.log("[*] Copying manifest file");
const srcManifestPath = path.resolve(__dirname, "../manifest.json");
const destManifestPath = path.join(DIST, "manifest.json");
const data = JSON.parse(fs.readFileSync(srcManifestPath, "utf-8"));
if (!validateManifest(data)) {
process.exit(1);
}
fs.copyFileSync(srcManifestPath, destManifestPath);

console.log("[*] Creating zip");
const zip = new JSZip();

addDirToZip(DIST, zip);

const zipPath = path.join(DIST, "plugin_package.zip");
zip
.generateAsync({
type: "nodebuffer",
compression: "DEFLATE",
compressionOptions: {
level: 9,
},
})
.then((content) => {
fs.writeFileSync(zipPath, content);
})
.catch((err) => console.error("[-] Error creating zip:", err));
24 changes: 24 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["ESNext"],

"jsx": "preserve",
"noImplicitAny": true,
"noUncheckedIndexedAccess": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,

"moduleResolution": "bundler",
"esModuleInterop": true,
"sourceMap": true,
"noUnusedLocals": true,

"useDefineForClassFields": true,
"isolatedModules": true,

"baseUrl": "."
}
}

0 comments on commit 2ad9a8c

Please sign in to comment.