Add logging and debug for backup configuration process
This commit is contained in:
parent
df338ed6a0
commit
d0f43b6318
@ -7,13 +7,21 @@ import {
|
||||
type BuildContextLike as BuildContextLike_prepareRealmConfig
|
||||
} from "./prepareRealmConfig";
|
||||
import * as fs from "fs";
|
||||
import { join as pathJoin, dirname as pathDirname } from "path";
|
||||
import {
|
||||
join as pathJoin,
|
||||
dirname as pathDirname,
|
||||
relative as pathRelative,
|
||||
sep as pathSep
|
||||
} from "path";
|
||||
import { existsAsync } from "../../tools/fs.existsAsync";
|
||||
import { readRealmJsonFile, type ParsedRealmJson } from "./ParsedRealmJson";
|
||||
import {
|
||||
dumpContainerConfig,
|
||||
type BuildContextLike as BuildContextLike_dumpContainerConfig
|
||||
} from "./dumpContainerConfig";
|
||||
import * as runExclusive from "run-exclusive";
|
||||
import { waitForDebounceFactory } from "powerhooks/tools/waitForDebounce";
|
||||
import chalk from "chalk";
|
||||
|
||||
export type BuildContextLike = BuildContextLike_dumpContainerConfig &
|
||||
BuildContextLike_prepareRealmConfig & {
|
||||
@ -89,7 +97,14 @@ export async function getRealmConfig(params: {
|
||||
|
||||
await writeRealmJsonFile({ parsedRealmJson });
|
||||
|
||||
async function onRealmConfigChange() {
|
||||
const { onRealmConfigChange } = (() => {
|
||||
const run = runExclusive.build(async () => {
|
||||
const start = Date.now();
|
||||
|
||||
console.log(
|
||||
chalk.grey(`Changes detected to the '${realmName}' config, backing up...`)
|
||||
);
|
||||
|
||||
const parsedRealmJson = await dumpContainerConfig({
|
||||
buildContext,
|
||||
realmName,
|
||||
@ -97,8 +112,35 @@ export async function getRealmConfig(params: {
|
||||
});
|
||||
|
||||
await writeRealmJsonFile({ parsedRealmJson });
|
||||
|
||||
console.log(
|
||||
[
|
||||
chalk.green(
|
||||
`✓ '${realmName}' config backed up completed in ${Date.now() - start}ms`
|
||||
),
|
||||
chalk.grey(
|
||||
`Save changed to \`.${pathSep}${pathRelative(buildContext.projectDirPath, realmJsonFilePath)}\``
|
||||
),
|
||||
chalk.grey(
|
||||
`Next time you'll be running \`keycloakify start-keycloak\`, the realm '${realmName}' will be restored to this state.`
|
||||
)
|
||||
].join("\n")
|
||||
);
|
||||
});
|
||||
|
||||
const { waitForDebounce } = waitForDebounceFactory({
|
||||
delay: 1_000
|
||||
});
|
||||
|
||||
async function onRealmConfigChange() {
|
||||
await waitForDebounce();
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
return { onRealmConfigChange };
|
||||
})();
|
||||
|
||||
return {
|
||||
realmJsonFilePath,
|
||||
clientName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user