mirror of
https://github.com/sern-handler/automata
synced 2026-06-28 02:32:16 +00:00
feat: babashka scripts
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
FROM node:lts-alpine
|
||||
|
||||
RUN apk add git bash curl
|
||||
RUN bash < <(curl -s https://raw.githubusercontent.com/babashka/babashka/master/install)
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
5
babashka/pst.clj
Normal file
5
babashka/pst.clj
Normal file
@@ -0,0 +1,5 @@
|
||||
(def now (java.time.ZonedDateTime/now))
|
||||
(def LA-timezone (java.time.ZoneId/of "America/Los_Angeles"))
|
||||
(def LA-time (.withZoneSameInstant now LA-timezone))
|
||||
(def pattern (java.time.format.DateTimeFormatter/ofPattern "HH:mm"))
|
||||
(println (.format LA-time pattern))
|
||||
3
babashka/scripts.json
Normal file
3
babashka/scripts.json
Normal file
@@ -0,0 +1,3 @@
|
||||
[
|
||||
{ "file": "pst.clj", "route": "/bb/getPstTime", "method": "GET" }
|
||||
]
|
||||
25
index.ts
25
index.ts
@@ -3,6 +3,7 @@ import bodyParser from 'body-parser';
|
||||
import 'dotenv/config';
|
||||
import { execa } from 'execa';
|
||||
import { validateJsonWebhook } from './util/validateJsonWebhook.js';
|
||||
import babashkaScripts from './babashka/scripts.json' assert { type: 'json' }
|
||||
|
||||
const app = express()
|
||||
app.use(bodyParser.json())
|
||||
@@ -34,4 +35,28 @@ app.post('/wh/updateDocsJson', async (req, res) => {
|
||||
})
|
||||
})
|
||||
|
||||
for (const script of babashkaScripts) {
|
||||
switch (script.method) {
|
||||
case 'GET':
|
||||
app.get(script.route, async (req, res) => {
|
||||
const command = await execa('bb', [`babashka/${script.file}`])
|
||||
res.send({
|
||||
success: command.exitCode === 0 ? true : false,
|
||||
cmdoutput: command.stdout
|
||||
})
|
||||
})
|
||||
break;
|
||||
case 'POST':
|
||||
app.post(script.route, async (req, res) => {
|
||||
const command = await execa('bb', [`babashka/${script.file}`])
|
||||
res.send({
|
||||
success: command.exitCode === 0 ? true : false,
|
||||
cmdoutput: command.stdout
|
||||
})
|
||||
})
|
||||
break;
|
||||
}
|
||||
console.log(`Babashka script ${script.file} was registered successfully in ${script.method} ${script.route}`)
|
||||
}
|
||||
|
||||
app.listen(3000, () => console.log('Listening!'))
|
||||
@@ -39,7 +39,7 @@
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
"resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ mkdir repos
|
||||
cd repos
|
||||
echo " done"
|
||||
|
||||
echo -ne "Installing sern CLI"
|
||||
npm install -g @sern/cli
|
||||
echo " done"
|
||||
|
||||
echo "Cloning repos"
|
||||
# handler (clone it as sernHandlerV2)
|
||||
echo -ne "- handler"
|
||||
|
||||
1
util/sleep.ts
Normal file
1
util/sleep.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
Reference in New Issue
Block a user