Last active 1 month ago

Create a new Squeebot plugin

mkplugin.sh Raw
1#!/usr/bin/env bash
2set -eu
3COMMAND_NAME=$1
4
5if [ -z $COMMAND_NAME ]; then
6 echo 'Please provide plugin name'
7 exit 1
8fi
9
10CLASS_NAME=${COMMAND_NAME^}
11LIB_VERSION=$(cat pluginlib/package.json | jq .version)
12
13echo "Creating plugin \"$COMMAND_NAME\" with class \"$CLASS_NAME\""
14
15# Template
16
17PACKAGE_JSON=$(cat <<EOF
18{
19 "name": "@squeebot/${COMMAND_NAME}",
20 "version": "1.0.0",
21 "description": "",
22 "main": "dist/index.js",
23 "types": "./dist/index.d.ts",
24 "exports": {
25 "./package.json": "./package.json",
26 ".": {
27 "require": {
28 "types": "./dist/index.d.ts",
29 "default": "./dist/index.js"
30 }
31 }
32 },
33 "scripts": {
34 "build": "npm run build:ts",
35 "build:ts": "tsc",
36 "prepare": "npm run build:ts"
37 },
38 "keywords": [],
39 "author": "Evert Prants <evert@lunasqu.ee>",
40 "license": "MIT",
41 "type": "commonjs",
42 "devDependencies": {
43 "@types/node": "^24.10.2",
44 "typescript": "^5.9.3"
45 },
46 "dependencies": {
47 "@squeebot/pluginlib": ${LIB_VERSION}
48 }
49}
50
51EOF
52)
53
54TSCONFIG=$(cat <<EOF
55{
56 // Visit https://aka.ms/tsconfig to read more about this file
57 "compilerOptions": {
58 // File Layout
59 "rootDir": "./src",
60 "outDir": "./dist",
61
62 // Environment Settings
63 // See also https://aka.ms/tsconfig/module
64 "module": "nodenext",
65 "target": "es6",
66 "lib": ["esnext"],
67 "types": ["node"],
68 "moduleResolution": "nodenext",
69
70 // Other Outputs
71 "sourceMap": false,
72 "declaration": true,
73 "declarationMap": false,
74
75 // Stricter Typechecking Options
76 "noUncheckedIndexedAccess": true,
77 "exactOptionalPropertyTypes": true,
78
79 // Recommended Options
80 "strict": true,
81 "verbatimModuleSyntax": false,
82 "isolatedModules": true,
83 "noUncheckedSideEffectImports": true,
84 "moduleDetection": "force",
85 "skipLibCheck": true
86 },
87 "include": ["src/**/*.ts"]
88}
89
90EOF
91)
92
93GITIGNORE=$(cat <<EOF
94/node_modules/
95/dist/
96
97EOF
98)
99
100NPMIGNORE=$(cat <<EOF
101/src/
102/.gitea
103
104EOF
105)
106
107CLASS=$(cat <<EOF
108import { Plugin } from '@squeebot/pluginlib/plugin';
109
110class ${CLASS_NAME} extends Plugin {
111 public name = ${CLASS_NAME}.name;
112}
113
114export default ${CLASS_NAME};
115
116EOF
117)
118
119GITEA=$(cat <<EOF
120name: Publish packages
121on:
122 push:
123 tags:
124 - '*'
125
126jobs:
127 publish-npm:
128 runs-on: ubuntu-latest
129 steps:
130 - uses: actions/checkout@v4
131 - name: Setup Node.js
132 uses: actions/setup-node@v6
133 with:
134 node-version: 'latest'
135 registry-url: 'https://git.icynet.eu/api/packages/Squeebot/npm/'
136 scope: '@squeebot'
137 - run: npm install
138 env:
139 NODE_AUTH_TOKEN: \${{ secrets.PUB_ACCESS_TOKEN }}
140 - run: npm run build
141 - run: npm publish
142 env:
143 NODE_AUTH_TOKEN: \${{ secrets.PUB_ACCESS_TOKEN }}
144
145EOF
146)
147
148# Build project
149TARGET="$COMMAND_NAME/"
150mkdir -p $TARGET/src
151mkdir -p $TARGET/.gitea/workflows
152
153echo "$CLASS" > $TARGET/src/index.ts
154echo "$PACKAGE_JSON" > $TARGET/package.json
155echo "$GITIGNORE" > $TARGET/.gitignore
156echo "$NPMIGNORE" > $TARGET/.npmignore
157echo "$TSCONFIG" > $TARGET/tsconfig.json
158echo "$GITEA" > $TARGET/.gitea/workflows/publish.yml
159
160cd $TARGET
161npm install
162git init
163