@modyo/cli
Version:
Modyo CLI Command line to expose local development tools
35 lines (34 loc) • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const node_path_1 = require("node:path");
const fs_extra_1 = require("fs-extra");
const core_1 = require("@oclif/core");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug = (0, debug_1.default)('get/moving-files-to-final-destination.ts');
async function movingFilesToFinalDestination(finalPath) {
const filesAndFolders = await (0, fs_extra_1.readdir)(finalPath);
if (filesAndFolders.length === 1) {
const innerFolderPath = (0, node_path_1.join)(finalPath, filesAndFolders[0]);
const stats = await (0, fs_extra_1.stat)(innerFolderPath);
if (stats.isDirectory()) {
const filesToMove = await (0, fs_extra_1.readdir)(innerFolderPath);
await Promise.all(filesToMove.map((file) => {
const fromPath = (0, node_path_1.join)(innerFolderPath, file);
const toPath = (0, node_path_1.join)(finalPath, file);
debug('moving from');
debug(fromPath);
debug('to:');
debug(toPath);
return (0, fs_extra_1.rename)(fromPath, toPath);
}));
core_1.ux.action.start('Removing unnecessary files');
debug('remove unnecessary files');
await (0, fs_extra_1.remove)(innerFolderPath);
core_1.ux.action.stop();
}
return true;
}
return false;
}
exports.default = movingFilesToFinalDestination;