Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private writeToFile(methodName: keyof Reporter, data: any) {
const filename = path.join(this.baseFolder, `${this.format(this.index++)}-${methodName}.json`);
this.log.debug(`Writing event ${methodName} to file ${filename}`);
return fsAsPromised.writeFile(filename, JSON.stringify(data), { encoding: 'utf8' });
}
private writeStrykerConfigRaw(rawConfig: string, rawHeader = '') {
this.out('Writing stryker.conf.js...');
const formattedConf = format(`${rawHeader}
module.exports = function(config){
config.set(
${rawConfig}
);
}`, { parser: 'babel' as unknown as 'babylon' });
return fsAsPromised.writeFile(STRYKER_CONFIG_FILE, formattedConf);
}
export async function writeFile(fileName: string, content: string) {
await mkdir(path.dirname(fileName));
await fsAsPromised.writeFile(fileName, content, 'utf8');
}
private async writeStrykerConfigRaw(rawConfig: string, rawHeader = '') {
this.out('Writing & formatting stryker.conf.js...');
const formattedConf = `${rawHeader}
module.exports = function(config){
config.set(
${rawConfig}
);
}`;
await fsAsPromised.writeFile(STRYKER_CONFIG_FILE, formattedConf);
try {
await childProcessAsPromised.exec(`npx prettier --write ${STRYKER_CONFIG_FILE}`);
} catch (error) {
this.log.debug('Prettier exited with error', error);
this.out('Unable to format stryker.conf.js file for you. This is not a big problem, but it might look a bit messy 🙈.');
}
}
export function writeFile(fileName: string, data: string | Buffer): Promise {
if (Buffer.isBuffer(data)) {
return fsAsPromised.writeFile(fileName, data);
} else {
return fsAsPromised.writeFile(fileName, data, 'utf8');
}
}
private writeToFile(methodName: keyof Reporter, data: any) {
const filename = path.join(this.baseFolder, `${this.format(this.index++)}-${methodName}.json`);
this.log.debug(`Writing event ${methodName} to file ${filename}`);
return fsAsPromised.writeFile(filename, JSON.stringify(data), { encoding: 'utf8' });
}
export function writeFile(fileName: string, data: string | Buffer): Promise {
if (Buffer.isBuffer(data)) {
return fsAsPromised.writeFile(fileName, data);
} else {
return fsAsPromised.writeFile(fileName, data, 'utf8');
}
}