nitro-codegen
Version:
The code-generator for react-native-nitro-modules.
20 lines (19 loc) • 745 B
JavaScript
import path from 'path';
import { promises as fs } from 'fs';
import { capitalizeName } from './utils.js';
import chalk from 'chalk';
import { Logger } from './Logger.js';
/**
* Writes the given file to disk and returns it's actual path.
*/
export async function writeFile(basePath, file) {
const filepath = path.join(basePath, ...file.subdirectory, file.name);
const language = capitalizeName(file.language);
Logger.debug(` ${chalk.dim(language)}: Creating ${file.name}...`);
const dir = path.dirname(filepath);
// Create directory if it doesn't exist yet
await fs.mkdir(dir, { recursive: true });
// Write file
await fs.writeFile(filepath, file.content.trim() + '\n', 'utf8');
return filepath;
}