@comet/admin-generator 8.0.0-beta.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 (55) hide show
  1. package/LICENSE +24 -0
  2. package/bin/admin-generator.js +5 -0
  3. package/lib/adminGenerator.d.ts +1 -0
  4. package/lib/adminGenerator.js +8 -0
  5. package/lib/commands/generate/generate-command.d.ts +197 -0
  6. package/lib/commands/generate/generate-command.js +114 -0
  7. package/lib/commands/generate/generateForm/generateComponentFormField.d.ts +5 -0
  8. package/lib/commands/generate/generateForm/generateComponentFormField.js +18 -0
  9. package/lib/commands/generate/generateForm/generateFields.d.ts +35 -0
  10. package/lib/commands/generate/generateForm/generateFields.js +88 -0
  11. package/lib/commands/generate/generateForm/generateForm.d.ts +13 -0
  12. package/lib/commands/generate/generateForm/generateForm.js +468 -0
  13. package/lib/commands/generate/generateForm/generateFormField.d.ts +12 -0
  14. package/lib/commands/generate/generateForm/generateFormField.js +525 -0
  15. package/lib/commands/generate/generateForm/generateFormLayout.d.ts +12 -0
  16. package/lib/commands/generate/generateForm/generateFormLayout.js +164 -0
  17. package/lib/commands/generate/generateForm/getForwardedGqlArgs.d.ts +19 -0
  18. package/lib/commands/generate/generateForm/getForwardedGqlArgs.js +79 -0
  19. package/lib/commands/generate/generateGrid/combinationColumn.d.ts +43 -0
  20. package/lib/commands/generate/generateGrid/combinationColumn.js +151 -0
  21. package/lib/commands/generate/generateGrid/findInputObjectType.d.ts +2 -0
  22. package/lib/commands/generate/generateGrid/findInputObjectType.js +16 -0
  23. package/lib/commands/generate/generateGrid/generateGqlFieldList.d.ts +5 -0
  24. package/lib/commands/generate/generateGrid/generateGqlFieldList.js +43 -0
  25. package/lib/commands/generate/generateGrid/generateGrid.d.ts +14 -0
  26. package/lib/commands/generate/generateGrid/generateGrid.js +827 -0
  27. package/lib/commands/generate/generateGrid/generateGridToolbar.d.ts +14 -0
  28. package/lib/commands/generate/generateGrid/generateGridToolbar.js +92 -0
  29. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.d.ts +14 -0
  30. package/lib/commands/generate/generateGrid/getForwardedGqlArgs.js +64 -0
  31. package/lib/commands/generate/generateGrid/getPropsForFilterProp.d.ts +12 -0
  32. package/lib/commands/generate/generateGrid/getPropsForFilterProp.js +14 -0
  33. package/lib/commands/generate/generateGrid/usableFields.d.ts +8 -0
  34. package/lib/commands/generate/generateGrid/usableFields.js +2 -0
  35. package/lib/commands/generate/utils/camelCaseToHumanReadable.d.ts +1 -0
  36. package/lib/commands/generate/utils/camelCaseToHumanReadable.js +8 -0
  37. package/lib/commands/generate/utils/columnVisibility.d.ts +6 -0
  38. package/lib/commands/generate/utils/columnVisibility.js +2 -0
  39. package/lib/commands/generate/utils/findMutationType.d.ts +3 -0
  40. package/lib/commands/generate/utils/findMutationType.js +19 -0
  41. package/lib/commands/generate/utils/findQueryType.d.ts +2 -0
  42. package/lib/commands/generate/utils/findQueryType.js +19 -0
  43. package/lib/commands/generate/utils/findRootBlocks.d.ts +8 -0
  44. package/lib/commands/generate/utils/findRootBlocks.js +67 -0
  45. package/lib/commands/generate/utils/generateImportsCode.d.ts +5 -0
  46. package/lib/commands/generate/utils/generateImportsCode.js +27 -0
  47. package/lib/commands/generate/utils/intl.d.ts +1 -0
  48. package/lib/commands/generate/utils/intl.js +7 -0
  49. package/lib/commands/generate/utils/isFieldOptional.d.ts +7 -0
  50. package/lib/commands/generate/utils/isFieldOptional.js +21 -0
  51. package/lib/commands/generate/utils/writeGenerated.d.ts +1 -0
  52. package/lib/commands/generate/utils/writeGenerated.js +57 -0
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.js +2 -0
  55. package/package.json +67 -0
@@ -0,0 +1,14 @@
1
+ type Options = {
2
+ componentName: string;
3
+ forwardToolbarAction: boolean | undefined;
4
+ hasSearch: boolean;
5
+ hasFilter: boolean;
6
+ excelExport: boolean | undefined;
7
+ allowAdding: boolean;
8
+ instanceGqlType: string;
9
+ gqlType: string;
10
+ newEntryText: string | undefined;
11
+ fragmentName: string;
12
+ };
13
+ export declare const generateGridToolbar: ({ componentName, forwardToolbarAction, hasSearch, hasFilter, excelExport, allowAdding, instanceGqlType, gqlType, newEntryText, fragmentName, }: Options) => string;
14
+ export {};
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateGridToolbar = void 0;
4
+ const change_case_1 = require("change-case");
5
+ const camelCaseToHumanReadable_1 = require("../utils/camelCaseToHumanReadable");
6
+ const intl_1 = require("../utils/intl");
7
+ const generateGridToolbar = ({ componentName, forwardToolbarAction, hasSearch, hasFilter, excelExport, allowAdding, instanceGqlType, gqlType, newEntryText, fragmentName, }) => {
8
+ return `${renderToolbarProps(componentName, !!forwardToolbarAction, !!excelExport)}
9
+ function ${componentName}(${getGridToolbarProps(componentName, !!forwardToolbarAction, !!excelExport)}) {
10
+ return (
11
+ <DataGridToolbar>
12
+ ${hasSearch ? searchItem : ""}
13
+ ${hasFilter ? filterItem : ""}
14
+ <FillSpace />
15
+ ${renderToolbarActions({
16
+ forwardToolbarAction,
17
+ addItemText: (0, intl_1.getFormattedMessageNode)(`${instanceGqlType}.${(0, change_case_1.camelCase)(fragmentName)}.newEntry`, newEntryText !== null && newEntryText !== void 0 ? newEntryText : `New ${(0, camelCaseToHumanReadable_1.camelCaseToHumanReadable)(gqlType)}`),
18
+ excelExport,
19
+ allowAdding,
20
+ })}
21
+ </DataGridToolbar>
22
+ );
23
+ }`.replace(/^\s+\n/gm, "");
24
+ };
25
+ exports.generateGridToolbar = generateGridToolbar;
26
+ const getGridToolbarProps = (componentName, toolbarAction, exportApi) => {
27
+ const props = [];
28
+ if (toolbarAction) {
29
+ props.push({
30
+ destructured: "toolbarAction",
31
+ typeDefinition: "toolbarAction?: ReactNode",
32
+ });
33
+ }
34
+ if (exportApi) {
35
+ props.push({
36
+ destructured: "exportApi",
37
+ typeDefinition: "exportApi: ExportApi",
38
+ });
39
+ }
40
+ if (!props.length) {
41
+ return "";
42
+ }
43
+ return `{
44
+ ${props.map((prop) => `${prop.destructured}`).join(",")}
45
+ }: ${componentName}ToolbarProps`;
46
+ };
47
+ const searchItem = `<ToolbarItem>
48
+ <GridToolbarQuickFilter />
49
+ </ToolbarItem>`;
50
+ const filterItem = `<ToolbarItem>
51
+ <GridFilterButton />
52
+ </ToolbarItem>`;
53
+ const renderToolbarActions = ({ forwardToolbarAction, addItemText, excelExport, allowAdding }) => {
54
+ const showMoreActionsMenu = excelExport;
55
+ if (!showMoreActionsMenu && !allowAdding) {
56
+ return "";
57
+ }
58
+ const moreActionsMenu = `<CrudMoreActionsMenu
59
+ slotProps={{
60
+ button: {
61
+ responsive: true
62
+ }
63
+ }}
64
+ overallActions={[
65
+ ${excelExport
66
+ ? `{
67
+ label: <FormattedMessage {...messages.downloadAsExcel} />,
68
+ icon: exportApi.loading ? <CircularProgress size={20} /> : <Excel />,
69
+ onClick: () => exportApi.exportGrid(),
70
+ disabled: exportApi.loading,
71
+ }`
72
+ : ""}
73
+ ]}
74
+ />`;
75
+ const defaultAddItemButton = `<Button responsive startIcon={<AddIcon />} component={StackLink} pageName="add" payload="add">
76
+ ${addItemText}
77
+ </Button>`;
78
+ const addAction = forwardToolbarAction ? "{toolbarAction}" : defaultAddItemButton;
79
+ return `<ToolbarActions>
80
+ ${showMoreActionsMenu ? moreActionsMenu : ""}
81
+ ${allowAdding ? addAction : ""}
82
+ </ToolbarActions>`;
83
+ };
84
+ const renderToolbarProps = (componentName, forwardToolbarAction, exportApi) => {
85
+ if (forwardToolbarAction || exportApi) {
86
+ return `interface ${componentName}ToolbarProps extends GridToolbarProps {
87
+ ${forwardToolbarAction && "toolbarAction: ReactNode;"}
88
+ ${exportApi ? "exportApi: ExportApi;" : ""}
89
+ }`;
90
+ }
91
+ return "";
92
+ };
@@ -0,0 +1,14 @@
1
+ import { type IntrospectionField } from "graphql";
2
+ import { type Imports } from "../utils/generateImportsCode";
3
+ import { type Prop } from "./generateGrid";
4
+ type GqlArg = {
5
+ type: string;
6
+ name: string;
7
+ queryOrMutationName: string;
8
+ };
9
+ export declare function getForwardedGqlArgs(gqlFields: IntrospectionField[]): {
10
+ imports: Imports;
11
+ props: Prop[];
12
+ gqlArgs: GqlArg[];
13
+ };
14
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getForwardedGqlArgs = void 0;
4
+ function getForwardedGqlArgs(gqlFields) {
5
+ const supportedGqlArgs = ["offset", "limit", "sort", "search", "filter", "scope", "input"]; // this arguments need to be handled differently or are already handled somewhere else
6
+ const imports = [];
7
+ const props = [];
8
+ const gqlArgs = [];
9
+ getArgs(gqlFields, supportedGqlArgs).forEach((arg) => {
10
+ if (arg.type === "ID" || arg.type === "String" || arg.type === "DateTime") {
11
+ props.push({ name: arg.name, optional: false, type: "string" });
12
+ }
13
+ else if (arg.type === "Boolean") {
14
+ props.push({ name: arg.name, optional: false, type: "boolean" });
15
+ }
16
+ else if (arg.type === "Int" || arg.type === "Float") {
17
+ props.push({ name: arg.name, optional: false, type: "number" });
18
+ }
19
+ else if (arg.type === "JSONObject") {
20
+ props.push({ name: arg.name, optional: false, type: "unknown" });
21
+ }
22
+ else {
23
+ props.push({ name: arg.name, optional: false, type: arg.type });
24
+ imports.push({ name: arg.type, importPath: "@src/graphql.generated" });
25
+ }
26
+ gqlArgs.push({ name: arg.name, type: arg.type, queryOrMutationName: arg.gqlField.name });
27
+ });
28
+ return {
29
+ imports,
30
+ props,
31
+ gqlArgs,
32
+ };
33
+ }
34
+ exports.getForwardedGqlArgs = getForwardedGqlArgs;
35
+ function getArgs(gqlFields, skipGqlArgs) {
36
+ return gqlFields.reduce((acc, gqlField) => {
37
+ gqlField.args.forEach((gqlArg) => {
38
+ if (skipGqlArgs.includes(gqlArg.name))
39
+ return acc;
40
+ if (gqlArg.type.kind !== "NON_NULL" || gqlArg.defaultValue)
41
+ return acc;
42
+ const gqlType = gqlArg.type.ofType;
43
+ let type = "unknown";
44
+ if (gqlType.kind === "SCALAR") {
45
+ const nativeScalars = ["ID", "String", "Boolean", "Int", "Float", "DateTime", "JSONObject"];
46
+ if (!nativeScalars.includes(gqlType.name)) {
47
+ // probably just add to gqlFields-array, but needs to be tested
48
+ console.warn(`Currently not supported special SCALAR of type ${gqlType.name} in param ${gqlArg.name} of ${gqlField.name}`);
49
+ }
50
+ else {
51
+ type = gqlType.name;
52
+ }
53
+ }
54
+ else if (gqlType.kind === "INPUT_OBJECT") {
55
+ type = gqlType.name;
56
+ }
57
+ else {
58
+ throw new Error(`Not supported kind ${gqlType.kind}, arg: ${gqlArg.name}`);
59
+ }
60
+ acc.push({ name: gqlArg.name, type, gqlArg, gqlField });
61
+ });
62
+ return acc;
63
+ }, []);
64
+ }
@@ -0,0 +1,12 @@
1
+ import { type IntrospectionInputObjectType } from "graphql";
2
+ import { type GridConfig } from "../generate-command";
3
+ import { type Imports } from "../utils/generateImportsCode";
4
+ import { type Prop } from "./generateGrid";
5
+ export declare function getPropsForFilterProp({ config, filterType, }: {
6
+ config: GridConfig<any>;
7
+ filterType: IntrospectionInputObjectType;
8
+ }): {
9
+ hasFilterProp: boolean;
10
+ imports: Imports;
11
+ props: Prop[];
12
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPropsForFilterProp = void 0;
4
+ function getPropsForFilterProp({ config, filterType, }) {
5
+ if (!config.filterProp)
6
+ return { hasFilterProp: false, imports: [], props: [] };
7
+ const filterTypeName = `GQL${filterType.name}`;
8
+ return {
9
+ hasFilterProp: true,
10
+ imports: [{ name: filterTypeName, importPath: "@src/graphql.generated" }],
11
+ props: [{ name: "filter", optional: true, type: filterTypeName }],
12
+ };
13
+ }
14
+ exports.getPropsForFilterProp = getPropsForFilterProp;
@@ -0,0 +1,8 @@
1
+ type GqlLeaves<T> = T extends any ? "__typename" extends keyof T ? {
2
+ [K in keyof T as K extends "__typename" ? never : K]-?: GqlLeaves<T[K]>;
3
+ } : never : never;
4
+ type FieldNames<T> = {
5
+ [K in keyof T]: `${Exclude<K, symbol>}${FieldNames<T[K]> extends never ? "" : `.${FieldNames<T[K]>}`}`;
6
+ }[keyof T];
7
+ export type UsableFields<T> = FieldNames<GqlLeaves<T>>;
8
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function camelCaseToHumanReadable(s: string): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.camelCaseToHumanReadable = void 0;
4
+ const change_case_1 = require("change-case");
5
+ function camelCaseToHumanReadable(s) {
6
+ return (0, change_case_1.capitalCase)(s);
7
+ }
8
+ exports.camelCaseToHumanReadable = camelCaseToHumanReadable;
@@ -0,0 +1,6 @@
1
+ import { type Breakpoint } from "@mui/material";
2
+ type BreakpointKey = `'${Breakpoint}'` | number;
3
+ type SingleValueBrakpointTypes = "up" | "down" | "only" | "not";
4
+ type MultiValueBrakpointTypes = "between";
5
+ export type ColumnVisibleOption = `${SingleValueBrakpointTypes}(${BreakpointKey})` | `${MultiValueBrakpointTypes}(${BreakpointKey}, ${BreakpointKey})`;
6
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ import { type IntrospectionQuery } from "graphql";
2
+ export declare function findMutationType(mutationName: string, schema: IntrospectionQuery): import("graphql").IntrospectionField | undefined;
3
+ export declare function findMutationTypeOrThrow(mutationName: string, schema: IntrospectionQuery): import("graphql").IntrospectionField;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findMutationTypeOrThrow = exports.findMutationType = void 0;
4
+ function findMutationType(mutationName, schema) {
5
+ if (!schema.__schema.mutationType)
6
+ throw new Error("Schema has no Mutation type");
7
+ const queryType = schema.__schema.types.find((type) => { var _a; return type.name === ((_a = schema.__schema.mutationType) === null || _a === void 0 ? void 0 : _a.name); });
8
+ if (!queryType)
9
+ throw new Error("Can't find Mutation type in gql schema");
10
+ return queryType.fields.find((field) => field.name === mutationName);
11
+ }
12
+ exports.findMutationType = findMutationType;
13
+ function findMutationTypeOrThrow(mutationName, schema) {
14
+ const ret = findMutationType(mutationName, schema);
15
+ if (!ret)
16
+ throw new Error(`Can't find Mutation ${mutationName} in gql schema`);
17
+ return ret;
18
+ }
19
+ exports.findMutationTypeOrThrow = findMutationTypeOrThrow;
@@ -0,0 +1,2 @@
1
+ import { type IntrospectionQuery } from "graphql";
2
+ export declare function findQueryTypeOrThrow(queryName: string, schema: IntrospectionQuery): import("graphql").IntrospectionField;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findQueryTypeOrThrow = void 0;
4
+ function findQueryType(queryName, schema) {
5
+ const queryType = schema.__schema.types.find((type) => type.name === schema.__schema.queryType.name);
6
+ if (!queryType)
7
+ throw new Error("Can't find Query type in gql schema");
8
+ const ret = queryType.fields.find((field) => field.name === queryName);
9
+ if (!ret)
10
+ throw new Error(`Can't find query ${queryName} in gql schema`);
11
+ return ret;
12
+ }
13
+ function findQueryTypeOrThrow(queryName, schema) {
14
+ const ret = findQueryType(queryName, schema);
15
+ if (!ret)
16
+ throw new Error(`Can't find query ${queryName} in gql schema`);
17
+ return ret;
18
+ }
19
+ exports.findQueryTypeOrThrow = findQueryTypeOrThrow;
@@ -0,0 +1,8 @@
1
+ import { type IntrospectionQuery } from "graphql";
2
+ export declare function findRootBlocks({ gqlType, targetDirectory }: {
3
+ gqlType: string;
4
+ targetDirectory: string;
5
+ }, schema: IntrospectionQuery): Record<string, {
6
+ import: string;
7
+ name: string;
8
+ }>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findRootBlocks = void 0;
4
+ const fs_1 = require("fs");
5
+ const fallbackLibraryBlocks = {
6
+ AnchorBlock: "@comet/cms-admin",
7
+ DamImageBlock: "@comet/cms-admin",
8
+ DamVideoBlock: "@comet/cms-admin",
9
+ ExternalLinkBlock: "@comet/cms-admin",
10
+ InternalLinkBlock: "@comet/cms-admin",
11
+ PixelImageBlock: "@comet/cms-admin",
12
+ SpaceBlock: "@comet/cms-admin",
13
+ SvgImageBlock: "@comet/cms-admin",
14
+ YouTubeVideoBlock: "@comet/cms-admin",
15
+ };
16
+ function findRootBlocks({ gqlType, targetDirectory }, schema) {
17
+ const ret = {};
18
+ const schemaEntity = schema.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
19
+ if (!schemaEntity)
20
+ throw new Error("didn't find entity in schema types");
21
+ schemaEntity.fields.forEach((field) => {
22
+ if (ret[field.name])
23
+ return; // already defined
24
+ let type = field.type;
25
+ if (type.kind == "NON_NULL")
26
+ type = type.ofType;
27
+ if (type.kind == "SCALAR" && type.name.endsWith("BlockData")) {
28
+ let match = false;
29
+ const blockName = `${type.name.replace(/BlockData$/, "")}Block`;
30
+ const checkNames = [
31
+ {
32
+ folderName: `${targetDirectory.replace(/\/generated$/, "")}/blocks`,
33
+ import: `../blocks/${blockName}`,
34
+ },
35
+ {
36
+ folderName: `src/common/blocks`,
37
+ import: `@src/common/blocks/${blockName}`,
38
+ },
39
+ ];
40
+ for (const checkName of checkNames) {
41
+ if ((0, fs_1.existsSync)(`${checkName.folderName}/${blockName}.tsx`)) {
42
+ match = true;
43
+ ret[field.name] = {
44
+ import: checkName.import,
45
+ name: blockName,
46
+ };
47
+ break;
48
+ }
49
+ }
50
+ if (!match) {
51
+ const fallback = fallbackLibraryBlocks[blockName];
52
+ if (fallback) {
53
+ ret[field.name] = {
54
+ import: fallback,
55
+ name: blockName,
56
+ };
57
+ match = true;
58
+ }
59
+ }
60
+ if (!match) {
61
+ throw new Error(`Didn't find admin block for ${blockName} in ${checkNames.map((c) => c.folderName).join(" or ")}`);
62
+ }
63
+ }
64
+ });
65
+ return ret;
66
+ }
67
+ exports.findRootBlocks = findRootBlocks;
@@ -0,0 +1,5 @@
1
+ export type Imports = Array<{
2
+ name: string;
3
+ importPath: string;
4
+ }>;
5
+ export declare function generateImportsCode(imports: Imports): string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateImportsCode = void 0;
4
+ // generate imports code and filter duplicates
5
+ function generateImportsCode(imports) {
6
+ const importsNameToPath = new Map(); // name -> importPath
7
+ const filteredImports = imports.filter((imp) => {
8
+ if (importsNameToPath.has(imp.name)) {
9
+ if (importsNameToPath.get(imp.name) !== imp.importPath) {
10
+ throw new Error(`Duplicate import name ${imp.name}`);
11
+ }
12
+ else {
13
+ // duplicate import, skip
14
+ return false;
15
+ }
16
+ }
17
+ importsNameToPath.set(imp.name, imp.importPath);
18
+ return true;
19
+ });
20
+ const importsString = filteredImports
21
+ .map((imp) => {
22
+ return `import { ${imp.name} } from "${imp.importPath}";`;
23
+ })
24
+ .join("\n");
25
+ return importsString;
26
+ }
27
+ exports.generateImportsCode = generateImportsCode;
@@ -0,0 +1 @@
1
+ export declare const getFormattedMessageNode: (id: string, defaultMessage?: string, values?: string) => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFormattedMessageNode = void 0;
4
+ const getFormattedMessageNode = (id, defaultMessage = "", values) => {
5
+ return `<FormattedMessage id="${id}" defaultMessage={\`${defaultMessage}\`} ${values ? `values={${values}}` : ""} />`;
6
+ };
7
+ exports.getFormattedMessageNode = getFormattedMessageNode;
@@ -0,0 +1,7 @@
1
+ import { type IntrospectionQuery } from "graphql";
2
+ import { type FormFieldConfig } from "../generate-command";
3
+ export declare const isFieldOptional: ({ config, gqlIntrospection, gqlType, }: {
4
+ config: FormFieldConfig<any>;
5
+ gqlIntrospection: IntrospectionQuery;
6
+ gqlType: string;
7
+ }) => boolean;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFieldOptional = void 0;
4
+ const isFieldOptional = ({ config, gqlIntrospection, gqlType, }) => {
5
+ if (config.required !== undefined) {
6
+ return !config.required;
7
+ }
8
+ if (config.readOnly) {
9
+ return true;
10
+ }
11
+ const schemaEntity = gqlIntrospection.__schema.types.find((type) => type.kind === "OBJECT" && type.name === gqlType);
12
+ if (!schemaEntity)
13
+ throw new Error(`didn't find entity ${gqlType} in schema types`);
14
+ if (schemaEntity.kind !== "OBJECT")
15
+ throw new Error(`kind of ${gqlType} is not object, but should be.`); // this should not happen
16
+ const fieldDef = schemaEntity.fields.find((field) => field.name === String(config.name));
17
+ if (!fieldDef)
18
+ throw new Error(`didn't find field ${String(config.name)} of ${gqlType} in introspected gql-schema.`);
19
+ return fieldDef.type.kind !== "NON_NULL";
20
+ };
21
+ exports.isFieldOptional = isFieldOptional;
@@ -0,0 +1 @@
1
+ export declare function writeGenerated(filePath: string, contents: string): Promise<void>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.writeGenerated = void 0;
36
+ const eslint_1 = require("eslint");
37
+ const fs_1 = require("fs");
38
+ const path = __importStar(require("path"));
39
+ function writeGenerated(filePath, contents) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const header = `// This file has been generated by comet admin-generator.
42
+ // You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
43
+ `;
44
+ yield fs_1.promises.mkdir(path.dirname(filePath), { recursive: true });
45
+ const eslint = new eslint_1.ESLint({
46
+ cwd: process.cwd(),
47
+ fix: true,
48
+ });
49
+ const lintResult = yield eslint.lintText(header + contents, {
50
+ filePath,
51
+ });
52
+ const output = lintResult[0] && lintResult[0].output ? lintResult[0].output : lintResult[0].source;
53
+ yield fs_1.promises.writeFile(filePath, output !== null && output !== void 0 ? output : contents);
54
+ console.log(`generated ${filePath}`);
55
+ });
56
+ }
57
+ exports.writeGenerated = writeGenerated;
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export type { FormConfig, FormFieldConfig, GeneratorConfig, GridColumnConfig, GridConfig } from "./commands/generate/generate-command";
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@comet/admin-generator",
3
+ "version": "8.0.0-beta.0",
4
+ "repository": {
5
+ "directory": "packages/admin/admin-generator",
6
+ "type": "git",
7
+ "url": "https://github.com/vivid-planet/comet"
8
+ },
9
+ "license": "BSD-2-Clause",
10
+ "main": "lib/index.js",
11
+ "typings": "lib/index.d.ts",
12
+ "bin": {
13
+ "comet-admin-generator": "bin/admin-generator.js"
14
+ },
15
+ "files": [
16
+ "bin/**/*.js",
17
+ "lib/*"
18
+ ],
19
+ "dependencies": {
20
+ "@graphql-tools/graphql-file-loader": "^7.5.17",
21
+ "@graphql-tools/load": "^7.8.14",
22
+ "change-case": "^4.1.2",
23
+ "commander": "^9.5.0",
24
+ "glob": "^10.4.5",
25
+ "graphql": "^16.10.0",
26
+ "object-path": "^0.11.8",
27
+ "pluralize": "^8.0.0",
28
+ "ts-node": "^10.9.2"
29
+ },
30
+ "devDependencies": {
31
+ "@mui/material": "^6.4.5",
32
+ "@mui/x-data-grid": "^7.27.0",
33
+ "@types/jest": "^29.5.14",
34
+ "@types/node": "^22.13.4",
35
+ "@types/object-path": "^0.11.4",
36
+ "@types/pluralize": "^0.0.33",
37
+ "@types/react": "^18.3.18",
38
+ "eslint": "^9.20.1",
39
+ "jest": "^29.7.0",
40
+ "npm-run-all2": "^5.0.2",
41
+ "prettier": "^3.5.1",
42
+ "react": "^18.3.1",
43
+ "react-intl": "^6.8.9",
44
+ "rimraf": "^6.0.1",
45
+ "ts-jest": "^29.2.5",
46
+ "typescript": "^4.9.5",
47
+ "@comet/admin": "8.0.0-beta.0",
48
+ "@comet/admin-icons": "8.0.0-beta.0",
49
+ "@comet/cms-admin": "8.0.0-beta.0",
50
+ "@comet/eslint-config": "8.0.0-beta.0"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "registry": "https://registry.npmjs.org"
55
+ },
56
+ "scripts": {
57
+ "build": "$npm_execpath run clean && tsc -p tsconfig.build.json",
58
+ "clean": "rimraf lib",
59
+ "dev": "tsc --watch --preserveWatchOutput -p tsconfig.build.json",
60
+ "lint": "run-p lint:prettier lint:eslint lint:tsc",
61
+ "lint:eslint": "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored",
62
+ "lint:prettier": "npx prettier --check './**/*.{js,json,md,yml,yaml}'",
63
+ "lint:tsc": "tsc",
64
+ "test": "jest --passWithNoTests",
65
+ "test:watch": "jest --watch"
66
+ }
67
+ }