Reneame the 'eject-file' command to 'own'
This commit is contained in:
parent
eddfb8e634
commit
4403f00274
@ -1,68 +0,0 @@
|
||||
import type { BuildContext } from "./shared/buildContext";
|
||||
import { getUiModuleFileSourceCodeReadyToBeCopied } from "./postinstall/getUiModuleFileSourceCodeReadyToBeCopied";
|
||||
import { getAbsoluteAndInOsFormatPath } from "./tools/getAbsoluteAndInOsFormatPath";
|
||||
import { relative as pathRelative, dirname as pathDirname, join as pathJoin } from "path";
|
||||
import { getUiModuleMetas } from "./postinstall/uiModuleMeta";
|
||||
import { getInstalledModuleDirPath } from "./tools/getInstalledModuleDirPath";
|
||||
import * as fsPr from "fs/promises";
|
||||
import {
|
||||
readManagedGitignoreFile,
|
||||
writeManagedGitignoreFile
|
||||
} from "./postinstall/managedGitignoreFile";
|
||||
|
||||
export async function command(params: {
|
||||
buildContext: BuildContext;
|
||||
cliCommandOptions: {
|
||||
file: string;
|
||||
};
|
||||
}) {
|
||||
const { buildContext, cliCommandOptions } = params;
|
||||
|
||||
const fileRelativePath = pathRelative(
|
||||
buildContext.themeSrcDirPath,
|
||||
getAbsoluteAndInOsFormatPath({
|
||||
cwd: buildContext.themeSrcDirPath,
|
||||
pathIsh: cliCommandOptions.file
|
||||
})
|
||||
);
|
||||
|
||||
const uiModuleMetas = await getUiModuleMetas({ buildContext });
|
||||
|
||||
const uiModuleMeta = uiModuleMetas.find(({ files }) =>
|
||||
files.map(({ fileRelativePath }) => fileRelativePath).includes(fileRelativePath)
|
||||
);
|
||||
|
||||
if (!uiModuleMeta) {
|
||||
throw new Error(`No UI module found for the file ${fileRelativePath}`);
|
||||
}
|
||||
|
||||
const uiModuleDirPath = await getInstalledModuleDirPath({
|
||||
moduleName: uiModuleMeta.moduleName,
|
||||
packageJsonDirPath: pathDirname(buildContext.packageJsonFilePath),
|
||||
projectDirPath: buildContext.projectDirPath
|
||||
});
|
||||
|
||||
const sourceCode = await getUiModuleFileSourceCodeReadyToBeCopied({
|
||||
buildContext,
|
||||
fileRelativePath,
|
||||
isForEjection: true,
|
||||
uiModuleName: uiModuleMeta.moduleName,
|
||||
uiModuleDirPath,
|
||||
uiModuleVersion: uiModuleMeta.version
|
||||
});
|
||||
|
||||
await fsPr.writeFile(
|
||||
pathJoin(buildContext.themeSrcDirPath, fileRelativePath),
|
||||
sourceCode
|
||||
);
|
||||
|
||||
const { ejectedFilesRelativePaths } = await readManagedGitignoreFile({
|
||||
buildContext
|
||||
});
|
||||
|
||||
await writeManagedGitignoreFile({
|
||||
buildContext,
|
||||
uiModuleMetas,
|
||||
ejectedFilesRelativePaths: [...ejectedFilesRelativePaths, fileRelativePath]
|
||||
});
|
||||
}
|
@ -67,9 +67,7 @@ export async function command(params: { buildContext: BuildContext }) {
|
||||
})();
|
||||
|
||||
if (themeType === "admin") {
|
||||
console.log(
|
||||
"Use `npx keycloakify eject-file` command instead, see documentation"
|
||||
);
|
||||
console.log("Use `npx keycloakify own` command instead, see documentation");
|
||||
|
||||
process.exit(-1);
|
||||
}
|
||||
|
@ -262,37 +262,38 @@ program
|
||||
|
||||
program
|
||||
.command<{
|
||||
file: string;
|
||||
path: string;
|
||||
}>({
|
||||
name: "eject-file",
|
||||
name: "own",
|
||||
description: [
|
||||
"WARNING: Not usable yet, will be used for future features",
|
||||
"Take ownership over a given file"
|
||||
].join(" ")
|
||||
})
|
||||
.option({
|
||||
key: "file",
|
||||
key: "path",
|
||||
name: (() => {
|
||||
const long = "file";
|
||||
const short = "f";
|
||||
const long = "path";
|
||||
const short = "p";
|
||||
|
||||
optionsKeys.push(long, short);
|
||||
|
||||
return { long, short };
|
||||
})(),
|
||||
description: [
|
||||
"Relative path of the file relative to the directory of your keycloak theme source",
|
||||
"Example `--file src/login/page/Login.tsx`"
|
||||
"Relative path of the file or the directory that you want to take ownership over.",
|
||||
"The path is relative to your theme directory.",
|
||||
"Example `--path admin/page/Login.tsx`"
|
||||
].join(" ")
|
||||
})
|
||||
.task({
|
||||
skip,
|
||||
handler: async ({ projectDirPath, file }) => {
|
||||
const { command } = await import("./eject-file");
|
||||
handler: async ({ projectDirPath, path }) => {
|
||||
const { command } = await import("./own");
|
||||
|
||||
await command({
|
||||
buildContext: getBuildContext({ projectDirPath }),
|
||||
cliCommandOptions: { file }
|
||||
cliCommandOptions: { path }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
96
src/bin/own.ts
Normal file
96
src/bin/own.ts
Normal file
@ -0,0 +1,96 @@
|
||||
import type { BuildContext } from "./shared/buildContext";
|
||||
import { getUiModuleFileSourceCodeReadyToBeCopied } from "./postinstall/getUiModuleFileSourceCodeReadyToBeCopied";
|
||||
import { getAbsoluteAndInOsFormatPath } from "./tools/getAbsoluteAndInOsFormatPath";
|
||||
import { relative as pathRelative, dirname as pathDirname, join as pathJoin } from "path";
|
||||
import { getUiModuleMetas } from "./postinstall/uiModuleMeta";
|
||||
import { getInstalledModuleDirPath } from "./tools/getInstalledModuleDirPath";
|
||||
import * as fsPr from "fs/promises";
|
||||
import {
|
||||
readManagedGitignoreFile,
|
||||
writeManagedGitignoreFile
|
||||
} from "./postinstall/managedGitignoreFile";
|
||||
import { isInside } from "./tools/isInside";
|
||||
import chalk from "chalk";
|
||||
|
||||
export async function command(params: {
|
||||
buildContext: BuildContext;
|
||||
cliCommandOptions: {
|
||||
path: string;
|
||||
};
|
||||
}) {
|
||||
const { buildContext, cliCommandOptions } = params;
|
||||
|
||||
const fileOrDirectoryRelativePath = pathRelative(
|
||||
buildContext.themeSrcDirPath,
|
||||
getAbsoluteAndInOsFormatPath({
|
||||
cwd: buildContext.themeSrcDirPath,
|
||||
pathIsh: cliCommandOptions.path
|
||||
})
|
||||
);
|
||||
|
||||
const uiModuleMetas = await getUiModuleMetas({ buildContext });
|
||||
|
||||
const fileRelativePaths = uiModuleMetas
|
||||
.map(({ files }) =>
|
||||
files
|
||||
.map(({ fileRelativePath }) => fileRelativePath)
|
||||
.filter(
|
||||
fileRelativePath =>
|
||||
fileRelativePath === fileOrDirectoryRelativePath ||
|
||||
isInside({
|
||||
dirPath: fileOrDirectoryRelativePath,
|
||||
filePath: fileRelativePath
|
||||
})
|
||||
)
|
||||
)
|
||||
.flat();
|
||||
|
||||
if (fileRelativePaths.length === 0) {
|
||||
console.log(
|
||||
chalk.yellow("There is no UI module files matching the provided path.")
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
for (const fileRelativePath of fileRelativePaths) {
|
||||
const uiModuleMeta = uiModuleMetas.find(({ files }) =>
|
||||
files
|
||||
.map(({ fileRelativePath }) => fileRelativePath)
|
||||
.includes(fileRelativePath)
|
||||
);
|
||||
|
||||
if (!uiModuleMeta) {
|
||||
throw new Error(`No UI module found for the file ${fileRelativePath}`);
|
||||
}
|
||||
|
||||
const uiModuleDirPath = await getInstalledModuleDirPath({
|
||||
moduleName: uiModuleMeta.moduleName,
|
||||
packageJsonDirPath: pathDirname(buildContext.packageJsonFilePath),
|
||||
projectDirPath: buildContext.projectDirPath
|
||||
});
|
||||
|
||||
const sourceCode = await getUiModuleFileSourceCodeReadyToBeCopied({
|
||||
buildContext,
|
||||
fileRelativePath,
|
||||
isForEjection: true,
|
||||
uiModuleName: uiModuleMeta.moduleName,
|
||||
uiModuleDirPath,
|
||||
uiModuleVersion: uiModuleMeta.version
|
||||
});
|
||||
|
||||
await fsPr.writeFile(
|
||||
pathJoin(buildContext.themeSrcDirPath, fileRelativePath),
|
||||
sourceCode
|
||||
);
|
||||
|
||||
const { ejectedFilesRelativePaths } = await readManagedGitignoreFile({
|
||||
buildContext
|
||||
});
|
||||
|
||||
await writeManagedGitignoreFile({
|
||||
buildContext,
|
||||
uiModuleMetas,
|
||||
ejectedFilesRelativePaths: [...ejectedFilesRelativePaths, fileRelativePath]
|
||||
});
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ export async function getUiModuleFileSourceCodeReadyToBeCopied(params: {
|
||||
: [
|
||||
`WARNING: Before modifying this file run the following command:`,
|
||||
``,
|
||||
`$ npx keycloakify eject-file --file '${fileRelativePath.split(pathSep).join("/")}'`,
|
||||
`$ npx keycloakify own --path '${fileRelativePath.split(pathSep).join("/")}'`,
|
||||
``,
|
||||
`This file comes from ${uiModuleName} version ${uiModuleVersion}.`,
|
||||
`This file has been copied over to your repo by your postinstall script: \`npx keycloakify postinstall\``
|
||||
@ -93,7 +93,7 @@ function addCommentToSourceCode(params: {
|
||||
`<!--`,
|
||||
...commentLines.map(
|
||||
line =>
|
||||
` ${line.replace("--file", "-f").replace("Before modifying", "Before modifying or replacing")}`
|
||||
` ${line.replace("--path", "-p").replace("Before modifying", "Before modifying or replacing")}`
|
||||
),
|
||||
`-->`
|
||||
].join("\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user