From ff094f7c75201fd1ee565cdfb5ae44253dcbb849 Mon Sep 17 00:00:00 2001 From: bniwredyc Date: Sat, 6 May 2023 13:11:45 +0200 Subject: [PATCH] hygen component generator --- README.md | 5 +++++ _templates/component/new/component.ejs.t | 18 ++++++++++++++++++ _templates/component/new/index.ejs.t | 4 ++++ _templates/component/new/styles.ejs.t | 7 +++++++ .../context/new/{hello.ejs.t => context.ejs.t} | 0 5 files changed, 34 insertions(+) create mode 100644 _templates/component/new/component.ejs.t create mode 100644 _templates/component/new/index.ejs.t create mode 100644 _templates/component/new/styles.ejs.t rename _templates/context/new/{hello.ejs.t => context.ejs.t} (100%) diff --git a/README.md b/README.md index 838c472a..12c7733a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ npm run typecheck:watch ``` ## Code generation +generate new SolidJS component: +``` +npx hygen component new NewComponentName +``` + generate new SolidJS context: ``` npx hygen context new NewContextName diff --git a/_templates/component/new/component.ejs.t b/_templates/component/new/component.ejs.t new file mode 100644 index 00000000..6f6a7c04 --- /dev/null +++ b/_templates/component/new/component.ejs.t @@ -0,0 +1,18 @@ +--- +to: src/components/<%= h.changeCase.pascal(name) %>/<%= h.changeCase.pascal(name) %>.tsx +--- + +import { clsx } from 'clsx' +import styles from './<%= h.changeCase.pascal(name) %>.module.scss' + +type Props = { + class?: string +} + +export const <%= h.changeCase.pascal(name) %> = (props: Props) => { + return ( +
, props.class)}> + <%= h.changeCase.pascal(name) %> +
+ ) +} diff --git a/_templates/component/new/index.ejs.t b/_templates/component/new/index.ejs.t new file mode 100644 index 00000000..13e22de4 --- /dev/null +++ b/_templates/component/new/index.ejs.t @@ -0,0 +1,4 @@ +--- +to: src/components/<%= h.changeCase.pascal(name) %>/index.ts +--- +export { <%= h.changeCase.pascal(name) %> } from './<%= h.changeCase.pascal(name) %>' diff --git a/_templates/component/new/styles.ejs.t b/_templates/component/new/styles.ejs.t new file mode 100644 index 00000000..2a0ed70c --- /dev/null +++ b/_templates/component/new/styles.ejs.t @@ -0,0 +1,7 @@ +--- +to: src/components/<%= h.changeCase.pascal(name) %>/<%= h.changeCase.pascal(name) %>.module.scss +--- + +.<%= h.changeCase.pascal(name) %> { + display: block; +} diff --git a/_templates/context/new/hello.ejs.t b/_templates/context/new/context.ejs.t similarity index 100% rename from _templates/context/new/hello.ejs.t rename to _templates/context/new/context.ejs.t