feat(node-utils): Add copyDirectory.

This commit is contained in:
Gervwyk 2022-01-20 16:09:30 +02:00
parent e15031d32d
commit 852a77a627
4 changed files with 62 additions and 0 deletions

3
.gitignore vendored
View File

@ -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/**

View File

@ -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;

View File

@ -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);
});

View File

@ -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,