Convert scripts to ESM (#859)
This commit is contained in:
parent
6d8db5d533
commit
c848c794d7
8 changed files with 58 additions and 48 deletions
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"env": {
|
"env": {
|
||||||
|
"node":true,
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"es6": true
|
"es6": true
|
||||||
},
|
},
|
||||||
|
|
4
.github/workflows/cypress.yml
vendored
4
.github/workflows/cypress.yml
vendored
|
@ -27,13 +27,13 @@ jobs:
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
|
||||||
- name: Run Keycloak
|
- name: Run Keycloak
|
||||||
run: ./start.js & sleep 40
|
run: ./start.mjs & sleep 40
|
||||||
|
|
||||||
- name: Run Admin Console
|
- name: Run Admin Console
|
||||||
run: npx http-server ./build -P http://localhost:8180/ & sleep 30
|
run: npx http-server ./build -P http://localhost:8180/ & sleep 30
|
||||||
|
|
||||||
- name: Admin Console client
|
- name: Admin Console client
|
||||||
run: ./import.js
|
run: ./import.mjs
|
||||||
|
|
||||||
- name: Cypress run
|
- name: Cypress run
|
||||||
run: npm run start:cypress-tests
|
run: npm run start:cypress-tests
|
||||||
|
|
|
@ -9,7 +9,7 @@ WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# replace Keycloak endpoints
|
# 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/${DEFAULT_KEYCLOAK_ENDPOINT}/${KEYCLOAK_ENDPOINT}/g" src/context/auth/keycloak.ts &&\
|
||||||
sed -i "s/adminv2//g" snowpack.config.js
|
sed -i "s/adminv2//g" snowpack.config.js
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ For development on this project you will need a running Keycloak server listenin
|
||||||
1. Start keycloak
|
1. Start keycloak
|
||||||
* Download and run with one command
|
* Download and run with one command
|
||||||
```bash
|
```bash
|
||||||
$> ./start.js
|
$> ./start.mjs
|
||||||
```
|
```
|
||||||
* or download Keycloak server from [keycloak downloads page][2] unpack and run it like:
|
* or download Keycloak server from [keycloak downloads page][2] unpack and run it like:
|
||||||
```bash
|
```bash
|
||||||
|
@ -19,7 +19,7 @@ For development on this project you will need a running Keycloak server listenin
|
||||||
* like this:
|
* like this:
|
||||||
![realm settings](./realm-settings.png "Realm Settings")
|
![realm settings](./realm-settings.png "Realm Settings")
|
||||||
* or click on the "Select file" button and import `security-admin-console-v2.json`
|
* 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:
|
1. Install dependencies and run:
|
||||||
```bash
|
```bash
|
||||||
|
|
23
import.js
23
import.js
|
@ -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
27
import.mjs
Executable 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);
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "snowpack build",
|
"build": "snowpack build",
|
||||||
"lint": "eslint \"./src/**/*.{js,jsx,ts,tsx}\"",
|
"lint": "eslint \"./src/**/*.{js,jsx,mjs,ts,tsx}\"",
|
||||||
"postinstall": "grunt",
|
"postinstall": "grunt",
|
||||||
"start": "snowpack dev",
|
"start": "snowpack dev",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
|
@ -93,6 +93,6 @@
|
||||||
"typescript": "4.2.4"
|
"typescript": "4.2.4"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{js,jsx,ts,tsx}": "eslint --cache --fix"
|
"*.{js,jsx,mjs,ts,tsx}": "eslint --cache --fix"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const http = require("https");
|
import http from "node:https";
|
||||||
const fs = require("fs");
|
import fs from "node:fs";
|
||||||
const path = require("path");
|
import path from "node:path";
|
||||||
const { spawn } = require("child_process");
|
import { spawn } from "node:child_process";
|
||||||
|
|
||||||
const decompress = require("decompress");
|
import decompress from "decompress";
|
||||||
const decompressTargz = require("decompress-targz");
|
import decompressTargz from "decompress-targz";
|
||||||
|
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const version = args[0] || "12.0.1";
|
const version = args[0] || "12.0.1";
|
||||||
|
@ -19,19 +19,24 @@ if (!fs.existsSync(folder)) {
|
||||||
fs.mkdirSync(folder);
|
fs.mkdirSync(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
const decompressKeycloak = () =>
|
async function decompressKeycloak() {
|
||||||
decompress(fileName, folder, {
|
try {
|
||||||
plugins: [decompressTargz()],
|
await decompress(fileName, folder, {
|
||||||
})
|
plugins: [decompressTargz()],
|
||||||
.then(() => {
|
});
|
||||||
console.log("Files decompressed");
|
|
||||||
})
|
console.log("Files decompressed");
|
||||||
.catch((e) => console.error(e));
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const run = () => {
|
const run = () => {
|
||||||
const addProc = spawn(path.join(serverPath, "bin", `add-user-keycloak${extension}`), [
|
const addProc = spawn(
|
||||||
"--user", "admin",
|
path.join(serverPath, "bin", `add-user-keycloak${extension}`),
|
||||||
"--password", "admin"
|
["--user", "admin", "--password", "admin"]
|
||||||
]);
|
);
|
||||||
|
|
||||||
addProc.on("exit", () => {
|
addProc.on("exit", () => {
|
||||||
const proc = spawn(path.join(serverPath, "bin", `standalone${extension}`), [
|
const proc = spawn(path.join(serverPath, "bin", `standalone${extension}`), [
|
||||||
"-Djboss.socket.binding.port-offset=100",
|
"-Djboss.socket.binding.port-offset=100",
|
Loading…
Reference in a new issue