Consistent naming scheme 'eject' -> 'own'
This commit is contained in:
parent
4403f00274
commit
cc3d0d61dd
@ -30,9 +30,10 @@ export async function command(params: {
|
|||||||
|
|
||||||
const uiModuleMetas = await getUiModuleMetas({ buildContext });
|
const uiModuleMetas = await getUiModuleMetas({ buildContext });
|
||||||
|
|
||||||
const fileRelativePaths = uiModuleMetas
|
const arr = uiModuleMetas
|
||||||
.map(({ files }) =>
|
.map(uiModuleMeta => ({
|
||||||
files
|
uiModuleMeta,
|
||||||
|
fileRelativePaths: uiModuleMeta.files
|
||||||
.map(({ fileRelativePath }) => fileRelativePath)
|
.map(({ fileRelativePath }) => fileRelativePath)
|
||||||
.filter(
|
.filter(
|
||||||
fileRelativePath =>
|
fileRelativePath =>
|
||||||
@ -42,37 +43,42 @@ export async function command(params: {
|
|||||||
filePath: fileRelativePath
|
filePath: fileRelativePath
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
}))
|
||||||
.flat();
|
.filter(({ fileRelativePaths }) => fileRelativePaths.length !== 0);
|
||||||
|
|
||||||
if (fileRelativePaths.length === 0) {
|
if (arr.length === 0) {
|
||||||
console.log(
|
console.log(
|
||||||
chalk.yellow("There is no UI module files matching the provided path.")
|
chalk.yellow("There is no UI module files matching the provided path.")
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const fileRelativePath of fileRelativePaths) {
|
const { ownedFilesRelativePaths: ownedFilesRelativePaths_before } =
|
||||||
const uiModuleMeta = uiModuleMetas.find(({ files }) =>
|
await readManagedGitignoreFile({
|
||||||
files
|
buildContext
|
||||||
.map(({ fileRelativePath }) => fileRelativePath)
|
});
|
||||||
.includes(fileRelativePath)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!uiModuleMeta) {
|
const ownedFilesRelativePaths_toAdd: string[] = [];
|
||||||
throw new Error(`No UI module found for the file ${fileRelativePath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (const { uiModuleMeta, fileRelativePaths } of arr) {
|
||||||
const uiModuleDirPath = await getInstalledModuleDirPath({
|
const uiModuleDirPath = await getInstalledModuleDirPath({
|
||||||
moduleName: uiModuleMeta.moduleName,
|
moduleName: uiModuleMeta.moduleName,
|
||||||
packageJsonDirPath: pathDirname(buildContext.packageJsonFilePath),
|
packageJsonDirPath: pathDirname(buildContext.packageJsonFilePath),
|
||||||
projectDirPath: buildContext.projectDirPath
|
projectDirPath: buildContext.projectDirPath
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const fileRelativePath of fileRelativePaths) {
|
||||||
|
if (ownedFilesRelativePaths_before.includes(fileRelativePath)) {
|
||||||
|
console.log(
|
||||||
|
chalk.yellow(`You already have ownership over "${fileRelativePath}".`)
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const sourceCode = await getUiModuleFileSourceCodeReadyToBeCopied({
|
const sourceCode = await getUiModuleFileSourceCodeReadyToBeCopied({
|
||||||
buildContext,
|
buildContext,
|
||||||
fileRelativePath,
|
fileRelativePath,
|
||||||
isForEjection: true,
|
isOwnershipAction: true,
|
||||||
uiModuleName: uiModuleMeta.moduleName,
|
uiModuleName: uiModuleMeta.moduleName,
|
||||||
uiModuleDirPath,
|
uiModuleDirPath,
|
||||||
uiModuleVersion: uiModuleMeta.version
|
uiModuleVersion: uiModuleMeta.version
|
||||||
@ -83,14 +89,21 @@ export async function command(params: {
|
|||||||
sourceCode
|
sourceCode
|
||||||
);
|
);
|
||||||
|
|
||||||
const { ejectedFilesRelativePaths } = await readManagedGitignoreFile({
|
ownedFilesRelativePaths_toAdd.push(fileRelativePath);
|
||||||
buildContext
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (ownedFilesRelativePaths_toAdd.length === 0) {
|
||||||
|
console.log(chalk.yellow("No new file claimed."));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
await writeManagedGitignoreFile({
|
await writeManagedGitignoreFile({
|
||||||
buildContext,
|
buildContext,
|
||||||
uiModuleMetas,
|
uiModuleMetas,
|
||||||
ejectedFilesRelativePaths: [...ejectedFilesRelativePaths, fileRelativePath]
|
ownedFilesRelativePaths: [
|
||||||
|
...ownedFilesRelativePaths_before,
|
||||||
|
...ownedFilesRelativePaths_toAdd
|
||||||
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -14,7 +14,7 @@ assert<BuildContext extends BuildContextLike ? true : false>();
|
|||||||
export async function getUiModuleFileSourceCodeReadyToBeCopied(params: {
|
export async function getUiModuleFileSourceCodeReadyToBeCopied(params: {
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
fileRelativePath: string;
|
fileRelativePath: string;
|
||||||
isForEjection: boolean;
|
isOwnershipAction: boolean;
|
||||||
uiModuleDirPath: string;
|
uiModuleDirPath: string;
|
||||||
uiModuleName: string;
|
uiModuleName: string;
|
||||||
uiModuleVersion: string;
|
uiModuleVersion: string;
|
||||||
@ -23,7 +23,7 @@ export async function getUiModuleFileSourceCodeReadyToBeCopied(params: {
|
|||||||
buildContext,
|
buildContext,
|
||||||
uiModuleDirPath,
|
uiModuleDirPath,
|
||||||
fileRelativePath,
|
fileRelativePath,
|
||||||
isForEjection,
|
isOwnershipAction,
|
||||||
uiModuleName,
|
uiModuleName,
|
||||||
uiModuleVersion
|
uiModuleVersion
|
||||||
} = params;
|
} = params;
|
||||||
@ -35,8 +35,10 @@ export async function getUiModuleFileSourceCodeReadyToBeCopied(params: {
|
|||||||
sourceCode = addCommentToSourceCode({
|
sourceCode = addCommentToSourceCode({
|
||||||
sourceCode,
|
sourceCode,
|
||||||
fileRelativePath,
|
fileRelativePath,
|
||||||
commentLines: isForEjection
|
commentLines: isOwnershipAction
|
||||||
? [`This file was ejected from ${uiModuleName} version ${uiModuleVersion}.`]
|
? [
|
||||||
|
`This file was claimed for ownership from ${uiModuleName} version ${uiModuleVersion}.`
|
||||||
|
]
|
||||||
: [
|
: [
|
||||||
`WARNING: Before modifying this file run the following command:`,
|
`WARNING: Before modifying this file run the following command:`,
|
||||||
``,
|
``,
|
||||||
|
@ -17,15 +17,15 @@ export type BuildContextLike = {
|
|||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
const DELIMITER_START = `# === Ejected files start ===`;
|
const DELIMITER_START = `# === Owned files start ===`;
|
||||||
const DELIMITER_END = `# === Ejected files end =====`;
|
const DELIMITER_END = `# === Owned files end =====`;
|
||||||
|
|
||||||
export async function writeManagedGitignoreFile(params: {
|
export async function writeManagedGitignoreFile(params: {
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
uiModuleMetas: UiModuleMeta[];
|
uiModuleMetas: UiModuleMeta[];
|
||||||
ejectedFilesRelativePaths: string[];
|
ownedFilesRelativePaths: string[];
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { buildContext, uiModuleMetas, ejectedFilesRelativePaths } = params;
|
const { buildContext, uiModuleMetas, ownedFilesRelativePaths } = params;
|
||||||
|
|
||||||
if (uiModuleMetas.length === 0) {
|
if (uiModuleMetas.length === 0) {
|
||||||
return;
|
return;
|
||||||
@ -38,7 +38,7 @@ export async function writeManagedGitignoreFile(params: {
|
|||||||
`# This file is managed by Keycloakify, do not edit it manually.`,
|
`# This file is managed by Keycloakify, do not edit it manually.`,
|
||||||
``,
|
``,
|
||||||
DELIMITER_START,
|
DELIMITER_START,
|
||||||
...ejectedFilesRelativePaths
|
...ownedFilesRelativePaths
|
||||||
.map(fileRelativePath => fileRelativePath.split(pathSep).join("/"))
|
.map(fileRelativePath => fileRelativePath.split(pathSep).join("/"))
|
||||||
.map(line => `# ${line}`),
|
.map(line => `# ${line}`),
|
||||||
DELIMITER_END,
|
DELIMITER_END,
|
||||||
@ -50,7 +50,7 @@ export async function writeManagedGitignoreFile(params: {
|
|||||||
.map(({ fileRelativePath }) => fileRelativePath)
|
.map(({ fileRelativePath }) => fileRelativePath)
|
||||||
.filter(
|
.filter(
|
||||||
fileRelativePath =>
|
fileRelativePath =>
|
||||||
!ejectedFilesRelativePaths.includes(fileRelativePath)
|
!ownedFilesRelativePaths.includes(fileRelativePath)
|
||||||
)
|
)
|
||||||
.map(
|
.map(
|
||||||
fileRelativePath =>
|
fileRelativePath =>
|
||||||
@ -92,14 +92,14 @@ export async function writeManagedGitignoreFile(params: {
|
|||||||
export async function readManagedGitignoreFile(params: {
|
export async function readManagedGitignoreFile(params: {
|
||||||
buildContext: BuildContextLike;
|
buildContext: BuildContextLike;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
ejectedFilesRelativePaths: string[];
|
ownedFilesRelativePaths: string[];
|
||||||
}> {
|
}> {
|
||||||
const { buildContext } = params;
|
const { buildContext } = params;
|
||||||
|
|
||||||
const filePath = pathJoin(buildContext.themeSrcDirPath, ".gitignore");
|
const filePath = pathJoin(buildContext.themeSrcDirPath, ".gitignore");
|
||||||
|
|
||||||
if (!(await existsAsync(filePath))) {
|
if (!(await existsAsync(filePath))) {
|
||||||
return { ejectedFilesRelativePaths: [] };
|
return { ownedFilesRelativePaths: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentStr = (await fsPr.readFile(filePath)).toString("utf8");
|
const contentStr = (await fsPr.readFile(filePath)).toString("utf8");
|
||||||
@ -116,10 +116,10 @@ export async function readManagedGitignoreFile(params: {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
if (payload === undefined) {
|
if (payload === undefined) {
|
||||||
return { ejectedFilesRelativePaths: [] };
|
return { ownedFilesRelativePaths: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const ejectedFilesRelativePaths = payload
|
const ownedFilesRelativePaths = payload
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map(line => line.trim())
|
.map(line => line.trim())
|
||||||
.map(line => line.replace(/^# /, ""))
|
.map(line => line.replace(/^# /, ""))
|
||||||
@ -132,5 +132,5 @@ export async function readManagedGitignoreFile(params: {
|
|||||||
)
|
)
|
||||||
.map(filePath => pathRelative(buildContext.themeSrcDirPath, filePath));
|
.map(filePath => pathRelative(buildContext.themeSrcDirPath, filePath));
|
||||||
|
|
||||||
return { ejectedFilesRelativePaths };
|
return { ownedFilesRelativePaths };
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,13 @@ export async function command(params: { buildContext: BuildContext }) {
|
|||||||
uiModuleMetas
|
uiModuleMetas
|
||||||
});
|
});
|
||||||
|
|
||||||
const { ejectedFilesRelativePaths } = await readManagedGitignoreFile({
|
const { ownedFilesRelativePaths } = await readManagedGitignoreFile({
|
||||||
buildContext
|
buildContext
|
||||||
});
|
});
|
||||||
|
|
||||||
await writeManagedGitignoreFile({
|
await writeManagedGitignoreFile({
|
||||||
buildContext,
|
buildContext,
|
||||||
ejectedFilesRelativePaths,
|
ownedFilesRelativePaths,
|
||||||
uiModuleMetas
|
uiModuleMetas
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ export async function command(params: { buildContext: BuildContext }) {
|
|||||||
Promise.all(
|
Promise.all(
|
||||||
uiModuleMeta.files.map(
|
uiModuleMeta.files.map(
|
||||||
async ({ fileRelativePath, copyableFilePath, hash }) => {
|
async ({ fileRelativePath, copyableFilePath, hash }) => {
|
||||||
if (ejectedFilesRelativePaths.includes(fileRelativePath)) {
|
if (ownedFilesRelativePaths.includes(fileRelativePath)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ export async function getUiModuleMetas(params: {
|
|||||||
await getUiModuleFileSourceCodeReadyToBeCopied({
|
await getUiModuleFileSourceCodeReadyToBeCopied({
|
||||||
buildContext,
|
buildContext,
|
||||||
fileRelativePath,
|
fileRelativePath,
|
||||||
isForEjection: false,
|
isOwnershipAction: false,
|
||||||
uiModuleDirPath: dirPath,
|
uiModuleDirPath: dirPath,
|
||||||
uiModuleName: moduleName,
|
uiModuleName: moduleName,
|
||||||
uiModuleVersion: version
|
uiModuleVersion: version
|
||||||
|
Loading…
x
Reference in New Issue
Block a user