Make Vite run copy-keaycloak-resources-to-public
This commit is contained in:
parent
6d4a948dd8
commit
ad70a4cffd
@ -1,17 +1,43 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { downloadKeycloakStaticResources } from "./keycloakify/generateTheme/downloadKeycloakStaticResources";
|
import { downloadKeycloakStaticResources, type BuildOptionsLike } from "./keycloakify/generateTheme/downloadKeycloakStaticResources";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { readBuildOptions } from "./keycloakify/buildOptions";
|
import { readBuildOptions } from "./keycloakify/buildOptions";
|
||||||
import { themeTypes, keycloak_resources, lastKeycloakVersionWithAccountV1 } from "./constants";
|
import { themeTypes, keycloak_resources, lastKeycloakVersionWithAccountV1 } from "./constants";
|
||||||
|
import { readThisNpmProjectVersion } from "./tools/readThisNpmProjectVersion";
|
||||||
|
import { assert, type Equals } from "tsafe/assert";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
import { rmSync } from "./tools/fs.rmSync";
|
||||||
|
|
||||||
(async () => {
|
export async function copyKeycloakResourcesToPublic(params: { processArgv: string[] }) {
|
||||||
const buildOptions = readBuildOptions({
|
const { processArgv } = params;
|
||||||
"processArgv": process.argv.slice(2)
|
|
||||||
|
const buildOptions = readBuildOptions({ processArgv });
|
||||||
|
|
||||||
|
const destDirPath = pathJoin(buildOptions.publicDirPath, keycloak_resources);
|
||||||
|
|
||||||
|
const keycloakifyBuildinfoFilePath = pathJoin(destDirPath, "keycloakify.buildinfo");
|
||||||
|
|
||||||
|
const { keycloakifyBuildinfoRaw } = generateKeycloakifyBuildinfoRaw({
|
||||||
|
"keycloakifyVersion": readThisNpmProjectVersion(),
|
||||||
|
buildOptions
|
||||||
});
|
});
|
||||||
|
|
||||||
const reservedDirPath = pathJoin(buildOptions.publicDirPath, keycloak_resources);
|
skip_if_already_done: {
|
||||||
|
if (!fs.existsSync(keycloakifyBuildinfoFilePath)) {
|
||||||
|
break skip_if_already_done;
|
||||||
|
}
|
||||||
|
|
||||||
|
const keycloakifyBuildinfoRaw_previousRun = fs.readFileSync(keycloakifyBuildinfoFilePath).toString("utf8");
|
||||||
|
|
||||||
|
if (keycloakifyBuildinfoRaw_previousRun !== keycloakifyBuildinfoRaw) {
|
||||||
|
break skip_if_already_done;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rmSync(destDirPath, { "force": true, "recursive": true });
|
||||||
|
|
||||||
for (const themeType of themeTypes) {
|
for (const themeType of themeTypes) {
|
||||||
await downloadKeycloakStaticResources({
|
await downloadKeycloakStaticResources({
|
||||||
@ -24,13 +50,13 @@ import * as fs from "fs";
|
|||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
themeType,
|
themeType,
|
||||||
"themeDirPath": reservedDirPath,
|
"themeDirPath": destDirPath,
|
||||||
buildOptions
|
buildOptions
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
pathJoin(reservedDirPath, "README.txt"),
|
pathJoin(destDirPath, "README.txt"),
|
||||||
Buffer.from(
|
Buffer.from(
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
[
|
[
|
||||||
@ -41,4 +67,44 @@ import * as fs from "fs";
|
|||||||
);
|
);
|
||||||
|
|
||||||
fs.writeFileSync(pathJoin(buildOptions.publicDirPath, keycloak_resources, ".gitignore"), Buffer.from("*", "utf8"));
|
fs.writeFileSync(pathJoin(buildOptions.publicDirPath, keycloak_resources, ".gitignore"), Buffer.from("*", "utf8"));
|
||||||
})();
|
|
||||||
|
fs.writeFileSync(keycloakifyBuildinfoFilePath, Buffer.from(keycloakifyBuildinfoRaw, "utf8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function generateKeycloakifyBuildinfoRaw(params: {
|
||||||
|
keycloakifyVersion: string;
|
||||||
|
buildOptions: BuildOptionsLike & {
|
||||||
|
loginThemeResourcesFromKeycloakVersion: string;
|
||||||
|
};
|
||||||
|
}) {
|
||||||
|
const { keycloakifyVersion, buildOptions } = params;
|
||||||
|
|
||||||
|
const { cacheDirPath, npmWorkspaceRootDirPath, loginThemeResourcesFromKeycloakVersion, ...rest } = buildOptions;
|
||||||
|
|
||||||
|
assert<Equals<typeof rest, {}>>(true);
|
||||||
|
|
||||||
|
const keycloakifyBuildinfoRaw = JSON.stringify(
|
||||||
|
{
|
||||||
|
keycloakifyVersion,
|
||||||
|
"buildOptions": {
|
||||||
|
loginThemeResourcesFromKeycloakVersion,
|
||||||
|
cacheDirPath,
|
||||||
|
npmWorkspaceRootDirPath
|
||||||
|
}
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
return { keycloakifyBuildinfoRaw };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
await copyKeycloakResourcesToPublic({
|
||||||
|
"processArgv": process.argv.slice(2)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
main();
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { getProjectRoot } from "./tools/getProjectRoot";
|
import { getThisCodebaseRootDirPath } from "./tools/getThisCodebaseRootDirPath";
|
||||||
import cliSelect from "cli-select";
|
import cliSelect from "cli-select";
|
||||||
import { loginThemePageIds, accountThemePageIds, type LoginThemePageId, type AccountThemePageId } from "./keycloakify/generateFtl";
|
import { loginThemePageIds, accountThemePageIds, type LoginThemePageId, type AccountThemePageId } from "./keycloakify/generateFtl";
|
||||||
import { capitalize } from "tsafe/capitalize";
|
import { capitalize } from "tsafe/capitalize";
|
||||||
@ -58,7 +58,7 @@ import { getReactAppRootDirPath } from "./keycloakify/buildOptions/getReactAppRo
|
|||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await writeFile(targetFilePath, await readFile(pathJoin(getProjectRoot(), "src", themeType, "pages", pageBasename)));
|
await writeFile(targetFilePath, await readFile(pathJoin(getThisCodebaseRootDirPath(), "src", themeType, "pages", pageBasename)));
|
||||||
|
|
||||||
console.log(`${pathRelative(process.cwd(), targetFilePath)} created`);
|
console.log(`${pathRelative(process.cwd(), targetFilePath)} created`);
|
||||||
})();
|
})();
|
||||||
|
@ -6,9 +6,9 @@ import { generateStartKeycloakTestingContainer } from "./generateStartKeycloakTe
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { readBuildOptions } from "./buildOptions";
|
import { readBuildOptions } from "./buildOptions";
|
||||||
import { getLogger } from "../tools/logger";
|
import { getLogger } from "../tools/logger";
|
||||||
import { assert } from "tsafe/assert";
|
|
||||||
import { getThemeSrcDirPath } from "../getThemeSrcDirPath";
|
import { getThemeSrcDirPath } from "../getThemeSrcDirPath";
|
||||||
import { getProjectRoot } from "../tools/getProjectRoot";
|
import { getThisCodebaseRootDirPath } from "../tools/getThisCodebaseRootDirPath";
|
||||||
|
import { readThisNpmProjectVersion } from "../tools/readThisNpmProjectVersion";
|
||||||
|
|
||||||
export async function main() {
|
export async function main() {
|
||||||
const buildOptions = readBuildOptions({
|
const buildOptions = readBuildOptions({
|
||||||
@ -18,23 +18,15 @@ export async function main() {
|
|||||||
const logger = getLogger({ "isSilent": buildOptions.isSilent });
|
const logger = getLogger({ "isSilent": buildOptions.isSilent });
|
||||||
logger.log("🔏 Building the keycloak theme...⌚");
|
logger.log("🔏 Building the keycloak theme...⌚");
|
||||||
|
|
||||||
const keycloakifyDirPath = getProjectRoot();
|
|
||||||
|
|
||||||
const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath });
|
const { themeSrcDirPath } = getThemeSrcDirPath({ "reactAppRootDirPath": buildOptions.reactAppRootDirPath });
|
||||||
|
|
||||||
for (const themeName of buildOptions.themeNames) {
|
for (const themeName of buildOptions.themeNames) {
|
||||||
await generateTheme({
|
await generateTheme({
|
||||||
themeName,
|
themeName,
|
||||||
themeSrcDirPath,
|
themeSrcDirPath,
|
||||||
"keycloakifySrcDirPath": pathJoin(keycloakifyDirPath, "src"),
|
"keycloakifySrcDirPath": pathJoin(getThisCodebaseRootDirPath(), "src"),
|
||||||
buildOptions,
|
"keycloakifyVersion": readThisNpmProjectVersion(),
|
||||||
"keycloakifyVersion": (() => {
|
buildOptions
|
||||||
const version = JSON.parse(fs.readFileSync(pathJoin(keycloakifyDirPath, "package.json")).toString("utf8"))["version"];
|
|
||||||
|
|
||||||
assert(typeof version === "string");
|
|
||||||
|
|
||||||
return version;
|
|
||||||
})()
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
function getProjectRootRec(dirPath: string): string {
|
function getThisCodebaseRootDirPath_rec(dirPath: string): string {
|
||||||
if (fs.existsSync(path.join(dirPath, "package.json"))) {
|
if (fs.existsSync(path.join(dirPath, "package.json"))) {
|
||||||
return dirPath;
|
return dirPath;
|
||||||
}
|
}
|
||||||
return getProjectRootRec(path.join(dirPath, ".."));
|
return getThisCodebaseRootDirPath_rec(path.join(dirPath, ".."));
|
||||||
}
|
}
|
||||||
|
|
||||||
let result: string | undefined = undefined;
|
let result: string | undefined = undefined;
|
||||||
|
|
||||||
export function getProjectRoot(): string {
|
export function getThisCodebaseRootDirPath(): string {
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (result = getProjectRootRec(__dirname));
|
return (result = getThisCodebaseRootDirPath_rec(__dirname));
|
||||||
}
|
}
|
@ -1,13 +1,15 @@
|
|||||||
import { getProjectRoot } from "./getProjectRoot";
|
import { getThisCodebaseRootDirPath } from "./getThisCodebaseRootDirPath";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { constants } from "fs";
|
import { constants } from "fs";
|
||||||
import { chmod, stat } from "fs/promises";
|
import { chmod, stat } from "fs/promises";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const { bin } = await import(pathJoin(getProjectRoot(), "package.json"));
|
const thisCodebaseRootDirPath = getThisCodebaseRootDirPath();
|
||||||
|
|
||||||
|
const { bin } = await import(pathJoin(thisCodebaseRootDirPath, "package.json"));
|
||||||
|
|
||||||
const promises = Object.values<string>(bin).map(async scriptPath => {
|
const promises = Object.values<string>(bin).map(async scriptPath => {
|
||||||
const fullPath = pathJoin(getProjectRoot(), scriptPath);
|
const fullPath = pathJoin(thisCodebaseRootDirPath, scriptPath);
|
||||||
const oldMode = (await stat(fullPath)).mode;
|
const oldMode = (await stat(fullPath)).mode;
|
||||||
const newMode = oldMode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH;
|
const newMode = oldMode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH;
|
||||||
await chmod(fullPath, newMode);
|
await chmod(fullPath, newMode);
|
||||||
|
12
src/bin/tools/readThisNpmProjectVersion.ts
Normal file
12
src/bin/tools/readThisNpmProjectVersion.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { getThisCodebaseRootDirPath } from "./getThisCodebaseRootDirPath";
|
||||||
|
import { assert } from "tsafe/assert";
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { join as pathJoin } from "path";
|
||||||
|
|
||||||
|
export function readThisNpmProjectVersion(): string {
|
||||||
|
const version = JSON.parse(fs.readFileSync(pathJoin(getThisCodebaseRootDirPath(), "package.json")).toString("utf8"))["version"];
|
||||||
|
|
||||||
|
assert(typeof version === "string");
|
||||||
|
|
||||||
|
return version;
|
||||||
|
}
|
@ -8,6 +8,7 @@ import { getCacheDirPath } from "../bin/keycloakify/buildOptions/getCacheDirPath
|
|||||||
import { replaceAll } from "../bin/tools/String.prototype.replaceAll";
|
import { replaceAll } from "../bin/tools/String.prototype.replaceAll";
|
||||||
import { id } from "tsafe/id";
|
import { id } from "tsafe/id";
|
||||||
import { rm } from "../bin/tools/fs.rm";
|
import { rm } from "../bin/tools/fs.rm";
|
||||||
|
import { copyKeycloakResourcesToPublic } from "../bin/copy-keycloak-resources-to-public";
|
||||||
|
|
||||||
export function keycloakify(): Plugin {
|
export function keycloakify(): Plugin {
|
||||||
let reactAppRootDirPath: string | undefined = undefined;
|
let reactAppRootDirPath: string | undefined = undefined;
|
||||||
@ -17,7 +18,7 @@ export function keycloakify(): Plugin {
|
|||||||
return {
|
return {
|
||||||
"name": "keycloakify",
|
"name": "keycloakify",
|
||||||
"apply": "build",
|
"apply": "build",
|
||||||
"configResolved": resolvedConfig => {
|
"configResolved": async resolvedConfig => {
|
||||||
reactAppRootDirPath = resolvedConfig.root;
|
reactAppRootDirPath = resolvedConfig.root;
|
||||||
urlPathname = (() => {
|
urlPathname = (() => {
|
||||||
let out = resolvedConfig.env.BASE_URL;
|
let out = resolvedConfig.env.BASE_URL;
|
||||||
@ -63,6 +64,10 @@ export function keycloakify(): Plugin {
|
|||||||
"utf8"
|
"utf8"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await copyKeycloakResourcesToPublic({
|
||||||
|
"processArgv": ["--project", reactAppRootDirPath]
|
||||||
|
});
|
||||||
},
|
},
|
||||||
"transform": (code, id) => {
|
"transform": (code, id) => {
|
||||||
assert(reactAppRootDirPath !== undefined);
|
assert(reactAppRootDirPath !== undefined);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user