import __SSugarConfig from '@coffeekraken/s-sugar-config'; import { __dirname, __readJsonSync, __writeJsonSync, } from '@coffeekraken/sugar/fs'; import { __packageJsonSync } from '@coffeekraken/sugar/package'; import { __packageRootDir } from '@coffeekraken/sugar/path'; import __fs from 'fs'; import type { ISKitchenIngredient } from '../../SKitchen.js'; /** * @name manifestIngredient * @namespace node.ingredients.manifest * @type ISKitchenIngredient * @static * * This ingredient represent the "manifest.json" file at the root of your project * * @since 2.0.0 * @author Olivier Bossel (https://coffeekraken.io) */ const manifestIngredient: ISKitchenIngredient = { id: 'manifest', description: 'Add the default manifest.json into your sugar project', projectTypes: ['unknown', 'sugar', 'next'], async add() { const packageJson = __packageJsonSync(); const publicDir = __SSugarConfig.get('storage.src.publicDir'); if (__fs.existsSync(`${publicDir}/manifest.json`)) { const json = __readJsonSync(`${publicDir}/manifest.json`); json.short_name = packageJson.name; json.name = packageJson.description; __writeJsonSync(`${publicDir}/manifest.json`, json); } else { const json = __readJsonSync( `${__packageRootDir( __dirname(), )}/src/data/manifest/manifest.json`, ); json.short_name = packageJson.name; json.name = packageJson.description; __writeJsonSync(`${publicDir}/manifest.json`, json); } console.verbose?.( `[manifest] Default manifest.json file addedd successfully`, ); return true; }, }; export default manifestIngredient;