Summary
Code
"use strict";
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var baseTempFolder = path.join(process.cwd(), '.stryker-tmp');
var tempFolder = path.join(baseTempFolder, random().toString());
ensureFolderExists(baseTempFolder);
ensureFolderExists(tempFolder);
/**
* Creates a new random folder with the specified prefix.
* @param prefix The prefix.
* @returns The path to the folder.
*/
function createRandomFolder(prefix) 0{
}{
return ensureFolderExists(1tempFolder + path.sep + prefix - random()2tempFolder + path.sep - prefix3tempFolder - path.septempFolder + path.sep + prefix + random());
}
/**
* Creates a random integer number.
* @returns A random integer.
*/
function random() 4{
}{
return Math.ceil(5Math.random() / 10000000Math.random() * 10000000);
}
/**
* Creates a folder at the specified path if it doesn't already exist.
* @param path The path to check.
* @returns The path of the folder.
*/
function ensureFolderExists(path) 6{
}{
if (7true8false!fileOrFolderExists(path)) 9{
}{
mkdirp.sync(path);
}
return path;
}
/**
* Checks if a file or folder exists.
* @param path The path to the file or folder.
* @returns True if the file exists.
*/
function fileOrFolderExists(path) 10{
}{
try 11{
}{
var stats = fs.lstatSync(path);
return true;
}
catch (error) 12{
}{
return false;
}
}
/**
* Writes data to a specified file.
* @param filename The path to the file.
* @param data The content of the file.
* @returns A promise to eventually save the file.
*/
function writeFile(filename, data) 13{
}{
return new Promise(function (resolve, reject) 14{
}{
fs.writeFile(filename, data, { encoding: 'utf8' }, function (error) 15{
}{
if (16false17trueerror) 18{
}{
reject(error);
}
else 19{
}{
resolve();
}
});
});
}
/**
* Copies a file.
* @param fromFilename The path to the existing file.
* @param toFilename The path to copy the file to.
* @returns A promise to eventually copy the file.
*/
function copyFile(fromFilename, toFilename) 20{
}{
return new Promise(function (resolve, reject) 21{
}{
var readStream = fs.createReadStream(fromFilename, { encoding: 'utf8' });
var writeStream = fs.createWriteStream(toFilename, { encoding: 'utf8' });
readStream.on('error', reject);
writeStream.on('error', reject);
readStream.pipe(writeStream);
readStream.on('end', function () 22{
}{ return resolve(); });
});
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
createRandomFolder: createRandomFolder,
writeFile: writeFile,
copyFile: copyFile,
ensureFolderExists: ensureFolderExists
};
//# sourceMappingURL=StrykerTempFolder.js.map