import { __packagePathSync } from '@coffeekraken/sugar/npm'; import { __packageRootDir } from '@coffeekraken/sugar/path'; import __fs from 'fs'; import type { ISKitchenIngredient } from '../../SKitchen.js'; /** * @name nvmrcIngredient * @namespace node.ingredients.nvmrc * @type ISKitchenIngredient * @static * * This ingredient represent the ".nvmrc" file at the root of your project * * @since 2.0.0 * @author Olivier Bossel (https://coffeekraken.io) */ const nvmrcIngredient: ISKitchenIngredient = { id: 'nvmrc', description: 'Add the default .nvmrc file into your project', projectTypes: ['unknown', 'sugar', 'next'], async add() { const packageRoot = __packageRootDir(); const cliPackagePath = __packagePathSync('@coffeekraken/cli'); if (!cliPackagePath) return false; let nvmrc; if (__fs.existsSync(`${cliPackagePath}/.nvmrc`)) { nvmrc = __fs.readFileSync(`${cliPackagePath}/.nvmrc`).toString(); __fs.writeFileSync(`${packageRoot}/.nvmrc`, nvmrc); console.verbose?.( `[nvmrc] Default .nvmrc file addedd successfully with node version ${nvmrc}`, ); return true; } return false; }, }; export default nvmrcIngredient;