From 675a013f4f29bef08d30b8ba1ff9a3eec5036733 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:26:30 +0100 Subject: [PATCH] Copy translations.json to @mui/docs build folder --- packages/mui-docs/package.json | 2 +- scripts/copyFiles.mjs | 7 ++++--- scripts/copyFilesUtils.mjs | 12 ++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/mui-docs/package.json b/packages/mui-docs/package.json index 751b37ec439659..e51299d52ee75f 100644 --- a/packages/mui-docs/package.json +++ b/packages/mui-docs/package.json @@ -29,7 +29,7 @@ "build:node": "node ../../scripts/build.mjs node", "build:stable": "node ../../scripts/build.mjs stable", "build:types": "node ../../scripts/buildTypes.mjs", - "build:copy-files": "node ../../scripts/copyFiles.mjs", + "build:copy-files": "node ../../scripts/copyFiles.mjs ./src/translations/translations.json:./translations/translations.json", "prebuild": "rimraf build", "release": "pnpm build && pnpm publish", "test": "exit 0" diff --git a/scripts/copyFiles.mjs b/scripts/copyFiles.mjs index 27eeaa53ac89e1..6a22cb96604213 100644 --- a/scripts/copyFiles.mjs +++ b/scripts/copyFiles.mjs @@ -52,9 +52,10 @@ async function run() { const packageData = await createPackageFile(); await Promise.all( - ['./README.md', '../../CHANGELOG.md', '../../LICENSE', ...extraFiles].map((file) => - includeFileInBuild(file), - ), + ['./README.md', '../../CHANGELOG.md', '../../LICENSE', ...extraFiles].map(async (file) => { + const [sourcePath, targetPath] = file.split(':'); + await includeFileInBuild(sourcePath, targetPath); + }), ); await addLicense(packageData); diff --git a/scripts/copyFilesUtils.mjs b/scripts/copyFilesUtils.mjs index f9a55addab0ca7..40b05542614f9e 100644 --- a/scripts/copyFilesUtils.mjs +++ b/scripts/copyFilesUtils.mjs @@ -6,9 +6,17 @@ import glob from 'fast-glob'; const packagePath = process.cwd(); const buildPath = path.join(packagePath, './build'); -export async function includeFileInBuild(file) { +/** + * Copies a file into the build directory. By default it copies it under the same + * base name in the root, but you can provide a second argument to specify a + * different subpath. + * @param {string} file source file path + * @param {string=} target target file path + * @returns {Promise} + */ +export async function includeFileInBuild(file, target = path.basename(file)) { const sourcePath = path.resolve(packagePath, file); - const targetPath = path.resolve(buildPath, path.basename(file)); + const targetPath = path.resolve(buildPath, target); await fse.copy(sourcePath, targetPath); console.log(`Copied ${sourcePath} to ${targetPath}`); }