diff --git a/.scaffolding/component.vsc-template.js b/.scaffolding/component.vsc-template.js new file mode 100644 index 0000000..9b074cc --- /dev/null +++ b/.scaffolding/component.vsc-template.js @@ -0,0 +1,152 @@ +(function Template() { + const toPascalCase = (str) => + str + .replace(/(?:^\w|[A-Z]|\b\w)/g, (fl) => fl.toUpperCase()) + .replace(/\W+/g, ''); + + const toCamelCase = (str) => + toPascalCase(str).replace(/^./, (firstLetter) => firstLetter.toLowerCase()); + + return { + userInputs: [ + { + title: 'Component page name', + argumentName: 'name', + defaultValue: 'Sample', + }, + ], + template: [ + { + type: 'folder', + name: (inputs) => `${toPascalCase(inputs.name)}`, + children: [ + { + type: 'file', + name: 'index.ts', + content: (inputs) => `import { ${toPascalCase( + inputs.name + )}, ${toPascalCase( + inputs.name + )}Props } from './${toCamelCase(inputs.name)}'; + +export { ${toPascalCase(inputs.name)} }; +export type { ${toPascalCase(inputs.name)}Props }; + `, + }, + { + type: 'file', + name: (inputs) => `${toCamelCase(inputs.name)}.tsx`, + content: ( + inputs + ) => `import { use${toPascalCase(inputs.name)}Hook } from './${toCamelCase(inputs.name)}.hook'; + +export interface ${toPascalCase(inputs.name)}Props { + data: string; +} + +export function ${toPascalCase(inputs.name)}(props: ${toPascalCase(inputs.name)}Props) { + const { data } = props; + + const { state } = use${toPascalCase(inputs.name)}Hook(props); + return ( +