@nx/react-native 18.0.0-beta.1 → 18.0.0-beta.2

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.
Files changed (161) hide show
  1. package/.eslintrc.json +6 -1
  2. package/executors.json +5 -0
  3. package/generators.json +12 -11
  4. package/migrations.json +73 -1
  5. package/package.json +10 -15
  6. package/plugins/metro-resolver.js +4 -1
  7. package/plugins/plugin.d.ts +2 -0
  8. package/plugins/plugin.js +12 -1
  9. package/plugins/with-nx-metro.js +6 -2
  10. package/src/executors/build-android/build-android.impl.js +1 -5
  11. package/src/executors/build-android/build-android.impl.ts +1 -5
  12. package/src/executors/bundle/schema.d.ts +1 -1
  13. package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
  14. package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
  15. package/src/executors/ensure-symlink/ensure-symlink.impl.ts +4 -0
  16. package/src/executors/run-android/run-android.impl.js +4 -16
  17. package/src/executors/run-android/run-android.impl.ts +8 -17
  18. package/src/executors/run-ios/run-ios.impl.js +4 -16
  19. package/src/executors/run-ios/run-ios.impl.ts +9 -18
  20. package/src/executors/start/schema.d.ts +1 -1
  21. package/src/executors/start/start.impl.js +11 -26
  22. package/src/executors/start/start.impl.ts +14 -28
  23. package/src/executors/storybook/storybook.impl.d.ts +4 -0
  24. package/src/executors/storybook/storybook.impl.js +8 -1
  25. package/src/executors/storybook/storybook.impl.ts +16 -5
  26. package/src/executors/sync-deps/sync-deps.impl.d.ts +3 -2
  27. package/src/executors/sync-deps/sync-deps.impl.js +28 -11
  28. package/src/executors/sync-deps/sync-deps.impl.ts +45 -19
  29. package/src/executors/upgrade/schema.d.ts +1 -0
  30. package/src/executors/upgrade/schema.json +11 -0
  31. package/src/executors/upgrade/upgrade.impl.d.ts +13 -0
  32. package/src/executors/upgrade/upgrade.impl.js +47 -0
  33. package/src/executors/upgrade/upgrade.impl.ts +64 -0
  34. package/src/generators/application/application.js +27 -8
  35. package/src/generators/application/application.spec.ts +29 -2
  36. package/src/generators/application/files/app/.babelrc.js.template +23 -0
  37. package/src/generators/application/files/app/android/app/build.gradle.template +12 -28
  38. package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +2 -6
  39. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +22 -0
  40. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +45 -0
  41. package/src/generators/application/files/app/android/build.gradle.template +7 -20
  42. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  43. package/src/generators/application/files/app/android/gradle.properties +0 -3
  44. package/src/generators/application/files/app/android/gradlew.template +12 -7
  45. package/src/generators/application/files/app/android/settings.gradle.template +2 -2
  46. package/src/generators/application/files/app/ios/Podfile.template +0 -7
  47. package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +5 -0
  48. package/src/generators/application/files/app/ios/__className__/Info.plist.template +5 -8
  49. package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +11 -33
  50. package/src/generators/application/files/app/metro.config.js.template +0 -4
  51. package/src/generators/application/files/app/src/app/App.tsx.template +29 -2
  52. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  53. package/src/generators/application/lib/add-e2e.js +47 -0
  54. package/src/generators/application/lib/add-project.js +13 -17
  55. package/src/generators/application/lib/normalize-options.d.ts +4 -0
  56. package/src/generators/application/lib/normalize-options.js +9 -3
  57. package/src/generators/application/lib/normalize-options.spec.ts +53 -5
  58. package/src/generators/application/schema.d.ts +5 -3
  59. package/src/generators/application/schema.json +13 -5
  60. package/src/generators/component-story/component-story.d.ts +5 -8
  61. package/src/generators/component-story/component-story.js +8 -69
  62. package/src/generators/component-story/schema.d.ts +1 -0
  63. package/src/generators/component-story/schema.json +10 -2
  64. package/src/generators/init/init.d.ts +1 -0
  65. package/src/generators/init/init.js +14 -7
  66. package/src/generators/init/init.spec.ts +6 -2
  67. package/src/generators/init/schema.d.ts +1 -0
  68. package/src/generators/library/files/lib/.babelrc.js.template +21 -0
  69. package/src/generators/library/lib/normalize-options.js +1 -0
  70. package/src/generators/library/library.js +2 -1
  71. package/src/generators/library/library.spec.ts +12 -41
  72. package/src/generators/library/schema.d.ts +1 -0
  73. package/src/generators/library/schema.json +1 -1
  74. package/src/generators/stories/schema.d.ts +2 -0
  75. package/src/generators/stories/schema.json +14 -1
  76. package/src/generators/stories/stories.d.ts +5 -2
  77. package/src/generators/stories/stories.js +7 -50
  78. package/src/generators/storybook-configuration/configuration.d.ts +7 -2
  79. package/src/generators/storybook-configuration/configuration.js +15 -48
  80. package/src/generators/storybook-configuration/schema.d.ts +4 -2
  81. package/src/generators/storybook-configuration/schema.json +21 -11
  82. package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
  83. package/src/generators/upgrade-native/schema.d.ts +1 -1
  84. package/src/generators/upgrade-native/schema.json +2 -2
  85. package/src/generators/upgrade-native/upgrade-native.d.ts +2 -0
  86. package/src/generators/upgrade-native/upgrade-native.js +3 -0
  87. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +23 -0
  88. package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +15 -0
  89. package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
  90. package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
  91. package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +9 -0
  92. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +82 -0
  93. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +23 -0
  94. package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
  95. package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
  96. package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +14 -0
  97. package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +9 -0
  98. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +77 -0
  99. package/src/generators/web-configuration/lib/normalize-schema.d.ts +17 -0
  100. package/src/generators/web-configuration/lib/normalize-schema.js +16 -0
  101. package/src/generators/web-configuration/lib/webpack-targets.d.ts +7 -0
  102. package/src/generators/web-configuration/lib/webpack-targets.js +75 -0
  103. package/src/generators/web-configuration/schema.d.ts +6 -0
  104. package/src/generators/web-configuration/schema.json +42 -0
  105. package/src/generators/web-configuration/web-configuration.d.ts +12 -0
  106. package/src/generators/web-configuration/web-configuration.js +85 -0
  107. package/src/migrations/update-16-6-0/update-metro-config.js +0 -4
  108. package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
  109. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +6 -0
  110. package/src/migrations/update-18-0-0/add-upgrade-target.js +33 -0
  111. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +8 -0
  112. package/src/migrations/update-18-0-0/add-web-configuration.js +33 -0
  113. package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +39 -0
  114. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +5 -0
  115. package/src/migrations/update-18-0-0/change-storybook-targets.js +57 -0
  116. package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
  117. package/src/migrations/update-18-0-0/remove-block-list.js +26 -0
  118. package/src/migrations/update-18-0-0/remove-block-list.spec.ts +68 -0
  119. package/src/migrations/update-18-0-0/remove-metro.d.ts +14 -0
  120. package/src/migrations/update-18-0-0/remove-metro.js +29 -0
  121. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
  122. package/src/migrations/update-18-0-0/remove-symlink-target.js +30 -0
  123. package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +40 -0
  124. package/src/utils/add-jest.d.ts +1 -1
  125. package/src/utils/add-jest.js +13 -1
  126. package/src/utils/add-linting.d.ts +1 -0
  127. package/src/utils/add-linting.js +1 -0
  128. package/src/utils/add-linting.spec.ts +2 -4
  129. package/src/utils/ensure-dependencies.js +2 -6
  130. package/src/utils/testing-generators.js +1 -0
  131. package/src/utils/versions.d.ts +9 -12
  132. package/src/utils/versions.js +10 -13
  133. package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -75
  134. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +0 -32
  135. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +0 -62
  136. package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -20
  137. package/src/generators/application/files/app/babel.config.json.template +0 -10
  138. package/src/generators/application/lib/add-detox.d.ts +0 -3
  139. package/src/generators/application/lib/add-detox.js +0 -23
  140. package/src/generators/component-story/component-story.spec.ts +0 -427
  141. package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +0 -32
  142. package/src/generators/library/files/lib/babel.config.json.template +0 -19
  143. package/src/generators/stories/stories-app.spec.ts +0 -128
  144. package/src/generators/stories/stories-lib.spec.ts +0 -105
  145. package/src/generators/storybook-configuration/configuration.spec.ts +0 -135
  146. package/src/generators/storybook-configuration/files/app/storybook.ts.template +0 -9
  147. package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +0 -74
  148. package/src/generators/storybook-configuration/files/root/story-loader.ts.template +0 -5
  149. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +0 -6
  150. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +0 -25
  151. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +0 -161
  152. package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +0 -6
  153. package/src/generators/storybook-configuration/lib/create-storybook-files.js +0 -42
  154. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +0 -7
  155. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +0 -29
  156. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +0 -65
  157. package/src/utils/find-all-npm-dependencies.d.ts +0 -2
  158. package/src/utils/find-all-npm-dependencies.js +0 -25
  159. package/src/utils/find-all-npm-dependencies.spec.ts +0 -95
  160. package/src/utils/symlink-task.d.ts +0 -2
  161. package/src/utils/symlink-task.js +0 -18
@@ -1,427 +0,0 @@
1
- import { getProjects, Tree, updateProjectConfiguration } from '@nx/devkit';
2
- import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
3
- import componentStoryGenerator from './component-story';
4
- import { Linter } from '@nx/eslint';
5
-
6
- import { formatFile } from '../../utils/format-file';
7
- import libraryGenerator from '../library/library';
8
- import componentGenerator from '../component/component';
9
-
10
- describe('react-native:component-story', () => {
11
- let appTree: Tree;
12
- let cmpPath = 'test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx';
13
- let storyFilePath = 'test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx';
14
-
15
- describe('default setup', () => {
16
- beforeEach(async () => {
17
- appTree = await createTestUILib('test-ui-lib');
18
- });
19
-
20
- describe('when file does not contain a component', () => {
21
- beforeEach(() => {
22
- appTree.write(
23
- cmpPath,
24
- `export const add = (a: number, b: number) => a + b;`
25
- );
26
- });
27
-
28
- it('should fail with a descriptive error message', async () => {
29
- try {
30
- await componentStoryGenerator(appTree, {
31
- componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
32
- project: 'test-ui-lib',
33
- });
34
- } catch (e) {
35
- expect(e.message).toContain(
36
- 'Could not find any React Native component in file test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx'
37
- );
38
- }
39
- });
40
- });
41
-
42
- describe('default component setup', () => {
43
- beforeEach(async () => {
44
- await componentStoryGenerator(appTree, {
45
- componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
46
- project: 'test-ui-lib',
47
- });
48
- });
49
-
50
- it('should create the story file', () => {
51
- expect(appTree.exists(storyFilePath)).toBeTruthy();
52
- });
53
-
54
- it('should properly set up the story', () => {
55
- expect(
56
- formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
57
- ).toContain(formatFile`
58
- import type { Meta } from '@storybook/react-native';
59
- import { TestUiLib } from './test-ui-lib';
60
- const Story: Meta<typeof TestUiLib> = {
61
- component: TestUiLib,
62
- title: 'TestUiLib',
63
- };
64
- export default Story;
65
- export const Primary = { args: {} };
66
- `);
67
- });
68
- });
69
-
70
- describe('when using plain JS components', () => {
71
- let storyFilePathPlain =
72
- 'test-ui-lib/src/lib/test-ui-libplain.stories.jsx';
73
-
74
- beforeEach(async () => {
75
- appTree.write(
76
- 'test-ui-lib/src/lib/test-ui-libplain.jsx',
77
- `import React from 'react';
78
-
79
- import './test.scss';
80
-
81
- export const Test = () => {
82
- return (
83
- <div>
84
- <h1>Welcome to test component</h1>
85
- </div>
86
- );
87
- };
88
-
89
- export default Test;
90
- `
91
- );
92
-
93
- await componentStoryGenerator(appTree, {
94
- componentPath: 'lib/test-ui-libplain.jsx',
95
- project: 'test-ui-lib',
96
- });
97
- });
98
-
99
- it('should create the story file', () => {
100
- expect(appTree.exists(storyFilePathPlain)).toBeTruthy();
101
- });
102
-
103
- it('should properly set up the story', () => {
104
- expect(formatFile`${appTree.read(storyFilePathPlain, 'utf-8')}`)
105
- .toContain(formatFile`
106
- import Test from './test-ui-libplain';
107
- export default { component: Test, title: 'Test' };
108
- export const Primary = { args: {} };
109
- `);
110
- });
111
- });
112
-
113
- describe('component without any props defined', () => {
114
- beforeEach(async () => {
115
- appTree.write(
116
- cmpPath,
117
- `import React from 'react';
118
-
119
- import { View, Text } from 'react-native';
120
-
121
- export function Test() {
122
- return (
123
- <View>
124
- <Text>Welcome to test!</Text>
125
- </View>
126
- );
127
- }
128
-
129
- export default Test;
130
- `
131
- );
132
- await componentStoryGenerator(appTree, {
133
- componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
134
- project: 'test-ui-lib',
135
- });
136
- });
137
-
138
- it('should create a story without controls', () => {
139
- expect(formatFile`${appTree.read(storyFilePath, 'utf-8')}`)
140
- .toContain(formatFile`
141
- import type { Meta } from '@storybook/react-native';
142
- import { Test } from './test-ui-lib';
143
- const Story: Meta<typeof Test> = { component: Test, title: 'Test' };
144
- export default Story;
145
- export const Primary = { args: {} };
146
- `);
147
- });
148
- });
149
-
150
- describe('component with props', () => {
151
- beforeEach(async () => {
152
- await componentStoryGenerator(appTree, {
153
- componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
154
- project: 'test-ui-lib',
155
- });
156
- });
157
-
158
- it('should setup controls based on the component props', () => {
159
- expect(
160
- formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
161
- ).toContain(formatFile`
162
- import type { Meta } from '@storybook/react-native';
163
- import { TestUiLib } from './test-ui-lib';
164
- const Story: Meta<typeof TestUiLib> = {
165
- component: TestUiLib,
166
- title: 'TestUiLib',
167
- };
168
- export default Story;
169
- export const Primary = { args: {} };
170
- `);
171
- });
172
- });
173
-
174
- describe('component with props and actions', () => {
175
- beforeEach(async () => {
176
- appTree.write(
177
- cmpPath,
178
- `import React from 'react';
179
-
180
- export type ButtonStyle = 'default' | 'primary' | 'warning';
181
-
182
- export interface TestProps {
183
- name: string;
184
- displayAge: boolean;
185
- someAction: (e: unknown) => void;
186
- style: ButtonStyle;
187
- }
188
-
189
- export const Test = (props: TestProps) => {
190
- return (
191
- <div>
192
- <h1>Welcome to test component, {props.name}</h1>
193
- <button onClick={props.someAction}>Click me!</button>
194
- </div>
195
- );
196
- };
197
-
198
- export default Test;
199
- `
200
- );
201
-
202
- await componentStoryGenerator(appTree, {
203
- componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
204
- project: 'test-ui-lib',
205
- });
206
- });
207
-
208
- it('should setup controls based on the component props', () => {
209
- expect(
210
- formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
211
- ).toContain(formatFile`
212
- import type { Meta } from '@storybook/react-native';
213
- import { Test } from './test-ui-lib';
214
- const Story: Meta<typeof Test> = {
215
- component: Test,
216
- title: 'Test',
217
- argTypes: { someAction: { action: 'someAction executed!' } },
218
- };
219
- export default Story;
220
- export const Primary = { args: { name: '', displayAge: false } };
221
- `);
222
- });
223
- });
224
-
225
- [
226
- {
227
- name: 'default export function',
228
- src: `export default function Test(props: TestProps) {
229
- return (
230
- <div>
231
- <h1>Welcome to test component, {props.name}</h1>
232
- </div>
233
- );
234
- };
235
- `,
236
- },
237
- {
238
- name: 'function and then export',
239
- src: `
240
- function Test(props: TestProps) {
241
- return (
242
- <div>
243
- <h1>Welcome to test component, {props.name}</h1>
244
- </div>
245
- );
246
- };
247
- export default Test;
248
- `,
249
- },
250
- {
251
- name: 'arrow function',
252
- src: `
253
- const Test = (props: TestProps) => {
254
- return (
255
- <div>
256
- <h1>Welcome to test component, {props.name}</h1>
257
- </div>
258
- );
259
- };
260
- export default Test;
261
- `,
262
- },
263
- {
264
- name: 'arrow function without {..}',
265
- src: `
266
- const Test = (props: TestProps) => <div><h1>Welcome to test component, {props.name}</h1></div>;
267
- export default Test
268
- `,
269
- },
270
- {
271
- name: 'direct export of component class',
272
- src: `
273
- export default class Test extends React.Component<TestProps> {
274
- render() {
275
- return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
276
- }
277
- }
278
- `,
279
- },
280
- {
281
- name: 'component class & then default export',
282
- src: `
283
- class Test extends React.Component<TestProps> {
284
- render() {
285
- return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
286
- }
287
- }
288
- export default Test
289
- `,
290
- },
291
- {
292
- name: 'PureComponent class & then default export',
293
- src: `
294
- class Test extends React.PureComponent<TestProps> {
295
- render() {
296
- return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
297
- }
298
- }
299
- export default Test
300
- `,
301
- },
302
- {
303
- name: 'direct export of component class new JSX transform',
304
- src: `
305
- export default class Test extends Component<TestProps> {
306
- render() {
307
- return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
308
- }
309
- }
310
- `,
311
- },
312
- {
313
- name: 'component class & then default export new JSX transform',
314
- src: `
315
- class Test extends Component<TestProps> {
316
- render() {
317
- return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
318
- }
319
- }
320
- export default Test
321
- `,
322
- },
323
- {
324
- name: 'PureComponent class & then default export new JSX transform',
325
- src: `
326
- class Test extends PureComponent<TestProps> {
327
- render() {
328
- return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
329
- }
330
- }
331
- export default Test
332
- `,
333
- },
334
- ].forEach((config) => {
335
- describe(`React Native component defined as:${config.name}`, () => {
336
- beforeEach(async () => {
337
- appTree.write(
338
- cmpPath,
339
- `import React from 'react';
340
-
341
- export interface TestProps {
342
- name: string;
343
- displayAge: boolean;
344
- }
345
-
346
- ${config.src}
347
- `
348
- );
349
-
350
- await componentStoryGenerator(appTree, {
351
- componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
352
- project: 'test-ui-lib',
353
- });
354
- });
355
-
356
- it('should properly setup the controls based on the component props', () => {
357
- expect(
358
- formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
359
- ).toContain(formatFile`
360
- import type { Meta } from '@storybook/react-native';
361
- import { Test } from './test-ui-lib';
362
- const Story: Meta<typeof Test> = { component: Test, title: 'Test' };
363
- export default Story;
364
- export const Primary = { args: { name: '', displayAge: false } };
365
- `);
366
- });
367
- });
368
- });
369
- });
370
-
371
- describe('using eslint', () => {
372
- beforeEach(async () => {
373
- appTree = await createTestUILib('test-ui-lib');
374
- await componentGenerator(appTree, {
375
- name: 'test-ui-lib',
376
- project: 'test-ui-lib',
377
- export: true,
378
- });
379
- await componentStoryGenerator(appTree, {
380
- componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
381
- project: 'test-ui-lib',
382
- });
383
- });
384
-
385
- it('should properly set up the story', () => {
386
- expect(formatFile`${appTree.read(storyFilePath, 'utf-8')}`)
387
- .toContain(formatFile`
388
- import type { Meta } from '@storybook/react-native';
389
- import { TestUiLib } from './test-ui-lib';
390
- const Story: Meta<typeof TestUiLib> = {
391
- component: TestUiLib,
392
- title: 'TestUiLib',
393
- };
394
- export default Story;
395
- export const Primary = { args: {} };
396
- `);
397
- });
398
- });
399
- });
400
-
401
- export async function createTestUILib(libName: string): Promise<Tree> {
402
- let appTree = createTreeWithEmptyWorkspace();
403
- appTree.write('.gitignore', '');
404
-
405
- await libraryGenerator(appTree, {
406
- name: libName,
407
- linter: Linter.EsLint,
408
- skipFormat: true,
409
- skipTsConfig: false,
410
- unitTestRunner: 'jest',
411
- projectNameAndRootFormat: 'as-provided',
412
- });
413
-
414
- await componentGenerator(appTree, {
415
- name: libName,
416
- project: libName,
417
- export: true,
418
- });
419
-
420
- const currentWorkspaceJson = getProjects(appTree);
421
-
422
- const projectConfig = currentWorkspaceJson.get(libName);
423
-
424
- updateProjectConfiguration(appTree, libName, projectConfig);
425
-
426
- return appTree;
427
- }
@@ -1,32 +0,0 @@
1
- <% if ( !isPlainJs ) { %>import type { Meta } from '@storybook/react-native';<% } %>
2
- import<% if ( !isPlainJs ) { %> { <% } %> <%= componentName %> <% if ( !isPlainJs ) { %> } <% } %> from './<%= componentImportFileName %>';
3
-
4
- <% if ( isPlainJs ) { %>
5
- export default {
6
- component: <%= componentName %>,
7
- title: '<%= componentName %>',<% if ( argTypes && argTypes.length > 0 ) { %>
8
- argTypes: {<% for (let argType of argTypes) { %>
9
- <%= argType.name %>: { <%- argType.type %> : "<%- argType.actionText %>" },<% } %>
10
- }
11
- <% } %>
12
- };
13
- <% } %>
14
-
15
-
16
- <% if ( !isPlainJs ) { %>
17
- const Story: Meta<typeof <%= componentName %>> = {
18
- component: <%= componentName %>,
19
- title: '<%= componentName %>',<% if ( argTypes && argTypes.length > 0 ) { %>
20
- argTypes: {<% for (let argType of argTypes) { %>
21
- <%= argType.name %>: { <%- argType.type %> : "<%- argType.actionText %>" },<% } %>
22
- }
23
- <% } %>
24
- };
25
- export default Story;
26
- <% } %>
27
-
28
- export const Primary = {
29
- args: {<% for (let prop of props) { %>
30
- <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
31
- },
32
- };
@@ -1,19 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@nx/react/babel",
5
- {
6
- "runtime": "automatic",
7
- "useBuiltIns": "usage"
8
- }
9
- ]
10
- ],
11
- "plugins": [],
12
- "env": {
13
- "test": {
14
- "presets": [
15
- ["module:metro-react-native-babel-preset", { "useTransformReactJSX": true }]
16
- ]
17
- }
18
- }
19
- }
@@ -1,128 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- import storiesGenerator from './stories';
3
- import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
4
- import applicationGenerator from '../application/application';
5
- import { Linter } from '@nx/eslint';
6
- import { reactNativeComponentGenerator } from '../component/component';
7
-
8
- describe('react:stories for applications', () => {
9
- let appTree: Tree;
10
-
11
- beforeEach(async () => {
12
- appTree = await createTestUIApp('test-ui-app');
13
- });
14
-
15
- it('should create the stories', async () => {
16
- await reactNativeComponentGenerator(appTree, {
17
- name: 'another-cmp',
18
- project: 'test-ui-app',
19
- });
20
- await storiesGenerator(appTree, {
21
- project: 'test-ui-app',
22
- });
23
-
24
- expect(appTree.exists('test-ui-app/src/app/App.tsx')).toBeTruthy();
25
- expect(appTree.exists('test-ui-app/src/app/App.stories.tsx')).toBeTruthy();
26
- expect(
27
- appTree.exists('test-ui-app/src/app/another-cmp/another-cmp.stories.tsx')
28
- ).toBeTruthy();
29
- });
30
-
31
- it('should ignore paths', async () => {
32
- await reactNativeComponentGenerator(appTree, {
33
- name: 'another-cmp',
34
- project: 'test-ui-app',
35
- });
36
- await storiesGenerator(appTree, {
37
- project: 'test-ui-app',
38
- ignorePaths: ['test-ui-app/src/app/**'],
39
- });
40
-
41
- expect(appTree.exists('test-ui-app/src/app/App.tsx')).toBeTruthy();
42
- expect(appTree.exists('test-ui-app/src/app/App.stories.tsx')).toBeFalsy();
43
- expect(
44
- appTree.exists('test-ui-app/src/app/another-cmp/another-cmp.stories.tsx')
45
- ).toBeFalsy();
46
- });
47
-
48
- it('should ignore paths with a direct path to a component', async () => {
49
- await reactNativeComponentGenerator(appTree, {
50
- name: 'another-new-cmp',
51
- project: 'test-ui-app',
52
- });
53
-
54
- await storiesGenerator(appTree, {
55
- project: 'test-ui-app',
56
- ignorePaths: ['test-ui-app/src/app/another-new-cmp/another-new-cmp.tsx'],
57
- });
58
-
59
- expect(appTree.exists('test-ui-app/src/app/App.tsx')).toBeTruthy();
60
- expect(appTree.exists('test-ui-app/src/app/App.stories.tsx')).toBeTruthy();
61
- expect(
62
- appTree.exists(
63
- 'test-ui-app/src/app/another-new-cmp/another-new-cmp.stories.tsx'
64
- )
65
- ).toBeFalsy();
66
- });
67
-
68
- it('should ignore a path that has a nested component, but still generate nested component stories', async () => {
69
- await reactNativeComponentGenerator(appTree, {
70
- name: 'another-new-cmp',
71
- project: 'test-ui-app',
72
- });
73
- await reactNativeComponentGenerator(appTree, {
74
- name: 'comp-a',
75
- directory: 'app/another-new-cmp',
76
- project: 'test-ui-app',
77
- });
78
- await storiesGenerator(appTree, {
79
- project: 'test-ui-app',
80
- ignorePaths: ['test-ui-app/src/app/another-new-cmp/another-new-cmp.tsx'],
81
- });
82
-
83
- expect(appTree.exists('test-ui-app/src/app/App.tsx')).toBeTruthy();
84
- expect(appTree.exists('test-ui-app/src/app/App.stories.tsx')).toBeTruthy();
85
- expect(
86
- appTree.exists(
87
- 'test-ui-app/src/app/another-new-cmp/comp-a/comp-a.stories.tsx'
88
- )
89
- ).toBeTruthy();
90
- expect(
91
- appTree.exists(
92
- 'test-ui-app/src/app/another-new-cmp/another-new-cmp.stories.tsx'
93
- )
94
- ).toBeFalsy();
95
- });
96
-
97
- it('should ignore files that do not contain components', async () => {
98
- // create another component
99
- appTree.write(
100
- 'test-ui-app/src/app/some-utils.js',
101
- `export const add = (a: number, b: number) => a + b;`
102
- );
103
-
104
- await storiesGenerator(appTree, {
105
- project: 'test-ui-app',
106
- });
107
-
108
- // should just create the story and not error, even though there's a js file
109
- // not containing any react component
110
- expect(appTree.exists('test-ui-app/src/app/App.stories.tsx')).toBeTruthy();
111
- });
112
- });
113
-
114
- export async function createTestUIApp(libName: string): Promise<Tree> {
115
- let appTree = createTreeWithEmptyWorkspace();
116
- appTree.write('.gitignore', '');
117
-
118
- await applicationGenerator(appTree, {
119
- linter: Linter.EsLint,
120
- skipFormat: false,
121
- style: 'css',
122
- unitTestRunner: 'none',
123
- name: libName,
124
- install: false,
125
- projectNameAndRootFormat: 'as-provided',
126
- });
127
- return appTree;
128
- }