just-scripts
Version:
Just Stack Scripts
32 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeCopyInstructions = void 0;
const path_1 = require("path");
const fs_extra_1 = require("fs-extra");
const arrayify_1 = require("../arrayUtils/arrayify");
const uniqueValues_1 = require("../arrayUtils/uniqueValues");
/**
* Function containing the core code for the copy task with a given config.
*/
async function executeCopyInstructions(config) {
if (config && config.copyInstructions) {
await createDirectories(config.copyInstructions);
await Promise.all(config.copyInstructions.map(executeSingleCopyInstruction));
}
}
exports.executeCopyInstructions = executeCopyInstructions;
function createDirectories(copyInstructions) {
return Promise.all(uniqueValues_1.uniqueValues(copyInstructions.map(instruction => path_1.dirname(instruction.destinationFilePath))).map(dirname => fs_extra_1.ensureDir(dirname)));
}
function executeSingleCopyInstruction(copyInstruction) {
const sourceFileNames = arrayify_1.arrayify(copyInstruction.sourceFilePath);
// source and dest are 1-to-1? perform binary copy.
if (sourceFileNames.length === 1) {
return fs_extra_1.copy(sourceFileNames[0], copyInstruction.destinationFilePath);
}
// perform text merge operation.
return Promise.all(sourceFileNames.map(fileName => fs_extra_1.readFile(fileName))).then(fileContents => {
return fs_extra_1.writeFile(copyInstruction.destinationFilePath, fileContents.join('\n'));
});
}
//# sourceMappingURL=executeCopyInstructions.js.map