@nx/react-native 18.0.0-beta.1 → 18.0.0-canary.20240201-8762c38
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 +6 -1
- package/executors.json +5 -0
- package/generators.json +10 -9
- package/migrations.json +73 -1
- package/package.json +10 -15
- package/plugins/metro-resolver.js +4 -1
- package/plugins/with-nx-metro.js +6 -2
- package/src/executors/build-android/build-android.impl.js +1 -5
- package/src/executors/build-android/build-android.impl.ts +1 -5
- package/src/executors/bundle/schema.d.ts +1 -1
- package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
- package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
- package/src/executors/ensure-symlink/ensure-symlink.impl.ts +4 -0
- package/src/executors/run-android/run-android.impl.js +4 -16
- package/src/executors/run-android/run-android.impl.ts +8 -17
- package/src/executors/run-ios/run-ios.impl.js +4 -16
- package/src/executors/run-ios/run-ios.impl.ts +9 -18
- package/src/executors/start/schema.d.ts +1 -1
- package/src/executors/start/start.impl.js +11 -26
- package/src/executors/start/start.impl.ts +14 -28
- package/src/executors/storybook/storybook.impl.d.ts +4 -0
- package/src/executors/storybook/storybook.impl.js +5 -1
- package/src/executors/storybook/storybook.impl.ts +13 -15
- package/src/executors/sync-deps/sync-deps.impl.d.ts +2 -2
- package/src/executors/sync-deps/sync-deps.impl.js +20 -5
- package/src/executors/sync-deps/sync-deps.impl.ts +20 -9
- 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.js +21 -7
- package/src/generators/application/application.spec.ts +27 -0
- package/src/generators/application/files/app/.babelrc.js.template +23 -0
- package/src/generators/application/files/app/android/app/build.gradle.template +12 -28
- package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +2 -6
- 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/build.gradle.template +7 -20
- package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
- package/src/generators/application/files/app/android/gradle.properties +0 -3
- package/src/generators/application/files/app/android/gradlew.template +12 -7
- package/src/generators/application/files/app/android/settings.gradle.template +2 -2
- package/src/generators/application/files/app/ios/Podfile.template +0 -7
- package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +5 -0
- package/src/generators/application/files/app/ios/__className__/Info.plist.template +5 -8
- package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +11 -33
- package/src/generators/application/files/app/metro.config.js.template +0 -4
- package/src/generators/application/files/app/src/app/App.tsx.template +5 -2
- package/src/generators/application/lib/add-e2e.d.ts +3 -0
- package/src/generators/application/lib/add-e2e.js +47 -0
- package/src/generators/application/lib/add-project.js +13 -17
- package/src/generators/application/lib/normalize-options.d.ts +4 -0
- package/src/generators/application/lib/normalize-options.js +8 -3
- package/src/generators/application/lib/normalize-options.spec.ts +48 -5
- package/src/generators/application/schema.d.ts +4 -3
- package/src/generators/application/schema.json +13 -5
- package/src/generators/component-story/component-story.d.ts +5 -8
- package/src/generators/component-story/component-story.js +8 -69
- package/src/generators/component-story/schema.d.ts +1 -0
- package/src/generators/component-story/schema.json +10 -2
- package/src/generators/init/init.js +0 -3
- package/src/generators/library/files/lib/.babelrc.js.template +21 -0
- package/src/generators/library/library.spec.ts +11 -0
- package/src/generators/library/schema.json +1 -1
- package/src/generators/stories/schema.d.ts +2 -0
- package/src/generators/stories/schema.json +14 -1
- package/src/generators/stories/stories.d.ts +5 -2
- package/src/generators/stories/stories.js +7 -50
- package/src/generators/storybook-configuration/configuration.d.ts +6 -2
- package/src/generators/storybook-configuration/configuration.js +7 -48
- package/src/generators/storybook-configuration/schema.d.ts +3 -2
- package/src/generators/storybook-configuration/schema.json +21 -11
- package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
- package/src/generators/upgrade-native/schema.d.ts +1 -1
- package/src/generators/upgrade-native/schema.json +2 -2
- package/src/generators/upgrade-native/upgrade-native.d.ts +2 -0
- package/src/generators/upgrade-native/upgrade-native.js +3 -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 +85 -0
- package/src/migrations/update-16-6-0/update-metro-config.js +0 -4
- package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
- 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 +26 -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.js +11 -0
- package/src/utils/ensure-dependencies.js +2 -6
- package/src/utils/testing-generators.js +1 -0
- package/src/utils/versions.d.ts +9 -12
- package/src/utils/versions.js +10 -13
- package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -75
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +0 -32
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +0 -62
- package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -20
- package/src/generators/application/files/app/babel.config.json.template +0 -10
- package/src/generators/application/lib/add-detox.d.ts +0 -3
- package/src/generators/application/lib/add-detox.js +0 -23
- package/src/generators/component-story/component-story.spec.ts +0 -427
- package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +0 -32
- package/src/generators/library/files/lib/babel.config.json.template +0 -19
- package/src/generators/stories/stories-app.spec.ts +0 -128
- package/src/generators/stories/stories-lib.spec.ts +0 -105
- package/src/generators/storybook-configuration/configuration.spec.ts +0 -135
- package/src/generators/storybook-configuration/files/app/storybook.ts.template +0 -9
- package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +0 -74
- package/src/generators/storybook-configuration/files/root/story-loader.ts.template +0 -5
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +0 -6
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +0 -25
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +0 -161
- package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +0 -6
- package/src/generators/storybook-configuration/lib/create-storybook-files.js +0 -42
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +0 -7
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +0 -29
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +0 -65
- package/src/utils/find-all-npm-dependencies.d.ts +0 -2
- package/src/utils/find-all-npm-dependencies.js +0 -25
- package/src/utils/find-all-npm-dependencies.spec.ts +0 -95
- package/src/utils/symlink-task.d.ts +0 -2
- package/src/utils/symlink-task.js +0 -18
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
package com.<%= lowerCaseName %>;
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.ReactActivity;
|
|
4
|
-
import com.facebook.react.ReactActivityDelegate;
|
|
5
|
-
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
|
6
|
-
import com.facebook.react.defaults.DefaultReactActivityDelegate;
|
|
7
|
-
|
|
8
|
-
public class MainActivity extends ReactActivity {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns the name of the main component registered from JavaScript. This is used to schedule
|
|
12
|
-
* rendering of the component.
|
|
13
|
-
*/
|
|
14
|
-
@Override
|
|
15
|
-
protected String getMainComponentName() {
|
|
16
|
-
return "<%= className %>";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
|
|
21
|
-
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
|
|
22
|
-
* (aka React 18) with two boolean flags.
|
|
23
|
-
*/
|
|
24
|
-
@Override
|
|
25
|
-
protected ReactActivityDelegate createReactActivityDelegate() {
|
|
26
|
-
return new DefaultReactActivityDelegate(
|
|
27
|
-
this,
|
|
28
|
-
getMainComponentName(),
|
|
29
|
-
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
|
|
30
|
-
DefaultNewArchitectureEntryPoint.getFabricEnabled());
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
package com.<%= lowerCaseName %>;
|
|
2
|
-
|
|
3
|
-
import android.app.Application;
|
|
4
|
-
import com.facebook.react.PackageList;
|
|
5
|
-
import com.facebook.react.ReactApplication;
|
|
6
|
-
import com.facebook.react.ReactNativeHost;
|
|
7
|
-
import com.facebook.react.ReactPackage;
|
|
8
|
-
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
|
9
|
-
import com.facebook.react.defaults.DefaultReactNativeHost;
|
|
10
|
-
import com.facebook.soloader.SoLoader;
|
|
11
|
-
import java.util.List;
|
|
12
|
-
|
|
13
|
-
public class MainApplication extends Application implements ReactApplication {
|
|
14
|
-
|
|
15
|
-
private final ReactNativeHost mReactNativeHost =
|
|
16
|
-
new DefaultReactNativeHost(this) {
|
|
17
|
-
@Override
|
|
18
|
-
public boolean getUseDeveloperSupport() {
|
|
19
|
-
return BuildConfig.DEBUG;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Override
|
|
23
|
-
protected List<ReactPackage> getPackages() {
|
|
24
|
-
@SuppressWarnings("UnnecessaryLocalVariable")
|
|
25
|
-
List<ReactPackage> packages = new PackageList(this).getPackages();
|
|
26
|
-
// Packages that cannot be autolinked yet can be added manually here, for example:
|
|
27
|
-
// packages.add(new MyReactNativePackage());
|
|
28
|
-
return packages;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@Override
|
|
32
|
-
protected String getJSMainModuleName() {
|
|
33
|
-
return "<%= entryFile %>";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@Override
|
|
37
|
-
protected boolean isNewArchEnabled() {
|
|
38
|
-
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@Override
|
|
42
|
-
protected Boolean isHermesEnabled() {
|
|
43
|
-
return BuildConfig.IS_HERMES_ENABLED;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
@Override
|
|
48
|
-
public ReactNativeHost getReactNativeHost() {
|
|
49
|
-
return mReactNativeHost;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Override
|
|
53
|
-
public void onCreate() {
|
|
54
|
-
super.onCreate();
|
|
55
|
-
SoLoader.init(this, /* native exopackage */ false);
|
|
56
|
-
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
57
|
-
// If you opted-in for the New Architecture, we load the native entry point for this app.
|
|
58
|
-
DefaultNewArchitectureEntryPoint.load();
|
|
59
|
-
}
|
|
60
|
-
ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
|
5
|
-
* directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
package com.<%= lowerCaseName %>;
|
|
8
|
-
|
|
9
|
-
import android.content.Context;
|
|
10
|
-
import com.facebook.react.ReactInstanceManager;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Class responsible of loading Flipper inside your React Native application. This is the release
|
|
14
|
-
* flavor of it so it's empty as we don't want to load Flipper.
|
|
15
|
-
*/
|
|
16
|
-
public class ReactNativeFlipper {
|
|
17
|
-
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
|
|
18
|
-
// Do nothing as we don't want to initialize Flipper on Release.
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addDetox = void 0;
|
|
4
|
-
const detox_1 = require("@nx/detox");
|
|
5
|
-
const eslint_1 = require("@nx/eslint");
|
|
6
|
-
async function addDetox(host, options) {
|
|
7
|
-
if (options?.e2eTestRunner !== 'detox') {
|
|
8
|
-
return () => { };
|
|
9
|
-
}
|
|
10
|
-
return (0, detox_1.detoxApplicationGenerator)(host, {
|
|
11
|
-
...options,
|
|
12
|
-
linter: eslint_1.Linter.EsLint,
|
|
13
|
-
e2eName: `${options.projectName}-e2e`,
|
|
14
|
-
e2eDirectory: `${options.appProjectRoot}-e2e`,
|
|
15
|
-
projectNameAndRootFormat: 'as-provided',
|
|
16
|
-
appProject: options.projectName,
|
|
17
|
-
appDisplayName: options.displayName,
|
|
18
|
-
appName: options.name,
|
|
19
|
-
framework: 'react-native',
|
|
20
|
-
skipFormat: true,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.addDetox = addDetox;
|
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import { getProjects, Tree, updateProjectConfiguration } from '@nx/devkit';
|
|
2
|
-
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
-
import componentStoryGenerator from './component-story';
|
|
4
|
-
import { Linter } from '@nx/eslint';
|
|
5
|
-
|
|
6
|
-
import { formatFile } from '../../utils/format-file';
|
|
7
|
-
import libraryGenerator from '../library/library';
|
|
8
|
-
import componentGenerator from '../component/component';
|
|
9
|
-
|
|
10
|
-
describe('react-native:component-story', () => {
|
|
11
|
-
let appTree: Tree;
|
|
12
|
-
let cmpPath = 'test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx';
|
|
13
|
-
let storyFilePath = 'test-ui-lib/src/lib/test-ui-lib/test-ui-lib.stories.tsx';
|
|
14
|
-
|
|
15
|
-
describe('default setup', () => {
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
appTree = await createTestUILib('test-ui-lib');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('when file does not contain a component', () => {
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
appTree.write(
|
|
23
|
-
cmpPath,
|
|
24
|
-
`export const add = (a: number, b: number) => a + b;`
|
|
25
|
-
);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should fail with a descriptive error message', async () => {
|
|
29
|
-
try {
|
|
30
|
-
await componentStoryGenerator(appTree, {
|
|
31
|
-
componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
|
|
32
|
-
project: 'test-ui-lib',
|
|
33
|
-
});
|
|
34
|
-
} catch (e) {
|
|
35
|
-
expect(e.message).toContain(
|
|
36
|
-
'Could not find any React Native component in file test-ui-lib/src/lib/test-ui-lib/test-ui-lib.tsx'
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('default component setup', () => {
|
|
43
|
-
beforeEach(async () => {
|
|
44
|
-
await componentStoryGenerator(appTree, {
|
|
45
|
-
componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
|
|
46
|
-
project: 'test-ui-lib',
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should create the story file', () => {
|
|
51
|
-
expect(appTree.exists(storyFilePath)).toBeTruthy();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should properly set up the story', () => {
|
|
55
|
-
expect(
|
|
56
|
-
formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
|
|
57
|
-
).toContain(formatFile`
|
|
58
|
-
import type { Meta } from '@storybook/react-native';
|
|
59
|
-
import { TestUiLib } from './test-ui-lib';
|
|
60
|
-
const Story: Meta<typeof TestUiLib> = {
|
|
61
|
-
component: TestUiLib,
|
|
62
|
-
title: 'TestUiLib',
|
|
63
|
-
};
|
|
64
|
-
export default Story;
|
|
65
|
-
export const Primary = { args: {} };
|
|
66
|
-
`);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('when using plain JS components', () => {
|
|
71
|
-
let storyFilePathPlain =
|
|
72
|
-
'test-ui-lib/src/lib/test-ui-libplain.stories.jsx';
|
|
73
|
-
|
|
74
|
-
beforeEach(async () => {
|
|
75
|
-
appTree.write(
|
|
76
|
-
'test-ui-lib/src/lib/test-ui-libplain.jsx',
|
|
77
|
-
`import React from 'react';
|
|
78
|
-
|
|
79
|
-
import './test.scss';
|
|
80
|
-
|
|
81
|
-
export const Test = () => {
|
|
82
|
-
return (
|
|
83
|
-
<div>
|
|
84
|
-
<h1>Welcome to test component</h1>
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export default Test;
|
|
90
|
-
`
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
await componentStoryGenerator(appTree, {
|
|
94
|
-
componentPath: 'lib/test-ui-libplain.jsx',
|
|
95
|
-
project: 'test-ui-lib',
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should create the story file', () => {
|
|
100
|
-
expect(appTree.exists(storyFilePathPlain)).toBeTruthy();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should properly set up the story', () => {
|
|
104
|
-
expect(formatFile`${appTree.read(storyFilePathPlain, 'utf-8')}`)
|
|
105
|
-
.toContain(formatFile`
|
|
106
|
-
import Test from './test-ui-libplain';
|
|
107
|
-
export default { component: Test, title: 'Test' };
|
|
108
|
-
export const Primary = { args: {} };
|
|
109
|
-
`);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('component without any props defined', () => {
|
|
114
|
-
beforeEach(async () => {
|
|
115
|
-
appTree.write(
|
|
116
|
-
cmpPath,
|
|
117
|
-
`import React from 'react';
|
|
118
|
-
|
|
119
|
-
import { View, Text } from 'react-native';
|
|
120
|
-
|
|
121
|
-
export function Test() {
|
|
122
|
-
return (
|
|
123
|
-
<View>
|
|
124
|
-
<Text>Welcome to test!</Text>
|
|
125
|
-
</View>
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export default Test;
|
|
130
|
-
`
|
|
131
|
-
);
|
|
132
|
-
await componentStoryGenerator(appTree, {
|
|
133
|
-
componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
|
|
134
|
-
project: 'test-ui-lib',
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should create a story without controls', () => {
|
|
139
|
-
expect(formatFile`${appTree.read(storyFilePath, 'utf-8')}`)
|
|
140
|
-
.toContain(formatFile`
|
|
141
|
-
import type { Meta } from '@storybook/react-native';
|
|
142
|
-
import { Test } from './test-ui-lib';
|
|
143
|
-
const Story: Meta<typeof Test> = { component: Test, title: 'Test' };
|
|
144
|
-
export default Story;
|
|
145
|
-
export const Primary = { args: {} };
|
|
146
|
-
`);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe('component with props', () => {
|
|
151
|
-
beforeEach(async () => {
|
|
152
|
-
await componentStoryGenerator(appTree, {
|
|
153
|
-
componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
|
|
154
|
-
project: 'test-ui-lib',
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should setup controls based on the component props', () => {
|
|
159
|
-
expect(
|
|
160
|
-
formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
|
|
161
|
-
).toContain(formatFile`
|
|
162
|
-
import type { Meta } from '@storybook/react-native';
|
|
163
|
-
import { TestUiLib } from './test-ui-lib';
|
|
164
|
-
const Story: Meta<typeof TestUiLib> = {
|
|
165
|
-
component: TestUiLib,
|
|
166
|
-
title: 'TestUiLib',
|
|
167
|
-
};
|
|
168
|
-
export default Story;
|
|
169
|
-
export const Primary = { args: {} };
|
|
170
|
-
`);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
describe('component with props and actions', () => {
|
|
175
|
-
beforeEach(async () => {
|
|
176
|
-
appTree.write(
|
|
177
|
-
cmpPath,
|
|
178
|
-
`import React from 'react';
|
|
179
|
-
|
|
180
|
-
export type ButtonStyle = 'default' | 'primary' | 'warning';
|
|
181
|
-
|
|
182
|
-
export interface TestProps {
|
|
183
|
-
name: string;
|
|
184
|
-
displayAge: boolean;
|
|
185
|
-
someAction: (e: unknown) => void;
|
|
186
|
-
style: ButtonStyle;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export const Test = (props: TestProps) => {
|
|
190
|
-
return (
|
|
191
|
-
<div>
|
|
192
|
-
<h1>Welcome to test component, {props.name}</h1>
|
|
193
|
-
<button onClick={props.someAction}>Click me!</button>
|
|
194
|
-
</div>
|
|
195
|
-
);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
export default Test;
|
|
199
|
-
`
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
await componentStoryGenerator(appTree, {
|
|
203
|
-
componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
|
|
204
|
-
project: 'test-ui-lib',
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('should setup controls based on the component props', () => {
|
|
209
|
-
expect(
|
|
210
|
-
formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
|
|
211
|
-
).toContain(formatFile`
|
|
212
|
-
import type { Meta } from '@storybook/react-native';
|
|
213
|
-
import { Test } from './test-ui-lib';
|
|
214
|
-
const Story: Meta<typeof Test> = {
|
|
215
|
-
component: Test,
|
|
216
|
-
title: 'Test',
|
|
217
|
-
argTypes: { someAction: { action: 'someAction executed!' } },
|
|
218
|
-
};
|
|
219
|
-
export default Story;
|
|
220
|
-
export const Primary = { args: { name: '', displayAge: false } };
|
|
221
|
-
`);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
[
|
|
226
|
-
{
|
|
227
|
-
name: 'default export function',
|
|
228
|
-
src: `export default function Test(props: TestProps) {
|
|
229
|
-
return (
|
|
230
|
-
<div>
|
|
231
|
-
<h1>Welcome to test component, {props.name}</h1>
|
|
232
|
-
</div>
|
|
233
|
-
);
|
|
234
|
-
};
|
|
235
|
-
`,
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
name: 'function and then export',
|
|
239
|
-
src: `
|
|
240
|
-
function Test(props: TestProps) {
|
|
241
|
-
return (
|
|
242
|
-
<div>
|
|
243
|
-
<h1>Welcome to test component, {props.name}</h1>
|
|
244
|
-
</div>
|
|
245
|
-
);
|
|
246
|
-
};
|
|
247
|
-
export default Test;
|
|
248
|
-
`,
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
name: 'arrow function',
|
|
252
|
-
src: `
|
|
253
|
-
const Test = (props: TestProps) => {
|
|
254
|
-
return (
|
|
255
|
-
<div>
|
|
256
|
-
<h1>Welcome to test component, {props.name}</h1>
|
|
257
|
-
</div>
|
|
258
|
-
);
|
|
259
|
-
};
|
|
260
|
-
export default Test;
|
|
261
|
-
`,
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
name: 'arrow function without {..}',
|
|
265
|
-
src: `
|
|
266
|
-
const Test = (props: TestProps) => <div><h1>Welcome to test component, {props.name}</h1></div>;
|
|
267
|
-
export default Test
|
|
268
|
-
`,
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
name: 'direct export of component class',
|
|
272
|
-
src: `
|
|
273
|
-
export default class Test extends React.Component<TestProps> {
|
|
274
|
-
render() {
|
|
275
|
-
return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
`,
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
name: 'component class & then default export',
|
|
282
|
-
src: `
|
|
283
|
-
class Test extends React.Component<TestProps> {
|
|
284
|
-
render() {
|
|
285
|
-
return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
export default Test
|
|
289
|
-
`,
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
name: 'PureComponent class & then default export',
|
|
293
|
-
src: `
|
|
294
|
-
class Test extends React.PureComponent<TestProps> {
|
|
295
|
-
render() {
|
|
296
|
-
return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
export default Test
|
|
300
|
-
`,
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
name: 'direct export of component class new JSX transform',
|
|
304
|
-
src: `
|
|
305
|
-
export default class Test extends Component<TestProps> {
|
|
306
|
-
render() {
|
|
307
|
-
return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
`,
|
|
311
|
-
},
|
|
312
|
-
{
|
|
313
|
-
name: 'component class & then default export new JSX transform',
|
|
314
|
-
src: `
|
|
315
|
-
class Test extends Component<TestProps> {
|
|
316
|
-
render() {
|
|
317
|
-
return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
export default Test
|
|
321
|
-
`,
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
name: 'PureComponent class & then default export new JSX transform',
|
|
325
|
-
src: `
|
|
326
|
-
class Test extends PureComponent<TestProps> {
|
|
327
|
-
render() {
|
|
328
|
-
return <div><h1>Welcome to test component, {this.props.name}</h1></div>;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
export default Test
|
|
332
|
-
`,
|
|
333
|
-
},
|
|
334
|
-
].forEach((config) => {
|
|
335
|
-
describe(`React Native component defined as:${config.name}`, () => {
|
|
336
|
-
beforeEach(async () => {
|
|
337
|
-
appTree.write(
|
|
338
|
-
cmpPath,
|
|
339
|
-
`import React from 'react';
|
|
340
|
-
|
|
341
|
-
export interface TestProps {
|
|
342
|
-
name: string;
|
|
343
|
-
displayAge: boolean;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
${config.src}
|
|
347
|
-
`
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
await componentStoryGenerator(appTree, {
|
|
351
|
-
componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
|
|
352
|
-
project: 'test-ui-lib',
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it('should properly setup the controls based on the component props', () => {
|
|
357
|
-
expect(
|
|
358
|
-
formatFile`${appTree.read(storyFilePath, 'utf-8').replace('·', '')}`
|
|
359
|
-
).toContain(formatFile`
|
|
360
|
-
import type { Meta } from '@storybook/react-native';
|
|
361
|
-
import { Test } from './test-ui-lib';
|
|
362
|
-
const Story: Meta<typeof Test> = { component: Test, title: 'Test' };
|
|
363
|
-
export default Story;
|
|
364
|
-
export const Primary = { args: { name: '', displayAge: false } };
|
|
365
|
-
`);
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
describe('using eslint', () => {
|
|
372
|
-
beforeEach(async () => {
|
|
373
|
-
appTree = await createTestUILib('test-ui-lib');
|
|
374
|
-
await componentGenerator(appTree, {
|
|
375
|
-
name: 'test-ui-lib',
|
|
376
|
-
project: 'test-ui-lib',
|
|
377
|
-
export: true,
|
|
378
|
-
});
|
|
379
|
-
await componentStoryGenerator(appTree, {
|
|
380
|
-
componentPath: 'lib/test-ui-lib/test-ui-lib.tsx',
|
|
381
|
-
project: 'test-ui-lib',
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it('should properly set up the story', () => {
|
|
386
|
-
expect(formatFile`${appTree.read(storyFilePath, 'utf-8')}`)
|
|
387
|
-
.toContain(formatFile`
|
|
388
|
-
import type { Meta } from '@storybook/react-native';
|
|
389
|
-
import { TestUiLib } from './test-ui-lib';
|
|
390
|
-
const Story: Meta<typeof TestUiLib> = {
|
|
391
|
-
component: TestUiLib,
|
|
392
|
-
title: 'TestUiLib',
|
|
393
|
-
};
|
|
394
|
-
export default Story;
|
|
395
|
-
export const Primary = { args: {} };
|
|
396
|
-
`);
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
export async function createTestUILib(libName: string): Promise<Tree> {
|
|
402
|
-
let appTree = createTreeWithEmptyWorkspace();
|
|
403
|
-
appTree.write('.gitignore', '');
|
|
404
|
-
|
|
405
|
-
await libraryGenerator(appTree, {
|
|
406
|
-
name: libName,
|
|
407
|
-
linter: Linter.EsLint,
|
|
408
|
-
skipFormat: true,
|
|
409
|
-
skipTsConfig: false,
|
|
410
|
-
unitTestRunner: 'jest',
|
|
411
|
-
projectNameAndRootFormat: 'as-provided',
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
await componentGenerator(appTree, {
|
|
415
|
-
name: libName,
|
|
416
|
-
project: libName,
|
|
417
|
-
export: true,
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
const currentWorkspaceJson = getProjects(appTree);
|
|
421
|
-
|
|
422
|
-
const projectConfig = currentWorkspaceJson.get(libName);
|
|
423
|
-
|
|
424
|
-
updateProjectConfiguration(appTree, libName, projectConfig);
|
|
425
|
-
|
|
426
|
-
return appTree;
|
|
427
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<% if ( !isPlainJs ) { %>import type { Meta } from '@storybook/react-native';<% } %>
|
|
2
|
-
import<% if ( !isPlainJs ) { %> { <% } %> <%= componentName %> <% if ( !isPlainJs ) { %> } <% } %> from './<%= componentImportFileName %>';
|
|
3
|
-
|
|
4
|
-
<% if ( isPlainJs ) { %>
|
|
5
|
-
export default {
|
|
6
|
-
component: <%= componentName %>,
|
|
7
|
-
title: '<%= componentName %>',<% if ( argTypes && argTypes.length > 0 ) { %>
|
|
8
|
-
argTypes: {<% for (let argType of argTypes) { %>
|
|
9
|
-
<%= argType.name %>: { <%- argType.type %> : "<%- argType.actionText %>" },<% } %>
|
|
10
|
-
}
|
|
11
|
-
<% } %>
|
|
12
|
-
};
|
|
13
|
-
<% } %>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<% if ( !isPlainJs ) { %>
|
|
17
|
-
const Story: Meta<typeof <%= componentName %>> = {
|
|
18
|
-
component: <%= componentName %>,
|
|
19
|
-
title: '<%= componentName %>',<% if ( argTypes && argTypes.length > 0 ) { %>
|
|
20
|
-
argTypes: {<% for (let argType of argTypes) { %>
|
|
21
|
-
<%= argType.name %>: { <%- argType.type %> : "<%- argType.actionText %>" },<% } %>
|
|
22
|
-
}
|
|
23
|
-
<% } %>
|
|
24
|
-
};
|
|
25
|
-
export default Story;
|
|
26
|
-
<% } %>
|
|
27
|
-
|
|
28
|
-
export const Primary = {
|
|
29
|
-
args: {<% for (let prop of props) { %>
|
|
30
|
-
<%= prop.name %>: <%- prop.defaultValue %>,<% } %>
|
|
31
|
-
},
|
|
32
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"presets": [
|
|
3
|
-
[
|
|
4
|
-
"@nx/react/babel",
|
|
5
|
-
{
|
|
6
|
-
"runtime": "automatic",
|
|
7
|
-
"useBuiltIns": "usage"
|
|
8
|
-
}
|
|
9
|
-
]
|
|
10
|
-
],
|
|
11
|
-
"plugins": [],
|
|
12
|
-
"env": {
|
|
13
|
-
"test": {
|
|
14
|
-
"presets": [
|
|
15
|
-
["module:metro-react-native-babel-preset", { "useTransformReactJSX": true }]
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|