2024-11-09 14:02:19 +01:00
|
|
|
import type { BuildContext } from "../shared/buildContext";
|
|
|
|
import { getUiModuleMetas, computeHash } from "./uiModuleMeta";
|
|
|
|
import { installUiModulesPeerDependencies } from "./installUiModulesPeerDependencies";
|
|
|
|
import {
|
|
|
|
readManagedGitignoreFile,
|
|
|
|
writeManagedGitignoreFile
|
|
|
|
} from "./managedGitignoreFile";
|
|
|
|
import { dirname as pathDirname } from "path";
|
|
|
|
import { join as pathJoin } from "path";
|
|
|
|
import { existsAsync } from "../tools/fs.existsAsync";
|
|
|
|
import * as fsPr from "fs/promises";
|
2024-11-18 03:42:22 +01:00
|
|
|
import { getIsTrackedByGit } from "../tools/isTrackedByGit";
|
|
|
|
import { untrackFromGit } from "../tools/untrackFromGit";
|
2024-11-09 14:02:19 +01:00
|
|
|
|
|
|
|
export async function command(params: { buildContext: BuildContext }) {
|
|
|
|
const { buildContext } = params;
|
|
|
|
|
|
|
|
const uiModuleMetas = await getUiModuleMetas({ buildContext });
|
|
|
|
|
|
|
|
await installUiModulesPeerDependencies({
|
|
|
|
buildContext,
|
|
|
|
uiModuleMetas
|
|
|
|
});
|
|
|
|
|
|
|
|
const { ejectedFilesRelativePaths } = await readManagedGitignoreFile({
|
|
|
|
buildContext
|
|
|
|
});
|
|
|
|
|
|
|
|
await writeManagedGitignoreFile({
|
|
|
|
buildContext,
|
|
|
|
ejectedFilesRelativePaths,
|
|
|
|
uiModuleMetas
|
|
|
|
});
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
uiModuleMetas
|
|
|
|
.map(uiModuleMeta =>
|
|
|
|
Promise.all(
|
|
|
|
uiModuleMeta.files.map(
|
|
|
|
async ({ fileRelativePath, copyableFilePath, hash }) => {
|
|
|
|
if (ejectedFilesRelativePaths.includes(fileRelativePath)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const destFilePath = pathJoin(
|
|
|
|
buildContext.themeSrcDirPath,
|
|
|
|
fileRelativePath
|
|
|
|
);
|
|
|
|
|
2024-11-18 03:42:22 +01:00
|
|
|
const doesFileExist = await existsAsync(destFilePath);
|
|
|
|
|
2024-11-09 14:02:19 +01:00
|
|
|
skip_condition: {
|
2024-11-18 03:42:22 +01:00
|
|
|
if (!doesFileExist) {
|
2024-11-09 14:02:19 +01:00
|
|
|
break skip_condition;
|
|
|
|
}
|
|
|
|
|
|
|
|
const destFileHash = computeHash(
|
|
|
|
await fsPr.readFile(destFilePath)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (destFileHash !== hash) {
|
|
|
|
break skip_condition;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-18 03:42:22 +01:00
|
|
|
git_untrack: {
|
|
|
|
if (!destFilePath) {
|
|
|
|
break git_untrack;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isTracked = await getIsTrackedByGit({
|
|
|
|
filePath: destFilePath
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!isTracked) {
|
|
|
|
break git_untrack;
|
|
|
|
}
|
|
|
|
|
|
|
|
await untrackFromGit({
|
|
|
|
filePath: destFilePath
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-09 14:02:19 +01:00
|
|
|
{
|
2024-11-18 00:26:48 +01:00
|
|
|
const dirName = pathDirname(destFilePath);
|
2024-11-09 14:02:19 +01:00
|
|
|
|
|
|
|
if (!(await existsAsync(dirName))) {
|
|
|
|
await fsPr.mkdir(dirName, { recursive: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await fsPr.copyFile(copyableFilePath, destFilePath);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.flat()
|
|
|
|
);
|
|
|
|
}
|