Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to change between app mode and storybook app mode #29

Conversation

pablonortiz
Copy link
Contributor

LINK DE TICKET:

https://janiscommerce.atlassian.net/browse/JUIP-133

DESCRIPCIÓN DEL REQUERIMIENTO:

Se requiere contar con la posibilidad de intercambiar entre la app de React Native, para así poder testear los componentes de una manera más fácil, y también poder ingresar en modo storybook.

DESCRIPCIÓN DE LA SOLUCIÓN:

Se añadió la librería https://www.npmjs.com/package/react-native-config ya que la misma se necesita para poder leer las variables del entorno.

A su vez, se creó el script set-app-mode.js, el cuál se encarga de escribir en el archivo .env si la key LOAD_STORYBOOK estará en true o false. En este sentido, se modificó el package.json, estos fueron los cambios que se hicieron:

  • El comando npm run android fue modificado para levantar el modo app en Android.
  • El comando npm run ios fue modificado para levantar el modo app en iOS
  • Se añadió el comando storybook:android para levantar la app en modo Storybook en Android.
  • Se añadió el comando storybook:ios para levantar la app en modo Storybook en iOS.
  • Se modificó el comando npm run storybook, cambiándolo por npm run storybook-server, para evitar confusiones.

Finalmente, se modificó el archivo index.js para cargar Storybook o la App dependiendo de la variable del entorno.

CÓMO SE PUEDE PROBAR?

Corriendo los comandos mencionados anteriormente:
npm run android para correr el modo app y npm run storybook:android para correr el modo storybook.

Copy link

@dam788 dam788 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anda joya

index.js Outdated

const Component = __DEV__ ? Storybook : App;
const Component = Config.LOAD_STORYBOOK === 'true' ? Storybook : App;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOAD_STORYBOOK ya es un booleano, es redundante compararlo con true.
Deberia quedar asi
const Component = Config.LOAD_STORYBOOK ? Storybook : App;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WilliamSaya-lvl30 parece que es un booleano pero en realidad es un string, ya estuve buscando y no está soportado por la librería el parsearlo a booleano, habría que instalar una librería para hacerlo cómo muestran acá: lugg/react-native-config#49 (comment), pero mepa que no va porque lo vamos a usar ahí sólo

Copy link
Contributor

@christian97dd christian97dd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dejé unos comentarios, la idea es volar la librería de rn config

storybook: 1,
};

fs.writeFileSync('.env', `LOAD_STORYBOOK=${!!modes[mode]}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nico, para no depender de la librería de rn config, aca lo que te conviene hacer es crear un archivo que en vez de .env, se llame env.json, donde setees la key LOAD_STORYBOOK. Entonces cuando queres levantarla, la levantas desde ese archivo, como hacemos en las apps, fijate que al correr cada ambiente (beta, qa y master), setteamos un env json distinto.
y acordate tambien de agregarlo al gitignore, cosa de que no se suba el archivo

@@ -1,4 +1,5 @@
apply plugin: "com.android.application"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aca deberías de volar esta linea

index.js Outdated
@@ -4,7 +4,8 @@ import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import Storybook from './storybook';
import Config from 'react-native-config';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aca es donde te importas la key que vos necesitas, pero de env.json

.env Outdated
@@ -0,0 +1 @@
LOAD_STORYBOOK=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

este archivo de .env, vuela

.gitignore Outdated

# .env
.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aca sería meter al env.json

@coveralls
Copy link

coveralls commented Nov 29, 2023

Pull Request Test Coverage Report for Build 7033399034

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 6798700218: 0.0%
Covered Lines: 350
Relevant Lines: 350

💛 - Coveralls

@pablonortiz
Copy link
Contributor Author

@christian97dd ahí hice los cambios

@christian97dd christian97dd merged commit 1c62a61 into master Dec 5, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants