feat: babashka scripts

This commit is contained in:
2023-05-06 12:28:48 +00:00
parent 3bf00e8bee
commit cdca979a7e
7 changed files with 40 additions and 1 deletions

View File

@@ -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
View 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
View File

@@ -0,0 +1,3 @@
[
{ "file": "pst.clj", "route": "/bb/getPstTime", "method": "GET" }
]

View File

@@ -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!'))

View File

@@ -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. */

View File

@@ -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
View File

@@ -0,0 +1 @@
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));