From e13e630cd6e4fc0b1ff92098a28a770794c7bb9a Mon Sep 17 00:00:00 2001
From: gabrhr <73925454+gabrhr@users.noreply.github.com>
Date: Wed, 20 Apr 2022 10:19:29 -0500
Subject: =?UTF-8?q?A=C3=B1adir=20plantilla?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Base para front
---
 .../internals/generators/component/class.js.hbs    |  31 ++++++
 .../internals/generators/component/index.js        | 109 +++++++++++++++++++++
 .../internals/generators/component/loadable.js.hbs |  12 +++
 .../internals/generators/component/messages.js.hbs |  14 +++
 .../generators/component/stateless.js.hbs          |  28 ++++++
 .../internals/generators/component/test.js.hbs     |  10 ++
 6 files changed, 204 insertions(+)
 create mode 100644 front/odiparpack/internals/generators/component/class.js.hbs
 create mode 100644 front/odiparpack/internals/generators/component/index.js
 create mode 100644 front/odiparpack/internals/generators/component/loadable.js.hbs
 create mode 100644 front/odiparpack/internals/generators/component/messages.js.hbs
 create mode 100644 front/odiparpack/internals/generators/component/stateless.js.hbs
 create mode 100644 front/odiparpack/internals/generators/component/test.js.hbs
(limited to 'front/odiparpack/internals/generators/component')
diff --git a/front/odiparpack/internals/generators/component/class.js.hbs b/front/odiparpack/internals/generators/component/class.js.hbs
new file mode 100644
index 0000000..310239a
--- /dev/null
+++ b/front/odiparpack/internals/generators/component/class.js.hbs
@@ -0,0 +1,31 @@
+/**
+ *
+ * {{ properCase name }}
+ *
+ */
+
+import React from 'react';
+// import PropTypes from 'prop-types';
+// import styled from 'styled-components';
+
+{{#if wantMessages}}
+import { FormattedMessage } from 'react-intl';
+import messages from './messages';
+{{/if}}
+
+/* eslint-disable react/prefer-stateless-function */
+class {{ properCase name }} extends {{{ type }}} {
+  render() {
+    return (
+      
+      {{#if wantMessages}}
+        
+      {{/if}}
+      
+    );
+  }
+}
+
+{{ properCase name }}.propTypes = {};
+
+export default {{ properCase name }};
diff --git a/front/odiparpack/internals/generators/component/index.js b/front/odiparpack/internals/generators/component/index.js
new file mode 100644
index 0000000..4ac51d9
--- /dev/null
+++ b/front/odiparpack/internals/generators/component/index.js
@@ -0,0 +1,109 @@
+/**
+ * Component Generator
+ */
+
+/* eslint strict: ["off"] */
+
+'use strict';
+
+const componentExists = require('../utils/componentExists');
+
+module.exports = {
+  description: 'Add an unconnected component',
+  prompts: [
+    {
+      type: 'list',
+      name: 'type',
+      message: 'Select the type of component',
+      default: 'Stateless Function',
+      choices: () => [
+        'Stateless Function',
+        'React.PureComponent',
+        'React.Component',
+      ],
+    },
+    {
+      type: 'input',
+      name: 'name',
+      message: 'What should it be called?',
+      default: 'Button',
+      validate: value => {
+        if (/.+/.test(value)) {
+          return componentExists(value)
+            ? 'A component or container with this name already exists'
+            : true;
+        }
+
+        return 'The name is required';
+      },
+    },
+    {
+      type: 'confirm',
+      name: 'wantMessages',
+      default: true,
+      message: 'Do you want i18n messages (i.e. will this component use text)?',
+    },
+    {
+      type: 'confirm',
+      name: 'wantLoadable',
+      default: false,
+      message: 'Do you want to load the component asynchronously?',
+    },
+  ],
+  actions: data => {
+    // Generate index.js and index.test.js
+    let componentTemplate;
+
+    switch (data.type) {
+      case 'Stateless Function': {
+        componentTemplate = './component/stateless.js.hbs';
+        break;
+      }
+      default: {
+        componentTemplate = './component/class.js.hbs';
+      }
+    }
+
+    const actions = [
+      {
+        type: 'add',
+        path: '../../app/components/{{properCase name}}/index.js',
+        templateFile: componentTemplate,
+        abortOnFail: true,
+      },
+      {
+        type: 'add',
+        path: '../../app/components/{{properCase name}}/tests/index.test.js',
+        templateFile: './component/test.js.hbs',
+        abortOnFail: true,
+      },
+    ];
+
+    // If they want a i18n messages file
+    if (data.wantMessages) {
+      actions.push({
+        type: 'add',
+        path: '../../app/components/{{properCase name}}/messages.js',
+        templateFile: './component/messages.js.hbs',
+        abortOnFail: true,
+      });
+    }
+
+    // If want Loadable.js to load the component asynchronously
+    if (data.wantLoadable) {
+      actions.push({
+        type: 'add',
+        path: '../../app/components/{{properCase name}}/Loadable.js',
+        templateFile: './component/loadable.js.hbs',
+        abortOnFail: true,
+      });
+    }
+
+    actions.push({
+      type: 'prettify',
+      path: '/components/',
+    });
+
+    return actions;
+  },
+};
diff --git a/front/odiparpack/internals/generators/component/loadable.js.hbs b/front/odiparpack/internals/generators/component/loadable.js.hbs
new file mode 100644
index 0000000..889bbf6
--- /dev/null
+++ b/front/odiparpack/internals/generators/component/loadable.js.hbs
@@ -0,0 +1,12 @@
+/**
+ *
+ * Asynchronously loads the component for {{ properCase name }}
+ *
+ */
+
+import Loadable from 'react-loadable';
+
+export default Loadable({
+  loader: () => import('./index'),
+  loading: () => null,
+});
diff --git a/front/odiparpack/internals/generators/component/messages.js.hbs b/front/odiparpack/internals/generators/component/messages.js.hbs
new file mode 100644
index 0000000..f73ee90
--- /dev/null
+++ b/front/odiparpack/internals/generators/component/messages.js.hbs
@@ -0,0 +1,14 @@
+/*
+ * {{ properCase name }} Messages
+ *
+ * This contains all the text for the {{ properCase name }} component.
+ */
+
+import { defineMessages } from 'react-intl';
+
+export default defineMessages({
+  header: {
+    id: 'app.components.{{ properCase name }}.header',
+    defaultMessage: 'This is the {{ properCase name}} component !',
+  },
+});
diff --git a/front/odiparpack/internals/generators/component/stateless.js.hbs b/front/odiparpack/internals/generators/component/stateless.js.hbs
new file mode 100644
index 0000000..04ba918
--- /dev/null
+++ b/front/odiparpack/internals/generators/component/stateless.js.hbs
@@ -0,0 +1,28 @@
+/**
+ *
+ * {{ properCase name }}
+ *
+ */
+
+import React from 'react';
+// import PropTypes from 'prop-types';
+// import styled from 'styled-components';
+
+{{#if wantMessages}}
+import { FormattedMessage } from 'react-intl';
+import messages from './messages';
+{{/if}}
+
+function {{ properCase name }}() {
+  return (
+    
+    {{#if wantMessages}}
+      
+    {{/if}}
+    
+  );
+}
+
+{{ properCase name }}.propTypes = {};
+
+export default {{ properCase name }};
diff --git a/front/odiparpack/internals/generators/component/test.js.hbs b/front/odiparpack/internals/generators/component/test.js.hbs
new file mode 100644
index 0000000..42c0e37
--- /dev/null
+++ b/front/odiparpack/internals/generators/component/test.js.hbs
@@ -0,0 +1,10 @@
+// import React from 'react';
+// import { shallow } from 'enzyme';
+
+// import {{ properCase name }} from '../index';
+
+describe('<{{ properCase name }} />', () => {
+  it('Expect to have unit tests specified', () => {
+    expect(true).toEqual(false);
+  });
+});
-- 
cgit v1.2.3