@alevnyacow/nzmt 0.41.1 → 0.42.0

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 +67 -3
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -1438,10 +1438,10 @@ function generateWidget(name, rootPath) {
1438
1438
  const widgetsPath = config.paths.widgets
1439
1439
  const root = findProjectRoot()
1440
1440
 
1441
- const folder = path.resolve(root, widgetsPath, rootPath ?? '.', name)
1441
+ const folder = path.resolve(root, `${config.coreFolder}${widgetsPath}`, rootPath ?? '.', name)
1442
1442
  fs.mkdirSync(folder, { recursive: true })
1443
1443
 
1444
- fs.writeFileSync(path.resolve(folder, `${lowerCase}.widget.tsx`), [
1444
+ fs.writeFileSync(path.resolve(folder, `${name}.widget.tsx`), [
1445
1445
  `import { FC } from 'react'`,
1446
1446
  `import styles from './${lowerCase}.widget.module.css'`,
1447
1447
  ``,
@@ -1452,7 +1452,7 @@ function generateWidget(name, rootPath) {
1452
1452
  `}`
1453
1453
  ].join('\n'))
1454
1454
 
1455
- fs.writeFileSync(path.resolve(folder, `${lowerCase}.widget.module.css`), [
1455
+ fs.writeFileSync(path.resolve(folder, `${name}.widget.module.css`), [
1456
1456
  ''
1457
1457
  ].join('\n'))
1458
1458
 
@@ -1469,4 +1469,68 @@ 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
+ `export const ${upperCase}HeadlessWidget: FC<${upperCase}HeadlessWidgetProps> = ({ Layout }) => {`,
1491
+ `\treturn <Layout />`,
1492
+ `}`
1493
+ ].join('\n'))
1494
+
1495
+ fs.writeFileSync(path.resolve(folder, `${name}.widget-layout.module.css`), [
1496
+ ''
1497
+ ].join('\n'))
1498
+
1499
+ fs.writeFileSync(path.resolve(folder, `${name}.widget-layout.tsx`), [
1500
+ `import { FC } from 'react'`,
1501
+ `import styles from './${name}.widget-layout.module.css'`,
1502
+ ``,
1503
+ `export type ${upperCase}WidgetLayoutProps = {}`,
1504
+ ``,
1505
+ `export const ${upperCase}WidgetLayout: FC<${upperCase}WidgetLayoutProps> = ({}) => {`,
1506
+ `\treturn undefined`,
1507
+ `}`
1508
+ ].join('\n'))
1509
+
1510
+ fs.writeFileSync(path.resolve(folder, `${name}.widget.tsx`), [
1511
+ `import { FC } from 'react'`,
1512
+ `import { ${upperCase}HeadlessWidget, ${upperCase}HeadlessWidgetProps } from './${name}.headless-widget'`,
1513
+ `import { ${upperCase}WidgetLayout } from './${name}.widget-layout'`,
1514
+ ``,
1515
+ `export type ${upperCase}WidgetProps = Omit<${upperCase}HeadlessWidgetProps, 'Layout'>`,
1516
+ ``,
1517
+ `export const ${upperCase}Widget: FC<${upperCase}WidgetProps> = (props) => {`,
1518
+ `\treturn <${upperCase}HeadlessWidget Layout={${upperCase}WidgetLayout} {...props}/>`,
1519
+ `}`
1520
+ ].join('\n'))
1521
+
1522
+ fs.writeFileSync(path.resolve(folder, `index.ts`), [
1523
+ `export * from './${name}.widget'`
1524
+ ].join('\n'))
1525
+ }
1526
+
1527
+
1528
+ if (command === 'lw') {
1529
+ let rootPath = undefined
1530
+ if (entityName.includes('/')) {
1531
+ const splitData = entityName.split('/')
1532
+ entityName = splitData.pop()
1533
+ rootPath = splitData.join('/')
1534
+ }
1535
+ generateLayoutedWidget(entityName, rootPath)
1472
1536
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.41.1",
3
+ "version": "0.42.0",
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": {