最終更新 1 month ago

Create a new Squeebot plugin

evert's Avatar evert revised this gist 1 month ago. Go to revision

1 file changed, 162 insertions

mkplugin.sh(file created)

@@ -0,0 +1,162 @@
1 + #!/usr/bin/env bash
2 + set -eu
3 + COMMAND_NAME=$1
4 +
5 + if [ -z $COMMAND_NAME ]; then
6 + echo 'Please provide plugin name'
7 + exit 1
8 + fi
9 +
10 + CLASS_NAME=${COMMAND_NAME^}
11 + LIB_VERSION=$(cat pluginlib/package.json | jq .version)
12 +
13 + echo "Creating plugin \"$COMMAND_NAME\" with class \"$CLASS_NAME\""
14 +
15 + # Template
16 +
17 + PACKAGE_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 +
51 + EOF
52 + )
53 +
54 + TSCONFIG=$(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 +
90 + EOF
91 + )
92 +
93 + GITIGNORE=$(cat <<EOF
94 + /node_modules/
95 + /dist/
96 +
97 + EOF
98 + )
99 +
100 + NPMIGNORE=$(cat <<EOF
101 + /src/
102 + /.gitea
103 +
104 + EOF
105 + )
106 +
107 + CLASS=$(cat <<EOF
108 + import { Plugin } from '@squeebot/pluginlib/plugin';
109 +
110 + class ${CLASS_NAME} extends Plugin {
111 + public name = ${CLASS_NAME}.name;
112 + }
113 +
114 + export default ${CLASS_NAME};
115 +
116 + EOF
117 + )
118 +
119 + GITEA=$(cat <<EOF
120 + name: Publish packages
121 + on:
122 + push:
123 + tags:
124 + - '*'
125 +
126 + jobs:
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 +
145 + EOF
146 + )
147 +
148 + # Build project
149 + TARGET="$COMMAND_NAME/"
150 + mkdir -p $TARGET/src
151 + mkdir -p $TARGET/.gitea/workflows
152 +
153 + echo "$CLASS" > $TARGET/src/index.ts
154 + echo "$PACKAGE_JSON" > $TARGET/package.json
155 + echo "$GITIGNORE" > $TARGET/.gitignore
156 + echo "$NPMIGNORE" > $TARGET/.npmignore
157 + echo "$TSCONFIG" > $TARGET/tsconfig.json
158 + echo "$GITEA" > $TARGET/.gitea/workflows/publish.yml
159 +
160 + cd $TARGET
161 + npm install
162 + git init
Newer Older