@nx/react-native 0.0.0-pr-22179-271588f → 0.0.0-pr-26482-ebe2dba
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/LICENSE +1 -1
- package/README.md +1 -1
- package/migrations.json +78 -287
- package/package.json +11 -10
- package/plugins/plugin.js +17 -38
- package/plugins/with-nx-metro.js +3 -2
- package/project.json +1 -3
- package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +1 -1
- package/src/executors/ensure-symlink/ensure-symlink.impl.js +1 -1
- package/src/executors/storybook/schema.d.ts +1 -0
- package/src/executors/storybook/storybook.impl.d.ts +1 -1
- package/src/executors/storybook/storybook.impl.js +10 -3
- package/src/generators/application/files/app/Gemfile.template +4 -2
- package/src/generators/application/files/app/android/app/build.gradle.template +0 -1
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +1 -3
- package/src/generators/application/files/app/android/build.gradle.template +3 -3
- package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/src/generators/application/files/app/android/gradlew.bat +10 -10
- package/src/generators/application/files/app/android/gradlew.template +7 -7
- package/src/generators/application/files/app/ios/Podfile.template +2 -17
- package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +2 -2
- package/src/generators/application/files/app/ios/__className__/Info.plist.template +1 -1
- package/src/generators/application/files/app/ios/__className__/PrivacyInfo.xcprivacy +38 -0
- package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +5 -1
- package/src/generators/application/files/app/metro.config.js.template +1 -1
- package/src/generators/application/files/app/tsconfig.app.json.template +1 -1
- package/src/generators/application/lib/normalize-options.d.ts +3 -0
- package/src/generators/application/lib/normalize-options.js +23 -0
- package/src/generators/application/schema.json +2 -2
- package/src/generators/component/schema.d.ts +1 -1
- package/src/generators/component/schema.json +1 -1
- package/src/generators/init/init.js +44 -31
- package/src/generators/init/lib/gitignore-entries.d.ts +1 -1
- package/src/generators/init/lib/gitignore-entries.js +2 -2
- package/src/generators/library/files/lib/tsconfig.lib.json.template +1 -1
- package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +3 -3
- package/src/migrations/update-18-0-0/change-storybook-targets.js +1 -1
- package/src/utils/add-jest.js +2 -2
- package/src/utils/versions.d.ts +9 -9
- package/src/utils/versions.js +9 -9
- package/src/executors/build-android/build-android.impl.ts +0 -69
- package/src/executors/build-ios/build-ios.impl.ts +0 -77
- package/src/executors/bundle/bundle.impl.ts +0 -77
- package/src/executors/ensure-symlink/ensure-symlink.impl.ts +0 -22
- package/src/executors/pod-install/pod-install.impl.ts +0 -21
- package/src/executors/run-android/run-android.impl.ts +0 -94
- package/src/executors/run-ios/run-ios.impl.ts +0 -92
- package/src/executors/start/start.impl.ts +0 -111
- package/src/executors/storybook/storybook.impl.ts +0 -85
- package/src/executors/sync-deps/sync-deps.impl.ts +0 -140
- package/src/executors/upgrade/upgrade.impl.ts +0 -64
- package/src/generators/application/application.spec.ts +0 -258
- package/src/generators/application/files/app/test-setup.ts.template +0 -1
- package/src/generators/application/lib/normalize-options.spec.ts +0 -196
- package/src/generators/component/component.spec.ts +0 -127
- package/src/generators/init/init.spec.ts +0 -38
- package/src/generators/library/files/lib/test-setup.ts.template +0 -1
- package/src/generators/library/library.spec.ts +0 -420
- package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +0 -2
- package/src/migrations/update-15-0-0/add-babel-inputs.js +0 -9
- package/src/migrations/update-15-0-0/add-babel-inputs.spec.ts +0 -73
- package/src/migrations/update-15-9-1/add-build-ios-target.d.ts +0 -5
- package/src/migrations/update-15-9-1/add-build-ios-target.js +0 -29
- package/src/migrations/update-15-9-1/add-build-ios-target.spec.ts +0 -36
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.spec.ts +0 -37
- package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +0 -39
- package/src/migrations/update-18-0-0/remove-block-list.spec.ts +0 -68
- package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +0 -40
- package/src/utils/add-linting.spec.ts +0 -40
- package/src/utils/ensure-node-modules-symlink.spec.ts +0 -108
- package/src/utils/find-all-npm-dependencies.spec.ts +0 -103
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { join, resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
import { ReactNativeBuildAndroidOptions } from './schema';
|
|
5
|
-
import { chmodAndroidGradlewFiles } from '../../utils/chmod-android-gradle-files';
|
|
6
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
7
|
-
|
|
8
|
-
export interface ReactNativeBuildOutput {
|
|
9
|
-
success: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function* buildAndroidExecutor(
|
|
13
|
-
options: ReactNativeBuildAndroidOptions,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeBuildOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
chmodAndroidGradlewFiles(join(context.root, projectRoot, 'android'));
|
|
19
|
-
|
|
20
|
-
await runCliBuild(context.root, projectRoot, options);
|
|
21
|
-
yield { success: true };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function runCliBuild(
|
|
25
|
-
workspaceRoot: string,
|
|
26
|
-
projectRoot: string,
|
|
27
|
-
options: ReactNativeBuildAndroidOptions
|
|
28
|
-
) {
|
|
29
|
-
return new Promise<ChildProcess>((res, reject) => {
|
|
30
|
-
const childProcess = fork(
|
|
31
|
-
require.resolve('react-native/cli.js'),
|
|
32
|
-
['build-android', ...createBuildAndroidOptions(options)],
|
|
33
|
-
{
|
|
34
|
-
stdio: 'inherit',
|
|
35
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
36
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Ensure the child process is killed when the parent exits
|
|
42
|
-
*/
|
|
43
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
44
|
-
childProcess.kill(signal);
|
|
45
|
-
process.exit();
|
|
46
|
-
};
|
|
47
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
48
|
-
process.once('SIGTERM', processExitListener);
|
|
49
|
-
process.once('SIGINT', processExitListener);
|
|
50
|
-
process.once('SIGQUIT', processExitListener);
|
|
51
|
-
|
|
52
|
-
childProcess.on('error', (err) => {
|
|
53
|
-
reject(err);
|
|
54
|
-
});
|
|
55
|
-
childProcess.on('exit', (code) => {
|
|
56
|
-
if (code === 0) {
|
|
57
|
-
res(childProcess);
|
|
58
|
-
} else {
|
|
59
|
-
reject(code);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const startOptions = ['port', 'resetCache'];
|
|
66
|
-
|
|
67
|
-
function createBuildAndroidOptions(options: ReactNativeBuildAndroidOptions) {
|
|
68
|
-
return getCliOptions<ReactNativeBuildAndroidOptions>(options, startOptions);
|
|
69
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
import { platform } from 'os';
|
|
5
|
-
|
|
6
|
-
import { ReactNativeBuildIosOptions } from './schema';
|
|
7
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
8
|
-
|
|
9
|
-
export interface ReactNativeBuildIosOutput {
|
|
10
|
-
success: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default async function* buildIosExecutor(
|
|
14
|
-
options: ReactNativeBuildIosOptions,
|
|
15
|
-
context: ExecutorContext
|
|
16
|
-
): AsyncGenerator<ReactNativeBuildIosOutput> {
|
|
17
|
-
if (platform() !== 'darwin') {
|
|
18
|
-
throw new Error(`The run-ios build requires Mac to run`);
|
|
19
|
-
}
|
|
20
|
-
const projectRoot =
|
|
21
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
22
|
-
|
|
23
|
-
await runCliBuildIOS(context.root, projectRoot, options);
|
|
24
|
-
return { success: true };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function runCliBuildIOS(
|
|
28
|
-
workspaceRoot: string,
|
|
29
|
-
projectRoot: string,
|
|
30
|
-
options: ReactNativeBuildIosOptions
|
|
31
|
-
): Promise<ChildProcess> {
|
|
32
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
33
|
-
const childProcess = fork(
|
|
34
|
-
require.resolve('react-native/cli.js'),
|
|
35
|
-
[
|
|
36
|
-
'build-ios',
|
|
37
|
-
...createBuildIOSOptions(options),
|
|
38
|
-
...(process.env.NX_VERBOSE_LOGGING === 'true' ? ['--verbose'] : []),
|
|
39
|
-
],
|
|
40
|
-
{
|
|
41
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
42
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Ensure the child process is killed when the parent exits
|
|
48
|
-
*/
|
|
49
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
50
|
-
childProcess.kill(signal);
|
|
51
|
-
process.exit();
|
|
52
|
-
};
|
|
53
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
54
|
-
process.once('SIGTERM', processExitListener);
|
|
55
|
-
process.once('SIGINT', processExitListener);
|
|
56
|
-
process.once('SIGQUIT', processExitListener);
|
|
57
|
-
|
|
58
|
-
childProcess.on('error', (err) => {
|
|
59
|
-
reject(err);
|
|
60
|
-
});
|
|
61
|
-
childProcess.on('exit', (code) => {
|
|
62
|
-
if (code === 0) {
|
|
63
|
-
resolve(childProcess);
|
|
64
|
-
} else {
|
|
65
|
-
reject(code);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const startOptions = ['port', 'resetCache'];
|
|
72
|
-
|
|
73
|
-
function createBuildIOSOptions(options: ReactNativeBuildIosOptions) {
|
|
74
|
-
return getCliOptions<ReactNativeBuildIosOptions>(options, startOptions, [
|
|
75
|
-
'buildFolder',
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createDirectory } from '@nx/workspace/src/utilities/fileutils';
|
|
2
|
-
import { names, ExecutorContext } from '@nx/devkit';
|
|
3
|
-
import { dirname, join, resolve as pathResolve } from 'path';
|
|
4
|
-
import { ChildProcess, fork } from 'child_process';
|
|
5
|
-
|
|
6
|
-
import { ReactNativeBundleOptions } from './schema';
|
|
7
|
-
|
|
8
|
-
export interface ReactNativeBundleOutput {
|
|
9
|
-
success: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function* bundleExecutor(
|
|
13
|
-
options: ReactNativeBundleOptions,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeBundleOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
|
|
19
|
-
options.bundleOutput = join(context.root, options.bundleOutput);
|
|
20
|
-
|
|
21
|
-
createDirectory(dirname(options.bundleOutput));
|
|
22
|
-
|
|
23
|
-
await runCliBuild(context.root, projectRoot, options);
|
|
24
|
-
yield { success: true };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function runCliBuild(
|
|
28
|
-
workspaceRoot: string,
|
|
29
|
-
projectRoot: string,
|
|
30
|
-
options: ReactNativeBundleOptions
|
|
31
|
-
): Promise<ChildProcess> {
|
|
32
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
33
|
-
const cliOptions = createBundleOptions(options);
|
|
34
|
-
const childProcess = fork(
|
|
35
|
-
require.resolve('react-native/cli.js'),
|
|
36
|
-
['bundle', ...cliOptions],
|
|
37
|
-
{
|
|
38
|
-
stdio: 'inherit',
|
|
39
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
40
|
-
env: process.env,
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Ensure the child process is killed when the parent exits
|
|
46
|
-
*/
|
|
47
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
48
|
-
childProcess.kill(signal);
|
|
49
|
-
process.exit();
|
|
50
|
-
};
|
|
51
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
52
|
-
process.once('SIGTERM', processExitListener);
|
|
53
|
-
process.once('SIGINT', processExitListener);
|
|
54
|
-
process.once('SIGQUIT', processExitListener);
|
|
55
|
-
|
|
56
|
-
childProcess.on('error', (err) => {
|
|
57
|
-
reject(err);
|
|
58
|
-
});
|
|
59
|
-
childProcess.on('exit', (code) => {
|
|
60
|
-
if (code === 0) {
|
|
61
|
-
resolve(childProcess);
|
|
62
|
-
} else {
|
|
63
|
-
reject(code);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function createBundleOptions(options: ReactNativeBundleOptions) {
|
|
70
|
-
return Object.keys(options).reduce((acc, _k) => {
|
|
71
|
-
const v = options[_k];
|
|
72
|
-
const k = names(_k).fileName;
|
|
73
|
-
if (v === undefined) return acc;
|
|
74
|
-
acc.push(`--${k}`, v);
|
|
75
|
-
return acc;
|
|
76
|
-
}, []);
|
|
77
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { ensureNodeModulesSymlink } from '../../utils/ensure-node-modules-symlink';
|
|
3
|
-
|
|
4
|
-
export interface ReactNativeEnsureSymlinkOutput {
|
|
5
|
-
success: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* TODO (@xiongemi): remove this function in v19.
|
|
10
|
-
* @deprecated It is no longer needed for react native 73.
|
|
11
|
-
*/
|
|
12
|
-
export default async function* ensureSymlinkExecutor(
|
|
13
|
-
_,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeEnsureSymlinkOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
|
|
19
|
-
ensureNodeModulesSymlink(context.root, projectRoot);
|
|
20
|
-
|
|
21
|
-
yield { success: true };
|
|
22
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
3
|
-
|
|
4
|
-
import { runPodInstall } from '../../utils/pod-install-task';
|
|
5
|
-
import { ReactNativePodInstallOptions } from './schema';
|
|
6
|
-
|
|
7
|
-
export interface ReactNativePodInstallOutput {
|
|
8
|
-
success: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default async function* podInstall(
|
|
12
|
-
options: ReactNativePodInstallOptions,
|
|
13
|
-
context: ExecutorContext
|
|
14
|
-
): AsyncGenerator<ReactNativePodInstallOutput> {
|
|
15
|
-
const projectRoot =
|
|
16
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
17
|
-
const iosDirectory = join(context.root, projectRoot, 'ios');
|
|
18
|
-
await runPodInstall(iosDirectory, true, options)();
|
|
19
|
-
|
|
20
|
-
yield { success: true };
|
|
21
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { join, resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
|
|
5
|
-
import { ReactNativeRunAndroidOptions } from './schema';
|
|
6
|
-
import { runCliStart } from '../start/start.impl';
|
|
7
|
-
import { chmodAndroidGradlewFiles } from '../../utils/chmod-android-gradle-files';
|
|
8
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
9
|
-
|
|
10
|
-
export interface ReactNativeRunAndroidOutput {
|
|
11
|
-
success: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let childProcess: ChildProcess;
|
|
15
|
-
|
|
16
|
-
export default async function* runAndroidExecutor(
|
|
17
|
-
options: ReactNativeRunAndroidOptions,
|
|
18
|
-
context: ExecutorContext
|
|
19
|
-
): AsyncGenerator<ReactNativeRunAndroidOutput> {
|
|
20
|
-
const projectRoot =
|
|
21
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
22
|
-
chmodAndroidGradlewFiles(join(context.root, projectRoot, 'android'));
|
|
23
|
-
|
|
24
|
-
const tasks = [runCliRunAndroid(context.root, projectRoot, options)];
|
|
25
|
-
|
|
26
|
-
if (options.mode !== 'Release') {
|
|
27
|
-
tasks.push(
|
|
28
|
-
runCliStart(context.root, projectRoot, {
|
|
29
|
-
port: options.port,
|
|
30
|
-
resetCache: options.resetCache,
|
|
31
|
-
interactive: true,
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await Promise.all(tasks);
|
|
37
|
-
|
|
38
|
-
yield { success: true };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function runCliRunAndroid(
|
|
42
|
-
workspaceRoot: string,
|
|
43
|
-
projectRoot: string,
|
|
44
|
-
options: ReactNativeRunAndroidOptions
|
|
45
|
-
): Promise<ChildProcess> {
|
|
46
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
47
|
-
/**
|
|
48
|
-
* Call the react native cli with option `--no-packager`
|
|
49
|
-
* Not passing '--packager' due to cli will launch start command from the project root
|
|
50
|
-
*/
|
|
51
|
-
childProcess = fork(
|
|
52
|
-
require.resolve('react-native/cli.js'),
|
|
53
|
-
['run-android', ...createRunAndroidOptions(options), '--no-packager'],
|
|
54
|
-
{
|
|
55
|
-
stdio: 'inherit',
|
|
56
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
57
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Ensure the child process is killed when the parent exits
|
|
63
|
-
*/
|
|
64
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
65
|
-
childProcess.kill(signal);
|
|
66
|
-
process.exit();
|
|
67
|
-
};
|
|
68
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
69
|
-
process.once('SIGTERM', processExitListener);
|
|
70
|
-
process.once('SIGINT', processExitListener);
|
|
71
|
-
process.once('SIGQUIT', processExitListener);
|
|
72
|
-
|
|
73
|
-
childProcess.on('error', (err) => {
|
|
74
|
-
reject(err);
|
|
75
|
-
});
|
|
76
|
-
childProcess.on('exit', (code) => {
|
|
77
|
-
if (code === 0) {
|
|
78
|
-
resolve(childProcess);
|
|
79
|
-
} else {
|
|
80
|
-
reject(code);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const startOptions = ['port', 'resetCache'];
|
|
87
|
-
|
|
88
|
-
function createRunAndroidOptions(options: ReactNativeRunAndroidOptions) {
|
|
89
|
-
return getCliOptions<ReactNativeRunAndroidOptions>(options, startOptions, [
|
|
90
|
-
'appId',
|
|
91
|
-
'appIdSuffix',
|
|
92
|
-
'deviceId',
|
|
93
|
-
]);
|
|
94
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext, GeneratorCallback, workspaceRoot } from '@nx/devkit';
|
|
2
|
-
import { resolve as pathResolve } from 'path';
|
|
3
|
-
import { ChildProcess, fork } from 'child_process';
|
|
4
|
-
import { platform } from 'os';
|
|
5
|
-
|
|
6
|
-
import { runCliStart } from '../start/start.impl';
|
|
7
|
-
import { getCliOptions } from '../../utils/get-cli-options';
|
|
8
|
-
|
|
9
|
-
import { ReactNativeRunIosOptions } from './schema';
|
|
10
|
-
export interface ReactNativeRunIosOutput {
|
|
11
|
-
success: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default async function* runIosExecutor(
|
|
15
|
-
options: ReactNativeRunIosOptions,
|
|
16
|
-
context: ExecutorContext
|
|
17
|
-
): AsyncGenerator<ReactNativeRunIosOutput> {
|
|
18
|
-
if (platform() !== 'darwin') {
|
|
19
|
-
throw new Error(`The run-ios build requires Mac to run`);
|
|
20
|
-
}
|
|
21
|
-
const projectRoot =
|
|
22
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
23
|
-
|
|
24
|
-
const tasks = [runCliRunIOS(context.root, projectRoot, options)];
|
|
25
|
-
|
|
26
|
-
if (options.mode !== 'Release') {
|
|
27
|
-
tasks.push(
|
|
28
|
-
runCliStart(context.root, projectRoot, {
|
|
29
|
-
port: options.port,
|
|
30
|
-
resetCache: options.resetCache,
|
|
31
|
-
interactive: true,
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await Promise.all(tasks);
|
|
37
|
-
|
|
38
|
-
yield { success: true };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function runCliRunIOS(
|
|
42
|
-
workspaceRoot: string,
|
|
43
|
-
projectRoot: string,
|
|
44
|
-
options: ReactNativeRunIosOptions
|
|
45
|
-
): Promise<ChildProcess> {
|
|
46
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
47
|
-
/**
|
|
48
|
-
* Call the react native cli with option `--no-packager`
|
|
49
|
-
* Not passing '--packager' due to cli will launch start command from the project root
|
|
50
|
-
*/
|
|
51
|
-
const childProcess = fork(
|
|
52
|
-
require.resolve('react-native/cli.js'),
|
|
53
|
-
['run-ios', ...createRunIOSOptions(options), '--no-packager'],
|
|
54
|
-
{
|
|
55
|
-
stdio: 'inherit',
|
|
56
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
57
|
-
env: { ...process.env, RCT_METRO_PORT: options.port.toString() },
|
|
58
|
-
}
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Ensure the child process is killed when the parent exits
|
|
63
|
-
*/
|
|
64
|
-
const processExitListener = (signal?: number | NodeJS.Signals) => () => {
|
|
65
|
-
childProcess.kill(signal);
|
|
66
|
-
process.exit();
|
|
67
|
-
};
|
|
68
|
-
process.once('exit', (signal) => childProcess.kill(signal));
|
|
69
|
-
process.once('SIGTERM', processExitListener);
|
|
70
|
-
process.once('SIGINT', processExitListener);
|
|
71
|
-
process.once('SIGQUIT', processExitListener);
|
|
72
|
-
|
|
73
|
-
childProcess.on('error', (err) => {
|
|
74
|
-
reject(err);
|
|
75
|
-
});
|
|
76
|
-
childProcess.on('exit', (code) => {
|
|
77
|
-
if (code === 0) {
|
|
78
|
-
resolve(childProcess);
|
|
79
|
-
} else {
|
|
80
|
-
reject(code);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const startOptions = ['port', 'resetCache'];
|
|
87
|
-
|
|
88
|
-
function createRunIOSOptions(options: ReactNativeRunIosOptions) {
|
|
89
|
-
return getCliOptions<ReactNativeRunIosOptions>(options, startOptions, [
|
|
90
|
-
'buildFolder',
|
|
91
|
-
]);
|
|
92
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext, logger } from '@nx/devkit';
|
|
2
|
-
import { ChildProcess, fork } from 'child_process';
|
|
3
|
-
import { resolve as pathResolve } from 'path';
|
|
4
|
-
import { isPackagerRunning } from './lib/is-packager-running';
|
|
5
|
-
import { ReactNativeStartOptions } from './schema';
|
|
6
|
-
|
|
7
|
-
export interface ReactNativeStartOutput {
|
|
8
|
-
port?: number;
|
|
9
|
-
success: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function* startExecutor(
|
|
13
|
-
options: ReactNativeStartOptions,
|
|
14
|
-
context: ExecutorContext
|
|
15
|
-
): AsyncGenerator<ReactNativeStartOutput> {
|
|
16
|
-
const projectRoot =
|
|
17
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
18
|
-
|
|
19
|
-
await runCliStart(context.root, projectRoot, options);
|
|
20
|
-
|
|
21
|
-
yield {
|
|
22
|
-
port: options.port,
|
|
23
|
-
success: true,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/*
|
|
28
|
-
* Starts the JS bundler and checks for "running" status before notifying
|
|
29
|
-
* that packager has started.
|
|
30
|
-
*/
|
|
31
|
-
export async function runCliStart(
|
|
32
|
-
workspaceRoot: string,
|
|
33
|
-
projectRoot: string,
|
|
34
|
-
options: ReactNativeStartOptions
|
|
35
|
-
): Promise<ChildProcess> {
|
|
36
|
-
const result = await isPackagerRunning(options.port);
|
|
37
|
-
if (result === 'running') {
|
|
38
|
-
logger.info(`JS server already running on port ${options.port}.`);
|
|
39
|
-
} else if (result === 'unrecognized') {
|
|
40
|
-
logger.warn('JS server not recognized.');
|
|
41
|
-
} else {
|
|
42
|
-
// result === 'not_running'
|
|
43
|
-
logger.info('Starting JS server...');
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
return await startAsync(workspaceRoot, projectRoot, options);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
logger.error(
|
|
49
|
-
`Failed to start the packager server. Error details: ${
|
|
50
|
-
error.message ?? error
|
|
51
|
-
}`
|
|
52
|
-
);
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function startAsync(
|
|
59
|
-
workspaceRoot: string,
|
|
60
|
-
projectRoot: string,
|
|
61
|
-
options: ReactNativeStartOptions
|
|
62
|
-
): Promise<ChildProcess> {
|
|
63
|
-
return new Promise<ChildProcess>((resolve, reject) => {
|
|
64
|
-
const childProcess = fork(
|
|
65
|
-
require.resolve('react-native/cli.js'),
|
|
66
|
-
['start', ...createStartOptions(options)],
|
|
67
|
-
{
|
|
68
|
-
cwd: pathResolve(workspaceRoot, projectRoot),
|
|
69
|
-
env: process.env,
|
|
70
|
-
stdio: 'inherit',
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
childProcess.on('error', (err) => {
|
|
75
|
-
reject(err);
|
|
76
|
-
});
|
|
77
|
-
childProcess.on('exit', (code) => {
|
|
78
|
-
if (code === 0) {
|
|
79
|
-
resolve(childProcess);
|
|
80
|
-
} else {
|
|
81
|
-
reject(code);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
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
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function createStartOptions(options) {
|
|
97
|
-
return Object.keys(options).reduce((acc, k) => {
|
|
98
|
-
if (k === 'resetCache') {
|
|
99
|
-
if (options[k] === true) {
|
|
100
|
-
acc.push(`--reset-cache`);
|
|
101
|
-
}
|
|
102
|
-
} else if (k === 'interactive') {
|
|
103
|
-
if (options[k] === false) {
|
|
104
|
-
acc.push(`--no-interactive`);
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
acc.push(`--${k}`, options[k]);
|
|
108
|
-
}
|
|
109
|
-
return acc;
|
|
110
|
-
}, []);
|
|
111
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import { ExecutorContext, logger, readJsonFile } from '@nx/devkit';
|
|
3
|
-
import { fileExists } from '@nx/workspace/src/utilities/fileutils';
|
|
4
|
-
import * as chalk from 'chalk';
|
|
5
|
-
import { sync as globSync } from 'glob';
|
|
6
|
-
|
|
7
|
-
import { ReactNativeStorybookOptions } from './schema';
|
|
8
|
-
import {
|
|
9
|
-
displayNewlyAddedDepsMessage,
|
|
10
|
-
syncDeps,
|
|
11
|
-
} from '../sync-deps/sync-deps.impl';
|
|
12
|
-
import { writeFileSync } from 'fs-extra';
|
|
13
|
-
import { PackageJson } from 'nx/src/utils/package-json';
|
|
14
|
-
|
|
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
|
-
export default async function* reactNativeStorybookExecutor(
|
|
20
|
-
options: ReactNativeStorybookOptions,
|
|
21
|
-
context: ExecutorContext
|
|
22
|
-
): AsyncGenerator<{ success: boolean }> {
|
|
23
|
-
const projectRoot =
|
|
24
|
-
context.projectsConfigurations.projects[context.projectName].root;
|
|
25
|
-
logger.info(
|
|
26
|
-
`${chalk.bold.cyan(
|
|
27
|
-
'info'
|
|
28
|
-
)} To see your Storybook stories on the device, you should start your mobile app for the <platform> of your choice (typically ios or android).`
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// add storybook addons to app's package.json
|
|
32
|
-
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
|
-
if (fileExists(packageJsonPath))
|
|
41
|
-
displayNewlyAddedDepsMessage(
|
|
42
|
-
context.projectName,
|
|
43
|
-
await syncDeps(
|
|
44
|
-
context.projectName,
|
|
45
|
-
projectPackageJson,
|
|
46
|
-
packageJsonPath,
|
|
47
|
-
workspacePackageJson,
|
|
48
|
-
context.projectGraph,
|
|
49
|
-
[
|
|
50
|
-
`@storybook/react-native`,
|
|
51
|
-
'@storybook/addon-ondevice-actions',
|
|
52
|
-
'@storybook/addon-ondevice-backgrounds',
|
|
53
|
-
'@storybook/addon-ondevice-controls',
|
|
54
|
-
'@storybook/addon-ondevice-notes',
|
|
55
|
-
'@react-native-async-storage/async-storage',
|
|
56
|
-
'react-native-safe-area-context',
|
|
57
|
-
]
|
|
58
|
-
)
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
runCliStorybook(context.root, options);
|
|
62
|
-
yield { success: true };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function runCliStorybook(
|
|
66
|
-
workspaceRoot: string,
|
|
67
|
-
options: ReactNativeStorybookOptions
|
|
68
|
-
) {
|
|
69
|
-
const storiesFiles: string[] = options.searchDir.flatMap((dir) =>
|
|
70
|
-
globSync(join(dir, options.pattern))
|
|
71
|
-
);
|
|
72
|
-
if (storiesFiles.length === 0) {
|
|
73
|
-
logger.warn(`${chalk.bold.yellow('warn')} No stories found.`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const newContents = `// Auto-generated file created by nx
|
|
77
|
-
// DO NOT EDIT.
|
|
78
|
-
export function loadStories() {
|
|
79
|
-
return [
|
|
80
|
-
${storiesFiles.map((story) => `require('${story}')`).join(',\n')}
|
|
81
|
-
];
|
|
82
|
-
}`;
|
|
83
|
-
|
|
84
|
-
writeFileSync(join(workspaceRoot, options.outputFile), newContents);
|
|
85
|
-
}
|