Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add component generator

dominik-zeglen921a7a3b115c
diff --git a/.plop/component/componentName.class.tsx.hbs b/.plop/component/componentName.class.tsx.hbs
new file mode 100644
index 0000000000..860ddb485e
--- /dev/null
+++ b/.plop/component/componentName.class.tsx.hbs
@@ -0,0 +1,45 @@
+{{#if styled}}
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+{{/if}}
+import * as React from "react";
+
+export interface {{ name }}Props {
+
+}
+interface {{ name }}State {
+
+}
+
+{{#if styled}}
+const styles = (theme: Theme) => createStyles({
+
+});
+const {{ name }} = withStyles(styles, { name: "{{ name }}" })(
+ class Inner{{ name }} extends React.Component<{{ name }}Props, {{ name }}State> {
+ state: {{ name }}State = {
+
+ }
+
+ render() {
+
+ }
+ }
+);
+{{else}}
+class {{ name }} extends React.Component<{{ name }}Props, {{ name }}State> {
+ state: {{ name }}State = {
+
+ }
+
+ render() {
+
+ }
+}
+{{/if}}
+{{ name }}.displayName = "{{ name }}";
+export default {{ name }};
diff --git a/.plop/component/componentName.fc.tsx.hbs b/.plop/component/componentName.fc.tsx.hbs
new file mode 100644
index 0000000000..1ed50cb245
--- /dev/null
+++ b/.plop/component/componentName.fc.tsx.hbs
@@ -0,0 +1,26 @@
+{{#if styled}}
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+{{/if}}
+import * as React from "react";
+
+export interface {{ name }}Props {
+
+}
+
+{{#if styled}}
+const styles = (theme: Theme) => createStyles({
+
+});
+const {{ name }} = withStyles(styles, { name: "{{ name }}" })(
+ ({ classes }: {{ name }}Props & WithStyles<typeof styles>) => <div />
+);
+{{else}}
+const {{ name }}: React.StatelessComponent<{{ name }}Props> = () => <div />;
+{{/if}}
+{{ name }}.displayName = "{{ name }}";
+export default {{ name }};
diff --git a/.plop/component/componentName.story.tsx.hbs b/.plop/component/componentName.story.tsx.hbs
new file mode 100644
index 0000000000..0f7e0c0ea9
--- /dev/null
+++ b/.plop/component/componentName.story.tsx.hbs
@@ -0,0 +1,15 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import {{ name }}, {
+ {{ name }}Props
+} from "../../../{{ section }}/components/{{ name }}";
+import Decorator from "../../Decorator";
+
+const props: {{ name }}Props = {
+
+};
+
+storiesOf("{{ sentenceCase section }} / {{ name }}", module)
+ .addDecorator(Decorator)
+ .add("default", () => <{{ name }} {...props} />);
diff --git a/.plop/component/index.ts.hbs b/.plop/component/index.ts.hbs
new file mode 100644
index 0000000000..2c10773b73
--- /dev/null
+++ b/.plop/component/index.ts.hbs
@@ -0,0 +1,2 @@
+export { default } from './{{ name }}';
+export * from './{{ name }}';
\ No newline at end of file
diff --git a/.plop/plopfile.js b/.plop/plopfile.js
new file mode 100644
index 0000000000..454357d9db
--- /dev/null
+++ b/.plop/plopfile.js
@@ -0,0 +1,68 @@
+const ROOT = "../saleor/static/dashboard-next";
+
+const componentGeneratorConfig = {
+ description: "New component",
+ prompts: [
+ {
+ type: "input",
+ name: "name",
+ message: "Name"
+ },
+ {
+ type: "input",
+ name: "section",
+ message: "Section"
+ },
+ {
+ type: "confirm",
+ name: "fc",
+ message: "Is it a functional component?",
+ default: "y"
+ },
+ {
+ type: "confirm",
+ name: "styled",
+ message: "Is it a styled component?",
+ default: "y"
+ },
+ {
+ type: "confirm",
+ name: "story",
+ message: "Create story?",
+ default: "y"
+ }
+ ],
+ actions: ({ fc, story }) => {
+ const actions = [
+ {
+ type: "add",
+ path: `${ROOT}/{{ section }}/{{ name }}/index.ts`,
+ templateFile: './component/index.ts.hbs',
+ abortOnFail: true
+ },
+ {
+ type: "add",
+ path: `${ROOT}/{{ section }}/{{ name }}/{{ name }}.tsx`,
+ templateFile: fc
+ ? "./component/componentName.fc.tsx.hbs"
+ : "./component/componentName.class.tsx.hbs",
+ abortOnFail: true
+ },
+ ];
+
+ if (story) {
+ actions.push({
+ type: "add",
+ path: `${ROOT}/storybook/stories/{{ section }}/{{ name }}.tsx`,
+ templateFile: "./component/componentName.story.tsx.hbs",
+ abortOnFail: true
+ });
+ }
+
+ return actions;
+ }
+};
+
+module.exports = plop => {
+ plop.setGenerator('component', componentGeneratorConfig);
+};