@nx/react-native 17.0.5 → 17.0.6

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 (181) hide show
  1. package/.eslintrc.json +1 -7
  2. package/LICENSE +1 -1
  3. package/README.md +4 -9
  4. package/executors.json +0 -5
  5. package/generators.json +11 -12
  6. package/migrations.json +0 -126
  7. package/package.json +15 -11
  8. package/plugins/metro-resolver.js +1 -4
  9. package/plugins/with-nx-metro.js +2 -6
  10. package/src/executors/build-android/build-android.impl.js +6 -2
  11. package/src/executors/build-android/build-android.impl.ts +6 -2
  12. package/src/executors/build-android/schema.json +1 -1
  13. package/src/executors/build-ios/schema.json +1 -1
  14. package/src/executors/bundle/schema.d.ts +1 -1
  15. package/src/executors/bundle/schema.json +1 -1
  16. package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +0 -4
  17. package/src/executors/ensure-symlink/ensure-symlink.impl.js +0 -4
  18. package/src/executors/ensure-symlink/ensure-symlink.impl.ts +0 -4
  19. package/src/executors/ensure-symlink/schema.json +1 -1
  20. package/src/executors/pod-install/schema.json +1 -1
  21. package/src/executors/run-android/run-android.impl.js +17 -5
  22. package/src/executors/run-android/run-android.impl.ts +18 -9
  23. package/src/executors/run-android/schema.json +1 -1
  24. package/src/executors/run-ios/run-ios.impl.js +16 -4
  25. package/src/executors/run-ios/run-ios.impl.ts +18 -9
  26. package/src/executors/run-ios/schema.json +1 -1
  27. package/src/executors/start/schema.d.ts +1 -1
  28. package/src/executors/start/schema.json +1 -1
  29. package/src/executors/start/start.impl.js +26 -11
  30. package/src/executors/start/start.impl.ts +28 -14
  31. package/src/executors/storybook/storybook.impl.d.ts +0 -4
  32. package/src/executors/storybook/storybook.impl.js +2 -15
  33. package/src/executors/storybook/storybook.impl.ts +7 -26
  34. package/src/executors/sync-deps/schema.d.ts +0 -1
  35. package/src/executors/sync-deps/schema.json +1 -6
  36. package/src/executors/sync-deps/sync-deps.impl.d.ts +1 -2
  37. package/src/executors/sync-deps/sync-deps.impl.js +11 -33
  38. package/src/executors/sync-deps/sync-deps.impl.ts +18 -57
  39. package/src/generators/application/application.js +8 -52
  40. package/src/generators/application/application.spec.ts +2 -29
  41. package/src/generators/application/files/app/Gemfile.template +1 -2
  42. package/src/generators/application/files/app/android/app/build.gradle.template +28 -12
  43. package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +6 -2
  44. package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +75 -0
  45. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +32 -0
  46. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +62 -0
  47. package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +20 -0
  48. package/src/generators/application/files/app/android/build.gradle.template +20 -7
  49. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  50. package/src/generators/application/files/app/android/gradle.properties +3 -0
  51. package/src/generators/application/files/app/android/gradlew.template +7 -12
  52. package/src/generators/application/files/app/android/settings.gradle.template +2 -2
  53. package/src/generators/application/files/app/babel.config.json.template +3 -0
  54. package/src/generators/application/files/app/ios/Podfile.template +7 -0
  55. package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +0 -5
  56. package/src/generators/application/files/app/ios/__className__/Info.plist.template +8 -5
  57. package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +33 -11
  58. package/src/generators/application/files/app/metro.config.js.template +5 -1
  59. package/src/generators/application/files/app/src/app/App.tsx.template +13 -50
  60. package/src/generators/application/lib/add-detox.d.ts +3 -0
  61. package/src/generators/application/lib/add-detox.js +23 -0
  62. package/src/generators/application/lib/add-project.js +18 -18
  63. package/src/generators/application/lib/normalize-options.d.ts +0 -7
  64. package/src/generators/application/lib/normalize-options.js +3 -35
  65. package/src/generators/application/lib/normalize-options.spec.ts +7 -70
  66. package/src/generators/application/schema.d.ts +3 -5
  67. package/src/generators/application/schema.json +6 -14
  68. package/src/generators/component/files/__fileName__.tsx__tmpl__ +1 -1
  69. package/src/generators/component/schema.d.ts +3 -3
  70. package/src/generators/component/schema.json +4 -4
  71. package/src/generators/component-story/component-story.d.ts +8 -5
  72. package/src/generators/component-story/component-story.js +69 -8
  73. package/src/generators/component-story/component-story.spec.ts +428 -0
  74. package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +32 -0
  75. package/src/generators/component-story/schema.d.ts +0 -1
  76. package/src/generators/component-story/schema.json +3 -11
  77. package/src/generators/init/init.d.ts +1 -2
  78. package/src/generators/init/init.js +56 -55
  79. package/src/generators/init/init.spec.ts +6 -7
  80. package/src/generators/init/schema.d.ts +3 -3
  81. package/src/generators/init/schema.json +18 -13
  82. package/src/generators/library/files/lib/babel.config.json.template +17 -0
  83. package/src/generators/library/lib/normalize-options.js +0 -5
  84. package/src/generators/library/library.js +38 -48
  85. package/src/generators/library/library.spec.ts +60 -12
  86. package/src/generators/library/schema.d.ts +0 -1
  87. package/src/generators/library/schema.json +2 -2
  88. package/src/generators/stories/schema.d.ts +0 -2
  89. package/src/generators/stories/schema.json +2 -15
  90. package/src/generators/stories/stories-app.spec.ts +128 -0
  91. package/src/generators/stories/stories-lib.spec.ts +105 -0
  92. package/src/generators/stories/stories.d.ts +2 -5
  93. package/src/generators/stories/stories.js +50 -7
  94. package/src/generators/storybook-configuration/configuration.d.ts +2 -7
  95. package/src/generators/storybook-configuration/configuration.js +48 -18
  96. package/src/generators/storybook-configuration/configuration.spec.ts +135 -0
  97. package/src/generators/storybook-configuration/files/app/storybook.ts.template +9 -0
  98. package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +74 -0
  99. package/src/generators/storybook-configuration/files/root/story-loader.ts.template +5 -0
  100. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +6 -0
  101. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +25 -0
  102. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +161 -0
  103. package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +6 -0
  104. package/src/generators/storybook-configuration/lib/create-storybook-files.js +42 -0
  105. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +7 -0
  106. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +29 -0
  107. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +65 -0
  108. package/src/generators/storybook-configuration/schema.d.ts +2 -4
  109. package/src/generators/storybook-configuration/schema.json +12 -22
  110. package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
  111. package/src/generators/upgrade-native/schema.d.ts +1 -1
  112. package/src/generators/upgrade-native/schema.json +3 -3
  113. package/src/generators/upgrade-native/upgrade-native.d.ts +0 -2
  114. package/src/generators/upgrade-native/upgrade-native.js +0 -3
  115. package/src/migrations/update-16-6-0/update-metro-config.js +5 -1
  116. package/src/migrations/update-16-9-0/remove-types-react-native.js +9 -2
  117. package/src/utils/add-jest.d.ts +1 -1
  118. package/src/utils/add-jest.js +1 -13
  119. package/src/utils/add-linting.d.ts +0 -1
  120. package/src/utils/add-linting.js +1 -1
  121. package/src/utils/add-linting.spec.ts +6 -4
  122. package/src/utils/chmod-android-gradle-files.js +2 -6
  123. package/src/utils/find-all-npm-dependencies.js +3 -5
  124. package/src/utils/find-all-npm-dependencies.spec.ts +9 -17
  125. package/src/utils/symlink-task.d.ts +2 -0
  126. package/src/utils/symlink-task.js +18 -0
  127. package/src/utils/testing-generators.js +0 -1
  128. package/src/utils/versions.d.ts +13 -10
  129. package/src/utils/versions.js +14 -11
  130. package/plugin.d.ts +0 -1
  131. package/plugin.js +0 -6
  132. package/plugins/plugin.d.ts +0 -14
  133. package/plugins/plugin.js +0 -162
  134. package/src/executors/upgrade/schema.d.ts +0 -1
  135. package/src/executors/upgrade/schema.json +0 -11
  136. package/src/executors/upgrade/upgrade.impl.d.ts +0 -13
  137. package/src/executors/upgrade/upgrade.impl.js +0 -47
  138. package/src/executors/upgrade/upgrade.impl.ts +0 -64
  139. package/src/generators/application/files/app/.babelrc.js.template +0 -23
  140. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +0 -22
  141. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +0 -45
  142. package/src/generators/application/lib/add-e2e.d.ts +0 -3
  143. package/src/generators/application/lib/add-e2e.js +0 -46
  144. package/src/generators/library/files/lib/.babelrc.js.template +0 -21
  145. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +0 -23
  146. package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +0 -15
  147. package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
  148. package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
  149. package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +0 -9
  150. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +0 -82
  151. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +0 -23
  152. package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
  153. package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
  154. package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +0 -14
  155. package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +0 -9
  156. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +0 -77
  157. package/src/generators/web-configuration/lib/normalize-schema.d.ts +0 -17
  158. package/src/generators/web-configuration/lib/normalize-schema.js +0 -16
  159. package/src/generators/web-configuration/lib/webpack-targets.d.ts +0 -7
  160. package/src/generators/web-configuration/lib/webpack-targets.js +0 -75
  161. package/src/generators/web-configuration/schema.d.ts +0 -6
  162. package/src/generators/web-configuration/schema.json +0 -42
  163. package/src/generators/web-configuration/web-configuration.d.ts +0 -12
  164. package/src/generators/web-configuration/web-configuration.js +0 -87
  165. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +0 -6
  166. package/src/migrations/update-18-0-0/add-upgrade-target.js +0 -33
  167. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +0 -8
  168. package/src/migrations/update-18-0-0/add-web-configuration.js +0 -33
  169. package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +0 -39
  170. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +0 -5
  171. package/src/migrations/update-18-0-0/change-storybook-targets.js +0 -57
  172. package/src/migrations/update-18-0-0/remove-block-list.d.ts +0 -6
  173. package/src/migrations/update-18-0-0/remove-block-list.js +0 -28
  174. package/src/migrations/update-18-0-0/remove-block-list.spec.ts +0 -68
  175. package/src/migrations/update-18-0-0/remove-metro.d.ts +0 -14
  176. package/src/migrations/update-18-0-0/remove-metro.js +0 -29
  177. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +0 -6
  178. package/src/migrations/update-18-0-0/remove-symlink-target.js +0 -30
  179. package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +0 -40
  180. package/src/utils/ensure-dependencies.d.ts +0 -2
  181. package/src/utils/ensure-dependencies.js +0 -30
@@ -1,7 +1,7 @@
1
1
  export interface Schema {
2
+ unitTestRunner?: 'jest' | 'none';
2
3
  skipFormat?: boolean;
4
+ e2eTestRunner?: 'detox' | 'none';
3
5
  skipPackageJson?: boolean; //default is false
4
- keepExistingVersions?: boolean; //default is false
5
- updatePackageScripts?: boolean;
6
- addPlugin?: boolean;
6
+ js?: boolean;
7
7
  }
@@ -1,34 +1,39 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxReactNativeInit",
4
- "$schema": "https://json-schema.org/schema",
4
+ "$schema": "http://json-schema.org/schema",
5
5
  "title": "Add Nx React Native Schematics",
6
6
  "description": "Add Nx React native schematics.",
7
7
  "type": "object",
8
8
  "properties": {
9
+ "unitTestRunner": {
10
+ "description": "Adds the specified unit test runner.",
11
+ "type": "string",
12
+ "enum": ["jest", "none"],
13
+ "default": "jest"
14
+ },
9
15
  "skipFormat": {
10
16
  "description": "Skip formatting files.",
11
17
  "type": "boolean",
12
18
  "default": false,
13
19
  "x-priority": "internal"
14
20
  },
21
+ "e2eTestRunner": {
22
+ "description": "Adds the specified E2E test runner.",
23
+ "type": "string",
24
+ "enum": ["detox", "none"],
25
+ "default": "detox"
26
+ },
27
+ "js": {
28
+ "type": "boolean",
29
+ "default": false,
30
+ "description": "Use JavaScript instead of TypeScript"
31
+ },
15
32
  "skipPackageJson": {
16
33
  "description": "Do not add dependencies to `package.json`.",
17
34
  "type": "boolean",
18
35
  "default": false,
19
36
  "x-priority": "internal"
20
- },
21
- "keepExistingVersions": {
22
- "type": "boolean",
23
- "x-priority": "internal",
24
- "description": "Keep existing dependencies versions",
25
- "default": false
26
- },
27
- "updatePackageScripts": {
28
- "type": "boolean",
29
- "x-priority": "internal",
30
- "description": "Update `package.json` scripts with inferred targets",
31
- "default": false
32
37
  }
33
38
  },
34
39
  "required": []
@@ -0,0 +1,17 @@
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": ["module:metro-react-native-babel-preset"]
15
+ }
16
+ }
17
+ }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
4
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
5
  async function normalizeOptions(host, options) {
7
6
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
@@ -12,10 +11,6 @@ async function normalizeOptions(host, options) {
12
11
  projectNameAndRootFormat: options.projectNameAndRootFormat,
13
12
  callingGenerator: '@nx/react-native:library',
14
13
  });
15
- const nxJson = (0, devkit_1.readNxJson)(host);
16
- const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
- nxJson.useInferencePlugins !== false;
18
- options.addPlugin ??= addPluginDefault;
19
14
  const parsedTags = options.tags
20
15
  ? options.tags.split(',').map((s) => s.trim())
21
16
  : [];
@@ -8,11 +8,8 @@ const add_linting_1 = require("../../utils/add-linting");
8
8
  const add_jest_1 = require("../../utils/add-jest");
9
9
  const versions_1 = require("../../utils/versions");
10
10
  const normalize_options_1 = require("./lib/normalize-options");
11
- const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
12
- const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
13
11
  async function reactNativeLibraryGenerator(host, schema) {
14
12
  return await reactNativeLibraryGeneratorInternal(host, {
15
- addPlugin: false,
16
13
  projectNameAndRootFormat: 'derived',
17
14
  ...schema,
18
15
  });
@@ -24,16 +21,12 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
24
21
  throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
25
22
  }
26
23
  const tasks = [];
27
- const jsInitTask = await (0, js_1.initGenerator)(host, {
28
- ...schema,
24
+ const initTask = await (0, init_1.default)(host, {
25
+ ...options,
29
26
  skipFormat: true,
27
+ e2eTestRunner: 'none',
30
28
  });
31
- tasks.push(jsInitTask);
32
- const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
33
29
  tasks.push(initTask);
34
- if (!options.skipPackageJson) {
35
- tasks.push((0, ensure_dependencies_1.ensureDependencies)(host));
36
- }
37
30
  const addProjectTask = await addProject(host, options);
38
31
  if (addProjectTask) {
39
32
  tasks.push(addProjectTask);
@@ -47,7 +40,7 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
47
40
  ],
48
41
  });
49
42
  tasks.push(lintTask);
50
- const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin);
43
+ const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson);
51
44
  tasks.push(jestTask);
52
45
  if (options.publishable || options.buildable) {
53
46
  updateLibPackageNpmScope(host, options);
@@ -60,52 +53,49 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
60
53
  if (!options.skipFormat) {
61
54
  await (0, devkit_1.formatFiles)(host);
62
55
  }
63
- tasks.push(() => {
64
- (0, log_show_project_command_1.logShowProjectCommand)(options.name);
65
- });
66
56
  return (0, devkit_1.runTasksInSerial)(...tasks);
67
57
  }
68
58
  exports.reactNativeLibraryGeneratorInternal = reactNativeLibraryGeneratorInternal;
69
59
  async function addProject(host, options) {
70
- const project = {
60
+ const targets = {};
61
+ let task;
62
+ if (options.publishable || options.buildable) {
63
+ const { rollupInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
64
+ const external = [
65
+ 'react/jsx-runtime',
66
+ 'react-native',
67
+ 'react',
68
+ 'react-dom',
69
+ ];
70
+ targets.build = {
71
+ executor: '@nx/rollup:rollup',
72
+ outputs: ['{options.outputPath}'],
73
+ options: {
74
+ outputPath: `dist/${options.projectRoot}`,
75
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
76
+ project: `${options.projectRoot}/package.json`,
77
+ entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
78
+ external,
79
+ rollupConfig: `@nx/react/plugins/bundle-rollup`,
80
+ assets: [
81
+ {
82
+ glob: `${options.projectRoot}/README.md`,
83
+ input: '.',
84
+ output: '.',
85
+ },
86
+ ],
87
+ },
88
+ };
89
+ task = await rollupInitGenerator(host, { ...options, skipFormat: true });
90
+ }
91
+ (0, devkit_1.addProjectConfiguration)(host, options.name, {
71
92
  root: options.projectRoot,
72
93
  sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
73
94
  projectType: 'library',
74
95
  tags: options.parsedTags,
75
- targets: {},
76
- };
77
- (0, devkit_1.addProjectConfiguration)(host, options.name, project);
78
- if (!options.publishable && !options.buildable) {
79
- return () => { };
80
- }
81
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
82
- const rollupConfigTask = await configurationGenerator(host, {
83
- ...options,
84
- project: options.name,
85
- skipFormat: true,
96
+ targets,
86
97
  });
87
- const external = ['react/jsx-runtime', 'react-native', 'react', 'react-dom'];
88
- project.targets.build = {
89
- executor: '@nx/rollup:rollup',
90
- outputs: ['{options.outputPath}'],
91
- options: {
92
- outputPath: `dist/${options.projectRoot}`,
93
- tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
94
- project: `${options.projectRoot}/package.json`,
95
- entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
96
- external,
97
- rollupConfig: `@nx/react/plugins/bundle-rollup`,
98
- assets: [
99
- {
100
- glob: `${options.projectRoot}/README.md`,
101
- input: '.',
102
- output: '.',
103
- },
104
- ],
105
- },
106
- };
107
- (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
108
- return rollupConfigTask;
98
+ return task;
109
99
  }
110
100
  function updateTsConfig(tree, options) {
111
101
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
@@ -20,7 +20,6 @@ describe('lib', () => {
20
20
  unitTestRunner: 'jest',
21
21
  strict: true,
22
22
  projectNameAndRootFormat: 'as-provided',
23
- addPlugin: true,
24
23
  };
25
24
 
26
25
  beforeEach(() => {
@@ -29,6 +28,21 @@ describe('lib', () => {
29
28
  });
30
29
 
31
30
  describe('not nested', () => {
31
+ it('should update project.json', async () => {
32
+ await libraryGenerator(appTree, { ...defaultSchema, tags: 'one,two' });
33
+ const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
34
+ expect(projectConfiguration.root).toEqual('my-lib');
35
+ expect(projectConfiguration.targets.build).toBeUndefined();
36
+ expect(projectConfiguration.targets.lint).toEqual({
37
+ executor: '@nx/eslint:lint',
38
+ outputs: ['{options.outputFile}'],
39
+ options: {
40
+ lintFilePatterns: ['my-lib/**/*.{ts,tsx,js,jsx}'],
41
+ },
42
+ });
43
+ expect(projectConfiguration.tags).toEqual(['one', 'two']);
44
+ });
45
+
32
46
  it('should update root tsconfig.base.json', async () => {
33
47
  await libraryGenerator(appTree, defaultSchema);
34
48
  const tsconfigJson = readJson(appTree, '/tsconfig.base.json');
@@ -135,6 +149,23 @@ describe('lib', () => {
135
149
  });
136
150
  });
137
151
 
152
+ it('should update project.json', async () => {
153
+ await libraryGenerator(appTree, {
154
+ ...defaultSchema,
155
+ directory: 'my-dir',
156
+ });
157
+ const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
158
+
159
+ expect(projectConfiguration.root).toEqual('my-dir');
160
+ expect(projectConfiguration.targets.lint).toEqual({
161
+ executor: '@nx/eslint:lint',
162
+ outputs: ['{options.outputFile}'],
163
+ options: {
164
+ lintFilePatterns: ['my-dir/**/*.{ts,tsx,js,jsx}'],
165
+ },
166
+ });
167
+ });
168
+
138
169
  it('should update root tsconfig.base.json', async () => {
139
170
  await libraryGenerator(appTree, {
140
171
  ...defaultSchema,
@@ -206,6 +237,15 @@ describe('lib', () => {
206
237
 
207
238
  expect(appTree.exists('my-lib/tsconfig.spec.json')).toBeFalsy();
208
239
  expect(appTree.exists('my-lib/jest.config.ts')).toBeFalsy();
240
+ const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
241
+ expect(projectConfiguration.targets.test).toBeUndefined();
242
+ expect(projectConfiguration.targets.lint).toMatchObject({
243
+ executor: '@nx/eslint:lint',
244
+ options: {
245
+ lintFilePatterns: ['my-lib/**/*.{ts,tsx,js,jsx}'],
246
+ },
247
+ outputs: ['{options.outputFile}'],
248
+ });
209
249
  });
210
250
 
211
251
  it('should generate test configuration', async () => {
@@ -249,21 +289,29 @@ describe('lib', () => {
249
289
  moduleNameMapper: {
250
290
  '\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
251
291
  },
252
- transform: {
253
- '^.+.(js|ts|tsx)$': [
254
- 'babel-jest',
255
- {
256
- configFile: __dirname + '/.babelrc.js',
257
- },
258
- ],
259
- '^.+.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
260
- 'react-native/jest/assetFileTransformer.js'
261
- ),
262
- },
263
292
  coverageDirectory: '../coverage/my-lib',
264
293
  };
265
294
  "
266
295
  `);
296
+ const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
297
+ expect(projectConfiguration.targets.test).toMatchInlineSnapshot(`
298
+ {
299
+ "configurations": {
300
+ "ci": {
301
+ "ci": true,
302
+ "codeCoverage": true,
303
+ },
304
+ },
305
+ "executor": "@nx/jest:jest",
306
+ "options": {
307
+ "jestConfig": "my-lib/jest.config.ts",
308
+ "passWithNoTests": true,
309
+ },
310
+ "outputs": [
311
+ "{workspaceRoot}/coverage/{projectRoot}",
312
+ ],
313
+ }
314
+ `);
267
315
  });
268
316
  });
269
317
 
@@ -21,5 +21,4 @@ export interface Schema {
21
21
  strict?: boolean;
22
22
  setParserOptionsProject?: boolean;
23
23
  skipPackageJson?: boolean; //default is false
24
- addPlugin?: boolean;
25
24
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxReactNativeLibrary",
4
- "$schema": "https://json-schema.org/schema",
4
+ "$schema": "http://json-schema.org/schema",
5
5
  "title": "Create a React Native Library for Nx",
6
6
  "description": "Create a React Native Library for Nx.",
7
7
  "type": "object",
@@ -36,7 +36,7 @@
36
36
  "linter": {
37
37
  "description": "The tool to use for running lint checks.",
38
38
  "type": "string",
39
- "enum": ["eslint", "none"],
39
+ "enum": ["eslint"],
40
40
  "default": "eslint"
41
41
  },
42
42
  "unitTestRunner": {
@@ -1,7 +1,5 @@
1
1
  export interface StorybookStoriesSchema {
2
2
  project: string;
3
- interactionTests?: boolean;
4
- js?: boolean;
5
3
  ignorePaths?: string[];
6
4
  skipFormat?: boolean;
7
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxReactNativeStorybookStories",
5
5
  "title": "Generate React Native Storybook stories",
@@ -14,20 +14,7 @@
14
14
  "$source": "projectName",
15
15
  "index": 0
16
16
  },
17
- "x-prompt": "For which project do you want to generate stories?",
18
- "x-priority": "important"
19
- },
20
- "interactionTests": {
21
- "type": "boolean",
22
- "description": "Set up Storybook interaction tests.",
23
- "x-prompt": "Do you want to set up Storybook interaction tests?",
24
- "x-priority": "important",
25
- "default": true
26
- },
27
- "js": {
28
- "type": "boolean",
29
- "description": "Generate JavaScript files rather than TypeScript files.",
30
- "default": false
17
+ "x-prompt": "For which project do you want to generate stories?"
31
18
  },
32
19
  "ignorePaths": {
33
20
  "type": "array",
@@ -0,0 +1,128 @@
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
+ }
@@ -0,0 +1,105 @@
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 libraryGenerator from '../library/library';
7
+ import reactNativeComponentGenerator from '../component/component';
8
+
9
+ describe('react-native:stories for libraries', () => {
10
+ let appTree: Tree;
11
+
12
+ beforeEach(async () => {
13
+ appTree = await createTestUILib('test-ui-lib');
14
+ });
15
+
16
+ it('should create the stories', async () => {
17
+ await reactNativeComponentGenerator(appTree, {
18
+ name: 'test-ui-lib',
19
+ project: 'test-ui-lib',
20
+ });
21
+ await reactNativeComponentGenerator(appTree, {
22
+ name: 'another-cmp',
23
+ project: 'test-ui-lib',
24
+ });
25
+ await storiesGenerator(appTree, {
26
+ project: 'test-ui-lib',
27
+ });
28
+
29
+ expect(
30
+ appTree.exists('test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx')
31
+ ).toBeTruthy();
32
+ expect(
33
+ appTree.exists('test-ui-lib/src/lib/another-cmp/another-cmp.stories.tsx')
34
+ ).toBeTruthy();
35
+ });
36
+
37
+ it('should ignore paths', async () => {
38
+ await reactNativeComponentGenerator(appTree, {
39
+ name: 'test-ui-lib',
40
+ project: 'test-ui-lib',
41
+ });
42
+ await reactNativeComponentGenerator(appTree, {
43
+ name: 'another-cmp',
44
+ project: 'test-ui-lib',
45
+ });
46
+ await storiesGenerator(appTree, {
47
+ project: 'test-ui-lib',
48
+ ignorePaths: ['test-ui-lib/src/lib/another-cmp/**'],
49
+ });
50
+
51
+ expect(
52
+ appTree.exists('test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx')
53
+ ).toBeTruthy();
54
+ expect(
55
+ appTree.exists('test-ui-lib/src/lib/another-cmp/another-cmp.stories.tsx')
56
+ ).toBeFalsy();
57
+ });
58
+
59
+ it('should ignore files that do not contain components', async () => {
60
+ await reactNativeComponentGenerator(appTree, {
61
+ name: 'test-ui-lib',
62
+ project: 'test-ui-lib',
63
+ });
64
+ // create another component
65
+ appTree.write(
66
+ 'test-ui-lib/src/lib/some-command-line-utils.ts',
67
+ `export const add = (a: number, b: number) => a + b;`
68
+ );
69
+
70
+ await storiesGenerator(appTree, {
71
+ project: 'test-ui-lib',
72
+ });
73
+
74
+ // should just create the story and not error, even though there's a js file
75
+ // not containing any react component
76
+ expect(
77
+ appTree.exists('test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx')
78
+ ).toBeTruthy();
79
+ });
80
+ });
81
+
82
+ export async function createTestUILib(libName: string): Promise<Tree> {
83
+ let appTree = createTreeWithEmptyWorkspace();
84
+ appTree.write('.gitignore', '');
85
+
86
+ await libraryGenerator(appTree, {
87
+ linter: Linter.EsLint,
88
+ skipFormat: true,
89
+ skipTsConfig: false,
90
+ unitTestRunner: 'none',
91
+ name: libName,
92
+ projectNameAndRootFormat: 'as-provided',
93
+ });
94
+
95
+ await applicationGenerator(appTree, {
96
+ e2eTestRunner: 'none',
97
+ linter: Linter.EsLint,
98
+ skipFormat: false,
99
+ unitTestRunner: 'none',
100
+ name: `${libName}-e2e`,
101
+ install: false,
102
+ projectNameAndRootFormat: 'as-provided',
103
+ });
104
+ return appTree;
105
+ }
@@ -1,8 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { StorybookStoriesSchema } from './schema';
3
- /**
4
- * @deprecated This would be a direct pass through to @nx/react:stories generator.
5
- * TODO (@xiongemi): remove this generator for v19
6
- */
7
- export declare function storiesGenerator(host: Tree, schema: StorybookStoriesSchema): Promise<import("@nx/devkit").GeneratorCallback>;
3
+ export declare function createAllStories(tree: Tree, projectName: string, ignorePaths?: string[]): Promise<void>;
4
+ export declare function storiesGenerator(host: Tree, schema: StorybookStoriesSchema): Promise<void>;
8
5
  export default storiesGenerator;