Convert scripts to ESM (#859)

This commit is contained in:
Jon Koops 2021-07-15 22:56:25 +02:00 committed by GitHub
parent 6d8db5d533
commit c848c794d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 48 deletions

View file

@ -1,5 +1,6 @@
{
"env": {
"node":true,
"browser": true,
"es6": true
},

View file

@ -27,13 +27,13 @@ jobs:
- run: npm run build
- name: Run Keycloak
run: ./start.js & sleep 40
run: ./start.mjs & sleep 40
- name: Run Admin Console
run: npx http-server ./build -P http://localhost:8180/ & sleep 30
- name: Admin Console client
run: ./import.js
run: ./import.mjs
- name: Cypress run
run: npm run start:cypress-tests

View file

@ -9,7 +9,7 @@ WORKDIR /app
COPY . .
# replace Keycloak endpoints
RUN sed -i "s/${DEFAULT_KEYCLOAK_ENDPOINT}/${KEYCLOAK_ENDPOINT}/g" import.js &&\
RUN sed -i "s/${DEFAULT_KEYCLOAK_ENDPOINT}/${KEYCLOAK_ENDPOINT}/g" import.mjs &&\
sed -i "s/${DEFAULT_KEYCLOAK_ENDPOINT}/${KEYCLOAK_ENDPOINT}/g" src/context/auth/keycloak.ts &&\
sed -i "s/adminv2//g" snowpack.config.js

View file

@ -8,7 +8,7 @@ For development on this project you will need a running Keycloak server listenin
1. Start keycloak
* Download and run with one command
```bash
$> ./start.js
$> ./start.mjs
```
* or download Keycloak server from [keycloak downloads page][2] unpack and run it like:
```bash
@ -19,7 +19,7 @@ For development on this project you will need a running Keycloak server listenin
* like this:
![realm settings](./realm-settings.png "Realm Settings")
* or click on the "Select file" button and import `security-admin-console-v2.json`
* or run `$> ./import.js`
* or run `$> ./import.mjs`
1. Install dependencies and run:
```bash

View file

@ -1,23 +0,0 @@
#!/usr/bin/env node
const KcAdminClient = require('keycloak-admin').default;
const consoleClientConfig = require("./security-admin-console-v2.json");
const adminClient = new KcAdminClient({
baseUrl: "http://localhost:8180/auth",
realmName: 'master',
});
(async () => {
await adminClient.auth({
username: 'admin',
password: 'admin',
grantType: 'password',
clientId: 'admin-cli',
});
const adminConsoleClient = await adminClient.clients.find({clientId: "security-admin-console-v2"});
if (adminConsoleClient.length === 0) {
adminClient.clients.create(consoleClientConfig);
}
})();

27
import.mjs Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env node
import { readFile } from "node:fs/promises";
import KcAdminClient from "keycloak-admin";
const consoleClientConfig = JSON.parse(
await readFile(new URL("./security-admin-console-v2.json", import.meta.url))
);
const adminClient = new KcAdminClient.default({
baseUrl: "http://localhost:8180/auth",
realmName: "master",
});
await adminClient.auth({
username: "admin",
password: "admin",
grantType: "password",
clientId: "admin-cli",
});
const adminConsoleClient = await adminClient.clients.find({
clientId: "security-admin-console-v2",
});
if (adminConsoleClient.length === 0) {
adminClient.clients.create(consoleClientConfig);
}

View file

@ -14,7 +14,7 @@
},
"scripts": {
"build": "snowpack build",
"lint": "eslint \"./src/**/*.{js,jsx,ts,tsx}\"",
"lint": "eslint \"./src/**/*.{js,jsx,mjs,ts,tsx}\"",
"postinstall": "grunt",
"start": "snowpack dev",
"test": "jest",
@ -93,6 +93,6 @@
"typescript": "4.2.4"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --cache --fix"
"*.{js,jsx,mjs,ts,tsx}": "eslint --cache --fix"
}
}

View file

@ -1,11 +1,11 @@
#!/usr/bin/env node
const http = require("https");
const fs = require("fs");
const path = require("path");
const { spawn } = require("child_process");
import http from "node:https";
import fs from "node:fs";
import path from "node:path";
import { spawn } from "node:child_process";
const decompress = require("decompress");
const decompressTargz = require("decompress-targz");
import decompress from "decompress";
import decompressTargz from "decompress-targz";
const args = process.argv.slice(2);
const version = args[0] || "12.0.1";
@ -19,19 +19,24 @@ if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
}
const decompressKeycloak = () =>
decompress(fileName, folder, {
plugins: [decompressTargz()],
})
.then(() => {
console.log("Files decompressed");
})
.catch((e) => console.error(e));
async function decompressKeycloak() {
try {
await decompress(fileName, folder, {
plugins: [decompressTargz()],
});
console.log("Files decompressed");
} catch (error) {
console.error(error);
}
}
const run = () => {
const addProc = spawn(path.join(serverPath, "bin", `add-user-keycloak${extension}`), [
"--user", "admin",
"--password", "admin"
]);
const addProc = spawn(
path.join(serverPath, "bin", `add-user-keycloak${extension}`),
["--user", "admin", "--password", "admin"]
);
addProc.on("exit", () => {
const proc = spawn(path.join(serverPath, "bin", `standalone${extension}`), [
"-Djboss.socket.binding.port-offset=100",