Use keycloakify-dev-resources instead of .keycloakify
This commit is contained in:
parent
07e4f99f80
commit
b4e94d3c00
@ -1,59 +1,8 @@
|
|||||||
import * as child_process from "child_process";
|
import * as child_process from "child_process";
|
||||||
import { transformCodebase } from "../src/bin/tools/transformCodebase";
|
|
||||||
import { join as pathJoin, sep as pathSep } from "path";
|
|
||||||
import { assert } from "tsafe/assert";
|
|
||||||
|
|
||||||
run("yarn build");
|
run("yarn build");
|
||||||
run("npx build-storybook");
|
run("npx build-storybook");
|
||||||
|
|
||||||
const storybookStaticDirPath = "storybook-static";
|
|
||||||
|
|
||||||
{
|
|
||||||
let hasPatched = false;
|
|
||||||
|
|
||||||
transformCodebase({
|
|
||||||
srcDirPath: storybookStaticDirPath,
|
|
||||||
destDirPath: storybookStaticDirPath,
|
|
||||||
transformSourceCode: ({ fileRelativePath, sourceCode }) => {
|
|
||||||
replace_dot_keycloakify: {
|
|
||||||
if (fileRelativePath.includes(pathSep)) {
|
|
||||||
break replace_dot_keycloakify;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fileRelativePath.endsWith(".js")) {
|
|
||||||
break replace_dot_keycloakify;
|
|
||||||
}
|
|
||||||
|
|
||||||
const search = `DOT_KEYCLOAKIFY:".keycloakify"`;
|
|
||||||
|
|
||||||
if (!sourceCode.includes(search)) {
|
|
||||||
break replace_dot_keycloakify;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasPatched = true;
|
|
||||||
|
|
||||||
return {
|
|
||||||
modifiedSourceCode: Buffer.from(
|
|
||||||
sourceCode
|
|
||||||
.toString("utf8")
|
|
||||||
.replace(search, `DOT_KEYCLOAKIFY:"dot_keycloakify"`),
|
|
||||||
"utf8"
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { modifiedSourceCode: sourceCode };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
assert(hasPatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
transformCodebase({
|
|
||||||
srcDirPath: pathJoin(storybookStaticDirPath, ".keycloakify"),
|
|
||||||
destDirPath: pathJoin(storybookStaticDirPath, "dot_keycloakify")
|
|
||||||
});
|
|
||||||
|
|
||||||
function run(command: string, options?: { env?: NodeJS.ProcessEnv }) {
|
function run(command: string, options?: { env?: NodeJS.ProcessEnv }) {
|
||||||
console.log(`$ ${command}`);
|
console.log(`$ ${command}`);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import { WELL_KNOWN_DIRECTORY_BASE_NAME } from "../../src/bin/shared/constants";
|
|||||||
import { assert, type Equals } from "tsafe/assert";
|
import { assert, type Equals } from "tsafe/assert";
|
||||||
import * as fsPr from "fs/promises";
|
import * as fsPr from "fs/promises";
|
||||||
|
|
||||||
export async function createPublicDotKeycloakifyDir() {
|
export async function createPublicKeycloakifyDevResourcesDir() {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
(["login", "account"] as const).map(async themeType => {
|
(["login", "account"] as const).map(async themeType => {
|
||||||
const { extractedDirPath } = await downloadKeycloakDefaultTheme({
|
const { extractedDirPath } = await downloadKeycloakDefaultTheme({
|
||||||
@ -27,7 +27,7 @@ export async function createPublicDotKeycloakifyDir() {
|
|||||||
"dist",
|
"dist",
|
||||||
"res",
|
"res",
|
||||||
"public",
|
"public",
|
||||||
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY,
|
WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES,
|
||||||
themeType
|
themeType
|
||||||
);
|
);
|
||||||
|
|
@ -3,7 +3,7 @@ import * as fs from "fs";
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { transformCodebase } from "../../src/bin/tools/transformCodebase";
|
import { transformCodebase } from "../../src/bin/tools/transformCodebase";
|
||||||
import { createPublicDotKeycloakifyDir } from "./createPublicDotKeycloakifyDir";
|
import { createPublicKeycloakifyDevResourcesDir } from "./createPublicKeycloakifyDevResourcesDir";
|
||||||
import { createAccountV1Dir } from "./createAccountV1Dir";
|
import { createAccountV1Dir } from "./createAccountV1Dir";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ import chalk from "chalk";
|
|||||||
fs.cpSync(dirBasename, destDirPath, { recursive: true });
|
fs.cpSync(dirBasename, destDirPath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
await createPublicDotKeycloakifyDir();
|
await createPublicKeycloakifyDevResourcesDir();
|
||||||
await createAccountV1Dir();
|
await createAccountV1Dir();
|
||||||
|
|
||||||
transformCodebase({
|
transformCodebase({
|
||||||
|
@ -4,7 +4,7 @@ import { id } from "tsafe/id";
|
|||||||
import type { KcContext } from "./KcContext";
|
import type { KcContext } from "./KcContext";
|
||||||
import { BASE_URL } from "keycloakify/lib/BASE_URL";
|
import { BASE_URL } from "keycloakify/lib/BASE_URL";
|
||||||
|
|
||||||
const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY}/account`;
|
const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES}/account`;
|
||||||
|
|
||||||
export const kcContextCommonMock: KcContext.Common = {
|
export const kcContextCommonMock: KcContext.Common = {
|
||||||
themeVersion: "0.0.0",
|
themeVersion: "0.0.0",
|
||||||
|
@ -99,7 +99,7 @@ export async function generateResourcesForMainTheme(params: {
|
|||||||
{
|
{
|
||||||
const dirPath = pathJoin(
|
const dirPath = pathJoin(
|
||||||
buildContext.projectBuildDirPath,
|
buildContext.projectBuildDirPath,
|
||||||
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY
|
WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fs.existsSync(dirPath)) {
|
if (fs.existsSync(dirPath)) {
|
||||||
@ -107,7 +107,7 @@ export async function generateResourcesForMainTheme(params: {
|
|||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
[
|
[
|
||||||
`Keycloakify build error: The ${WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY} directory shouldn't exist in your build directory.`,
|
`Keycloakify build error: The ${WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES} directory shouldn't exist in your build directory.`,
|
||||||
`(${pathRelative(process.cwd(), dirPath)}).\n`,
|
`(${pathRelative(process.cwd(), dirPath)}).\n`,
|
||||||
`Theses assets are only required for local development with Storybook.",
|
`Theses assets are only required for local development with Storybook.",
|
||||||
"Please remove this directory as an additional step of your command.\n`,
|
"Please remove this directory as an additional step of your command.\n`,
|
||||||
@ -256,7 +256,7 @@ export async function generateResourcesForMainTheme(params: {
|
|||||||
getThisCodebaseRootDirPath(),
|
getThisCodebaseRootDirPath(),
|
||||||
"res",
|
"res",
|
||||||
"public",
|
"public",
|
||||||
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY,
|
WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES,
|
||||||
themeType
|
themeType
|
||||||
),
|
),
|
||||||
destDirPath: pathJoin(themeTypeDirPath, "resources")
|
destDirPath: pathJoin(themeTypeDirPath, "resources")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export const WELL_KNOWN_DIRECTORY_BASE_NAME = {
|
export const WELL_KNOWN_DIRECTORY_BASE_NAME = {
|
||||||
DOT_KEYCLOAKIFY: ".keycloakify",
|
KEYCLOAKIFY_DEV_RESOURCES: "keycloakify-dev-resources",
|
||||||
RESOURCES_COMMON: "resources-common",
|
RESOURCES_COMMON: "resources-common",
|
||||||
DIST: "dist"
|
DIST: "dist"
|
||||||
} as const;
|
} as const;
|
||||||
|
@ -21,7 +21,7 @@ export function copyKeycloakResourcesToPublic(params: {
|
|||||||
|
|
||||||
const destDirPath = pathJoin(
|
const destDirPath = pathJoin(
|
||||||
buildContext.publicDirPath,
|
buildContext.publicDirPath,
|
||||||
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY
|
WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES
|
||||||
);
|
);
|
||||||
|
|
||||||
const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo");
|
const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo");
|
||||||
@ -67,7 +67,7 @@ export function copyKeycloakResourcesToPublic(params: {
|
|||||||
getThisCodebaseRootDirPath(),
|
getThisCodebaseRootDirPath(),
|
||||||
"res",
|
"res",
|
||||||
"public",
|
"public",
|
||||||
WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY
|
WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES
|
||||||
),
|
),
|
||||||
destDirPath
|
destDirPath
|
||||||
});
|
});
|
||||||
|
@ -75,7 +75,7 @@ const attributesByName = Object.fromEntries(
|
|||||||
]).map(attribute => [attribute.name, attribute])
|
]).map(attribute => [attribute.name, attribute])
|
||||||
);
|
);
|
||||||
|
|
||||||
const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY}/login`;
|
const resourcesPath = `${BASE_URL}${WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES}/login`;
|
||||||
|
|
||||||
export const kcContextCommonMock: KcContext.Common = {
|
export const kcContextCommonMock: KcContext.Common = {
|
||||||
themeVersion: "0.0.0",
|
themeVersion: "0.0.0",
|
||||||
|
@ -201,7 +201,10 @@ export function keycloakify(params: keycloakify.Params) {
|
|||||||
assert(buildDirPath !== undefined);
|
assert(buildDirPath !== undefined);
|
||||||
|
|
||||||
await rm(
|
await rm(
|
||||||
pathJoin(buildDirPath, WELL_KNOWN_DIRECTORY_BASE_NAME.DOT_KEYCLOAKIFY),
|
pathJoin(
|
||||||
|
buildDirPath,
|
||||||
|
WELL_KNOWN_DIRECTORY_BASE_NAME.KEYCLOAKIFY_DEV_RESOURCES
|
||||||
|
),
|
||||||
{
|
{
|
||||||
recursive: true,
|
recursive: true,
|
||||||
force: true
|
force: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user