@postxl/generator 0.16.5 → 0.16.7

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.
package/dist/generator.js CHANGED
@@ -224,8 +224,14 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
224
224
  // Merge with existing files.
225
225
  vfs.copy(generated, './');
226
226
  // Flush to disk.
227
- const changes = yield vfs.flush(process.cwd(), { force: config.force });
228
- const log = lock_1.ConsoleUtils.getFilesChangelog(changes.filter((c) => !c.static));
227
+ // NOTE: We use a special "internal" variable to force regeneration of all files so that
228
+ // the template files are always up to date.
229
+ const FORCE = process.env.POSTXL_FORCE_REWRITE === 'true';
230
+ if (FORCE) {
231
+ console.debug('Forcing regeneration of all files due to POSTXL_FORCE_REWRITE=true!');
232
+ }
233
+ const changes = yield vfs.flush(process.cwd(), { force: config.force || FORCE });
234
+ const log = lock_1.ConsoleUtils.getFilesChangelog(changes.filter((c) => !c.static && c.status !== 'skipped'));
229
235
  console.info(log);
230
236
  });
231
237
  }
@@ -24,11 +24,19 @@ function generateEnumSelect({ enumerator, meta }) {
24
24
  items: [enumerator.tsTypeName],
25
25
  from: meta.types.importPath,
26
26
  });
27
+ let description = '';
28
+ if (enumerator.description) {
29
+ description = `
30
+ /**
31
+ * ${enumerator.description}
32
+ */`;
33
+ }
27
34
  return `
28
35
  import { useField } from 'formik'
29
36
  import React from 'react'
30
37
 
31
38
  import { ButtonSwitcher } from '@components/atoms/ButtonSwitcher'
39
+ import { MenuSelectInput, MenuSelectField } from '@components/atoms/MenuSelect'
32
40
  import { SelectInput, SelectField } from '@components/atoms/SelectInput'
33
41
  import { UnionOmit } from '@lib/types'
34
42
 
@@ -45,6 +53,7 @@ const OPTIONS: Option[] = [
45
53
 
46
54
  // Switcher
47
55
 
56
+ ${description}
48
57
  export const ${meta.react.switcherInputName} = ({ ...delegated }: UnionOmit<
49
58
  React.ComponentPropsWithoutRef<typeof ButtonSwitcher<${enumerator.tsTypeName}>>,
50
59
  'options'
@@ -52,6 +61,7 @@ export const ${meta.react.switcherInputName} = ({ ...delegated }: UnionOmit<
52
61
  <ButtonSwitcher options={OPTIONS} {...delegated} />
53
62
  )
54
63
 
64
+ ${description}
55
65
  export const ${meta.react.switcherFieldName} = ({
56
66
  name,
57
67
  ...delegated
@@ -66,16 +76,34 @@ export const ${meta.react.switcherFieldName} = ({
66
76
 
67
77
  // Select
68
78
 
79
+ ${description}
69
80
  export const ${meta.react.selectInputName} = ({
70
81
  ...delegated
71
82
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof SelectInput<Option>>, 'label' | 'options'>) => {
72
83
  return <SelectInput<Option> options={OPTIONS} label={(l) => l.label} {...delegated} />
73
84
  }
74
85
 
86
+ ${description}
75
87
  export const ${meta.react.selectFieldName} = ({
76
88
  ...delegated
77
89
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof SelectField<Option>>, 'label' | 'options'>) => {
78
90
  return <SelectField<Option> options={OPTIONS} label={(l) => l.label} {...delegated} />
79
91
  }
92
+
93
+ // Menu
94
+
95
+ ${description}
96
+ export const ${meta.react.menuInputName} = ({
97
+ ...delegated
98
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectInput<Option>>, 'label' | 'options'>) => {
99
+ return <MenuSelectInput<Option> options={OPTIONS} label={(l) => l.label} {...delegated} />
100
+ }
101
+
102
+ ${description}
103
+ export const ${meta.react.menuFieldName} = ({
104
+ ...delegated
105
+ }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectField<Option>>, 'label' | 'options'>) => {
106
+ return <MenuSelectField<Option> options={OPTIONS} label={(l) => l.label} {...delegated} />
107
+ }
80
108
  `;
81
109
  }
@@ -22,6 +22,13 @@ function generateModelLookupComponents({ model, meta }) {
22
22
  const hasNameField = model.nameField != null;
23
23
  const tsOmittedFields = hasNameField ? `'label' | 'options' | 'loading'` : `'options' | 'loading'`;
24
24
  const reactLabelField = hasNameField ? `label={(l) => l.name}` : '';
25
+ let description = '';
26
+ if (model.description) {
27
+ description = `
28
+ /**
29
+ * ${model.description}
30
+ */`;
31
+ }
25
32
  return `
26
33
  import React from 'react'
27
34
 
@@ -37,6 +44,7 @@ ${imports.generate()}
37
44
 
38
45
  // Select
39
46
 
47
+ ${description}
40
48
  export const ${components.forms.selectInputName} = ({
41
49
  ...delegated
42
50
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof SelectInput<${typeName}>>, ${tsOmittedFields}>) => {
@@ -44,6 +52,7 @@ export const ${components.forms.selectInputName} = ({
44
52
  return <SelectInput<${typeName}> options={list} ${reactLabelField} loading={!ready} {...delegated} />
45
53
  }
46
54
 
55
+ ${description}
47
56
  export const ${components.forms.selectFieldName} = ({
48
57
  ...delegated
49
58
  }: Omit<React.ComponentPropsWithoutRef<typeof SelectField<${typeName}>>, ${tsOmittedFields}>) => {
@@ -53,6 +62,7 @@ export const ${components.forms.selectFieldName} = ({
53
62
 
54
63
  // Menu Select
55
64
 
65
+ ${description}
56
66
  export const ${components.forms.menuSelectInputName} = ({
57
67
  ...delegated
58
68
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectInput<${typeName}>>, ${tsOmittedFields}>) => {
@@ -60,6 +70,7 @@ export const ${components.forms.menuSelectInputName} = ({
60
70
  return <MenuSelectInput<${typeName}> options={list} ${reactLabelField} loading={!ready} {...delegated} />
61
71
  }
62
72
 
73
+ ${description}
63
74
  export const ${components.forms.menuSelectFieldName} = ({
64
75
  ...delegated
65
76
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof MenuSelectField<${typeName}>>, ${tsOmittedFields}>) => {
@@ -69,12 +80,15 @@ export const ${components.forms.menuSelectFieldName} = ({
69
80
 
70
81
  // Search
71
82
 
83
+ ${description}
72
84
  export const ${components.forms.searchInputName} = ({
73
85
  ...delegated
74
86
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof SearchInput<${typeName}>>, ${tsOmittedFields}>) => {
75
87
  const { list, ready } = ${context.hookFnName}()
76
88
  return <SearchInput<${typeName}> options={list} ${reactLabelField} loading={!ready} {...delegated} />
77
89
  }
90
+
91
+ ${description}
78
92
  export const ${components.forms.searchFieldName} = ({
79
93
  ...delegated
80
94
  }: Omit<React.ComponentPropsWithoutRef<typeof SearchField<${typeName}>>, ${tsOmittedFields}>) => {
@@ -84,6 +98,7 @@ export const ${components.forms.searchFieldName} = ({
84
98
 
85
99
  // Table
86
100
 
101
+ ${description}
87
102
  export const ${components.forms.tableSelectInputName} = ({
88
103
  ...delegated
89
104
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectInput<${typeName}>>, ${tsOmittedFields}>) => {
@@ -91,6 +106,7 @@ export const ${components.forms.tableSelectInputName} = ({
91
106
  return <TableSelectInput<${typeName}> options={list} ${reactLabelField} loading={!ready} {...delegated} />
92
107
  }
93
108
 
109
+ ${description}
94
110
  export const ${components.forms.tableSelectFieldName} = ({
95
111
  ...delegated
96
112
  }: UnionOmit<React.ComponentPropsWithoutRef<typeof TableSelectField<${typeName}>>, ${tsOmittedFields}>) => {
@@ -502,6 +502,8 @@ export type EnumMetaData = {
502
502
  selectFieldName: Types.VariableName;
503
503
  switcherInputName: Types.VariableName;
504
504
  switcherFieldName: Types.VariableName;
505
+ menuInputName: Types.VariableName;
506
+ menuFieldName: Types.VariableName;
505
507
  };
506
508
  types: {
507
509
  /**
package/dist/lib/meta.js CHANGED
@@ -229,6 +229,8 @@ function getEnumMetadata({ enumerator: { name, schemaConfig: config }, }) {
229
229
  selectFieldName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SelectField`),
230
230
  switcherInputName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SwitcherInput`),
231
231
  switcherFieldName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SwitcherField`),
232
+ menuInputName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}MenuInput`),
233
+ menuFieldName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}MenuField`),
232
234
  },
233
235
  types: {
234
236
  membersList: Types.toVariableName(`${(0, string_1.toCamelCase)(name)}Members`),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.16.5",
3
+ "version": "0.16.7",
4
4
  "main": "./dist/generator.js",
5
5
  "typings": "./dist/generator.d.ts",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  "prettier": "^2.8.7",
23
23
  "remeda": "1.9.4",
24
24
  "zod": "3.21.4",
25
- "@postxl/lock": "0.4.5"
25
+ "@postxl/lock": "0.4.6"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@prisma/client": "4.12.0",