@alevnyacow/nzmt 0.41.2 → 0.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +65 -0
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -1469,4 +1469,69 @@ if (command === 'w') {
1469
1469
  rootPath = splitData.join('/')
1470
1470
  }
1471
1471
  generateWidget(entityName, rootPath)
1472
+ }
1473
+
1474
+ function generateLayoutedWidget(name, rootPath) {
1475
+ const [lowerCase, upperCase] = camelizeVariants(name)
1476
+
1477
+ const widgetsPath = config.paths.widgets
1478
+ const root = findProjectRoot()
1479
+
1480
+ const folder = path.resolve(root, `${config.coreFolder}${widgetsPath}`, rootPath ?? '.', name)
1481
+ fs.mkdirSync(folder, { recursive: true })
1482
+
1483
+ fs.writeFileSync(path.resolve(folder, `${name}.headless-widget.tsx`), [
1484
+ `import { FC } from 'react'`,
1485
+ `import { ${upperCase}WidgetLayoutProps } from './${name}.widget-layout'`,
1486
+ ``,
1487
+ `export type ${upperCase}HeadlessWidgetProps = {`,
1488
+ `\tLayout: FC<${upperCase}WidgetLayoutProps>,`,
1489
+ `}`,
1490
+ ``,
1491
+ `export const ${upperCase}HeadlessWidget: FC<${upperCase}HeadlessWidgetProps> = ({ Layout }) => {`,
1492
+ `\treturn <Layout />`,
1493
+ `}`
1494
+ ].join('\n'))
1495
+
1496
+ fs.writeFileSync(path.resolve(folder, `${name}.widget-layout.module.css`), [
1497
+ ''
1498
+ ].join('\n'))
1499
+
1500
+ fs.writeFileSync(path.resolve(folder, `${name}.widget-layout.tsx`), [
1501
+ `import { FC } from 'react'`,
1502
+ `import styles from './${name}.widget-layout.module.css'`,
1503
+ ``,
1504
+ `export type ${upperCase}WidgetLayoutProps = {}`,
1505
+ ``,
1506
+ `export const ${upperCase}WidgetLayout: FC<${upperCase}WidgetLayoutProps> = ({}) => {`,
1507
+ `\treturn undefined`,
1508
+ `}`
1509
+ ].join('\n'))
1510
+
1511
+ fs.writeFileSync(path.resolve(folder, `${name}.widget.tsx`), [
1512
+ `import { FC } from 'react'`,
1513
+ `import { ${upperCase}HeadlessWidget, ${upperCase}HeadlessWidgetProps } from './${name}.headless-widget'`,
1514
+ `import { ${upperCase}WidgetLayout } from './${name}.widget-layout'`,
1515
+ ``,
1516
+ `export type ${upperCase}WidgetProps = Omit<${upperCase}HeadlessWidgetProps, 'Layout'>`,
1517
+ ``,
1518
+ `export const ${upperCase}Widget: FC<${upperCase}WidgetProps> = (props) => {`,
1519
+ `\treturn <${upperCase}HeadlessWidget Layout={${upperCase}WidgetLayout} {...props}/>`,
1520
+ `}`
1521
+ ].join('\n'))
1522
+
1523
+ fs.writeFileSync(path.resolve(folder, `index.ts`), [
1524
+ `export * from './${name}.widget'`
1525
+ ].join('\n'))
1526
+ }
1527
+
1528
+
1529
+ if (command === 'lw') {
1530
+ let rootPath = undefined
1531
+ if (entityName.includes('/')) {
1532
+ const splitData = entityName.split('/')
1533
+ entityName = splitData.pop()
1534
+ rootPath = splitData.join('/')
1535
+ }
1536
+ generateLayoutedWidget(entityName, rootPath)
1472
1537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.41.2",
3
+ "version": "0.42.1",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "keywords": ["next", "full-stack", "server", "backend", "cli", "scaffolding", "zod", "rest", "contract programming", "contract-first", "react-query", "ddd", "domain-driven"],
6
6
  "repository": {