Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generator): handle all function for generate form and grid #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 254 additions & 157 deletions apps/docs/src/app/app.tsx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './components/builder/builder';
export * from './components/builder/builder.types';
export type * from './components/builder/builder.types';
12 changes: 12 additions & 0 deletions packages/generator/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
18 changes: 18 additions & 0 deletions packages/generator/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# generator

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test generator` to execute the unit tests via [Jest](https://jestjs.io).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The verification process has revealed that the package.json file in the packages/generator directory does not contain a scripts section. This confirms that the command nx test generator mentioned in the README.md is not set up and therefore, cannot be functional as described.

Conclusion:

  • The command nx test generator is not correctly set up in the package.json scripts, as there is no scripts section present in the file.
Analysis chain

Confirm the command nx test generator is correct and functional as described.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the 'nx test generator' command is set up correctly in package.json scripts.
cat packages/generator/package.json | jq '.scripts | has("test")'

Length of output: 73



Script:

#!/bin/bash
# Check the entire 'scripts' section of the package.json to see if there's any script related to testing the generator.
cat packages/generator/package.json | jq '.scripts'

Length of output: 56

4 changes: 4 additions & 0 deletions packages/generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@mui-builder/generator",
"version": "0.0.1"
}
29 changes: 29 additions & 0 deletions packages/generator/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "generator",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/generator/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/generator",
"tsConfig": "packages/generator/tsconfig.lib.json",
"project": "packages/generator/package.json",
"entryFile": "packages/generator/src/index.ts",
"external": ["react", "react-dom", "react/jsx-runtime"],
"rollupConfig": "@nx/react/plugins/bundle-rollup",
"compiler": "babel",
"assets": [
{
"glob": "packages/generator/README.md",
"input": ".",
"output": "."
}
]
}
}
}
}
11 changes: 11 additions & 0 deletions packages/generator/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import generateActionSubmit from './utils/actionSubmit/actionSubmit';
import generateFieldText from './utils/fieldText/fieldText';
import generateGridContainer from './utils/gridContainer/gridContainer';
import generateGridItem from './utils/gridItem/gridItem';

export {
generateGridContainer,
generateActionSubmit,
generateGridItem,
generateFieldText,
};
11 changes: 11 additions & 0 deletions packages/generator/src/types/public.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FormBuilderProps } from '@mui-builder/core';
import { Configs } from '@mui-builder/form';

export type GeneratorProps<T, C = FormBuilderProps | FormBuilderProps[]> = {
children?: C;
props?: T;
configs?: Configs;
};
export type Generator<T, C = FormBuilderProps | FormBuilderProps[]> = (
props: GeneratorProps<T, C>
) => FormBuilderProps;
22 changes: 22 additions & 0 deletions packages/generator/src/utils/actionSubmit/actionSubmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { SubmitFieldProps } from 'packages/components/form/src/components/actions/submit/submit.types';

import { Generator } from '../../types/public.types';

import generateID from '../id/id';

const generateActionSubmit: Generator<SubmitFieldProps, string> = ({
props,
configs,
}) => {
return {
id: generateID(),
groupType: 'form',
type: 'action-submit',
props: {
...(props as SubmitFieldProps),
},
configs,
};
};

export default generateActionSubmit;
18 changes: 18 additions & 0 deletions packages/generator/src/utils/fieldText/fieldText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TextProps } from 'packages/components/form/src/components/fields/text/text.types';

import { Generator } from '../../types/public.types';

import generateID from '../id/id';

const generateFieldText: Generator<TextProps> = ({ props }) => {
return {
id: generateID(),
groupType: 'form',
type: 'field-text',
props: {
...props,
},
};
};

export default generateFieldText;
21 changes: 21 additions & 0 deletions packages/generator/src/utils/gridContainer/gridContainer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { GridProps } from '@mui-builder/grid';

import { Generator } from '../../types/public.types';

import generateID from '../id/id';

const generateGridContainer: Generator<GridProps> = ({ children, props }) => {
return {
id: generateID(),
groupType: 'grid',
type: 'container',
props: {
rowSpacing: 20,
columnSpacing: 20,
children,
...props,
},
};
};

export default generateGridContainer;
21 changes: 21 additions & 0 deletions packages/generator/src/utils/gridItem/gridItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { GridProps } from '@mui-builder/grid';

import { Generator } from '../../types/public.types';

import generateID from '../id/id';

const generateGridItem: Generator<GridProps> = ({ children, props }) => {
return {
id: generateID(),
groupType: 'grid',
type: 'container',
props: {
rowSpacing: 2,
columnSpacing: 2,
children,
...props,
},
};
};

export default generateGridItem;
12 changes: 12 additions & 0 deletions packages/generator/src/utils/id/id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function generateID(): string {
// Create a timestamp in milliseconds
const timestamp = new Date().getTime();

// Generate a random number based on the timestamp
const randomPart = Math.floor((Math.random() + 1) * timestamp);

// Convert to base-36 (numbers + letters), and get the substring to ensure a fixed length
return `${timestamp.toString(36)}-${randomPart.toString(36)}`;
}

export default generateID;
17 changes: 17 additions & 0 deletions packages/generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
],
"extends": "../../tsconfig.base.json"
}
24 changes: 24 additions & 0 deletions packages/generator/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": [
"node",

"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"exclude": [
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"paths": {
"@mui-builder/core": ["packages/core/src/index.ts"],
"@mui-builder/form": ["packages/components/form/src/index.ts"],
"@mui-builder/generator": ["packages/generator/src/index.ts"],
"@mui-builder/grid": ["packages/components/grid/src/index.ts"],
"@mui-builder/utils": ["packages/utils/src/index.ts"]
}
Expand Down
Loading