@nx/react-native 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca

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 (97) hide show
  1. package/.eslintrc.json +4 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/generators.json +1 -1
  5. package/migrations.json +69 -335
  6. package/package.json +8 -10
  7. package/plugin.d.ts +1 -1
  8. package/plugin.js +2 -2
  9. package/plugins/metro-resolver.js +11 -11
  10. package/plugins/plugin.d.ts +2 -2
  11. package/plugins/plugin.js +57 -34
  12. package/project.json +2 -8
  13. package/src/executors/run-android/schema.json +1 -0
  14. package/src/executors/run-ios/schema.json +1 -0
  15. package/src/executors/start/lib/is-packager-running.js +1 -2
  16. package/src/executors/start/schema.json +1 -0
  17. package/src/executors/storybook/storybook.impl.js +3 -3
  18. package/src/executors/sync-deps/sync-deps.impl.js +4 -4
  19. package/src/generators/application/application.js +24 -4
  20. package/src/generators/application/files/app/.babelrc.js.template +1 -1
  21. package/src/generators/application/files/app/Gemfile.template +4 -4
  22. package/src/generators/application/files/app/android/app/build.gradle.template +9 -8
  23. package/src/generators/application/files/app/android/app/src/main/AndroidManifest.xml.template +1 -0
  24. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +7 -6
  25. package/src/generators/application/files/app/android/build.gradle.template +4 -4
  26. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  27. package/src/generators/application/files/app/android/gradle.properties +1 -3
  28. package/src/generators/application/files/app/android/gradlew.bat +94 -92
  29. package/src/generators/application/files/app/android/gradlew.template +5 -2
  30. package/src/generators/application/files/app/android/settings.gradle.template +3 -1
  31. package/src/generators/application/files/app/tsconfig.app.json.template +11 -1
  32. package/src/generators/application/files/app/tsconfig.json.template +2 -0
  33. package/src/generators/application/lib/add-e2e.js +2 -1
  34. package/src/generators/application/lib/add-project.js +26 -3
  35. package/src/generators/application/lib/normalize-options.d.ts +3 -1
  36. package/src/generators/application/lib/normalize-options.js +9 -5
  37. package/src/generators/application/schema.d.ts +6 -5
  38. package/src/generators/application/schema.json +20 -18
  39. package/src/generators/component/component.d.ts +0 -1
  40. package/src/generators/component/component.js +20 -29
  41. package/src/generators/component/files/js/__fileName__.__ext__ +28 -0
  42. package/src/generators/component/files/{__fileName__.tsx__tmpl__ → ts/__fileName__.__ext__} +6 -6
  43. package/src/generators/component/files/ts/__fileName__.spec.__ext__ +11 -0
  44. package/src/generators/component/lib/normalize-options.d.ts +6 -1
  45. package/src/generators/component/lib/normalize-options.js +13 -26
  46. package/src/generators/component/schema.d.ts +6 -14
  47. package/src/generators/component/schema.json +26 -40
  48. package/src/generators/convert-to-inferred/convert-to-inferred.js +1 -1
  49. package/src/generators/init/init.js +1 -1
  50. package/src/generators/library/files/lib/tsconfig.json.template +2 -0
  51. package/src/generators/library/files/lib/tsconfig.lib.json.template +11 -1
  52. package/src/generators/library/lib/normalize-options.d.ts +2 -0
  53. package/src/generators/library/lib/normalize-options.js +6 -3
  54. package/src/generators/library/library.js +119 -60
  55. package/src/generators/library/schema.d.ts +3 -5
  56. package/src/generators/library/schema.json +17 -21
  57. package/src/generators/storybook-configuration/schema.json +2 -1
  58. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +1 -1
  59. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +4 -9
  60. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +1 -1
  61. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +4 -0
  62. package/src/generators/web-configuration/schema.json +1 -1
  63. package/src/generators/web-configuration/web-configuration.js +7 -0
  64. package/src/utils/add-jest.d.ts +1 -1
  65. package/src/utils/add-jest.js +2 -1
  66. package/src/utils/add-linting.js +3 -2
  67. package/src/utils/ensure-dependencies.js +2 -0
  68. package/src/utils/pod-install-task.js +6 -6
  69. package/src/utils/testing-generators.js +2 -4
  70. package/src/utils/versions.d.ts +17 -13
  71. package/src/utils/versions.js +18 -14
  72. package/src/generators/library/files/lib/package.json.template +0 -4
  73. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
  74. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
  75. package/src/migrations/update-16-1-0/upgrade-storybook-6-5.d.ts +0 -6
  76. package/src/migrations/update-16-1-0/upgrade-storybook-6-5.js +0 -21
  77. package/src/migrations/update-16-6-0/add-depends-on.d.ts +0 -6
  78. package/src/migrations/update-16-6-0/add-depends-on.js +0 -63
  79. package/src/migrations/update-16-6-0/update-metro-config.d.ts +0 -6
  80. package/src/migrations/update-16-6-0/update-metro-config.js +0 -63
  81. package/src/migrations/update-16-9-0/remove-types-react-native.d.ts +0 -7
  82. package/src/migrations/update-16-9-0/remove-types-react-native.js +0 -13
  83. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +0 -6
  84. package/src/migrations/update-18-0-0/add-upgrade-target.js +0 -31
  85. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +0 -8
  86. package/src/migrations/update-18-0-0/add-web-configuration.js +0 -33
  87. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +0 -5
  88. package/src/migrations/update-18-0-0/change-storybook-targets.js +0 -57
  89. package/src/migrations/update-18-0-0/remove-block-list.d.ts +0 -6
  90. package/src/migrations/update-18-0-0/remove-block-list.js +0 -28
  91. package/src/migrations/update-18-0-0/remove-metro.d.ts +0 -14
  92. package/src/migrations/update-18-0-0/remove-metro.js +0 -29
  93. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +0 -6
  94. package/src/migrations/update-18-0-0/remove-symlink-target.js +0 -30
  95. package/src/utils/format-file.d.ts +0 -1
  96. package/src/utils/format-file.js +0 -15
  97. /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → js/__fileName__.spec.__ext__} +0 -0
@@ -1,92 +1,94 @@
1
- @rem
2
- @rem Copyright 2015 the original author or authors.
3
- @rem
4
- @rem Licensed under the Apache License, Version 2.0 (the "License");
5
- @rem you may not use this file except in compliance with the License.
6
- @rem You may obtain a copy of the License at
7
- @rem
8
- @rem https://www.apache.org/licenses/LICENSE-2.0
9
- @rem
10
- @rem Unless required by applicable law or agreed to in writing, software
11
- @rem distributed under the License is distributed on an "AS IS" BASIS,
12
- @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- @rem See the License for the specific language governing permissions and
14
- @rem limitations under the License.
15
- @rem
16
-
17
- @if "%DEBUG%"=="" @echo off
18
- @rem ##########################################################################
19
- @rem
20
- @rem Gradle startup script for Windows
21
- @rem
22
- @rem ##########################################################################
23
-
24
- @rem Set local scope for the variables with windows NT shell
25
- if "%OS%"=="Windows_NT" setlocal
26
-
27
- set DIRNAME=%~dp0
28
- if "%DIRNAME%"=="" set DIRNAME=.
29
- @rem This is normally unused
30
- set APP_BASE_NAME=%~n0
31
- set APP_HOME=%DIRNAME%
32
-
33
- @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34
- for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35
-
36
- @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37
- set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38
-
39
- @rem Find java.exe
40
- if defined JAVA_HOME goto findJavaFromJavaHome
41
-
42
- set JAVA_EXE=java.exe
43
- %JAVA_EXE% -version >NUL 2>&1
44
- if %ERRORLEVEL% equ 0 goto execute
45
-
46
- echo. 1>&2
47
- echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48
- echo. 1>&2
49
- echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50
- echo location of your Java installation. 1>&2
51
-
52
- goto fail
53
-
54
- :findJavaFromJavaHome
55
- set JAVA_HOME=%JAVA_HOME:"=%
56
- set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57
-
58
- if exist "%JAVA_EXE%" goto execute
59
-
60
- echo. 1>&2
61
- echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62
- echo. 1>&2
63
- echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64
- echo location of your Java installation. 1>&2
65
-
66
- goto fail
67
-
68
- :execute
69
- @rem Setup the command line
70
-
71
- set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72
-
73
-
74
- @rem Execute Gradle
75
- "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76
-
77
- :end
78
- @rem End local scope for the variables with windows NT shell
79
- if %ERRORLEVEL% equ 0 goto mainEnd
80
-
81
- :fail
82
- rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83
- rem the _cmd.exe /c_ return code!
84
- set EXIT_CODE=%ERRORLEVEL%
85
- if %EXIT_CODE% equ 0 set EXIT_CODE=1
86
- if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87
- exit /b %EXIT_CODE%
88
-
89
- :mainEnd
90
- if "%OS%"=="Windows_NT" endlocal
91
-
92
- :omega
1
+ @rem
2
+ @rem Copyright 2015 the original author or authors.
3
+ @rem
4
+ @rem Licensed under the Apache License, Version 2.0 (the "License");
5
+ @rem you may not use this file except in compliance with the License.
6
+ @rem You may obtain a copy of the License at
7
+ @rem
8
+ @rem https://www.apache.org/licenses/LICENSE-2.0
9
+ @rem
10
+ @rem Unless required by applicable law or agreed to in writing, software
11
+ @rem distributed under the License is distributed on an "AS IS" BASIS,
12
+ @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ @rem See the License for the specific language governing permissions and
14
+ @rem limitations under the License.
15
+ @rem
16
+ @rem SPDX-License-Identifier: Apache-2.0
17
+ @rem
18
+
19
+ @if "%DEBUG%"=="" @echo off
20
+ @rem ##########################################################################
21
+ @rem
22
+ @rem Gradle startup script for Windows
23
+ @rem
24
+ @rem ##########################################################################
25
+
26
+ @rem Set local scope for the variables with windows NT shell
27
+ if "%OS%"=="Windows_NT" setlocal
28
+
29
+ set DIRNAME=%~dp0
30
+ if "%DIRNAME%"=="" set DIRNAME=.
31
+ @rem This is normally unused
32
+ set APP_BASE_NAME=%~n0
33
+ set APP_HOME=%DIRNAME%
34
+
35
+ @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36
+ for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37
+
38
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39
+ set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40
+
41
+ @rem Find java.exe
42
+ if defined JAVA_HOME goto findJavaFromJavaHome
43
+
44
+ set JAVA_EXE=java.exe
45
+ %JAVA_EXE% -version >NUL 2>&1
46
+ if %ERRORLEVEL% equ 0 goto execute
47
+
48
+ echo. 1>&2
49
+ echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50
+ echo. 1>&2
51
+ echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52
+ echo location of your Java installation. 1>&2
53
+
54
+ goto fail
55
+
56
+ :findJavaFromJavaHome
57
+ set JAVA_HOME=%JAVA_HOME:"=%
58
+ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59
+
60
+ if exist "%JAVA_EXE%" goto execute
61
+
62
+ echo. 1>&2
63
+ echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64
+ echo. 1>&2
65
+ echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66
+ echo location of your Java installation. 1>&2
67
+
68
+ goto fail
69
+
70
+ :execute
71
+ @rem Setup the command line
72
+
73
+ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
74
+
75
+
76
+ @rem Execute Gradle
77
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
78
+
79
+ :end
80
+ @rem End local scope for the variables with windows NT shell
81
+ if %ERRORLEVEL% equ 0 goto mainEnd
82
+
83
+ :fail
84
+ rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85
+ rem the _cmd.exe /c_ return code!
86
+ set EXIT_CODE=%ERRORLEVEL%
87
+ if %EXIT_CODE% equ 0 set EXIT_CODE=1
88
+ if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89
+ exit /b %EXIT_CODE%
90
+
91
+ :mainEnd
92
+ if "%OS%"=="Windows_NT" endlocal
93
+
94
+ :omega
@@ -15,6 +15,8 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
  #
18
+ # SPDX-License-Identifier: Apache-2.0
19
+ #
18
20
 
19
21
  ##############################################################################
20
22
  #
@@ -55,7 +57,7 @@
55
57
  # Darwin, MinGW, and NonStop.
56
58
  #
57
59
  # (3) This script is generated from the Groovy template
58
- # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60
+ # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59
61
  # within the Gradle project.
60
62
  #
61
63
  # You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,8 @@ done
84
86
  # shellcheck disable=SC2034
85
87
  APP_BASE_NAME=${0##*/}
86
88
  # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87
- APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89
+ APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90
+ ' "$PWD" ) || exit
88
91
 
89
92
  # Use the maximum available, or set MAX_FD != -1 to use that value.
90
93
  MAX_FD=maximum
@@ -1,4 +1,6 @@
1
+ pluginManagement { includeBuild("<%= offsetFromRoot %>../node_modules/@react-native/gradle-plugin") }
2
+ plugins { id("com.facebook.react.settings") }
3
+ extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
1
4
  rootProject.name = '<%= className %>'
2
- apply from: file("<%= offsetFromRoot %>../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
3
5
  include ':app'
4
6
  includeBuild('<%= offsetFromRoot %>../node_modules/@react-native/gradle-plugin')
@@ -5,6 +5,16 @@
5
5
  "types": ["node"]
6
6
  },
7
7
  "files": ["<%= offsetFromRoot %>node_modules/@nx/react-native/typings/svg.d.ts"],
8
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.spec.tsx", "src/test-setup.ts"],
8
+ "exclude": [
9
+ "src/**/*.test.ts",
10
+ "src/**/*.spec.ts",
11
+ "src/**/*.test.tsx",
12
+ "src/**/*.spec.tsx",
13
+ "src/**/*.test.js",
14
+ "src/**/*.spec.js",
15
+ "src/**/*.test.jsx",
16
+ "src/**/*.spec.jsx",
17
+ "src/test-setup.ts"
18
+ ],
9
19
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"]
10
20
  }
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "extends": "<%= rootTsConfigPath %>",
3
+ <%_ if (!isTsSolutionSetup) { _%>
3
4
  "compilerOptions": {
4
5
  "allowSyntheticDefaultImports": true,
5
6
  "jsx": "react-native",
@@ -9,6 +10,7 @@
9
10
  "resolveJsonModule": true,
10
11
  "declaration": true
11
12
  },
13
+ <%_ } _%>
12
14
  "files": [],
13
15
  "include": [],
14
16
  "references": [
@@ -14,6 +14,7 @@ async function addE2e(host, options) {
14
14
  styledModule: null,
15
15
  hasStyles: false,
16
16
  unitTestRunner: 'none',
17
+ names: (0, devkit_1.names)(options.name),
17
18
  });
18
19
  case 'playwright':
19
20
  return (0, add_e2e_1.addE2e)(host, {
@@ -23,6 +24,7 @@ async function addE2e(host, options) {
23
24
  styledModule: null,
24
25
  hasStyles: false,
25
26
  unitTestRunner: 'none',
27
+ names: (0, devkit_1.names)(options.name),
26
28
  });
27
29
  case 'detox':
28
30
  const { detoxApplicationGenerator } = (0, devkit_1.ensurePackage)('@nx/detox', versions_1.nxVersion);
@@ -30,7 +32,6 @@ async function addE2e(host, options) {
30
32
  ...options,
31
33
  e2eName: options.e2eProjectName,
32
34
  e2eDirectory: options.e2eProjectRoot,
33
- projectNameAndRootFormat: 'as-provided',
34
35
  appProject: options.projectName,
35
36
  appDisplayName: options.displayName,
36
37
  appName: options.name,
@@ -14,9 +14,32 @@ function addProject(host, options) {
14
14
  targets: hasPlugin ? {} : getTargets(options),
15
15
  tags: options.parsedTags,
16
16
  };
17
- (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
18
- ...project,
19
- });
17
+ const packageJson = {
18
+ name: options.importPath,
19
+ version: '0.0.1',
20
+ private: true,
21
+ };
22
+ if (!options.useProjectJson) {
23
+ if (options.projectName !== options.importPath) {
24
+ packageJson.nx = { name: options.projectName };
25
+ }
26
+ if (!hasPlugin) {
27
+ packageJson.nx ??= {};
28
+ packageJson.nx.targets = getTargets(options);
29
+ }
30
+ if (options.parsedTags?.length) {
31
+ packageJson.nx ??= {};
32
+ packageJson.nx.tags = options.parsedTags;
33
+ }
34
+ }
35
+ else {
36
+ (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
37
+ ...project,
38
+ });
39
+ }
40
+ if (!options.useProjectJson || options.isTsSolutionSetup) {
41
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
42
+ }
20
43
  }
21
44
  function getTargets(options) {
22
45
  const architect = {};
@@ -1,6 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from '../schema';
3
- export interface NormalizedSchema extends Schema {
3
+ export interface NormalizedSchema extends Omit<Schema, 'useTsSolution'> {
4
4
  className: string;
5
5
  fileName: string;
6
6
  projectName: string;
@@ -13,5 +13,7 @@ export interface NormalizedSchema extends Schema {
13
13
  rootProject: boolean;
14
14
  e2eProjectName: string;
15
15
  e2eProjectRoot: string;
16
+ importPath: string;
17
+ isTsSolutionSetup: boolean;
16
18
  }
17
19
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -3,23 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = normalizeOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
6
7
  async function normalizeOptions(host, options) {
7
- const { projectName: appProjectName, names: projectNames, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
9
+ const { projectName, names: projectNames, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
10
  name: options.name,
9
11
  projectType: 'application',
10
12
  directory: options.directory,
11
- projectNameAndRootFormat: options.projectNameAndRootFormat,
12
- callingGenerator: '@nx/react-native:application',
13
13
  });
14
- options.projectNameAndRootFormat = projectNameAndRootFormat;
15
14
  const nxJson = (0, devkit_1.readNxJson)(host);
16
15
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
16
  nxJson.useInferencePlugins !== false;
18
17
  options.addPlugin ??= addPluginDefault;
19
- const { className, fileName } = (0, devkit_1.names)(options.name);
18
+ const { className, fileName } = (0, devkit_1.names)(projectNames.projectSimpleName);
20
19
  const iosProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'ios');
21
20
  const androidProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'android');
22
21
  const rootProject = appProjectRoot === '.';
22
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
23
+ const appProjectName = !isTsSolutionSetup || options.name ? projectName : importPath;
23
24
  const e2eProjectName = rootProject ? 'e2e' : `${appProjectName}-e2e`;
24
25
  const e2eProjectRoot = rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
25
26
  const parsedTags = options.tags
@@ -35,6 +36,7 @@ async function normalizeOptions(host, options) {
35
36
  displayName: options.displayName || className,
36
37
  projectName: appProjectName,
37
38
  appProjectRoot,
39
+ importPath,
38
40
  iosProjectRoot,
39
41
  androidProjectRoot,
40
42
  parsedTags,
@@ -42,5 +44,7 @@ async function normalizeOptions(host, options) {
42
44
  rootProject,
43
45
  e2eProjectName,
44
46
  e2eProjectRoot,
47
+ isTsSolutionSetup,
48
+ useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
45
49
  };
46
50
  }
@@ -1,16 +1,13 @@
1
- import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
1
  import type { Linter, LinterType } from '@nx/eslint';
3
2
 
4
3
  export interface Schema {
5
- name: string;
4
+ directory: string;
5
+ name?: string;
6
6
  displayName?: string;
7
7
  style?: string;
8
8
  skipFormat?: boolean;
9
- directory?: string;
10
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
9
  tags?: string;
12
10
  unitTestRunner: 'jest' | 'none'; // default is jest
13
- pascalCaseFiles?: boolean;
14
11
  classComponent?: boolean;
15
12
  js?: boolean;
16
13
  linter: Linter | LinterType;
@@ -19,6 +16,10 @@ export interface Schema {
19
16
  bundler: 'webpack' | 'vite'; // default is webpack
20
17
  install: boolean; // default is true
21
18
  skipPackageJson?: boolean; //default is false
19
+ // Internal options
22
20
  addPlugin?: boolean;
23
21
  nxCloudToken?: string;
22
+ useTsSolution?: boolean;
23
+ formatter?: 'prettier' | 'none';
24
+ useProjectJson?: boolean;
24
25
  }
@@ -16,29 +16,24 @@
16
16
  ],
17
17
  "type": "object",
18
18
  "properties": {
19
- "name": {
20
- "description": "The name of the application.",
19
+ "directory": {
20
+ "description": "The directory of the new application.",
21
21
  "type": "string",
22
22
  "$default": {
23
23
  "$source": "argv",
24
24
  "index": 0
25
25
  },
26
- "x-prompt": "What name would you like to use for the application?",
27
- "pattern": "^[a-zA-Z][^:]*$"
26
+ "x-prompt": "Which directory do you want to create the application in?"
28
27
  },
29
- "displayName": {
30
- "description": "The display name to show in the application. Defaults to name.",
28
+ "name": {
29
+ "description": "The name of the application.",
30
+ "pattern": "^[a-zA-Z][^:]*$",
31
31
  "type": "string"
32
32
  },
33
- "directory": {
34
- "description": "The directory of the new application.",
33
+ "displayName": {
34
+ "description": "The display name to show in the application. Defaults to name.",
35
35
  "type": "string"
36
36
  },
37
- "projectNameAndRootFormat": {
38
- "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
39
- "type": "string",
40
- "enum": ["as-provided", "derived"]
41
- },
42
37
  "skipFormat": {
43
38
  "description": "Skip formatting files",
44
39
  "type": "boolean",
@@ -49,13 +44,15 @@
49
44
  "description": "The tool to use for running lint checks.",
50
45
  "type": "string",
51
46
  "enum": ["eslint", "none"],
52
- "default": "eslint"
47
+ "default": "none",
48
+ "x-priority": "important"
53
49
  },
54
50
  "unitTestRunner": {
55
51
  "type": "string",
56
52
  "enum": ["jest", "none"],
57
53
  "description": "Test runner to use for unit tests",
58
- "default": "jest"
54
+ "default": "none",
55
+ "x-priority": "important"
59
56
  },
60
57
  "tags": {
61
58
  "type": "string",
@@ -76,7 +73,8 @@
76
73
  "description": "Adds the specified e2e test runner.",
77
74
  "type": "string",
78
75
  "enum": ["playwright", "cypress", "detox", "none"],
79
- "default": "playwright"
76
+ "default": "none",
77
+ "x-priority": "important"
80
78
  },
81
79
  "install": {
82
80
  "type": "boolean",
@@ -95,9 +93,13 @@
95
93
  "type": "string",
96
94
  "enum": ["vite", "webpack"],
97
95
  "x-prompt": "Which bundler do you want to use to build the application?",
98
- "default": "webpack",
96
+ "default": "vite",
99
97
  "x-priority": "important"
98
+ },
99
+ "useProjectJson": {
100
+ "type": "boolean",
101
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
100
102
  }
101
103
  },
102
- "required": []
104
+ "required": ["directory"]
103
105
  }
@@ -1,5 +1,4 @@
1
1
  import { Schema } from './schema';
2
2
  import { Tree } from '@nx/devkit';
3
3
  export declare function reactNativeComponentGenerator(host: Tree, schema: Schema): Promise<void>;
4
- export declare function reactNativeComponentGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
5
4
  export default reactNativeComponentGenerator;
@@ -1,40 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeComponentGenerator = reactNativeComponentGenerator;
4
- exports.reactNativeComponentGeneratorInternal = reactNativeComponentGeneratorInternal;
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const normalize_options_1 = require("./lib/normalize-options");
7
6
  const add_import_1 = require("./lib/add-import");
8
7
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
9
8
  const path_1 = require("path");
9
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
10
10
  async function reactNativeComponentGenerator(host, schema) {
11
- return reactNativeComponentGeneratorInternal(host, {
12
- nameAndDirectoryFormat: 'derived',
13
- ...schema,
14
- });
15
- }
16
- async function reactNativeComponentGeneratorInternal(host, schema) {
17
11
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
18
12
  createComponentFiles(host, options);
19
13
  addExportsToBarrel(host, options);
20
- await (0, devkit_1.formatFiles)(host);
14
+ if (!options.skipFormat) {
15
+ await (0, devkit_1.formatFiles)(host);
16
+ }
21
17
  }
22
18
  function createComponentFiles(host, options) {
23
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.directory, {
19
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files', options.fileExtensionType), options.directory, {
24
20
  ...options,
25
- tmpl: '',
21
+ ext: options.fileExtension,
26
22
  });
27
- for (const c of host.listChanges()) {
28
- let deleteFile = false;
29
- if (options.skipTests && /.*spec.tsx/.test(c.path)) {
30
- deleteFile = true;
31
- }
32
- if (deleteFile) {
33
- host.delete(c.path);
34
- }
35
- }
36
- if (options.js) {
37
- (0, devkit_1.toJS)(host);
23
+ if (options.skipTests) {
24
+ host.delete((0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.${options.fileExtension}`));
38
25
  }
39
26
  }
40
27
  let tsModule;
@@ -43,16 +30,20 @@ function addExportsToBarrel(host, options) {
43
30
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
44
31
  }
45
32
  const workspace = (0, devkit_1.getProjects)(host);
46
- const isApp = workspace.get(options.projectName).projectType === 'application';
33
+ const proj = workspace.get(options.projectName);
34
+ const isApp = (0, ts_solution_setup_1.getProjectType)(host, proj.root, proj.projectType) === 'application';
47
35
  if (options.export && !isApp) {
48
- const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts');
49
- const indexSource = host.read(indexFilePath, 'utf-8');
50
- if (indexSource !== null) {
51
- const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
52
- const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
53
- const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
54
- host.write(indexFilePath, changes);
36
+ const indexFilePath = (0, devkit_1.joinPathFragments)(...(options.projectSourceRoot
37
+ ? [options.projectSourceRoot]
38
+ : [options.projectRoot, 'src']), options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
39
+ if (!host.exists(indexFilePath)) {
40
+ return;
55
41
  }
42
+ const indexSource = host.read(indexFilePath, 'utf-8');
43
+ const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
44
+ const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
45
+ const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
46
+ host.write(indexFilePath, changes);
56
47
  }
57
48
  }
58
49
  function getRelativeImportToFile(indexPath, filePath) {
@@ -0,0 +1,28 @@
1
+ <%_ if (classComponent) { _%>
2
+ import { Component } from 'react';
3
+ <%_ } else { _%>
4
+ import React from 'react';
5
+ <%_ } _%>
6
+ import { View, Text } from 'react-native';
7
+
8
+ <%_ if (classComponent) { _%>
9
+ export class <%= className %> extends Component {
10
+ render() {
11
+ return (
12
+ <View>
13
+ <Text>Welcome to <%= name %>!</Text>
14
+ </View>
15
+ );
16
+ }
17
+ }
18
+ <%_ } else { _%>
19
+ export function <%= className %>(props) {
20
+ return (
21
+ <View>
22
+ <Text>Welcome to <%= name %>!</Text>
23
+ </View>
24
+ );
25
+ }
26
+ <%_ } _%>
27
+
28
+ export default <%= className %>;
@@ -1,15 +1,15 @@
1
- <% if (classComponent) { %>
1
+ <%_ if (classComponent) { _%>
2
2
  import { Component } from 'react';
3
- <% } else { %>
3
+ <%_ } else { _%>
4
4
  import React from 'react';
5
- <% } %>
5
+ <%_ } _%>
6
6
  import { View, Text } from 'react-native';
7
7
 
8
8
  /* eslint-disable-next-line */
9
9
  export interface <%= className %>Props {
10
10
  }
11
11
 
12
- <% if (classComponent) { %>
12
+ <%_ if (classComponent) { _%>
13
13
  export class <%= className %> extends Component<<%= className %>Props> {
14
14
  render() {
15
15
  return (
@@ -19,7 +19,7 @@ export class <%= className %> extends Component<<%= className %>Props> {
19
19
  );
20
20
  }
21
21
  }
22
- <% } else { %>
22
+ <%_ } else { _%>
23
23
  export function <%= className %>(props: <%= className %>Props) {
24
24
  return (
25
25
  <View>
@@ -27,6 +27,6 @@ export function <%= className %>(props: <%= className %>Props) {
27
27
  </View>
28
28
  );
29
29
  }
30
- <% } %>
30
+ <%_ } _%>
31
31
 
32
32
  export default <%= className %>;