@nx/react-native 0.0.0-pr-22179-271588f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +48 -0
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/executors.json +59 -0
- package/generators.json +58 -0
- package/index.d.ts +5 -0
- package/index.js +13 -0
- package/migrations.json +632 -0
- package/package.json +57 -0
- package/plugin.d.ts +1 -0
- package/plugin.js +6 -0
- package/plugins/jest/svg-mock.d.ts +0 -0
- package/plugins/jest/svg-mock.js +3 -0
- package/plugins/metro-resolver.d.ts +1 -0
- package/plugins/metro-resolver.js +136 -0
- package/plugins/plugin.d.ts +14 -0
- package/plugins/plugin.js +162 -0
- package/plugins/with-nx-metro.d.ts +8 -0
- package/plugins/with-nx-metro.js +31 -0
- package/project.json +54 -0
- package/src/executors/build-android/build-android.impl.d.ts +6 -0
- package/src/executors/build-android/build-android.impl.js +48 -0
- package/src/executors/build-android/build-android.impl.ts +69 -0
- package/src/executors/build-android/schema.d.ts +14 -0
- package/src/executors/build-android/schema.json +81 -0
- package/src/executors/build-ios/build-ios.impl.d.ts +6 -0
- package/src/executors/build-ios/build-ios.impl.js +55 -0
- package/src/executors/build-ios/build-ios.impl.ts +77 -0
- package/src/executors/build-ios/schema.d.ts +17 -0
- package/src/executors/build-ios/schema.json +91 -0
- package/src/executors/bundle/bundle.impl.d.ts +6 -0
- package/src/executors/bundle/bundle.impl.js +56 -0
- package/src/executors/bundle/bundle.impl.ts +77 -0
- package/src/executors/bundle/schema.d.ts +16 -0
- package/src/executors/bundle/schema.json +92 -0
- package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +9 -0
- package/src/executors/ensure-symlink/ensure-symlink.impl.js +13 -0
- package/src/executors/ensure-symlink/ensure-symlink.impl.ts +22 -0
- package/src/executors/ensure-symlink/schema.json +11 -0
- package/src/executors/pod-install/pod-install.impl.d.ts +6 -0
- package/src/executors/pod-install/pod-install.impl.js +11 -0
- package/src/executors/pod-install/pod-install.impl.ts +21 -0
- package/src/executors/pod-install/schema.d.ts +6 -0
- package/src/executors/pod-install/schema.json +33 -0
- package/src/executors/run-android/run-android.impl.d.ts +6 -0
- package/src/executors/run-android/run-android.impl.js +66 -0
- package/src/executors/run-android/run-android.impl.ts +94 -0
- package/src/executors/run-android/schema.d.ts +13 -0
- package/src/executors/run-android/schema.json +100 -0
- package/src/executors/run-ios/run-ios.impl.d.ts +6 -0
- package/src/executors/run-ios/run-ios.impl.js +65 -0
- package/src/executors/run-ios/run-ios.impl.ts +92 -0
- package/src/executors/run-ios/schema.d.ts +7 -0
- package/src/executors/run-ios/schema.json +96 -0
- package/src/executors/start/lib/is-packager-running.d.ts +1 -0
- package/src/executors/start/lib/is-packager-running.js +15 -0
- package/src/executors/start/schema.d.ts +7 -0
- package/src/executors/start/schema.json +28 -0
- package/src/executors/start/start.impl.d.ts +10 -0
- package/src/executors/start/start.impl.js +87 -0
- package/src/executors/start/start.impl.ts +111 -0
- package/src/executors/storybook/schema.d.ts +5 -0
- package/src/executors/storybook/schema.json +29 -0
- package/src/executors/storybook/storybook.impl.d.ts +10 -0
- package/src/executors/storybook/storybook.impl.js +51 -0
- package/src/executors/storybook/storybook.impl.ts +85 -0
- package/src/executors/sync-deps/schema.d.ts +5 -0
- package/src/executors/sync-deps/schema.json +33 -0
- package/src/executors/sync-deps/sync-deps.impl.d.ts +9 -0
- package/src/executors/sync-deps/sync-deps.impl.js +78 -0
- package/src/executors/sync-deps/sync-deps.impl.ts +140 -0
- package/src/executors/upgrade/schema.d.ts +1 -0
- package/src/executors/upgrade/schema.json +11 -0
- package/src/executors/upgrade/upgrade.impl.d.ts +13 -0
- package/src/executors/upgrade/upgrade.impl.js +47 -0
- package/src/executors/upgrade/upgrade.impl.ts +64 -0
- package/src/generators/application/application.d.ts +5 -0
- package/src/generators/application/application.js +87 -0
- package/src/generators/application/application.spec.ts +258 -0
- package/src/generators/application/files/app/.babelrc.js.template +23 -0
- package/src/generators/application/files/app/Gemfile.template +7 -0
- package/src/generators/application/files/app/android/app/build.gradle.template +119 -0
- package/src/generators/application/files/app/android/app/debug.keystore +0 -0
- package/src/generators/application/files/app/android/app/proguard-rules.pro +10 -0
- package/src/generators/application/files/app/android/app/src/androidTest/java/com/__lowerCaseName__/DetoxTest.java.template +30 -0
- package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +10 -0
- package/src/generators/application/files/app/android/app/src/main/AndroidManifest.xml.template +26 -0
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +22 -0
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +45 -0
- package/src/generators/application/files/app/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/src/generators/application/files/app/android/app/src/main/res/values/strings.xml.template +3 -0
- package/src/generators/application/files/app/android/app/src/main/res/values/styles.xml +9 -0
- package/src/generators/application/files/app/android/app/src/main/res/xml/network_security_config.xml +7 -0
- package/src/generators/application/files/app/android/build.gradle.template +21 -0
- package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/src/generators/application/files/app/android/gradle.properties +41 -0
- package/src/generators/application/files/app/android/gradlew.bat +92 -0
- package/src/generators/application/files/app/android/gradlew.template +249 -0
- package/src/generators/application/files/app/android/settings.gradle.template +4 -0
- package/src/generators/application/files/app/app.json.template +4 -0
- package/src/generators/application/files/app/ios/.xcode.env.template +12 -0
- package/src/generators/application/files/app/ios/Podfile.template +55 -0
- package/src/generators/application/files/app/ios/__className__/AppDelegate.h +6 -0
- package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +31 -0
- package/src/generators/application/files/app/ios/__className__/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/src/generators/application/files/app/ios/__className__/Images.xcassets/Contents.json +6 -0
- package/src/generators/application/files/app/ios/__className__/Info.plist.template +52 -0
- package/src/generators/application/files/app/ios/__className__/LaunchScreen.storyboard.template +47 -0
- package/src/generators/application/files/app/ios/__className__/main.m +10 -0
- package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +684 -0
- package/src/generators/application/files/app/ios/__className__.xcodeproj/xcshareddata/xcschemes/__className__.xcscheme.template +88 -0
- package/src/generators/application/files/app/ios/__className__.xcworkspace/contents.xcworkspacedata +10 -0
- package/src/generators/application/files/app/ios/__className__Tests/Info.plist +24 -0
- package/src/generators/application/files/app/ios/__className__Tests/__className__Tests.m +66 -0
- package/src/generators/application/files/app/metro.config.js.template +31 -0
- package/src/generators/application/files/app/package.json.template +14 -0
- package/src/generators/application/files/app/src/app/App.spec.tsx.template +9 -0
- package/src/generators/application/files/app/src/app/App.tsx.template +731 -0
- package/src/generators/application/files/app/src/main.tsx.template +4 -0
- package/src/generators/application/files/app/test-setup.ts.template +1 -0
- package/src/generators/application/files/app/tsconfig.app.json.template +10 -0
- package/src/generators/application/files/app/tsconfig.json.template +19 -0
- package/src/generators/application/lib/add-e2e.d.ts +3 -0
- package/src/generators/application/lib/add-e2e.js +46 -0
- package/src/generators/application/lib/add-project.d.ts +3 -0
- package/src/generators/application/lib/add-project.js +91 -0
- package/src/generators/application/lib/create-application-files.d.ts +3 -0
- package/src/generators/application/lib/create-application-files.js +24 -0
- package/src/generators/application/lib/normalize-options.d.ts +17 -0
- package/src/generators/application/lib/normalize-options.js +47 -0
- package/src/generators/application/lib/normalize-options.spec.ts +196 -0
- package/src/generators/application/schema.d.ts +23 -0
- package/src/generators/application/schema.json +103 -0
- package/src/generators/component/component.d.ts +5 -0
- package/src/generators/component/component.js +64 -0
- package/src/generators/component/component.spec.ts +127 -0
- package/src/generators/component/files/__fileName__.spec.tsx__tmpl__ +11 -0
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +32 -0
- package/src/generators/component/lib/add-import.d.ts +3 -0
- package/src/generators/component/lib/add-import.js +33 -0
- package/src/generators/component/lib/normalize-options.d.ts +10 -0
- package/src/generators/component/lib/normalize-options.js +50 -0
- package/src/generators/component/schema.d.ts +24 -0
- package/src/generators/component/schema.json +85 -0
- package/src/generators/component-story/component-story.d.ts +8 -0
- package/src/generators/component-story/component-story.js +15 -0
- package/src/generators/component-story/schema.d.ts +6 -0
- package/src/generators/component-story/schema.json +42 -0
- package/src/generators/init/init.d.ts +6 -0
- package/src/generators/init/init.js +78 -0
- package/src/generators/init/init.spec.ts +38 -0
- package/src/generators/init/lib/add-git-ignore-entry.d.ts +2 -0
- package/src/generators/init/lib/add-git-ignore-entry.js +24 -0
- package/src/generators/init/lib/gitignore-entries.d.ts +1 -0
- package/src/generators/init/lib/gitignore-entries.js +74 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +35 -0
- package/src/generators/library/files/lib/.babelrc.js.template +21 -0
- package/src/generators/library/files/lib/README.md +7 -0
- package/src/generators/library/files/lib/package.json.template +4 -0
- package/src/generators/library/files/lib/src/index.ts.template +0 -0
- package/src/generators/library/files/lib/test-setup.ts.template +1 -0
- package/src/generators/library/files/lib/tsconfig.json.template +16 -0
- package/src/generators/library/files/lib/tsconfig.lib.json.template +9 -0
- package/src/generators/library/lib/normalize-options.d.ts +12 -0
- package/src/generators/library/lib/normalize-options.js +33 -0
- package/src/generators/library/library.d.ts +5 -0
- package/src/generators/library/library.js +154 -0
- package/src/generators/library/library.spec.ts +420 -0
- package/src/generators/library/schema.d.ts +25 -0
- package/src/generators/library/schema.json +107 -0
- package/src/generators/stories/schema.d.ts +7 -0
- package/src/generators/stories/schema.json +58 -0
- package/src/generators/stories/stories.d.ts +8 -0
- package/src/generators/stories/stories.js +13 -0
- package/src/generators/storybook-configuration/configuration.d.ts +9 -0
- package/src/generators/storybook-configuration/configuration.js +26 -0
- package/src/generators/storybook-configuration/schema.d.ts +13 -0
- package/src/generators/storybook-configuration/schema.json +79 -0
- package/src/generators/upgrade-native/lib/create-native-files.d.ts +3 -0
- package/src/generators/upgrade-native/lib/create-native-files.js +14 -0
- package/src/generators/upgrade-native/lib/normalize-options.d.ts +12 -0
- package/src/generators/upgrade-native/lib/normalize-options.js +27 -0
- package/src/generators/upgrade-native/schema.d.ts +9 -0
- package/src/generators/upgrade-native/schema.json +41 -0
- package/src/generators/upgrade-native/upgrade-native.d.ts +10 -0
- package/src/generators/upgrade-native/upgrade-native.js +31 -0
- package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +23 -0
- package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +15 -0
- package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
- package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
- package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +9 -0
- package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +82 -0
- package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +23 -0
- package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
- package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
- package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +14 -0
- package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +9 -0
- package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +77 -0
- package/src/generators/web-configuration/lib/normalize-schema.d.ts +17 -0
- package/src/generators/web-configuration/lib/normalize-schema.js +16 -0
- package/src/generators/web-configuration/lib/webpack-targets.d.ts +7 -0
- package/src/generators/web-configuration/lib/webpack-targets.js +75 -0
- package/src/generators/web-configuration/schema.d.ts +6 -0
- package/src/generators/web-configuration/schema.json +42 -0
- package/src/generators/web-configuration/web-configuration.d.ts +12 -0
- package/src/generators/web-configuration/web-configuration.js +87 -0
- package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +2 -0
- package/src/migrations/update-15-0-0/add-babel-inputs.js +9 -0
- package/src/migrations/update-15-0-0/add-babel-inputs.spec.ts +73 -0
- package/src/migrations/update-15-9-1/add-build-ios-target.d.ts +5 -0
- package/src/migrations/update-15-9-1/add-build-ios-target.js +29 -0
- package/src/migrations/update-15-9-1/add-build-ios-target.spec.ts +36 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.spec.ts +37 -0
- package/src/migrations/update-16-1-0/upgrade-storybook-6-5.d.ts +6 -0
- package/src/migrations/update-16-1-0/upgrade-storybook-6-5.js +21 -0
- package/src/migrations/update-16-6-0/add-depends-on.d.ts +6 -0
- package/src/migrations/update-16-6-0/add-depends-on.js +63 -0
- package/src/migrations/update-16-6-0/update-metro-config.d.ts +6 -0
- package/src/migrations/update-16-6-0/update-metro-config.js +63 -0
- package/src/migrations/update-16-9-0/remove-types-react-native.d.ts +7 -0
- package/src/migrations/update-16-9-0/remove-types-react-native.js +13 -0
- package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +6 -0
- package/src/migrations/update-18-0-0/add-upgrade-target.js +33 -0
- package/src/migrations/update-18-0-0/add-web-configuration.d.ts +8 -0
- package/src/migrations/update-18-0-0/add-web-configuration.js +33 -0
- package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +39 -0
- package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +5 -0
- package/src/migrations/update-18-0-0/change-storybook-targets.js +57 -0
- package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
- package/src/migrations/update-18-0-0/remove-block-list.js +28 -0
- package/src/migrations/update-18-0-0/remove-block-list.spec.ts +68 -0
- package/src/migrations/update-18-0-0/remove-metro.d.ts +14 -0
- package/src/migrations/update-18-0-0/remove-metro.js +29 -0
- package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
- package/src/migrations/update-18-0-0/remove-symlink-target.js +30 -0
- package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +40 -0
- package/src/utils/add-jest.d.ts +2 -0
- package/src/utils/add-jest.js +48 -0
- package/src/utils/add-linting.d.ts +13 -0
- package/src/utils/add-linting.js +36 -0
- package/src/utils/add-linting.spec.ts +40 -0
- package/src/utils/chmod-android-gradle-files.d.ts +3 -0
- package/src/utils/chmod-android-gradle-files.js +27 -0
- package/src/utils/ensure-dependencies.d.ts +2 -0
- package/src/utils/ensure-dependencies.js +30 -0
- package/src/utils/ensure-node-modules-symlink.d.ts +9 -0
- package/src/utils/ensure-node-modules-symlink.js +28 -0
- package/src/utils/ensure-node-modules-symlink.spec.ts +108 -0
- package/src/utils/find-all-npm-dependencies.d.ts +2 -0
- package/src/utils/find-all-npm-dependencies.js +27 -0
- package/src/utils/find-all-npm-dependencies.spec.ts +103 -0
- package/src/utils/format-file.d.ts +1 -0
- package/src/utils/format-file.js +16 -0
- package/src/utils/get-cli-options.d.ts +8 -0
- package/src/utils/get-cli-options.js +33 -0
- package/src/utils/pod-install-task.d.ts +18 -0
- package/src/utils/pod-install-task.js +73 -0
- package/src/utils/testing-generators.d.ts +3 -0
- package/src/utils/testing-generators.js +32 -0
- package/src/utils/versions.d.ts +17 -0
- package/src/utils/versions.js +20 -0
- package/typings/svg.d.ts +7 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reactNativeComponentGeneratorInternal = exports.reactNativeComponentGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const normalize_options_1 = require("./lib/normalize-options");
|
|
6
|
+
const add_import_1 = require("./lib/add-import");
|
|
7
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
async function reactNativeComponentGenerator(host, schema) {
|
|
10
|
+
return reactNativeComponentGeneratorInternal(host, {
|
|
11
|
+
nameAndDirectoryFormat: 'derived',
|
|
12
|
+
...schema,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.reactNativeComponentGenerator = reactNativeComponentGenerator;
|
|
16
|
+
async function reactNativeComponentGeneratorInternal(host, schema) {
|
|
17
|
+
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
18
|
+
createComponentFiles(host, options);
|
|
19
|
+
addExportsToBarrel(host, options);
|
|
20
|
+
await (0, devkit_1.formatFiles)(host);
|
|
21
|
+
}
|
|
22
|
+
exports.reactNativeComponentGeneratorInternal = reactNativeComponentGeneratorInternal;
|
|
23
|
+
function createComponentFiles(host, options) {
|
|
24
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.directory, {
|
|
25
|
+
...options,
|
|
26
|
+
tmpl: '',
|
|
27
|
+
});
|
|
28
|
+
for (const c of host.listChanges()) {
|
|
29
|
+
let deleteFile = false;
|
|
30
|
+
if (options.skipTests && /.*spec.tsx/.test(c.path)) {
|
|
31
|
+
deleteFile = true;
|
|
32
|
+
}
|
|
33
|
+
if (deleteFile) {
|
|
34
|
+
host.delete(c.path);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (options.js) {
|
|
38
|
+
(0, devkit_1.toJS)(host);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
let tsModule;
|
|
42
|
+
function addExportsToBarrel(host, options) {
|
|
43
|
+
if (!tsModule) {
|
|
44
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
45
|
+
}
|
|
46
|
+
const workspace = (0, devkit_1.getProjects)(host);
|
|
47
|
+
const isApp = workspace.get(options.projectName).projectType === 'application';
|
|
48
|
+
if (options.export && !isApp) {
|
|
49
|
+
const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts');
|
|
50
|
+
const indexSource = host.read(indexFilePath, 'utf-8');
|
|
51
|
+
if (indexSource !== null) {
|
|
52
|
+
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
53
|
+
const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
|
|
54
|
+
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
|
|
55
|
+
host.write(indexFilePath, changes);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function getRelativeImportToFile(indexPath, filePath) {
|
|
60
|
+
const { name, dir } = (0, path_1.parse)(filePath);
|
|
61
|
+
const relativeDirToTarget = (0, path_1.relative)((0, path_1.dirname)(indexPath), dir);
|
|
62
|
+
return `./${(0, devkit_1.joinPathFragments)(relativeDirToTarget, name)}`;
|
|
63
|
+
}
|
|
64
|
+
exports.default = reactNativeComponentGenerator;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { logger, Tree } from '@nx/devkit';
|
|
2
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
+
import { createApp, createLib } from '../../utils/testing-generators';
|
|
4
|
+
import { reactNativeComponentGenerator } from './component';
|
|
5
|
+
|
|
6
|
+
describe('component', () => {
|
|
7
|
+
let appTree: Tree;
|
|
8
|
+
let projectName: string;
|
|
9
|
+
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
projectName = 'my-lib';
|
|
12
|
+
appTree = createTreeWithEmptyWorkspace();
|
|
13
|
+
appTree.write('.gitignore', '');
|
|
14
|
+
await createApp(appTree, 'my-app');
|
|
15
|
+
await createLib(appTree, projectName);
|
|
16
|
+
jest.spyOn(logger, 'warn').mockImplementation(() => {});
|
|
17
|
+
jest.spyOn(logger, 'debug').mockImplementation(() => {});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
jest.restoreAllMocks();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should generate component files', async () => {
|
|
25
|
+
await reactNativeComponentGenerator(appTree, {
|
|
26
|
+
name: 'hello',
|
|
27
|
+
project: projectName,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
expect(appTree.exists('my-lib/src/lib/hello/hello.tsx')).toBeTruthy();
|
|
31
|
+
expect(appTree.exists('my-lib/src/lib/hello/hello.spec.tsx')).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should generate files for an app', async () => {
|
|
35
|
+
await reactNativeComponentGenerator(appTree, {
|
|
36
|
+
name: 'hello',
|
|
37
|
+
project: 'my-app',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(appTree.exists('my-app/src/app/hello/hello.tsx')).toBeTruthy();
|
|
41
|
+
expect(appTree.exists('my-app/src/app/hello/hello.spec.tsx')).toBeTruthy();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('--export', () => {
|
|
45
|
+
it('should add to index.ts barrel', async () => {
|
|
46
|
+
await reactNativeComponentGenerator(appTree, {
|
|
47
|
+
name: 'hello',
|
|
48
|
+
project: projectName,
|
|
49
|
+
export: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const indexContent = appTree.read('my-lib/src/index.ts', 'utf-8');
|
|
53
|
+
|
|
54
|
+
expect(indexContent).toMatch(/lib\/hello/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should not export from an app', async () => {
|
|
58
|
+
await reactNativeComponentGenerator(appTree, {
|
|
59
|
+
name: 'hello',
|
|
60
|
+
project: 'my-app',
|
|
61
|
+
export: true,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const indexContent = appTree.read('my-lib/src/index.ts', 'utf-8');
|
|
65
|
+
|
|
66
|
+
expect(indexContent).not.toMatch(/lib\/hello/);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('--pascalCaseFiles', () => {
|
|
71
|
+
it('should generate component files with upper case names', async () => {
|
|
72
|
+
await reactNativeComponentGenerator(appTree, {
|
|
73
|
+
name: 'hello',
|
|
74
|
+
project: projectName,
|
|
75
|
+
pascalCaseFiles: true,
|
|
76
|
+
});
|
|
77
|
+
expect(appTree.exists('my-lib/src/lib/hello/Hello.tsx')).toBeTruthy();
|
|
78
|
+
expect(
|
|
79
|
+
appTree.exists('my-lib/src/lib/hello/Hello.spec.tsx')
|
|
80
|
+
).toBeTruthy();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('--directory', () => {
|
|
85
|
+
it('should create component under the directory', async () => {
|
|
86
|
+
await reactNativeComponentGenerator(appTree, {
|
|
87
|
+
name: 'hello',
|
|
88
|
+
project: projectName,
|
|
89
|
+
directory: 'components',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(appTree.exists('my-lib/src/components/hello/hello.tsx'));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should create with nested directories', async () => {
|
|
96
|
+
await reactNativeComponentGenerator(appTree, {
|
|
97
|
+
name: 'helloWorld',
|
|
98
|
+
project: projectName,
|
|
99
|
+
directory: 'lib/foo',
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(appTree.exists('my-lib/src/lib/foo/hello-world/hello-world.tsx'));
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('--flat', () => {
|
|
107
|
+
it('should create in project directory rather than in its own folder', async () => {
|
|
108
|
+
await reactNativeComponentGenerator(appTree, {
|
|
109
|
+
name: 'hello',
|
|
110
|
+
project: projectName,
|
|
111
|
+
flat: true,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(appTree.exists('my-lib/src/lib/hello.tsx'));
|
|
115
|
+
});
|
|
116
|
+
it('should work with custom directory path', async () => {
|
|
117
|
+
await reactNativeComponentGenerator(appTree, {
|
|
118
|
+
name: 'hello',
|
|
119
|
+
project: projectName,
|
|
120
|
+
flat: true,
|
|
121
|
+
directory: 'components',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(appTree.exists('my-lib/src/components/hello.tsx'));
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
3
|
+
|
|
4
|
+
import <%= className %> from './<%= fileName %>';
|
|
5
|
+
|
|
6
|
+
describe('<%= className %>', () => {
|
|
7
|
+
it('should render successfully', () => {
|
|
8
|
+
const { root } = render(< <%= className %> />);
|
|
9
|
+
expect(root).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
/* eslint-disable-next-line */
|
|
9
|
+
export interface <%= className %>Props {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
<% if (classComponent) { %>
|
|
13
|
+
export class <%= className %> extends Component<<%= className %>Props> {
|
|
14
|
+
render() {
|
|
15
|
+
return (
|
|
16
|
+
<View>
|
|
17
|
+
<Text>Welcome to <%= name %>!</Text>
|
|
18
|
+
</View>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
<% } else { %>
|
|
23
|
+
export function <%= className %>(props: <%= className %>Props) {
|
|
24
|
+
return (
|
|
25
|
+
<View>
|
|
26
|
+
<Text>Welcome to <%= name %>!</Text>
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
<% } %>
|
|
31
|
+
|
|
32
|
+
export default <%= className %>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addImport = void 0;
|
|
4
|
+
const js_1 = require("@nx/js");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
7
|
+
let tsModule;
|
|
8
|
+
function addImport(source, statement) {
|
|
9
|
+
if (!tsModule) {
|
|
10
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
11
|
+
}
|
|
12
|
+
const allImports = (0, js_1.findNodes)(source, tsModule.SyntaxKind.ImportDeclaration);
|
|
13
|
+
if (allImports.length > 0) {
|
|
14
|
+
const lastImport = allImports[allImports.length - 1];
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
type: devkit_1.ChangeType.Insert,
|
|
18
|
+
index: lastImport.end + 1,
|
|
19
|
+
text: `\n${statement}\n`,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
type: devkit_1.ChangeType.Insert,
|
|
27
|
+
index: 0,
|
|
28
|
+
text: `\n${statement}\n`,
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.addImport = addImport;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from '../schema';
|
|
3
|
+
export interface NormalizedSchema extends Schema {
|
|
4
|
+
projectSourceRoot: string;
|
|
5
|
+
fileName: string;
|
|
6
|
+
className: string;
|
|
7
|
+
filePath: string;
|
|
8
|
+
projectName: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
6
|
+
async function normalizeOptions(host, options) {
|
|
7
|
+
assertValidOptions(options);
|
|
8
|
+
const { artifactName: name, directory, fileName, filePath, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
|
9
|
+
artifactType: 'component',
|
|
10
|
+
callingGenerator: '@nx/react-native:component',
|
|
11
|
+
name: options.name,
|
|
12
|
+
directory: options.directory,
|
|
13
|
+
derivedDirectory: options.directory,
|
|
14
|
+
flat: options.flat,
|
|
15
|
+
nameAndDirectoryFormat: options.nameAndDirectoryFormat,
|
|
16
|
+
project: options.project,
|
|
17
|
+
fileExtension: 'tsx',
|
|
18
|
+
pascalCaseFile: options.pascalCaseFiles,
|
|
19
|
+
});
|
|
20
|
+
const project = (0, devkit_1.getProjects)(host).get(projectName);
|
|
21
|
+
const { className } = (0, devkit_1.names)(name);
|
|
22
|
+
const { sourceRoot: projectSourceRoot, projectType } = project;
|
|
23
|
+
if (options.export && projectType === 'application') {
|
|
24
|
+
devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
|
|
25
|
+
}
|
|
26
|
+
options.classComponent = options.classComponent ?? false;
|
|
27
|
+
return {
|
|
28
|
+
...options,
|
|
29
|
+
directory,
|
|
30
|
+
className,
|
|
31
|
+
fileName,
|
|
32
|
+
filePath,
|
|
33
|
+
projectSourceRoot,
|
|
34
|
+
projectName,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.normalizeOptions = normalizeOptions;
|
|
38
|
+
function assertValidOptions(options) {
|
|
39
|
+
const slashes = ['/', '\\'];
|
|
40
|
+
slashes.forEach((s) => {
|
|
41
|
+
if (options.name.indexOf(s) !== -1) {
|
|
42
|
+
const [name, ...rest] = options.name.split(s).reverse();
|
|
43
|
+
let suggestion = rest.map((x) => x.toLowerCase()).join(s);
|
|
44
|
+
if (options.directory) {
|
|
45
|
+
suggestion = `${options.directory}${s}${suggestion}`;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`Found "${s}" in the component name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Same as the @nx/react library schema, except it removes keys: style, routing, globalCss
|
|
3
|
+
*/
|
|
4
|
+
export interface Schema {
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19.
|
|
8
|
+
*/
|
|
9
|
+
project: string;
|
|
10
|
+
skipTests?: boolean;
|
|
11
|
+
directory?: string;
|
|
12
|
+
export?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
15
|
+
*/
|
|
16
|
+
pascalCaseFiles?: boolean;
|
|
17
|
+
classComponent?: boolean;
|
|
18
|
+
js?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
|
|
21
|
+
*/
|
|
22
|
+
flat?: boolean;
|
|
23
|
+
nameAndDirectoryFormat?: 'as-provided' | 'derived';
|
|
24
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cli": "nx",
|
|
3
|
+
"$id": "NxReactNativeApplication",
|
|
4
|
+
"$schema": "https://json-schema.org/schema",
|
|
5
|
+
"title": "Create a React Native Component for Nx",
|
|
6
|
+
"description": "Create a React native Component for Nx.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"command": "nx g @nx/react-native:component my-component --project=mylib",
|
|
11
|
+
"description": "Generate a component in the `mylib` library"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"command": "nx g @nx/react-native:component my-component --project=mylib --classComponent",
|
|
15
|
+
"description": "Generate a class component in the `mylib` library"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"properties": {
|
|
19
|
+
"project": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "The name of the project.",
|
|
22
|
+
"alias": "p",
|
|
23
|
+
"$default": {
|
|
24
|
+
"$source": "projectName"
|
|
25
|
+
},
|
|
26
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19."
|
|
27
|
+
},
|
|
28
|
+
"name": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "The name of the component.",
|
|
31
|
+
"$default": {
|
|
32
|
+
"$source": "argv",
|
|
33
|
+
"index": 0
|
|
34
|
+
},
|
|
35
|
+
"x-prompt": "What name would you like to use for the component?"
|
|
36
|
+
},
|
|
37
|
+
"js": {
|
|
38
|
+
"type": "boolean",
|
|
39
|
+
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
40
|
+
"default": false
|
|
41
|
+
},
|
|
42
|
+
"skipTests": {
|
|
43
|
+
"type": "boolean",
|
|
44
|
+
"description": "When true, does not create `spec.ts` test files for the new component.",
|
|
45
|
+
"default": false
|
|
46
|
+
},
|
|
47
|
+
"directory": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
|
|
50
|
+
"x-priority": "important"
|
|
51
|
+
},
|
|
52
|
+
"nameAndDirectoryFormat": {
|
|
53
|
+
"description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
|
|
54
|
+
"type": "string",
|
|
55
|
+
"enum": ["as-provided", "derived"]
|
|
56
|
+
},
|
|
57
|
+
"flat": {
|
|
58
|
+
"type": "boolean",
|
|
59
|
+
"description": "Create component at the source root rather than its own directory.",
|
|
60
|
+
"default": false,
|
|
61
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
|
|
62
|
+
},
|
|
63
|
+
"export": {
|
|
64
|
+
"type": "boolean",
|
|
65
|
+
"description": "When true, the component is exported from the project `index.ts` (if it exists).",
|
|
66
|
+
"alias": "e",
|
|
67
|
+
"default": false,
|
|
68
|
+
"x-prompt": "Should this component be exported in the project?"
|
|
69
|
+
},
|
|
70
|
+
"pascalCaseFiles": {
|
|
71
|
+
"type": "boolean",
|
|
72
|
+
"description": "Use pascal case component file name (e.g. `App.tsx`).",
|
|
73
|
+
"alias": "P",
|
|
74
|
+
"default": false,
|
|
75
|
+
"x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
76
|
+
},
|
|
77
|
+
"classComponent": {
|
|
78
|
+
"type": "boolean",
|
|
79
|
+
"alias": "C",
|
|
80
|
+
"description": "Use class components instead of functional component.",
|
|
81
|
+
"default": false
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"required": ["name"]
|
|
85
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { CreateComponentStoriesFileSchema } from './schema';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated This would be a direct pass through to @nx/react:component-story generator.
|
|
5
|
+
* TODO (@xiongemi): remove this generator for v19
|
|
6
|
+
*/
|
|
7
|
+
export declare function componentStoryGenerator(host: Tree, schema: CreateComponentStoriesFileSchema): Promise<void>;
|
|
8
|
+
export default componentStoryGenerator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.componentStoryGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const react_1 = require("@nx/react");
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated This would be a direct pass through to @nx/react:component-story generator.
|
|
8
|
+
* TODO (@xiongemi): remove this generator for v19
|
|
9
|
+
*/
|
|
10
|
+
async function componentStoryGenerator(host, schema) {
|
|
11
|
+
devkit_1.logger.warn(`Please run 'nx run @nx/react:component-story ${schema.project}' instead.`);
|
|
12
|
+
return (0, react_1.componentStoryGenerator)(host, schema);
|
|
13
|
+
}
|
|
14
|
+
exports.componentStoryGenerator = componentStoryGenerator;
|
|
15
|
+
exports.default = componentStoryGenerator;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"cli": "nx",
|
|
4
|
+
"$id": "NxReactNativeComponentStory",
|
|
5
|
+
"title": "React native component story",
|
|
6
|
+
"description": "Generate storybook story for a react-native component.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"aliases": ["name", "projectName"],
|
|
12
|
+
"description": "The project where to add the components.",
|
|
13
|
+
"examples": ["shared-ui-component"],
|
|
14
|
+
"$default": {
|
|
15
|
+
"$source": "projectName",
|
|
16
|
+
"index": 0
|
|
17
|
+
},
|
|
18
|
+
"x-prompt": "What's name of the project where the component lives?",
|
|
19
|
+
"x-priority": "important"
|
|
20
|
+
},
|
|
21
|
+
"componentPath": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Relative path to the component file from the library root.",
|
|
24
|
+
"examples": ["lib/components"],
|
|
25
|
+
"x-prompt": "What's path of the component relative to the project's lib root?",
|
|
26
|
+
"x-priority": "important"
|
|
27
|
+
},
|
|
28
|
+
"skipFormat": {
|
|
29
|
+
"description": "Skip formatting files.",
|
|
30
|
+
"type": "boolean",
|
|
31
|
+
"default": false,
|
|
32
|
+
"x-priority": "internal"
|
|
33
|
+
},
|
|
34
|
+
"interactionTests": {
|
|
35
|
+
"type": "boolean",
|
|
36
|
+
"description": "Set up Storybook interaction tests.",
|
|
37
|
+
"default": true,
|
|
38
|
+
"x-priority": "important"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"required": ["project", "componentPath"]
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export declare function reactNativeInitGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function reactNativeInitGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
5
|
+
export declare function updateDependencies(host: Tree, schema: Schema): GeneratorCallback;
|
|
6
|
+
export default reactNativeInitGenerator;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateDependencies = exports.reactNativeInitGeneratorInternal = exports.reactNativeInitGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
|
|
6
|
+
const plugin_1 = require("../../../plugins/plugin");
|
|
7
|
+
const versions_1 = require("../../utils/versions");
|
|
8
|
+
const add_git_ignore_entry_1 = require("./lib/add-git-ignore-entry");
|
|
9
|
+
function reactNativeInitGenerator(host, schema) {
|
|
10
|
+
return reactNativeInitGeneratorInternal(host, {
|
|
11
|
+
addPlugin: false,
|
|
12
|
+
...schema,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.reactNativeInitGenerator = reactNativeInitGenerator;
|
|
16
|
+
async function reactNativeInitGeneratorInternal(host, schema) {
|
|
17
|
+
(0, add_git_ignore_entry_1.addGitIgnoreEntry)(host);
|
|
18
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
19
|
+
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
20
|
+
nxJson.useInferencePlugins !== false;
|
|
21
|
+
schema.addPlugin ??= addPluginDefault;
|
|
22
|
+
if (schema.addPlugin) {
|
|
23
|
+
addPlugin(host);
|
|
24
|
+
}
|
|
25
|
+
const tasks = [];
|
|
26
|
+
if (!schema.skipPackageJson) {
|
|
27
|
+
tasks.push(moveDependency(host));
|
|
28
|
+
tasks.push(updateDependencies(host, schema));
|
|
29
|
+
}
|
|
30
|
+
if (schema.updatePackageScripts) {
|
|
31
|
+
await (0, update_package_scripts_1.updatePackageScripts)(host, plugin_1.createNodes);
|
|
32
|
+
}
|
|
33
|
+
if (!schema.skipFormat) {
|
|
34
|
+
await (0, devkit_1.formatFiles)(host);
|
|
35
|
+
}
|
|
36
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
37
|
+
}
|
|
38
|
+
exports.reactNativeInitGeneratorInternal = reactNativeInitGeneratorInternal;
|
|
39
|
+
function updateDependencies(host, schema) {
|
|
40
|
+
return (0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
41
|
+
react: versions_1.reactVersion,
|
|
42
|
+
'react-dom': versions_1.reactDomVersion,
|
|
43
|
+
'react-native': versions_1.reactNativeVersion,
|
|
44
|
+
}, {
|
|
45
|
+
'@nx/react-native': versions_1.nxVersion,
|
|
46
|
+
}, undefined, schema.keepExistingVersions);
|
|
47
|
+
}
|
|
48
|
+
exports.updateDependencies = updateDependencies;
|
|
49
|
+
function moveDependency(host) {
|
|
50
|
+
return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react-native'], []);
|
|
51
|
+
}
|
|
52
|
+
function addPlugin(host) {
|
|
53
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
54
|
+
nxJson.plugins ??= [];
|
|
55
|
+
for (const plugin of nxJson.plugins) {
|
|
56
|
+
if (typeof plugin === 'string'
|
|
57
|
+
? plugin === '@nx/react-native/plugin'
|
|
58
|
+
: plugin.plugin === '@nx/react-native/plugin') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
nxJson.plugins.push({
|
|
63
|
+
plugin: '@nx/react-native/plugin',
|
|
64
|
+
options: {
|
|
65
|
+
startTargetName: 'start',
|
|
66
|
+
podInstallTargetName: 'pod-install',
|
|
67
|
+
bundleTargetName: 'bundle',
|
|
68
|
+
runIosTargetName: 'run-ios',
|
|
69
|
+
runAndroidTargetName: 'run-android',
|
|
70
|
+
buildIosTargetName: 'build-ios',
|
|
71
|
+
buildAndroidTargetName: 'build-android',
|
|
72
|
+
syncDepsTargetName: 'sync-deps',
|
|
73
|
+
upgradeTargetname: 'upgrade',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
(0, devkit_1.updateNxJson)(host, nxJson);
|
|
77
|
+
}
|
|
78
|
+
exports.default = reactNativeInitGenerator;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Tree, readJson } from '@nx/devkit';
|
|
2
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
+
import { reactNativeInitGenerator } from './init';
|
|
4
|
+
|
|
5
|
+
describe('init', () => {
|
|
6
|
+
let tree: Tree;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
tree = createTreeWithEmptyWorkspace();
|
|
10
|
+
tree.write('.gitignore', '');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should add react native dependencies', async () => {
|
|
14
|
+
await reactNativeInitGenerator(tree, {
|
|
15
|
+
addPlugin: true,
|
|
16
|
+
});
|
|
17
|
+
const packageJson = readJson(tree, 'package.json');
|
|
18
|
+
expect(packageJson.dependencies['react']).toBeDefined();
|
|
19
|
+
expect(packageJson.dependencies['react-native']).toBeDefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should add .gitignore entries for React native files and directories', async () => {
|
|
23
|
+
tree.write(
|
|
24
|
+
'/.gitignore',
|
|
25
|
+
`
|
|
26
|
+
/node_modules
|
|
27
|
+
`
|
|
28
|
+
);
|
|
29
|
+
await reactNativeInitGenerator(tree, {
|
|
30
|
+
addPlugin: true,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const content = tree.read('/.gitignore').toString();
|
|
34
|
+
|
|
35
|
+
expect(content).toMatch(/# React Native/);
|
|
36
|
+
expect(content).toMatch(/# Nested node_modules/);
|
|
37
|
+
});
|
|
38
|
+
});
|