@apia/cli 4.0.16 → 4.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/cli.cjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const { program } = require('commander');
4
4
  const { spawn } = require('child_process');
@@ -42,7 +42,7 @@ program
42
42
  .command('compile')
43
43
  .argument('<component_name>', 'The name of the component to be compiled.')
44
44
  .description('Compiles the component into the OUT_DIR declared in the .env file.')
45
- .option('--watch', 'Starts the compiler in watch mode.') // Define the '--y' option
45
+ .option('--watch', 'Starts the compiler in watch mode.')
46
46
  .action(async (componentName, { watch }) => {
47
47
  const parsedName = componentName.charAt(0).toUpperCase() + componentName.slice(1)
48
48
  logger.info(`Compiling ${parsedName}`);
@@ -84,33 +84,43 @@ program
84
84
  .command('create')
85
85
  .argument('<component_name>', 'The name of the component to be created.')
86
86
  .description('Creates the boilerplate for the given component name.')
87
- .action((componentName) => {
88
- const parsedName = componentName.charAt(0).toUpperCase() + componentName.slice(1)
89
- const destinationFile = path.resolve(componentFolderResolver(parsedName), 'index.tsx');
90
- const sourcePath = path.resolve(__dirname, 'component_base.tsx');
91
-
92
- if (fs.existsSync(destinationFile)) {
93
- logger.error(`Already exists component with name "${parsedName}" in ${destinationFile}`);
87
+ .option('--extended', 'Creates a more advanced boilerplate that can be used as a tutorial like one.')
88
+ .action((componentName, { extended }) => {
89
+ const parsedName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
90
+ const snakeName = parsedName.split(/([A-Z][a-z0-9_-]+)/).filter(Boolean).map(c => c.toLowerCase()).join('_');
91
+
92
+ const destinationDir = componentFolderResolver(parsedName);
93
+ const destinationReact = path.resolve(destinationDir, 'index.tsx');
94
+ const destinationJava = path.resolve(destinationDir, 'component.java');
95
+ const reactComponent = path.resolve(__dirname, 'templates', extended ? 'component_extended.tsx' : 'component_base.tsx');
96
+ const javaComponent = path.resolve(__dirname, 'templates', extended ? 'component_extended.java' : 'component_base.java');
97
+
98
+ if (fs.existsSync(destinationReact)) {
99
+ logger.error(`Already exists component with name "${parsedName}" in ${destinationReact}`);
94
100
  process.exit(1);
95
101
  } else {
96
-
97
- const destinationDir = componentFolderResolver(parsedName);
98
102
  if (!fs.existsSync(destinationDir)) {
99
103
  fs.mkdirSync(destinationDir, { recursive: true })
100
104
  }
101
105
 
102
- if (!fs.existsSync(sourcePath)) {
106
+ if (!fs.existsSync(reactComponent) || !fs.existsSync(javaComponent)) {
103
107
  logger.internalE(`Cannot find the template file.`);
104
108
  process.exit(1);
105
109
  }
106
110
 
107
111
  // Read the content from the source file
108
- const content = fs.readFileSync(sourcePath, 'utf-8').replaceAll('__COMPONENT_NAME__', parsedName);
112
+ const reactContent = fs.readFileSync(reactComponent, 'utf-8')
113
+ .replaceAll('__COMPONENT_NAME__', parsedName)
114
+ .replaceAll('__COMPONENT_NAME_SNAKE__', snakeName);
115
+ const javaContent = fs.readFileSync(javaComponent, 'utf-8')
116
+ .replaceAll('__COMPONENT_NAME__', parsedName)
117
+ .replaceAll('__COMPONENT_NAME_SNAKE__', snakeName);
109
118
 
110
119
  // Write the content to the new file
111
- fs.writeFileSync(destinationFile, content);
120
+ fs.writeFileSync(destinationReact, reactContent);
121
+ fs.writeFileSync(destinationJava, javaContent);
112
122
 
113
- logger.success(`Plugin created at: ${destinationFile}`);
123
+ logger.success(`Plugin created at: ${destinationDir}`);
114
124
  }
115
125
  });
116
126
 
@@ -0,0 +1,38 @@
1
+ package test;
2
+
3
+ import com.dogma.busClass.BusClassException;
4
+ import com.dogma.busClass.FormsAPI;
5
+ import com.dogma.busClass.customComponent.AbstractCustomComponent;
6
+ import com.dogma.busClass.customComponent.CustomComponentAttribute;
7
+ import com.dogma.busClass.customComponent.CustomComponentData;
8
+ import com.dogma.busClass.customComponent.CustomComponentEvent;
9
+
10
+ /**
11
+ * This is a very basic custom component, used only as boilerplate.
12
+ *
13
+ * If you need a more advanced use case, use the <code>--extended</code> flag when calling
14
+ * <code>apia create <component_name> --extended</code>.
15
+ */
16
+ @CustomComponentData(
17
+ name = "__COMPONENT_NAME__",
18
+ title = "Contador de ejemplo",
19
+ description = "Componente contador de ejemplo")
20
+ public class __COMPONENT_NAME__ extends AbstractCustomComponent {
21
+
22
+ @CustomComponentEvent(name = "onChange")
23
+ public Event onChange;
24
+
25
+ @CustomComponentAttribute(name = "count", title = "Cuenta", description = "Atributo donde guardar la cuenta")
26
+ public Attribute count;
27
+
28
+ @Override
29
+ public String getComponentName() {
30
+ return "__COMPONENT_NAME__";
31
+ }
32
+
33
+ @Override
34
+ public void setValue(SetValuePayload payload) throws BusClassException {
35
+ super.setValue(payload);
36
+ onChange.fire();
37
+ }
38
+ }
@@ -0,0 +1,38 @@
1
+ import { FC } from 'react';
2
+ import { AbstractCustomComponent, Plugin } from '@apia/execution-react';
3
+ import { makeObservable, observable } from 'mobx';
4
+ import { observer } from 'mobx-react-lite';
5
+ import { Box, ThemeUICSSObject } from '@apia/theme';
6
+ import { SimpleButton } from '@apia/components';
7
+
8
+ const __COMPONENT_NAME__Styles: ThemeUICSSObject = {
9
+ '&.__COMPONENT_NAME_SNAKE__': {},
10
+ };
11
+
12
+ class __COMPONENT_NAME__ extends AbstractCustomComponent {
13
+ state = {
14
+ count: 0,
15
+ };
16
+
17
+ constructor() {
18
+ super();
19
+ makeObservable(this, { state: observable });
20
+ }
21
+
22
+ protected Component: FC = observer(() => {
23
+ return (
24
+ <Box className="__COMPONENT_NAME_SNAKE__" sx={__COMPONENT_NAME__Styles}>
25
+ <SimpleButton
26
+ disabled={this.isLoading}
27
+ onClick={() => {
28
+ this.setValue('count', this.getValue('count') + 1, 0);
29
+ }}
30
+ >
31
+ {this.getValue('count', 0)}
32
+ </SimpleButton>
33
+ </Box>
34
+ );
35
+ });
36
+ }
37
+
38
+ new Plugin('__COMPONENT_NAME__', __COMPONENT_NAME__);
@@ -0,0 +1,115 @@
1
+ package test;
2
+
3
+ import java.util.List;
4
+ import java.util.stream.Collectors;
5
+
6
+ import com.dogma.busClass.BusClassException;
7
+ import com.dogma.busClass.customComponent.AbstractCustomComponent;
8
+ import com.dogma.busClass.customComponent.CustomComponentAttribute;
9
+ import com.dogma.busClass.customComponent.CustomComponentData;
10
+ import com.dogma.busClass.customComponent.CustomComponentEvent;
11
+ import com.dogma.busClass.customComponent.CustomComponentProperty;
12
+ import com.dogma.busClass.object.Entity;
13
+ import com.google.gson.JsonArray;
14
+ import com.google.gson.JsonObject;
15
+
16
+ @CustomComponentData(
17
+ name = "__COMPONENT_NAME__",
18
+ title = "Selector de planes",
19
+ description = "Componente de demo que renderiza un selector de planes con checkbox para avanzado y comentario en textarea."
20
+ )
21
+ public class __COMPONENT_NAME__ extends AbstractCustomComponent {
22
+
23
+ @CustomComponentAttribute(name = "selectedPlan", title = "lblPlnSel", description = "lblPlnSel")
24
+ public Attribute selectedPlan;
25
+ @CustomComponentAttribute(name = "comment", title = "lblComment", description = "lblComment")
26
+ public Attribute comment;
27
+
28
+ @CustomComponentAttribute(
29
+ name = "planName",
30
+ title = "Nombre del plan",
31
+ description = "Atributo donde se guarda el nombre del plan",
32
+ serverOnly = true)
33
+ public Attribute planName;
34
+ @CustomComponentAttribute(
35
+ name = "planDescription",
36
+ title = "Desc del plan",
37
+ description = "Atributo donde se guarda la descripción del plan",
38
+ serverOnly = true)
39
+ public Attribute planDescription;
40
+ @CustomComponentAttribute(
41
+ name = "planPrice",
42
+ title = "Precio del plan",
43
+ description = "Atributo donde se guarda el precio del plan",
44
+ serverOnly = true)
45
+ public Attribute planPrice;
46
+
47
+ @CustomComponentProperty(
48
+ name = "entityName",
49
+ title = "lblEnt",
50
+ description = "Entidad desde la cual se van a leer los planes disponibles",
51
+ visualization = CustomComponentViewType.INPUT,
52
+ dataType = CustomComponentDataType.STRING)
53
+ public Property entityName;
54
+ @CustomComponentProperty(
55
+ name = "toggleAdvancedInfo",
56
+ title = "lblTogAdvInfo",
57
+ description = "lblTogAdvInfo",
58
+ visualization = CustomComponentViewType.CHECKBOX,
59
+ dataType = CustomComponentDataType.STRING)
60
+ public Property toggleAdvancedInfo;
61
+
62
+ @CustomComponentEvent(name = "onChange")
63
+ public Event onChange;
64
+
65
+ @Override
66
+ protected String getAdditionalState() throws BusClassException {
67
+ JsonObject o = new JsonObject();
68
+ JsonArray a = new JsonArray();
69
+ o.add("instances", a);
70
+
71
+ this.getApi().findEntities(entityName.getValue().toString(), null).stream().forEach(identifier -> {
72
+ try {
73
+ Entity inst = this.getApi()
74
+ .getEntity(entityName.getValue().toString(), identifier.getPrefix(), identifier.getNumber(),
75
+ identifier.getPostfix());
76
+
77
+ JsonObject instJson = new JsonObject();
78
+
79
+ instJson.addProperty("name", inst.getAttribute(planName.getAttName()).getValueAsString());
80
+ instJson.addProperty("description", inst.getAttribute(planDescription.getAttName()).getValueAsString());
81
+ instJson.addProperty("monthlyPrice", inst.getAttribute(planPrice.getAttName()).getValueAsString());
82
+
83
+ a.add(instJson);
84
+ } catch (BusClassException exception) {
85
+ exception.printStackTrace();
86
+ }
87
+ });
88
+
89
+ return o.toString();
90
+ }
91
+
92
+ @Override
93
+ public String[] getLabels() {
94
+ return new String[] { "monthlyPrice" };
95
+ }
96
+
97
+ @Override
98
+ public void setValue(SetValuePayload payload) throws BusClassException {
99
+ super.setValue(payload);
100
+
101
+ /**
102
+ * Solo se dispara el evento onChange si se setea el plan seleccionado.
103
+ *
104
+ * Este método `setValue` también se ejecuta al cambiar el valor de comentario en el textarea.
105
+ */
106
+ if ("selectedPlan".equals(payload.getAttName())) {
107
+ onChange.schedule();
108
+ }
109
+ }
110
+
111
+ @Override
112
+ public String getComponentName() {
113
+ return "__COMPONENT_NAME__";
114
+ }
115
+ }
@@ -0,0 +1,128 @@
1
+ import { FC } from 'react';
2
+ import { AbstractCustomComponent, Plugin } from '@apia/execution-react';
3
+ import { makeObservable, observable } from 'mobx';
4
+ import { observer } from 'mobx-react-lite';
5
+ import {
6
+ Box,
7
+ Heading,
8
+ Label,
9
+ responsive,
10
+ Textarea,
11
+ ThemeUICSSObject,
12
+ } from '@apia/theme';
13
+ import { Checkbox } from '@apia/components';
14
+ import { getLabel } from '@apia/util';
15
+
16
+ /**
17
+ * This file is a demonstration on how to use the different aspects of a CustomComponent.
18
+ */
19
+
20
+ const __COMPONENT_NAME__Styles: ThemeUICSSObject = {
21
+ '&.__COMPONENT_NAME_SNAKE__': {
22
+ display: 'flex',
23
+ flexDirection: 'column',
24
+ gap: 7,
25
+ p: 7,
26
+ border: '2px solid',
27
+ borderColor: 'palette.border.section',
28
+ borderRadius: 7,
29
+
30
+ '.plans': {
31
+ display: 'grid',
32
+ gridTemplateColumns: responsive({
33
+ 0: '1fr',
34
+ 3: '1fr 1fr 1fr',
35
+ }),
36
+ gap: 5,
37
+ },
38
+
39
+ '.plan': {
40
+ boxSizing: 'border-box',
41
+ border: '1px solid',
42
+ borderColor: 'palette.border.section',
43
+ borderRadius: 8,
44
+ p: 5,
45
+ display: 'flex',
46
+ flexDirection: 'column',
47
+ gap: 6,
48
+ },
49
+
50
+ '.plan__heading': {
51
+ fontWeight: 'bold',
52
+ },
53
+
54
+ '.plan__princing_wrapper': {
55
+ mt: 'auto',
56
+ whiteSpace: 'nowrap',
57
+ textAlign: 'right',
58
+ },
59
+
60
+ '.plan.selected': {
61
+ outline: '3px solid',
62
+ outlineColor: 'palette.primary.main',
63
+ },
64
+ },
65
+ };
66
+
67
+ class __COMPONENT_NAME__ extends AbstractCustomComponent {
68
+ state = {
69
+ count: 0,
70
+ };
71
+
72
+ constructor() {
73
+ super();
74
+ makeObservable(this, { state: observable });
75
+ }
76
+
77
+ protected Component: FC = observer(() => {
78
+ console.log(this.getStringValue('selectedPlan'));
79
+ return (
80
+ <Box className="__COMPONENT_NAME_SNAKE__" sx={__COMPONENT_NAME__Styles}>
81
+ <Heading as="h3">Selecciona un plan</Heading>
82
+ <Label>
83
+ <Checkbox
84
+ native
85
+ checked={this.getProperty('toggleAdvancedInfo')}
86
+ onChange={(ev) => {
87
+ this.setProperty('toggleAdvancedInfo', ev.target.checked);
88
+ }}
89
+ />
90
+ {getLabel('toggleAdvancedInfo').text}
91
+ </Label>
92
+ <Box className="plans">
93
+ {this.getAdditional<{
94
+ instances: {
95
+ name: string;
96
+ description: string;
97
+ monthlyPrice: string;
98
+ }[];
99
+ }>().instances.map((c) => (
100
+ <Box
101
+ className={`plan ${this.getStringValue('selectedPlan') === c.name ? 'selected' : ''}`}
102
+ key={c.name}
103
+ onClick={() => {
104
+ this.setStringValue('selectedPlan', c.name);
105
+ }}
106
+ >
107
+ <strong>{c.name}</strong>
108
+ {this.getProperty('toggleAdvancedInfo') && <p>{c.description}</p>}
109
+ <small>{c.monthlyPrice}</small>
110
+ </Box>
111
+ ))}
112
+ </Box>
113
+ <Heading as="h3">Deja un comentario</Heading>
114
+ <Textarea
115
+ value={this.getIntermediateString('comment')}
116
+ onChange={(ev) =>
117
+ this.setIntermediateStringValue('comment', ev.target.value)
118
+ }
119
+ onBlur={(ev) =>
120
+ this.confirmIntermediateString('comment', ev.target.value)
121
+ }
122
+ />
123
+ </Box>
124
+ );
125
+ });
126
+ }
127
+
128
+ new Plugin('__COMPONENT_NAME__', __COMPONENT_NAME__);
@@ -45,7 +45,9 @@ module.exports = (_, argv) => {
45
45
  '@apia/components': 'apiaComponents',
46
46
  '@apia/execution-react': 'execReact',
47
47
  '@apia/theme': 'apiaTheme',
48
+ '@apia/theme/jsx-runtime': 'jsxRuntime',
48
49
  '@apia/util': 'apiaUtil',
50
+ '@emotion/react': 'emotionReact',
49
51
  mobx: 'mobx',
50
52
  'mobx-react-lite': 'mobxReact'
51
53
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apia/cli",
3
- "version": "4.0.16",
3
+ "version": "4.0.17",
4
4
  "sideEffects": true,
5
5
  "author": "Alexis Leite <alexisleite@live.com>",
6
6
  "bin": {
@@ -14,8 +14,9 @@
14
14
  "access": "public",
15
15
  "registry": "https://registry.npmjs.org/"
16
16
  },
17
- "gitHead": "7c6a8c2281bfd78469eece56b7efaca115734db4",
17
+ "gitHead": "e1292a9ad0d1ba4792853f060935ba37b6f7a512",
18
18
  "devDependencies": {
19
- "ts-loader": "^9.5.2"
19
+ "ts-loader": "^9.5.2",
20
+ "wrapper-webpack-plugin": "^2.2.2"
20
21
  }
21
22
  }
@@ -1,59 +0,0 @@
1
- import { FC } from 'react';
2
- import { AbstractCustomComponent, Plugin } from '@apia/execution-react';
3
- import { makeObservable, observable } from 'mobx';
4
- import { SimpleButton } from '@apia/components';
5
- import { observer } from 'mobx-react-lite';
6
-
7
- /**
8
- * README:
9
- *
10
- * In order to run the following component, the declarations in the Java AbstractCustomComponent must include
11
- * an attribute named 'selectedPlan'.
12
- *
13
- * @example
14
- \@CustomComponentAttribute(name = "selectedPlan", title = "lblPlnSel", description = "lblPlnSel")
15
- public Attribute selectedPlan;
16
- */
17
-
18
- export default class __COMPONENT_NAME__ extends AbstractCustomComponent {
19
- state = {
20
- count: 0,
21
- };
22
-
23
- constructor() {
24
- super();
25
- makeObservable(this, { state: observable });
26
- }
27
-
28
- protected Component: FC = observer(() => {
29
- return (
30
- <>
31
- <Input
32
- value={this.getIntermediateString('selectedPlan')}
33
- onChange={(ev) =>
34
- this.setIntermediateStringValue('selectedPlan', ev.target.value)
35
- }
36
- onBlur={(ev: any) => {
37
- this.confirmIntermediateString('selectedPlan', ev.target.value);
38
- }}
39
- />
40
- <SimpleButton
41
- onClick={() => {
42
- this.state.count++;
43
- }}
44
- >
45
- Counter {this.state.count}
46
- </SimpleButton>
47
- <SimpleButton
48
- onClick={() => {
49
- this.state.count++;
50
- }}
51
- >
52
- Counter {this.state.count}
53
- </SimpleButton>
54
- </>
55
- );
56
- });
57
- }
58
-
59
- new Plugin('__COMPONENT_NAME__', __COMPONENT_NAME__);
package/dist/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { EventEmitter } from '@apia/util';
2
-
3
- declare global {
4
- interface Window {
5
- dispatchComponent: EventEmitter<{
6
- dispatch: any;
7
- ready: null;
8
- }>;
9
- }
10
- }
11
- declare class Plugin {
12
- constructor(name: string, fc: any);
13
- }
14
-
15
- export { Plugin };
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/dist/index.js DELETED
@@ -1,10 +0,0 @@
1
- class Plugin {
2
- constructor(name, fc) {
3
- window.dispatchComponent.on("ready", () => {
4
- window.dispatchComponent.emit("dispatch", { name, fc });
5
- });
6
- }
7
- }
8
-
9
- export { Plugin };
10
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/Plugin.ts"],"sourcesContent":["import { EventEmitter } from '@apia/util';\r\n\r\ndeclare global {\r\n interface Window {\r\n dispatchComponent: EventEmitter<{\r\n dispatch: any;\r\n ready: null;\r\n }>;\r\n }\r\n}\r\n\r\nexport class Plugin {\r\n constructor(name: string, fc: any) {\r\n window.dispatchComponent.on('ready', () => {\r\n window.dispatchComponent.emit('dispatch', { name, fc });\r\n });\r\n }\r\n}\r\n"],"names":[],"mappings":"AAWO,MAAM,MAAO,CAAA;AAAA,EAClB,WAAA,CAAY,MAAc,EAAS,EAAA;AACjC,IAAO,MAAA,CAAA,iBAAA,CAAkB,EAAG,CAAA,OAAA,EAAS,MAAM;AACzC,MAAA,MAAA,CAAO,kBAAkB,IAAK,CAAA,UAAA,EAAY,EAAE,IAAA,EAAM,IAAI,CAAA,CAAA;AAAA,KACvD,CAAA,CAAA;AAAA,GACH;AACF;;;;"}