Remove eslint and run prettier (changelog ignore)

This commit is contained in:
garronej
2021-10-11 21:35:40 +02:00
parent 9f8218efb7
commit 305ce9e44d
76 changed files with 27255 additions and 22419 deletions

View File

@ -1,9 +1,8 @@
import { join as pathJoin } from "path";
import { generateKeycloakThemeResources } from "../../bin/build-keycloak-theme/generateKeycloakThemeResources";
import {
setupSampleReactProject,
sampleReactProjectDirPath
sampleReactProjectDirPath,
} from "./setupSampleReactProject";
setupSampleReactProject();
@ -11,11 +10,13 @@ setupSampleReactProject();
generateKeycloakThemeResources({
"themeName": "keycloakify-demo-app",
"reactAppBuildDirPath": pathJoin(sampleReactProjectDirPath, "build"),
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme"),
"keycloakThemeBuildingDirPath": pathJoin(
sampleReactProjectDirPath,
"build_keycloak_theme",
),
"urlPathname": "/keycloakify-demo-app/",
"urlOrigin": undefined,
"extraPagesId": ["my-custom-page.ftl"],
"extraThemeProperties": ["env=test"],
"keycloakVersion": "11.0.3"
"keycloakVersion": "11.0.3",
});

View File

@ -1,8 +1,6 @@
import {
setupSampleReactProject,
sampleReactProjectDirPath
sampleReactProjectDirPath,
} from "./setupSampleReactProject";
import * as st from "scripting-tools";
import { join as pathJoin } from "path";
@ -10,15 +8,15 @@ import { getProjectRoot } from "../../bin/tools/getProjectRoot";
setupSampleReactProject();
const binDirPath= pathJoin(getProjectRoot(), "dist", "bin");
const binDirPath = pathJoin(getProjectRoot(), "dist", "bin");
st.execSyncTrace(
//`node ${pathJoin(binDirPath, "build-keycloak-theme")} --external-assets`,
`node ${pathJoin(binDirPath, "build-keycloak-theme")}`,
{ "cwd": sampleReactProjectDirPath }
{ "cwd": sampleReactProjectDirPath },
);
st.execSyncTrace(
`node ${pathJoin(binDirPath, "download-builtin-keycloak-theme")}`,
{ "cwd": sampleReactProjectDirPath }
{ "cwd": sampleReactProjectDirPath },
);

View File

@ -1,8 +1,7 @@
import { 
import {
replaceImportsFromStaticInJsCode,
replaceImportsInCssCode,
generateCssCodeToDefineGlobals
generateCssCodeToDefineGlobals,
} from "../../bin/build-keycloak-theme/replaceImportFromStatic";
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
@ -19,7 +18,7 @@ const { fixedJsCode } = replaceImportsFromStaticInJsCode({
}[e] + ".chunk.js"
}
`,
"urlOrigin": undefined
"urlOrigin": undefined,
});
const { fixedJsCode: fixedJsCodeExternal } = replaceImportsFromStaticInJsCode({
@ -36,10 +35,10 @@ const { fixedJsCode: fixedJsCodeExternal } = replaceImportsFromStaticInJsCode({
}[e] + ".chunk.js"
}
`,
"urlOrigin": "https://www.example.com"
"urlOrigin": "https://www.example.com",
});
console.log({ fixedJsCode, fixedJsCodeExternal });
console.log({ fixedJsCode, fixedJsCodeExternal });
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
"cssCode": `
@ -55,13 +54,14 @@ const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
.my-div {
background-image: url(/static/media/something.svg);
}
`
`,
});
console.log({ fixedCssCode, cssGlobalsToDefine });
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
cssGlobalsToDefine,
"urlPathname": "/",
});
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({ cssGlobalsToDefine, "urlPathname": "/" });
console.log({ cssCodeToPrependInHead });
console.log({ cssCodeToPrependInHead });

View File

@ -1,14 +1,15 @@
import { getProjectRoot } from "../../bin/tools/getProjectRoot";
import { join as pathJoin } from "path";
import { downloadAndUnzip } from "../../bin/tools/downloadAndUnzip";
export const sampleReactProjectDirPath = pathJoin(getProjectRoot(), "sample_react_project");
export const sampleReactProjectDirPath = pathJoin(
getProjectRoot(),
"sample_react_project",
);
export function setupSampleReactProject() {
downloadAndUnzip({
"url": "https://github.com/garronej/keycloakify/releases/download/v0.0.1/sample_build_dir_and_package_json.zip",
"destDirPath": sampleReactProjectDirPath
"destDirPath": sampleReactProjectDirPath,
});
}

View File

@ -1,249 +1,279 @@
import { getKcContext } from "../../lib/getKcContext";
import type { KcContextBase } from "../../lib/getKcContext";
import type { ExtendsKcContextBase } from "../../lib/getKcContext/getKcContext";
import { same } from "evt/tools/inDepth";
import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
import { kcContextMocks, kcContextCommonMock } from "../../lib/getKcContext/kcContextMocks";
import type { Equals } from "tsafe";
import {
kcContextMocks,
kcContextCommonMock,
} from "../../lib/getKcContext/kcContextMocks";
import { deepClone } from "../../lib/tools/deepClone";
{
const authorizedMailDomains = [
"example.com",
"another-example.com",
"*.yet-another-example.com",
"*.example.com",
"hello-world.com",
];
const displayName = "this is an overwritten common value";
const aNonStandardValue1 = "a non standard value 1";
const aNonStandardValue2 = "a non standard value 2";
type KcContextExtended =
| {
pageId: "register.ftl";
authorizedMailDomains: string[];
}
| {
pageId: "info.ftl";
aNonStandardValue1: string;
}
| {
pageId: "my-extra-page-1.ftl";
}
| {
pageId: "my-extra-page-2.ftl";
aNonStandardValue2: string;
};
const getKcContextProxy = (params: {
mockPageId: ExtendsKcContextBase<KcContextExtended>["pageId"];
}) => {
const { mockPageId } = params;
const { kcContext } = getKcContext<KcContextExtended>({
mockPageId,
"mockData": [
{
"pageId": "login.ftl",
"realm": { displayName },
},
{
"pageId": "info.ftl",
aNonStandardValue1,
},
{
"pageId": "register.ftl",
authorizedMailDomains,
},
{
"pageId": "my-extra-page-2.ftl",
aNonStandardValue2,
},
],
});
return { kcContext };
};
{
const pageId = "login.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
assert<Equals<typeof kcContext, KcContextBase.Login>>();
assert(
same(
//NOTE: deepClone for printIfExists or other functions...
deepClone(kcContext),
(() => {
const mock = deepClone(
kcContextMocks.find(
({ pageId: pageId_i }) => pageId_i === pageId,
)!,
);
mock.realm.displayName = displayName;
return mock;
})(),
),
);
console.log(`PASS ${pageId}`);
}
{
const pageId = "info.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
assert<
Equals<
typeof kcContext,
KcContextBase.Info & {
pageId: typeof pageId;
aNonStandardValue1: string;
}
>
>();
assert(
same(
deepClone(kcContext),
(() => {
const mock = deepClone(
kcContextMocks.find(
({ pageId: pageId_i }) => pageId_i === pageId,
)!,
);
Object.assign(mock, { aNonStandardValue1 });
return mock;
})(),
),
);
console.log(`PASS ${pageId}`);
}
{
const pageId = "register.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
assert<
Equals<
typeof kcContext,
KcContextBase.Register & {
pageId: typeof pageId;
authorizedMailDomains: string[];
}
>
>();
assert(
same(
deepClone(kcContext),
(() => {
const mock = deepClone(
kcContextMocks.find(
({ pageId: pageId_i }) => pageId_i === pageId,
)!,
);
Object.assign(mock, { authorizedMailDomains });
return mock;
})(),
),
);
console.log(`PASS ${pageId}`);
}
{
const pageId = "my-extra-page-2.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
assert<
Equals<
typeof kcContext,
KcContextBase.Common & {
pageId: typeof pageId;
aNonStandardValue2: string;
}
>
>();
kcContext.aNonStandardValue2;
assert(
same(
deepClone(kcContext),
(() => {
const mock = deepClone(kcContextCommonMock);
Object.assign(mock, { pageId, aNonStandardValue2 });
return mock;
})(),
),
);
console.log(`PASS ${pageId}`);
}
{
const pageId = "my-extra-page-1.ftl";
console.log("We expect a warning here =>");
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
assert<
Equals<
typeof kcContext,
KcContextBase.Common & { pageId: typeof pageId }
>
>();
const authorizedMailDomains = [
"example.com",
"another-example.com",
"*.yet-another-example.com",
"*.example.com",
"hello-world.com"
];
assert(
same(
deepClone(kcContext),
(() => {
const mock = deepClone(kcContextCommonMock);
const displayName = "this is an overwritten common value";
Object.assign(mock, { pageId });
const aNonStandardValue1 = "a non standard value 1";
const aNonStandardValue2 = "a non standard value 2";
type KcContextExtended = {
pageId: "register.ftl";
authorizedMailDomains: string[];
} | {
pageId: "info.ftl";
aNonStandardValue1: string;
} | {
pageId: "my-extra-page-1.ftl";
} | {
pageId: "my-extra-page-2.ftl";
aNonStandardValue2: string;
};
const getKcContextProxy = (
params: {
mockPageId: ExtendsKcContextBase<KcContextExtended>["pageId"];
}
) => {
const { mockPageId } = params;
const { kcContext } = getKcContext<KcContextExtended>({
mockPageId,
"mockData": [
{
"pageId": "login.ftl",
"realm": { displayName }
},
{
"pageId": "info.ftl",
aNonStandardValue1
},
{
"pageId": "register.ftl",
authorizedMailDomains
},
{
"pageId": "my-extra-page-2.ftl",
aNonStandardValue2
}
]
});
return { kcContext };
};
{
const pageId = "login.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
assert<Equals<typeof kcContext, KcContextBase.Login>>();
assert(same(
//NOTE: deepClone for printIfExists or other functions...
deepClone(kcContext),
(() => {
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
mock.realm.displayName = displayName;
return mock;
})()
));
console.log(`PASS ${pageId}`);
}
{
const pageId = "info.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
assert<Equals<typeof kcContext, KcContextBase.Info & { pageId: typeof pageId; aNonStandardValue1: string; }>>();
assert(same(
deepClone(kcContext),
(() => {
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
Object.assign(mock, { aNonStandardValue1 });
return mock;
})()
));
console.log(`PASS ${pageId}`);
}
{
const pageId = "register.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
//NOTE: I don't understand the need to add: pageId: typeof pageId; ...
assert<Equals<typeof kcContext, KcContextBase.Register & { pageId: typeof pageId; authorizedMailDomains: string[]; }>>();
assert(same(
deepClone(kcContext),
(() => {
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
Object.assign(mock, { authorizedMailDomains });
return mock;
})()
));
console.log(`PASS ${pageId}`);
}
{
const pageId = "my-extra-page-2.ftl";
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
assert<Equals<typeof kcContext, KcContextBase.Common & { pageId: typeof pageId; aNonStandardValue2: string; }>>();
kcContext.aNonStandardValue2;
assert(same(
deepClone(kcContext),
(() => {
const mock = deepClone(kcContextCommonMock);
Object.assign(mock, { pageId, aNonStandardValue2 });
return mock;
})()
));
console.log(`PASS ${pageId}`);
}
{
const pageId = "my-extra-page-1.ftl";
console.log("We expect a warning here =>");
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
assert(kcContext?.pageId === pageId);
assert<Equals<typeof kcContext, KcContextBase.Common & { pageId: typeof pageId; }>>();
assert(same(
deepClone(kcContext),
(() => {
const mock = deepClone(kcContextCommonMock);
Object.assign(mock, { pageId });
return mock;
})()
));
console.log(`PASS ${pageId}`);
}
return mock;
})(),
),
);
console.log(`PASS ${pageId}`);
}
}
{
const pageId = "login.ftl";
const pageId = "login.ftl";
const { kcContext } = getKcContext({
"mockPageId": pageId,
});
const { kcContext } = getKcContext({
"mockPageId": pageId
});
assert<Equals<typeof kcContext, KcContextBase | undefined>>();
assert<Equals<typeof kcContext, KcContextBase | undefined>>();
assert(same(
deepClone(kcContext),
deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!)
));
console.log("PASS no extension");
assert(
same(
deepClone(kcContext),
deepClone(
kcContextMocks.find(
({ pageId: pageId_i }) => pageId_i === pageId,
)!,
),
),
);
console.log("PASS no extension");
}
{
const { kcContext } = getKcContext();
const { kcContext } = getKcContext();
assert<Equals<typeof kcContext, KcContextBase | undefined>>();
assert<Equals<typeof kcContext, KcContextBase | undefined>>();
assert(kcContext === undefined);
console.log("PASS no extension, no mock");
assert(kcContext === undefined);
console.log("PASS no extension, no mock");
}

View File

@ -1,2 +1 @@
import "./getKcContext";
import "./getKcContext";

View File

@ -1,91 +1,79 @@
import { AndByDiscriminatingKey } from "../../../lib/tools/AndByDiscriminatingKey";
import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
type Base =
{ pageId: "a"; onlyA: string; } |
{ pageId: "b"; onlyB: string; } |
{ pageId: "only base"; onlyBase: string; };
| { pageId: "a"; onlyA: string }
| { pageId: "b"; onlyB: string }
| { pageId: "only base"; onlyBase: string };
type Extension =
{ pageId: "a"; onlyExtA: string; } |
{ pageId: "b"; onlyExtB: string; } |
{ pageId: "only ext"; onlyExt: string; };
| { pageId: "a"; onlyExtA: string }
| { pageId: "b"; onlyExtB: string }
| { pageId: "only ext"; onlyExt: string };
type Got = AndByDiscriminatingKey<"pageId", Extension, Base>;
type Expected =
{ pageId: "a"; onlyA: string; onlyExtA: string; } |
{ pageId: "b"; onlyB: string; onlyExtB: string; } |
{ pageId: "only base"; onlyBase: string; } |
{ pageId: "only ext"; onlyExt: string; };
| { pageId: "a"; onlyA: string; onlyExtA: string }
| { pageId: "b"; onlyB: string; onlyExtB: string }
| { pageId: "only base"; onlyBase: string }
| { pageId: "only ext"; onlyExt: string };
assert<Equals<Got, Expected>>();
const x: Got = null as any;
if (x.pageId === "a") {
x.onlyA;
x.onlyExtA;
x.onlyA;
x.onlyExtA;
//@ts-expect-error
x.onlyB;
//@ts-expect-error
x.onlyB;
//@ts-expect-error
x.onlyBase;
//@ts-expect-error
x.onlyExt;
//@ts-expect-error
x.onlyBase;
//@ts-expect-error
x.onlyExt;
}
if (x.pageId === "b") {
x.onlyB;
x.onlyExtB;
x.onlyB;
x.onlyExtB;
//@ts-expect-error
x.onlyA;
//@ts-expect-error
x.onlyA;
//@ts-expect-error
x.onlyBase;
//@ts-expect-error
x.onlyExt;
//@ts-expect-error
x.onlyBase;
//@ts-expect-error
x.onlyExt;
}
if (x.pageId === "only base") {
x.onlyBase;
x.onlyBase;
//@ts-expect-error
x.onlyA;
//@ts-expect-error
x.onlyA;
//@ts-expect-error
x.onlyB;
//@ts-expect-error
x.onlyExt;
//@ts-expect-error
x.onlyB;
//@ts-expect-error
x.onlyExt;
}
if (x.pageId === "only ext") {
x.onlyExt;
x.onlyExt;
//@ts-expect-error
x.onlyA;
//@ts-expect-error
x.onlyB;
//@ts-expect-error
x.onlyA;
//@ts-expect-error
x.onlyB;
//@ts-expect-error
x.onlyBase;
//@ts-expect-error
x.onlyBase;
}