@nx/react-native 17.0.5 → 17.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +1 -7
- package/LICENSE +1 -1
- package/README.md +4 -9
- package/executors.json +0 -5
- package/generators.json +11 -12
- package/migrations.json +0 -126
- package/package.json +15 -11
- package/plugins/metro-resolver.js +1 -4
- package/plugins/with-nx-metro.js +2 -6
- package/src/executors/build-android/build-android.impl.js +6 -2
- package/src/executors/build-android/build-android.impl.ts +6 -2
- package/src/executors/build-android/schema.json +1 -1
- package/src/executors/build-ios/schema.json +1 -1
- package/src/executors/bundle/schema.d.ts +1 -1
- package/src/executors/bundle/schema.json +1 -1
- package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +0 -4
- package/src/executors/ensure-symlink/ensure-symlink.impl.js +0 -4
- package/src/executors/ensure-symlink/ensure-symlink.impl.ts +0 -4
- package/src/executors/ensure-symlink/schema.json +1 -1
- package/src/executors/pod-install/schema.json +1 -1
- package/src/executors/run-android/run-android.impl.js +17 -5
- package/src/executors/run-android/run-android.impl.ts +18 -9
- package/src/executors/run-android/schema.json +1 -1
- package/src/executors/run-ios/run-ios.impl.js +16 -4
- package/src/executors/run-ios/run-ios.impl.ts +18 -9
- package/src/executors/run-ios/schema.json +1 -1
- package/src/executors/start/schema.d.ts +1 -1
- package/src/executors/start/schema.json +1 -1
- package/src/executors/start/start.impl.js +26 -11
- package/src/executors/start/start.impl.ts +28 -14
- package/src/executors/storybook/storybook.impl.d.ts +0 -4
- package/src/executors/storybook/storybook.impl.js +2 -15
- package/src/executors/storybook/storybook.impl.ts +7 -26
- package/src/executors/sync-deps/schema.d.ts +0 -1
- package/src/executors/sync-deps/schema.json +1 -6
- package/src/executors/sync-deps/sync-deps.impl.d.ts +1 -2
- package/src/executors/sync-deps/sync-deps.impl.js +11 -33
- package/src/executors/sync-deps/sync-deps.impl.ts +18 -57
- package/src/generators/application/application.js +8 -52
- package/src/generators/application/application.spec.ts +2 -29
- package/src/generators/application/files/app/Gemfile.template +1 -2
- package/src/generators/application/files/app/android/app/build.gradle.template +28 -12
- package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +6 -2
- package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +75 -0
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +32 -0
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +62 -0
- package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +20 -0
- package/src/generators/application/files/app/android/build.gradle.template +20 -7
- package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +1 -2
- package/src/generators/application/files/app/android/gradle.properties +3 -0
- package/src/generators/application/files/app/android/gradlew.template +7 -12
- package/src/generators/application/files/app/android/settings.gradle.template +2 -2
- package/src/generators/application/files/app/babel.config.json.template +3 -0
- package/src/generators/application/files/app/ios/Podfile.template +7 -0
- package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +0 -5
- package/src/generators/application/files/app/ios/__className__/Info.plist.template +8 -5
- package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +33 -11
- package/src/generators/application/files/app/metro.config.js.template +5 -1
- package/src/generators/application/files/app/src/app/App.tsx.template +13 -50
- package/src/generators/application/lib/add-detox.d.ts +3 -0
- package/src/generators/application/lib/add-detox.js +23 -0
- package/src/generators/application/lib/add-project.js +18 -18
- package/src/generators/application/lib/normalize-options.d.ts +0 -7
- package/src/generators/application/lib/normalize-options.js +3 -35
- package/src/generators/application/lib/normalize-options.spec.ts +7 -70
- package/src/generators/application/schema.d.ts +3 -5
- package/src/generators/application/schema.json +6 -14
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +1 -1
- package/src/generators/component/schema.d.ts +3 -3
- package/src/generators/component/schema.json +4 -4
- package/src/generators/component-story/component-story.d.ts +8 -5
- package/src/generators/component-story/component-story.js +69 -8
- package/src/generators/component-story/component-story.spec.ts +428 -0
- package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +32 -0
- package/src/generators/component-story/schema.d.ts +0 -1
- package/src/generators/component-story/schema.json +3 -11
- package/src/generators/init/init.d.ts +1 -2
- package/src/generators/init/init.js +56 -55
- package/src/generators/init/init.spec.ts +6 -7
- package/src/generators/init/schema.d.ts +3 -3
- package/src/generators/init/schema.json +18 -13
- package/src/generators/library/files/lib/babel.config.json.template +17 -0
- package/src/generators/library/lib/normalize-options.js +0 -5
- package/src/generators/library/library.js +38 -48
- package/src/generators/library/library.spec.ts +60 -12
- package/src/generators/library/schema.d.ts +0 -1
- package/src/generators/library/schema.json +2 -2
- package/src/generators/stories/schema.d.ts +0 -2
- package/src/generators/stories/schema.json +2 -15
- package/src/generators/stories/stories-app.spec.ts +128 -0
- package/src/generators/stories/stories-lib.spec.ts +105 -0
- package/src/generators/stories/stories.d.ts +2 -5
- package/src/generators/stories/stories.js +50 -7
- package/src/generators/storybook-configuration/configuration.d.ts +2 -7
- package/src/generators/storybook-configuration/configuration.js +48 -18
- package/src/generators/storybook-configuration/configuration.spec.ts +135 -0
- package/src/generators/storybook-configuration/files/app/storybook.ts.template +9 -0
- package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +74 -0
- package/src/generators/storybook-configuration/files/root/story-loader.ts.template +5 -0
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +6 -0
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +25 -0
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +161 -0
- package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +6 -0
- package/src/generators/storybook-configuration/lib/create-storybook-files.js +42 -0
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +7 -0
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +29 -0
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +65 -0
- package/src/generators/storybook-configuration/schema.d.ts +2 -4
- package/src/generators/storybook-configuration/schema.json +12 -22
- 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 +3 -3
- package/src/generators/upgrade-native/upgrade-native.d.ts +0 -2
- package/src/generators/upgrade-native/upgrade-native.js +0 -3
- package/src/migrations/update-16-6-0/update-metro-config.js +5 -1
- package/src/migrations/update-16-9-0/remove-types-react-native.js +9 -2
- package/src/utils/add-jest.d.ts +1 -1
- package/src/utils/add-jest.js +1 -13
- package/src/utils/add-linting.d.ts +0 -1
- package/src/utils/add-linting.js +1 -1
- package/src/utils/add-linting.spec.ts +6 -4
- package/src/utils/chmod-android-gradle-files.js +2 -6
- package/src/utils/find-all-npm-dependencies.js +3 -5
- package/src/utils/find-all-npm-dependencies.spec.ts +9 -17
- package/src/utils/symlink-task.d.ts +2 -0
- package/src/utils/symlink-task.js +18 -0
- package/src/utils/testing-generators.js +0 -1
- package/src/utils/versions.d.ts +13 -10
- package/src/utils/versions.js +14 -11
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -6
- package/plugins/plugin.d.ts +0 -14
- package/plugins/plugin.js +0 -162
- package/src/executors/upgrade/schema.d.ts +0 -1
- package/src/executors/upgrade/schema.json +0 -11
- package/src/executors/upgrade/upgrade.impl.d.ts +0 -13
- package/src/executors/upgrade/upgrade.impl.js +0 -47
- package/src/executors/upgrade/upgrade.impl.ts +0 -64
- package/src/generators/application/files/app/.babelrc.js.template +0 -23
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +0 -22
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +0 -45
- package/src/generators/application/lib/add-e2e.d.ts +0 -3
- package/src/generators/application/lib/add-e2e.js +0 -46
- package/src/generators/library/files/lib/.babelrc.js.template +0 -21
- package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +0 -23
- package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +0 -15
- 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__ +0 -9
- package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +0 -82
- package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +0 -23
- 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__ +0 -14
- package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +0 -9
- package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +0 -77
- package/src/generators/web-configuration/lib/normalize-schema.d.ts +0 -17
- package/src/generators/web-configuration/lib/normalize-schema.js +0 -16
- package/src/generators/web-configuration/lib/webpack-targets.d.ts +0 -7
- package/src/generators/web-configuration/lib/webpack-targets.js +0 -75
- package/src/generators/web-configuration/schema.d.ts +0 -6
- package/src/generators/web-configuration/schema.json +0 -42
- package/src/generators/web-configuration/web-configuration.d.ts +0 -12
- package/src/generators/web-configuration/web-configuration.js +0 -87
- package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +0 -6
- package/src/migrations/update-18-0-0/add-upgrade-target.js +0 -33
- package/src/migrations/update-18-0-0/add-web-configuration.d.ts +0 -8
- package/src/migrations/update-18-0-0/add-web-configuration.js +0 -33
- package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +0 -39
- package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +0 -5
- package/src/migrations/update-18-0-0/change-storybook-targets.js +0 -57
- package/src/migrations/update-18-0-0/remove-block-list.d.ts +0 -6
- package/src/migrations/update-18-0-0/remove-block-list.js +0 -28
- package/src/migrations/update-18-0-0/remove-block-list.spec.ts +0 -68
- package/src/migrations/update-18-0-0/remove-metro.d.ts +0 -14
- package/src/migrations/update-18-0-0/remove-metro.js +0 -29
- package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +0 -6
- package/src/migrations/update-18-0-0/remove-symlink-target.js +0 -30
- package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +0 -40
- package/src/utils/ensure-dependencies.d.ts +0 -2
- package/src/utils/ensure-dependencies.js +0 -30
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ExecutorContext
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { resolve as pathResolve } from 'path';
|
|
3
3
|
import { ChildProcess, fork } from 'child_process';
|
|
4
4
|
import { platform } from 'os';
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import startExecutor from '../start/start.impl';
|
|
7
7
|
import { getCliOptions } from '../../utils/get-cli-options';
|
|
8
8
|
|
|
9
9
|
import { ReactNativeRunIosOptions } from './schema';
|
|
@@ -21,20 +21,29 @@ export default async function* runIosExecutor(
|
|
|
21
21
|
const projectRoot =
|
|
22
22
|
context.projectsConfigurations.projects[context.projectName].root;
|
|
23
23
|
|
|
24
|
-
const tasks = [runCliRunIOS(context.root, projectRoot, options)];
|
|
25
|
-
|
|
26
24
|
if (options.mode !== 'Release') {
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const startResults = startExecutor(
|
|
26
|
+
{
|
|
29
27
|
port: options.port,
|
|
30
28
|
resetCache: options.resetCache,
|
|
31
29
|
interactive: true,
|
|
32
|
-
}
|
|
30
|
+
},
|
|
31
|
+
context
|
|
33
32
|
);
|
|
33
|
+
for await (const result of startResults) {
|
|
34
|
+
if (result.success) {
|
|
35
|
+
await runCliRunIOS(context.root, projectRoot, options);
|
|
36
|
+
yield {
|
|
37
|
+
success: true,
|
|
38
|
+
};
|
|
39
|
+
} else {
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
await runCliRunIOS(context.root, projectRoot, options);
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
await Promise.all(tasks);
|
|
37
|
-
|
|
38
47
|
yield { success: true };
|
|
39
48
|
}
|
|
40
49
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"outputCapture": "direct-nodejs",
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"$id": "NxReactNativeRunIos",
|
|
6
|
-
"$schema": "
|
|
6
|
+
"$schema": "http://json-schema.org/schema",
|
|
7
7
|
"title": "Run iOS application",
|
|
8
8
|
"description": "Run iOS target options.",
|
|
9
9
|
"type": "object",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// options from https://github.com/
|
|
1
|
+
// options from https://github.com/react-native-community/cli/blob/main/packages/cli-plugin-metro/src/commands/start/index.ts
|
|
2
2
|
|
|
3
3
|
export interface ReactNativeStartOptions {
|
|
4
4
|
port: number;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"outputCapture": "direct-nodejs",
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"$id": "NxReactNativeStart",
|
|
6
|
-
"$schema": "
|
|
6
|
+
"$schema": "http://json-schema.org/schema",
|
|
7
7
|
"title": "Packager Server for React Native",
|
|
8
8
|
"description": "Packager Server target options.",
|
|
9
9
|
"type": "object",
|
|
@@ -7,11 +7,25 @@ const path_1 = require("path");
|
|
|
7
7
|
const is_packager_running_1 = require("./lib/is-packager-running");
|
|
8
8
|
async function* startExecutor(options, context) {
|
|
9
9
|
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
10
|
-
await runCliStart(context.root, projectRoot, options);
|
|
10
|
+
const startProcess = await runCliStart(context.root, projectRoot, options);
|
|
11
11
|
yield {
|
|
12
12
|
port: options.port,
|
|
13
13
|
success: true,
|
|
14
14
|
};
|
|
15
|
+
if (!startProcess) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
await new Promise((resolve) => {
|
|
19
|
+
const processExitListener = (signal) => () => {
|
|
20
|
+
startProcess.kill(signal);
|
|
21
|
+
resolve();
|
|
22
|
+
process.exit();
|
|
23
|
+
};
|
|
24
|
+
process.once('exit', (signal) => startProcess.kill(signal));
|
|
25
|
+
process.once('SIGTERM', processExitListener);
|
|
26
|
+
process.once('SIGINT', processExitListener);
|
|
27
|
+
process.once('SIGQUIT', processExitListener);
|
|
28
|
+
});
|
|
15
29
|
}
|
|
16
30
|
exports.default = startExecutor;
|
|
17
31
|
/*
|
|
@@ -33,7 +47,7 @@ async function runCliStart(workspaceRoot, projectRoot, options) {
|
|
|
33
47
|
return await startAsync(workspaceRoot, projectRoot, options);
|
|
34
48
|
}
|
|
35
49
|
catch (error) {
|
|
36
|
-
devkit_1.logger.error(`Failed to start the packager server. Error details: ${error.message
|
|
50
|
+
devkit_1.logger.error(`Failed to start the packager server. Error details: ${error.message}`);
|
|
37
51
|
throw error;
|
|
38
52
|
}
|
|
39
53
|
}
|
|
@@ -44,7 +58,16 @@ function startAsync(workspaceRoot, projectRoot, options) {
|
|
|
44
58
|
const childProcess = (0, child_process_1.fork)(require.resolve('react-native/cli.js'), ['start', ...createStartOptions(options)], {
|
|
45
59
|
cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
|
|
46
60
|
env: process.env,
|
|
47
|
-
stdio: 'inherit',
|
|
61
|
+
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
|
62
|
+
});
|
|
63
|
+
childProcess.stdout.on('data', (data) => {
|
|
64
|
+
process.stdout.write(data);
|
|
65
|
+
if (data.toString().includes('reload the app')) {
|
|
66
|
+
resolve(childProcess);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
childProcess.stderr.on('data', (data) => {
|
|
70
|
+
process.stderr.write(data);
|
|
48
71
|
});
|
|
49
72
|
childProcess.on('error', (err) => {
|
|
50
73
|
reject(err);
|
|
@@ -57,14 +80,6 @@ function startAsync(workspaceRoot, projectRoot, options) {
|
|
|
57
80
|
reject(code);
|
|
58
81
|
}
|
|
59
82
|
});
|
|
60
|
-
const processExitListener = (signal) => () => {
|
|
61
|
-
childProcess.kill(signal);
|
|
62
|
-
process.exit();
|
|
63
|
-
};
|
|
64
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
65
|
-
process.once('SIGTERM', processExitListener);
|
|
66
|
-
process.once('SIGINT', processExitListener);
|
|
67
|
-
process.once('SIGQUIT', processExitListener);
|
|
68
83
|
});
|
|
69
84
|
}
|
|
70
85
|
function createStartOptions(options) {
|
|
@@ -16,12 +16,27 @@ export default async function* startExecutor(
|
|
|
16
16
|
const projectRoot =
|
|
17
17
|
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
18
|
|
|
19
|
-
await runCliStart(context.root, projectRoot, options);
|
|
19
|
+
const startProcess = await runCliStart(context.root, projectRoot, options);
|
|
20
20
|
|
|
21
21
|
yield {
|
|
22
22
|
port: options.port,
|
|
23
23
|
success: true,
|
|
24
24
|
};
|
|
25
|
+
|
|
26
|
+
if (!startProcess) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
await new Promise<void>((resolve) => {
|
|
30
|
+
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
31
|
+
startProcess.kill(signal);
|
|
32
|
+
resolve();
|
|
33
|
+
process.exit();
|
|
34
|
+
};
|
|
35
|
+
process.once('exit', (signal) => startProcess.kill(signal));
|
|
36
|
+
process.once('SIGTERM', processExitListener);
|
|
37
|
+
process.once('SIGINT', processExitListener);
|
|
38
|
+
process.once('SIGQUIT', processExitListener);
|
|
39
|
+
});
|
|
25
40
|
}
|
|
26
41
|
|
|
27
42
|
/*
|
|
@@ -46,9 +61,7 @@ export async function runCliStart(
|
|
|
46
61
|
return await startAsync(workspaceRoot, projectRoot, options);
|
|
47
62
|
} catch (error) {
|
|
48
63
|
logger.error(
|
|
49
|
-
`Failed to start the packager server. Error details: ${
|
|
50
|
-
error.message ?? error
|
|
51
|
-
}`
|
|
64
|
+
`Failed to start the packager server. Error details: ${error.message}`
|
|
52
65
|
);
|
|
53
66
|
throw error;
|
|
54
67
|
}
|
|
@@ -67,10 +80,20 @@ function startAsync(
|
|
|
67
80
|
{
|
|
68
81
|
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
69
82
|
env: process.env,
|
|
70
|
-
stdio: 'inherit',
|
|
83
|
+
stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
|
|
71
84
|
}
|
|
72
85
|
);
|
|
73
86
|
|
|
87
|
+
childProcess.stdout.on('data', (data) => {
|
|
88
|
+
process.stdout.write(data);
|
|
89
|
+
if (data.toString().includes('reload the app')) {
|
|
90
|
+
resolve(childProcess);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
childProcess.stderr.on('data', (data) => {
|
|
94
|
+
process.stderr.write(data);
|
|
95
|
+
});
|
|
96
|
+
|
|
74
97
|
childProcess.on('error', (err) => {
|
|
75
98
|
reject(err);
|
|
76
99
|
});
|
|
@@ -81,15 +104,6 @@ function startAsync(
|
|
|
81
104
|
reject(code);
|
|
82
105
|
}
|
|
83
106
|
});
|
|
84
|
-
|
|
85
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
86
|
-
childProcess.kill(signal);
|
|
87
|
-
process.exit();
|
|
88
|
-
};
|
|
89
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
90
|
-
process.once('SIGTERM', processExitListener);
|
|
91
|
-
process.once('SIGINT', processExitListener);
|
|
92
|
-
process.once('SIGQUIT', processExitListener);
|
|
93
107
|
});
|
|
94
108
|
}
|
|
95
109
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { ReactNativeStorybookOptions } from './schema';
|
|
3
|
-
/**
|
|
4
|
-
* TODO (@xiongemi): remove this function in v19.
|
|
5
|
-
* @deprecated Going to use the default react storybook target. Use @nx/react:storybook executor instead.
|
|
6
|
-
*/
|
|
7
3
|
export default function reactNativeStorybookExecutor(options: ReactNativeStorybookOptions, context: ExecutorContext): AsyncGenerator<{
|
|
8
4
|
success: boolean;
|
|
9
5
|
}>;
|
|
@@ -8,20 +8,13 @@ const chalk = require("chalk");
|
|
|
8
8
|
const glob_1 = require("glob");
|
|
9
9
|
const sync_deps_impl_1 = require("../sync-deps/sync-deps.impl");
|
|
10
10
|
const fs_extra_1 = require("fs-extra");
|
|
11
|
-
/**
|
|
12
|
-
* TODO (@xiongemi): remove this function in v19.
|
|
13
|
-
* @deprecated Going to use the default react storybook target. Use @nx/react:storybook executor instead.
|
|
14
|
-
*/
|
|
15
11
|
async function* reactNativeStorybookExecutor(options, context) {
|
|
16
12
|
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
17
13
|
devkit_1.logger.info(`${chalk.bold.cyan('info')} To see your Storybook stories on the device, you should start your mobile app for the <platform> of your choice (typically ios or android).`);
|
|
18
14
|
// add storybook addons to app's package.json
|
|
19
15
|
const packageJsonPath = (0, path_1.join)(context.root, projectRoot, 'package.json');
|
|
20
|
-
const workspacePackageJsonPath = (0, path_1.join)(context.root, 'package.json');
|
|
21
|
-
const workspacePackageJson = (0, devkit_1.readJsonFile)(workspacePackageJsonPath);
|
|
22
|
-
const projectPackageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
23
16
|
if ((0, fileutils_1.fileExists)(packageJsonPath))
|
|
24
|
-
(0, sync_deps_impl_1.displayNewlyAddedDepsMessage)(context.projectName, await (0, sync_deps_impl_1.syncDeps)(context.projectName,
|
|
17
|
+
(0, sync_deps_impl_1.displayNewlyAddedDepsMessage)(context.projectName, await (0, sync_deps_impl_1.syncDeps)(context.projectName, projectRoot, context.root, context.projectGraph, [
|
|
25
18
|
`@storybook/react-native`,
|
|
26
19
|
'@storybook/addon-ondevice-actions',
|
|
27
20
|
'@storybook/addon-ondevice-backgrounds',
|
|
@@ -35,13 +28,7 @@ async function* reactNativeStorybookExecutor(options, context) {
|
|
|
35
28
|
}
|
|
36
29
|
exports.default = reactNativeStorybookExecutor;
|
|
37
30
|
function runCliStorybook(workspaceRoot, options) {
|
|
38
|
-
const storiesFiles = options.searchDir.flatMap((dir) =>
|
|
39
|
-
const storyFilePaths = (0, glob_1.sync)((0, path_1.join)(dir, options.pattern));
|
|
40
|
-
return storyFilePaths.map((storyFilePath) => {
|
|
41
|
-
const loaderPath = (0, path_1.resolve)((0, path_1.dirname)(options.outputFile));
|
|
42
|
-
return (0, path_1.relative)(loaderPath, storyFilePath);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
31
|
+
const storiesFiles = options.searchDir.flatMap((dir) => (0, glob_1.sync)((0, path_1.join)(dir, options.pattern)));
|
|
45
32
|
if (storiesFiles.length === 0) {
|
|
46
33
|
devkit_1.logger.warn(`${chalk.bold.yellow('warn')} No stories found.`);
|
|
47
34
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { join
|
|
2
|
-
import { ExecutorContext, logger
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import { ExecutorContext, logger } from '@nx/devkit';
|
|
3
3
|
import { fileExists } from '@nx/workspace/src/utilities/fileutils';
|
|
4
4
|
import * as chalk from 'chalk';
|
|
5
5
|
import { sync as globSync } from 'glob';
|
|
@@ -10,12 +10,7 @@ import {
|
|
|
10
10
|
syncDeps,
|
|
11
11
|
} from '../sync-deps/sync-deps.impl';
|
|
12
12
|
import { writeFileSync } from 'fs-extra';
|
|
13
|
-
import { PackageJson } from 'nx/src/utils/package-json';
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
* TODO (@xiongemi): remove this function in v19.
|
|
17
|
-
* @deprecated Going to use the default react storybook target. Use @nx/react:storybook executor instead.
|
|
18
|
-
*/
|
|
19
14
|
export default async function* reactNativeStorybookExecutor(
|
|
20
15
|
options: ReactNativeStorybookOptions,
|
|
21
16
|
context: ExecutorContext
|
|
@@ -30,21 +25,13 @@ export default async function* reactNativeStorybookExecutor(
|
|
|
30
25
|
|
|
31
26
|
// add storybook addons to app's package.json
|
|
32
27
|
const packageJsonPath = join(context.root, projectRoot, 'package.json');
|
|
33
|
-
const workspacePackageJsonPath = join(context.root, 'package.json');
|
|
34
|
-
|
|
35
|
-
const workspacePackageJson = readJsonFile<PackageJson>(
|
|
36
|
-
workspacePackageJsonPath
|
|
37
|
-
);
|
|
38
|
-
const projectPackageJson = readJsonFile<PackageJson>(packageJsonPath);
|
|
39
|
-
|
|
40
28
|
if (fileExists(packageJsonPath))
|
|
41
29
|
displayNewlyAddedDepsMessage(
|
|
42
30
|
context.projectName,
|
|
43
31
|
await syncDeps(
|
|
44
32
|
context.projectName,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
workspacePackageJson,
|
|
33
|
+
projectRoot,
|
|
34
|
+
context.root,
|
|
48
35
|
context.projectGraph,
|
|
49
36
|
[
|
|
50
37
|
`@storybook/react-native`,
|
|
@@ -66,15 +53,9 @@ export function runCliStorybook(
|
|
|
66
53
|
workspaceRoot: string,
|
|
67
54
|
options: ReactNativeStorybookOptions
|
|
68
55
|
) {
|
|
69
|
-
const storiesFiles: string[] = options.searchDir.flatMap((dir) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return storyFilePaths.map((storyFilePath) => {
|
|
73
|
-
const loaderPath: string = resolve(dirname(options.outputFile));
|
|
74
|
-
return relative(loaderPath, storyFilePath);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
56
|
+
const storiesFiles: string[] = options.searchDir.flatMap((dir) =>
|
|
57
|
+
globSync(join(dir, options.pattern))
|
|
58
|
+
);
|
|
78
59
|
if (storiesFiles.length === 0) {
|
|
79
60
|
logger.warn(`${chalk.bold.yellow('warn')} No stories found.`);
|
|
80
61
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"outputCapture": "direct-nodejs",
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"$id": "NxReactNativeSyncDeps",
|
|
6
|
-
"$schema": "
|
|
6
|
+
"$schema": "http://json-schema.org/schema",
|
|
7
7
|
"title": "Sync Deps for React Native",
|
|
8
8
|
"description": "Updates `package.json` with project dependencies.",
|
|
9
9
|
"type": "object",
|
|
@@ -23,11 +23,6 @@
|
|
|
23
23
|
},
|
|
24
24
|
"default": [],
|
|
25
25
|
"description": "An array of npm packages to exclude."
|
|
26
|
-
},
|
|
27
|
-
"all": {
|
|
28
|
-
"type": "boolean",
|
|
29
|
-
"description": "Copy all dependencies and devDependencies from the workspace root package.json.",
|
|
30
|
-
"default": false
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
28
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ExecutorContext, ProjectGraph } from '@nx/devkit';
|
|
2
2
|
import { ReactNativeSyncDepsOptions } from './schema';
|
|
3
|
-
import { PackageJson } from 'nx/src/utils/package-json';
|
|
4
3
|
export interface ReactNativeSyncDepsOutput {
|
|
5
4
|
success: boolean;
|
|
6
5
|
}
|
|
7
6
|
export default function syncDepsExecutor(options: ReactNativeSyncDepsOptions, context: ExecutorContext): AsyncGenerator<ReactNativeSyncDepsOutput>;
|
|
8
|
-
export declare function syncDeps(projectName: string,
|
|
7
|
+
export declare function syncDeps(projectName: string, projectRoot: string, workspaceRoot: string, projectGraph: ProjectGraph, include?: string[], exclude?: string[]): Promise<string[]>;
|
|
9
8
|
export declare function displayNewlyAddedDepsMessage(projectName: string, deps: string[]): void;
|
|
@@ -7,29 +7,22 @@ const devkit_1 = require("@nx/devkit");
|
|
|
7
7
|
const find_all_npm_dependencies_1 = require("../../utils/find-all-npm-dependencies");
|
|
8
8
|
async function* syncDepsExecutor(options, context) {
|
|
9
9
|
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
|
|
10
|
-
|
|
11
|
-
const projectPackageJsonPath = (0, path_1.join)(context.root, projectRoot, 'package.json');
|
|
12
|
-
const workspacePackageJson = (0, devkit_1.readJsonFile)(workspacePackageJsonPath);
|
|
13
|
-
const projectPackageJson = (0, devkit_1.readJsonFile)(projectPackageJsonPath);
|
|
14
|
-
displayNewlyAddedDepsMessage(context.projectName, await syncDeps(context.projectName, projectPackageJson, projectPackageJsonPath, workspacePackageJson, context.projectGraph, typeof options.include === 'string'
|
|
10
|
+
displayNewlyAddedDepsMessage(context.projectName, await syncDeps(context.projectName, projectRoot, context.root, context.projectGraph, typeof options.include === 'string'
|
|
15
11
|
? options.include.split(',')
|
|
16
12
|
: options.include, typeof options.exclude === 'string'
|
|
17
13
|
? options.exclude.split(',')
|
|
18
|
-
: options.exclude
|
|
14
|
+
: options.exclude));
|
|
19
15
|
yield { success: true };
|
|
20
16
|
}
|
|
21
17
|
exports.default = syncDepsExecutor;
|
|
22
|
-
async function syncDeps(projectName,
|
|
23
|
-
let npmDeps =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let npmDevdeps = all
|
|
27
|
-
? Object.keys(workspacePackageJson.devDependencies || {})
|
|
28
|
-
: [];
|
|
18
|
+
async function syncDeps(projectName, projectRoot, workspaceRoot, projectGraph, include = [], exclude = []) {
|
|
19
|
+
let npmDeps = (0, find_all_npm_dependencies_1.findAllNpmDependencies)(projectGraph, projectName);
|
|
20
|
+
const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
|
|
21
|
+
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
29
22
|
const newDeps = [];
|
|
30
23
|
let updated = false;
|
|
31
|
-
if (!
|
|
32
|
-
|
|
24
|
+
if (!packageJson.dependencies) {
|
|
25
|
+
packageJson.dependencies = {};
|
|
33
26
|
updated = true;
|
|
34
27
|
}
|
|
35
28
|
if (include && include.length) {
|
|
@@ -38,30 +31,15 @@ async function syncDeps(projectName, projectPackageJson, projectPackageJsonPath,
|
|
|
38
31
|
if (exclude && exclude.length) {
|
|
39
32
|
npmDeps = npmDeps.filter((dep) => !exclude.includes(dep));
|
|
40
33
|
}
|
|
41
|
-
if (!projectPackageJson.devDependencies) {
|
|
42
|
-
projectPackageJson.devDependencies = {};
|
|
43
|
-
}
|
|
44
|
-
if (!projectPackageJson.dependencies) {
|
|
45
|
-
projectPackageJson.dependencies = {};
|
|
46
|
-
}
|
|
47
34
|
npmDeps.forEach((dep) => {
|
|
48
|
-
if (!
|
|
49
|
-
|
|
50
|
-
projectPackageJson.dependencies[dep] = '*';
|
|
51
|
-
newDeps.push(dep);
|
|
52
|
-
updated = true;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
npmDevdeps.forEach((dep) => {
|
|
56
|
-
if (!projectPackageJson.dependencies[dep] &&
|
|
57
|
-
!projectPackageJson.devDependencies[dep]) {
|
|
58
|
-
projectPackageJson.devDependencies[dep] = '*';
|
|
35
|
+
if (!packageJson.dependencies[dep]) {
|
|
36
|
+
packageJson.dependencies[dep] = '*';
|
|
59
37
|
newDeps.push(dep);
|
|
60
38
|
updated = true;
|
|
61
39
|
}
|
|
62
40
|
});
|
|
63
41
|
if (updated) {
|
|
64
|
-
(0, devkit_1.writeJsonFile)(
|
|
42
|
+
(0, devkit_1.writeJsonFile)(packageJsonPath, packageJson);
|
|
65
43
|
}
|
|
66
44
|
return newDeps;
|
|
67
45
|
}
|
|
@@ -2,16 +2,15 @@ import { join } from 'path';
|
|
|
2
2
|
import * as chalk from 'chalk';
|
|
3
3
|
import {
|
|
4
4
|
ExecutorContext,
|
|
5
|
-
ProjectGraph,
|
|
6
5
|
logger,
|
|
7
|
-
|
|
6
|
+
ProjectGraph,
|
|
8
7
|
readJsonFile,
|
|
9
8
|
writeJsonFile,
|
|
10
9
|
} from '@nx/devkit';
|
|
11
10
|
|
|
12
|
-
import { ReactNativeSyncDepsOptions } from './schema';
|
|
13
11
|
import { findAllNpmDependencies } from '../../utils/find-all-npm-dependencies';
|
|
14
|
-
|
|
12
|
+
|
|
13
|
+
import { ReactNativeSyncDepsOptions } from './schema';
|
|
15
14
|
|
|
16
15
|
export interface ReactNativeSyncDepsOutput {
|
|
17
16
|
success: boolean;
|
|
@@ -23,31 +22,19 @@ export default async function* syncDepsExecutor(
|
|
|
23
22
|
): AsyncGenerator<ReactNativeSyncDepsOutput> {
|
|
24
23
|
const projectRoot =
|
|
25
24
|
context.projectsConfigurations.projects[context.projectName].root;
|
|
26
|
-
|
|
27
|
-
const workspacePackageJsonPath = join(context.root, 'package.json');
|
|
28
|
-
const projectPackageJsonPath = join(
|
|
29
|
-
context.root,
|
|
30
|
-
projectRoot,
|
|
31
|
-
'package.json'
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
|
|
35
|
-
const projectPackageJson = readJsonFile(projectPackageJsonPath);
|
|
36
25
|
displayNewlyAddedDepsMessage(
|
|
37
26
|
context.projectName,
|
|
38
27
|
await syncDeps(
|
|
39
28
|
context.projectName,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
workspacePackageJson,
|
|
29
|
+
projectRoot,
|
|
30
|
+
context.root,
|
|
43
31
|
context.projectGraph,
|
|
44
32
|
typeof options.include === 'string'
|
|
45
33
|
? options.include.split(',')
|
|
46
34
|
: options.include,
|
|
47
35
|
typeof options.exclude === 'string'
|
|
48
36
|
? options.exclude.split(',')
|
|
49
|
-
: options.exclude
|
|
50
|
-
options.all
|
|
37
|
+
: options.exclude
|
|
51
38
|
)
|
|
52
39
|
);
|
|
53
40
|
|
|
@@ -56,26 +43,20 @@ export default async function* syncDepsExecutor(
|
|
|
56
43
|
|
|
57
44
|
export async function syncDeps(
|
|
58
45
|
projectName: string,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
projectGraph: ProjectGraph = readCachedProjectGraph(),
|
|
46
|
+
projectRoot: string,
|
|
47
|
+
workspaceRoot: string,
|
|
48
|
+
projectGraph: ProjectGraph,
|
|
63
49
|
include: string[] = [],
|
|
64
|
-
exclude: string[] = []
|
|
65
|
-
all: boolean = false
|
|
50
|
+
exclude: string[] = []
|
|
66
51
|
): Promise<string[]> {
|
|
67
|
-
let npmDeps =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
let npmDevdeps = all
|
|
71
|
-
? Object.keys(workspacePackageJson.devDependencies || {})
|
|
72
|
-
: [];
|
|
73
|
-
|
|
52
|
+
let npmDeps = findAllNpmDependencies(projectGraph, projectName);
|
|
53
|
+
const packageJsonPath = join(workspaceRoot, projectRoot, 'package.json');
|
|
54
|
+
const packageJson = readJsonFile(packageJsonPath);
|
|
74
55
|
const newDeps = [];
|
|
75
56
|
let updated = false;
|
|
76
57
|
|
|
77
|
-
if (!
|
|
78
|
-
|
|
58
|
+
if (!packageJson.dependencies) {
|
|
59
|
+
packageJson.dependencies = {};
|
|
79
60
|
updated = true;
|
|
80
61
|
}
|
|
81
62
|
|
|
@@ -86,36 +67,16 @@ export async function syncDeps(
|
|
|
86
67
|
npmDeps = npmDeps.filter((dep) => !exclude.includes(dep));
|
|
87
68
|
}
|
|
88
69
|
|
|
89
|
-
if (!projectPackageJson.devDependencies) {
|
|
90
|
-
projectPackageJson.devDependencies = {};
|
|
91
|
-
}
|
|
92
|
-
if (!projectPackageJson.dependencies) {
|
|
93
|
-
projectPackageJson.dependencies = {};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
70
|
npmDeps.forEach((dep) => {
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
!projectPackageJson.devDependencies[dep]
|
|
100
|
-
) {
|
|
101
|
-
projectPackageJson.dependencies[dep] = '*';
|
|
102
|
-
newDeps.push(dep);
|
|
103
|
-
updated = true;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
npmDevdeps.forEach((dep) => {
|
|
107
|
-
if (
|
|
108
|
-
!projectPackageJson.dependencies[dep] &&
|
|
109
|
-
!projectPackageJson.devDependencies[dep]
|
|
110
|
-
) {
|
|
111
|
-
projectPackageJson.devDependencies[dep] = '*';
|
|
71
|
+
if (!packageJson.dependencies[dep]) {
|
|
72
|
+
packageJson.dependencies[dep] = '*';
|
|
112
73
|
newDeps.push(dep);
|
|
113
74
|
updated = true;
|
|
114
75
|
}
|
|
115
76
|
});
|
|
116
77
|
|
|
117
78
|
if (updated) {
|
|
118
|
-
writeJsonFile(
|
|
79
|
+
writeJsonFile(packageJsonPath, packageJson);
|
|
119
80
|
}
|
|
120
81
|
|
|
121
82
|
return newDeps;
|