From 98e28ef6a982490b462dedb2ae975a3f4c65d1f6 Mon Sep 17 00:00:00 2001 From: Willy Brauner Date: Wed, 7 Feb 2024 14:13:02 +0100 Subject: [PATCH] Remove DOM component from scaffolder --- .../scaffold-component/scaffold-component.js | 111 +++--------------- 1 file changed, 18 insertions(+), 93 deletions(-) diff --git a/cli/tasks/scaffold-component/scaffold-component.js b/cli/tasks/scaffold-component/scaffold-component.js index 093c827..36dac7b 100644 --- a/cli/tasks/scaffold-component/scaffold-component.js +++ b/cli/tasks/scaffold-component/scaffold-component.js @@ -51,44 +51,15 @@ const _reactComponentBuilder = async ({ }) } -/** - * DOM Component builder - */ -const _domComponentBuilder = async ({ - componentPath, - upperComponentName, - componentsTemplatesDir, - twigComponentPath, -}) => { - // scaffold component file - await createFile({ - templateFilePath: `${componentsTemplatesDir}/dom/component.ts.template`, - destinationFilePath: `${componentPath}/${upperComponentName}.ts`, - replaceExpressions: { upperComponentName }, - }) - // scaffold scss module - await createFile({ - templateFilePath: `${componentsTemplatesDir}/dom/component.scss.template`, - destinationFilePath: `${componentPath}/${upperComponentName}.scss`, - replaceExpressions: { upperComponentName }, - }) - // scaffold Twig - await createFile({ - templateFilePath: `${componentsTemplatesDir}/dom/component.twig.template`, - destinationFilePath: `${twigComponentPath}/${upperComponentName}.twig`, - replaceExpressions: { upperComponentName }, - }) -} - /** * @name index * @description Ask question and scaffold a component with a specific script template */ const _scaffoldComponent = ({ srcDir, - pComponentType, // dom | react componentCompatibleFolders, componentsTemplatesDir, + pComponentType, // react | ... }) => { return new Promise(async (resolve) => { // Get sub-folder @@ -104,36 +75,22 @@ const _scaffoldComponent = ({ componentName = answer.componentName }) - // formated name "lowerCase" + // formatted name "lowerCase" let lowerComponentName = changeCase.camelCase(componentName) - // formated name "UpperCase" + // formatted name "UpperCase" let upperComponentName = changeCase.pascalCase(componentName) // Base path of the component (no extension at the end here) let componentPath = `${srcDir}/${subFolder}/${lowerComponentName}` - let twigComponentPath = `${config.twigTemplates}/${subFolder}` log("component will be created here: componentPath", componentPath) // build REACT component - if (pComponentType === "react") { - await _reactComponentBuilder({ - subFolder, - upperComponentName, - componentPath, - componentCompatibleFolders, - componentsTemplatesDir, - }) - } - - // build DOM component - if (pComponentType === "dom") { - await _domComponentBuilder({ - upperComponentName, - componentPath, - twigComponentPath, - componentCompatibleFolders, - componentsTemplatesDir, - }) - } + await _reactComponentBuilder({ + subFolder, + upperComponentName, + componentPath, + componentCompatibleFolders, + componentsTemplatesDir, + }) // final log logs.done("Component created.") @@ -143,45 +100,13 @@ const _scaffoldComponent = ({ // ----------------------------------------------------------------------------- PUBLIC -const scaffoldComponent = () => { - const TYPES = [ - { - name: "React component", - exec: () => - _scaffoldComponent({ - pComponentType: "react", - componentCompatibleFolders: config.componentCompatibleFolders, - componentsTemplatesDir: config.componentsTemplatesDir, - srcDir: config.frontSrcDir, - }), - }, - { - name: "DOM component", - exec: () => - _scaffoldComponent({ - pComponentType: "dom", - componentCompatibleFolders: config.componentCompatibleFolders, - componentsTemplatesDir: config.componentsTemplatesDir, - srcDir: config.frontSrcDir, - }), - }, - ] - - let scaffolderTypes = TYPES.map((scaffolder) => scaffolder.name) - - // List available scaffolders to user - Inquirer.prompt({ - type: "list", - name: "type", - message: "What kind of component to create?", - choices: scaffolderTypes, - pageSize: 20, - }).then((answer) => { - // Get scaffolder index - const scaffolderIndex = scaffolderTypes.indexOf(answer.type) - // Start this scaffolder - TYPES[scaffolderIndex].exec() +(async ()=> +{ + await _scaffoldComponent({ + pComponentType: "react", + componentCompatibleFolders: config.componentCompatibleFolders, + componentsTemplatesDir: config.componentsTemplatesDir, + srcDir: config.frontSrcDir, }) -} -scaffoldComponent() +})()