diff --git a/.gitignore b/.gitignore index 01bc0772f..c16fdff42 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ packages/build/build/** packages/plugins/connections/connection-mongodb/mongod-* packages/plugins/connections/connection-mongodb/globalConfig.json packages/plugins/connections/connection-mongodb/*.lock + +packages/utils/node-utils/test/writeFile/writeFile.txt +packages/utils/node-utils/test/copyDirectory/** diff --git a/packages/utils/node-utils/src/copyDirectory.js b/packages/utils/node-utils/src/copyDirectory.js new file mode 100644 index 000000000..ab4563691 --- /dev/null +++ b/packages/utils/node-utils/src/copyDirectory.js @@ -0,0 +1,23 @@ +/* + Copyright 2020-2021 Lowdefy, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import fsExtra from 'fs-extra'; + +async function copyDirectory(dirPathFrom, dirPathTo) { + await fsExtra.copy(dirPathFrom, dirPathTo); +} + +export default copyDirectory; diff --git a/packages/utils/node-utils/src/copyDirectory.test.js b/packages/utils/node-utils/src/copyDirectory.test.js new file mode 100644 index 000000000..4ce374b6f --- /dev/null +++ b/packages/utils/node-utils/src/copyDirectory.test.js @@ -0,0 +1,34 @@ +/* + Copyright 2020-2021 Lowdefy, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +import fs from 'fs-extra'; +import path from 'path'; +import copyDirectory from './copyDirectory.js'; + +test('copyDirectory', 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'); + + fs.mkdirSync(dirPathFrom, { + recursive: true, + }); + fs.writeFileSync(filePathFrom, 'copyDirectory'); + + await copyDirectory(dirPathFrom, dirPathTo); + 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 c735592ff..343cbeb93 100644 --- a/packages/utils/node-utils/src/index.js +++ b/packages/utils/node-utils/src/index.js @@ -15,6 +15,7 @@ */ import cleanDirectory from './cleanDirectory.js'; +import copyDirectory from './copyDirectory.js'; import getConfigFromEnv from './getConfigFromEnv.js'; import getFileExtension, { getFileSubExtension } from './getFileExtension.js'; import getSecretsFromEnv from './getSecretsFromEnv.js'; @@ -24,6 +25,7 @@ import writeFile from './writeFile.js'; export { cleanDirectory, + copyDirectory, getConfigFromEnv, getFileExtension, getFileSubExtension,