Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 6x 6x 6x 6x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 6x 6x 6x 6x | import * as path from 'node:path';
import { generateFiles, getWorkspaceLayout, type Tree } from '@nx/devkit';
import { kebabCase } from 'lodash-es';
import { type GenericReactHookGeneratorSchema } from './schema.d';
function generateHook(tree: Tree, options: GenericReactHookGeneratorSchema) {
const hookFolderName = kebabCase(options.hookName);
const directoryPath = path.join(getWorkspaceLayout(tree).libsDir, 'ext/react/hooks/src/lib', hookFolderName);
generateFiles(tree, path.join(__dirname, 'files'), directoryPath, options);
}
function addExportToIndex(tree: Tree, options: GenericReactHookGeneratorSchema) {
const designSystemIndexPath = path.join(getWorkspaceLayout(tree).libsDir, 'ext/react/hooks/src/index.ts');
const fileContent = tree.read(designSystemIndexPath, 'utf-8')?.toString() ?? '';
const pathToComponentFromIndex = path.join('lib', kebabCase(options.hookName), options.hookName);
tree.write(designSystemIndexPath, `${fileContent}export * from './${pathToComponentFromIndex}';\n`);
}
export default function genericReactHookGenerator(tree: Tree, options: GenericReactHookGeneratorSchema) {
generateHook(tree, options);
addExportToIndex(tree, options);
}
|