diff --git a/.gitignore b/.gitignore index fa2f0303a..75753f5d6 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ packages/plugins/connections/connection-mongodb/*.lock packages/utils/node-utils/test/writeFile/writeFile.txt packages/utils/node-utils/test/copyDirectory/** +packages/utils/node-utils/test/copyFile/** app/** packages/server-dev/plugins/** diff --git a/packages/utils/node-utils/src/copyDirectory.js b/packages/utils/node-utils/src/copyFileOrDirectory.js similarity index 86% rename from packages/utils/node-utils/src/copyDirectory.js rename to packages/utils/node-utils/src/copyFileOrDirectory.js index 73aec497e..06b5391d8 100644 --- a/packages/utils/node-utils/src/copyDirectory.js +++ b/packages/utils/node-utils/src/copyFileOrDirectory.js @@ -16,8 +16,8 @@ import fsExtra from 'fs-extra'; -async function copyDirectory(dirPathFrom, dirPathTo, options) { +async function copyFileOrDirectory(dirPathFrom, dirPathTo, options) { await fsExtra.copy(dirPathFrom, dirPathTo, options); } -export default copyDirectory; +export default copyFileOrDirectory; diff --git a/packages/utils/node-utils/src/copyDirectory.test.js b/packages/utils/node-utils/src/copyFileOrDirectory.test.js similarity index 60% rename from packages/utils/node-utils/src/copyDirectory.test.js rename to packages/utils/node-utils/src/copyFileOrDirectory.test.js index 5e9a1da46..d8d566277 100644 --- a/packages/utils/node-utils/src/copyDirectory.test.js +++ b/packages/utils/node-utils/src/copyFileOrDirectory.test.js @@ -16,11 +16,11 @@ import fs from 'fs-extra'; import path from 'path'; -import copyDirectory from './copyDirectory.js'; +import copyFileOrDirectory from './copyFileOrDirectory.js'; -test('copyDirectory', async () => { - const dirPathFrom = path.resolve(process.cwd(), 'test/copyDirectory/From/'); - const dirPathTo = path.resolve(process.cwd(), 'test/copyDirectory/To/'); +test('copy directory', async () => { + const dirPathFrom = path.resolve(process.cwd(), 'test/copyDirectory/from/'); + const dirPathTo = path.resolve(process.cwd(), 'test/copyDirectory/to/'); const filePathFrom = path.resolve(dirPathFrom, 'copyDirectory.txt'); const filePathTo = path.resolve(dirPathTo, 'copyDirectory.txt'); @@ -29,6 +29,21 @@ test('copyDirectory', async () => { }); fs.writeFileSync(filePathFrom, 'copyDirectory'); - await copyDirectory(dirPathFrom, dirPathTo); + await copyFileOrDirectory(dirPathFrom, dirPathTo); + expect(fs.existsSync(filePathTo)).toBe(true); +}); + +test('copy file', async () => { + const dirPathFrom = path.resolve(process.cwd(), 'test/copyFile/from/'); + const dirPathTo = path.resolve(process.cwd(), 'test/copyFile/to/'); + const filePathFrom = path.resolve(dirPathFrom, 'copyFile.txt'); + const filePathTo = path.resolve(dirPathTo, 'copyFile.txt'); + + fs.mkdirSync(dirPathFrom, { + recursive: true, + }); + fs.writeFileSync(filePathFrom, 'copyFile'); + + await copyFileOrDirectory(filePathFrom, filePathTo); expect(fs.existsSync(filePathTo)).toBe(true); }); diff --git a/packages/utils/node-utils/src/index.js b/packages/utils/node-utils/src/index.js index eb48dcdf0..1c5bfeaec 100644 --- a/packages/utils/node-utils/src/index.js +++ b/packages/utils/node-utils/src/index.js @@ -15,7 +15,7 @@ */ import cleanDirectory from './cleanDirectory.js'; -import copyDirectory from './copyDirectory.js'; +import copyFileOrDirectory from './copyFileOrDirectory.js'; import getConfigFromEnv from './getConfigFromEnv.js'; import getFileExtension, { getFileSubExtension } from './getFileExtension.js'; import getSecretsFromEnv from './getSecretsFromEnv.js'; @@ -25,7 +25,7 @@ import writeFile from './writeFile.js'; export { cleanDirectory, - copyDirectory, + copyFileOrDirectory, getConfigFromEnv, getFileExtension, getFileSubExtension,