@react-native/community-cli-plugin 0.73.0
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/README.md +87 -0
- package/dist/commands/bundle/assetCatalogIOS.js +74 -0
- package/dist/commands/bundle/assetCatalogIOS.js.flow +77 -0
- package/dist/commands/bundle/assetPathUtils.js +79 -0
- package/dist/commands/bundle/assetPathUtils.js.flow +93 -0
- package/dist/commands/bundle/buildBundle.js +112 -0
- package/dist/commands/bundle/buildBundle.js.flow +120 -0
- package/dist/commands/bundle/bundle.js +44 -0
- package/dist/commands/bundle/bundle.js.flow +37 -0
- package/dist/commands/bundle/bundleCommandLineArgs.js +116 -0
- package/dist/commands/bundle/bundleCommandLineArgs.js.flow +129 -0
- package/dist/commands/bundle/filterPlatformAssetScales.js +47 -0
- package/dist/commands/bundle/filterPlatformAssetScales.js.flow +45 -0
- package/dist/commands/bundle/getAssetDestPathAndroid.js +32 -0
- package/dist/commands/bundle/getAssetDestPathAndroid.js.flow +26 -0
- package/dist/commands/bundle/getAssetDestPathIOS.js +34 -0
- package/dist/commands/bundle/getAssetDestPathIOS.js.flow +28 -0
- package/dist/commands/bundle/ramBundle.js +47 -0
- package/dist/commands/bundle/ramBundle.js.flow +43 -0
- package/dist/commands/bundle/saveAssets.js +138 -0
- package/dist/commands/bundle/saveAssets.js.flow +139 -0
- package/dist/commands/start/index.js +110 -0
- package/dist/commands/start/index.js.flow +97 -0
- package/dist/commands/start/runServer.js +123 -0
- package/dist/commands/start/runServer.js.flow +156 -0
- package/dist/commands/start/startServerInNewWindow.js +132 -0
- package/dist/commands/start/startServerInNewWindow.js.flow +125 -0
- package/dist/commands/start/watchMode.js +95 -0
- package/dist/commands/start/watchMode.js.flow +101 -0
- package/dist/index.flow.js +36 -0
- package/dist/index.flow.js.flow +16 -0
- package/dist/index.js +3 -0
- package/dist/index.js.flow +20 -0
- package/dist/utils/loadMetroConfig.js +108 -0
- package/dist/utils/loadMetroConfig.js.flow +125 -0
- package/dist/utils/metroPlatformResolver.js +46 -0
- package/dist/utils/metroPlatformResolver.js.flow +44 -0
- package/launchPackager.bat +7 -0
- package/launchPackager.command +10 -0
- package/package.json +29 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type {Config} from '@react-native-community/cli-types';
|
|
13
|
+
import type {Reporter} from 'metro/src/lib/reporting';
|
|
14
|
+
import type {TerminalReportableEvent} from 'metro/src/lib/TerminalReporter';
|
|
15
|
+
import typeof TerminalReporter from 'metro/src/lib/TerminalReporter';
|
|
16
|
+
import type Server from 'metro/src/Server';
|
|
17
|
+
import type {Middleware} from 'metro-config';
|
|
18
|
+
|
|
19
|
+
import Metro from 'metro';
|
|
20
|
+
import {Terminal} from 'metro-core';
|
|
21
|
+
import path from 'path';
|
|
22
|
+
import {
|
|
23
|
+
createDevServerMiddleware,
|
|
24
|
+
indexPageMiddleware,
|
|
25
|
+
} from '@react-native-community/cli-server-api';
|
|
26
|
+
|
|
27
|
+
import loadMetroConfig from '../../utils/loadMetroConfig';
|
|
28
|
+
import {version} from '@react-native-community/cli-tools';
|
|
29
|
+
import enableWatchMode from './watchMode';
|
|
30
|
+
|
|
31
|
+
export type Args = {
|
|
32
|
+
assetPlugins?: string[],
|
|
33
|
+
cert?: string,
|
|
34
|
+
customLogReporterPath?: string,
|
|
35
|
+
host?: string,
|
|
36
|
+
https?: boolean,
|
|
37
|
+
maxWorkers?: number,
|
|
38
|
+
key?: string,
|
|
39
|
+
platforms?: string[],
|
|
40
|
+
port?: number,
|
|
41
|
+
resetCache?: boolean,
|
|
42
|
+
sourceExts?: string[],
|
|
43
|
+
transformer?: string,
|
|
44
|
+
watchFolders?: string[],
|
|
45
|
+
config?: string,
|
|
46
|
+
projectRoot?: string,
|
|
47
|
+
interactive: boolean,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
async function runServer(_argv: Array<string>, ctx: Config, args: Args) {
|
|
51
|
+
let reportEvent: (event: any) => void;
|
|
52
|
+
const terminal = new Terminal(process.stdout);
|
|
53
|
+
const ReporterImpl = getReporterImpl(args.customLogReporterPath);
|
|
54
|
+
const terminalReporter = new ReporterImpl(terminal);
|
|
55
|
+
const reporter: Reporter = {
|
|
56
|
+
update(event: TerminalReportableEvent) {
|
|
57
|
+
terminalReporter.update(event);
|
|
58
|
+
if (reportEvent) {
|
|
59
|
+
reportEvent(event);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const metroConfig = await loadMetroConfig(ctx, {
|
|
65
|
+
config: args.config,
|
|
66
|
+
maxWorkers: args.maxWorkers,
|
|
67
|
+
port: args.port,
|
|
68
|
+
resetCache: args.resetCache,
|
|
69
|
+
watchFolders: args.watchFolders,
|
|
70
|
+
projectRoot: args.projectRoot,
|
|
71
|
+
sourceExts: args.sourceExts,
|
|
72
|
+
reporter,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (args.assetPlugins) {
|
|
76
|
+
// $FlowIgnore[cannot-write] Assigning to readonly property
|
|
77
|
+
metroConfig.transformer.assetPlugins = args.assetPlugins.map(plugin =>
|
|
78
|
+
require.resolve(plugin),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const {
|
|
83
|
+
middleware,
|
|
84
|
+
websocketEndpoints,
|
|
85
|
+
messageSocketEndpoint,
|
|
86
|
+
eventsSocketEndpoint,
|
|
87
|
+
} = createDevServerMiddleware({
|
|
88
|
+
host: args.host,
|
|
89
|
+
port: metroConfig.server.port,
|
|
90
|
+
watchFolders: metroConfig.watchFolders,
|
|
91
|
+
});
|
|
92
|
+
middleware.use(indexPageMiddleware);
|
|
93
|
+
|
|
94
|
+
const customEnhanceMiddleware = metroConfig.server.enhanceMiddleware;
|
|
95
|
+
// $FlowIgnore[cannot-write] Assigning to readonly property
|
|
96
|
+
metroConfig.server.enhanceMiddleware = (
|
|
97
|
+
metroMiddleware: Middleware,
|
|
98
|
+
server: Server,
|
|
99
|
+
) => {
|
|
100
|
+
if (customEnhanceMiddleware) {
|
|
101
|
+
metroMiddleware = customEnhanceMiddleware(metroMiddleware, server);
|
|
102
|
+
}
|
|
103
|
+
return middleware.use(metroMiddleware);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const serverInstance = await Metro.runServer(metroConfig, {
|
|
107
|
+
host: args.host,
|
|
108
|
+
secure: args.https,
|
|
109
|
+
secureCert: args.cert,
|
|
110
|
+
secureKey: args.key,
|
|
111
|
+
// $FlowFixMe[incompatible-call] Incompatibly defined WebSocketServer type
|
|
112
|
+
websocketEndpoints,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
reportEvent = eventsSocketEndpoint.reportEvent;
|
|
116
|
+
|
|
117
|
+
if (args.interactive) {
|
|
118
|
+
enableWatchMode(messageSocketEndpoint, ctx);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// In Node 8, the default keep-alive for an HTTP connection is 5 seconds. In
|
|
122
|
+
// early versions of Node 8, this was implemented in a buggy way which caused
|
|
123
|
+
// some HTTP responses (like those containing large JS bundles) to be
|
|
124
|
+
// terminated early.
|
|
125
|
+
//
|
|
126
|
+
// As a workaround, arbitrarily increase the keep-alive from 5 to 30 seconds,
|
|
127
|
+
// which should be enough to send even the largest of JS bundles.
|
|
128
|
+
//
|
|
129
|
+
// For more info: https://github.com/nodejs/node/issues/13391
|
|
130
|
+
//
|
|
131
|
+
serverInstance.keepAliveTimeout = 30000;
|
|
132
|
+
|
|
133
|
+
await version.logIfUpdateAvailable(ctx.root);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function getReporterImpl(customLogReporterPath?: string): TerminalReporter {
|
|
137
|
+
if (customLogReporterPath == null) {
|
|
138
|
+
return require('metro/src/lib/TerminalReporter');
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
// First we let require resolve it, so we can require packages in node_modules
|
|
142
|
+
// as expected. eg: require('my-package/reporter');
|
|
143
|
+
// $FlowIgnore[unsupported-syntax]
|
|
144
|
+
return require(customLogReporterPath);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
147
|
+
throw e;
|
|
148
|
+
}
|
|
149
|
+
// If that doesn't work, then we next try relative to the cwd, eg:
|
|
150
|
+
// require('./reporter');
|
|
151
|
+
// $FlowIgnore[unsupported-syntax]
|
|
152
|
+
return require(path.resolve(customLogReporterPath));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default runServer;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.startServerInNewWindow = startServerInNewWindow;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
var _execa = _interopRequireDefault(require("execa"));
|
|
10
|
+
var _cliTools = require("@react-native-community/cli-tools");
|
|
11
|
+
function _interopRequireDefault(obj) {
|
|
12
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
* @format
|
|
22
|
+
* @oncall react_native
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function startServerInNewWindow(port, terminal, projectRoot, reactNativePath) {
|
|
26
|
+
/**
|
|
27
|
+
* Set up OS-specific filenames and commands
|
|
28
|
+
*/
|
|
29
|
+
const isWindows = /^win/.test(process.platform);
|
|
30
|
+
const scriptFile = isWindows
|
|
31
|
+
? "launchPackager.bat"
|
|
32
|
+
: "launchPackager.command";
|
|
33
|
+
const packagerEnvFilename = isWindows ? ".packager.bat" : ".packager.env";
|
|
34
|
+
const packagerEnvFileExportContent = isWindows
|
|
35
|
+
? `set RCT_METRO_PORT=${port}\nset PROJECT_ROOT=${projectRoot}\nset REACT_NATIVE_PATH=${reactNativePath}`
|
|
36
|
+
: `export RCT_METRO_PORT=${port}\nexport PROJECT_ROOT=${projectRoot}\nexport REACT_NATIVE_PATH=${reactNativePath}`;
|
|
37
|
+
const nodeModulesPath = (0, _cliTools.resolveNodeModuleDir)(
|
|
38
|
+
projectRoot,
|
|
39
|
+
".bin"
|
|
40
|
+
);
|
|
41
|
+
const cliPluginMetroPath = _path.default.join(
|
|
42
|
+
_path.default.dirname(
|
|
43
|
+
require.resolve("@react-native/community-cli-plugin/package.json")
|
|
44
|
+
),
|
|
45
|
+
"build"
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set up the `.packager.(env|bat)` file to ensure the packager starts on the right port and in right directory.
|
|
50
|
+
*/
|
|
51
|
+
const packagerEnvFile = _path.default.join(
|
|
52
|
+
nodeModulesPath,
|
|
53
|
+
`${packagerEnvFilename}`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Set up the `launchPackager.(command|bat)` file.
|
|
58
|
+
* It lives next to `.packager.(bat|env)`
|
|
59
|
+
*/
|
|
60
|
+
const launchPackagerScript = _path.default.join(nodeModulesPath, scriptFile);
|
|
61
|
+
const procConfig = {
|
|
62
|
+
cwd: _path.default.dirname(packagerEnvFile),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Ensure we overwrite file by passing the `w` flag
|
|
67
|
+
*/
|
|
68
|
+
_fs.default.writeFileSync(packagerEnvFile, packagerEnvFileExportContent, {
|
|
69
|
+
encoding: "utf8",
|
|
70
|
+
flag: "w",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Copy files into `node_modules/.bin`.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
if (isWindows) {
|
|
79
|
+
_fs.default.copyFileSync(
|
|
80
|
+
_path.default.join(cliPluginMetroPath, "launchPackager.bat"),
|
|
81
|
+
_path.default.join(nodeModulesPath, "launchPackager.bat")
|
|
82
|
+
);
|
|
83
|
+
} else {
|
|
84
|
+
_fs.default.copyFileSync(
|
|
85
|
+
_path.default.join(cliPluginMetroPath, "launchPackager.command"),
|
|
86
|
+
_path.default.join(nodeModulesPath, "launchPackager.command")
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
return new _cliTools.CLIError(
|
|
91
|
+
`Couldn't copy the script for running bundler. Please check if the "${scriptFile}" file exists in the "node_modules/@react-native/community-cli-plugin" folder and try again.`,
|
|
92
|
+
error
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (process.platform === "darwin") {
|
|
96
|
+
try {
|
|
97
|
+
return _execa.default.sync(
|
|
98
|
+
"open",
|
|
99
|
+
["-a", terminal, launchPackagerScript],
|
|
100
|
+
procConfig
|
|
101
|
+
);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return _execa.default.sync("open", [launchPackagerScript], procConfig);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (process.platform === "linux") {
|
|
107
|
+
try {
|
|
108
|
+
return _execa.default.sync(
|
|
109
|
+
terminal,
|
|
110
|
+
["-e", `sh ${launchPackagerScript}`],
|
|
111
|
+
{
|
|
112
|
+
...procConfig,
|
|
113
|
+
detached: true,
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
// By default, the child shell process will be attached to the parent
|
|
118
|
+
return _execa.default.sync("sh", [launchPackagerScript], procConfig);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (isWindows) {
|
|
122
|
+
// Awaiting this causes the CLI to hang indefinitely, so this must execute without await.
|
|
123
|
+
return (0, _execa.default)("cmd.exe", ["/C", launchPackagerScript], {
|
|
124
|
+
...procConfig,
|
|
125
|
+
detached: true,
|
|
126
|
+
stdio: "ignore",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
_cliTools.logger.error(
|
|
130
|
+
`Cannot start the packager. Unknown platform ${process.platform}`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type {ExecaPromise, SyncResult} from 'execa';
|
|
13
|
+
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import fs from 'fs';
|
|
16
|
+
import execa from 'execa';
|
|
17
|
+
import {
|
|
18
|
+
CLIError,
|
|
19
|
+
logger,
|
|
20
|
+
resolveNodeModuleDir,
|
|
21
|
+
} from '@react-native-community/cli-tools';
|
|
22
|
+
|
|
23
|
+
export function startServerInNewWindow(
|
|
24
|
+
port: number,
|
|
25
|
+
terminal: string,
|
|
26
|
+
projectRoot: string,
|
|
27
|
+
reactNativePath: string,
|
|
28
|
+
): SyncResult | ExecaPromise | CLIError | void {
|
|
29
|
+
/**
|
|
30
|
+
* Set up OS-specific filenames and commands
|
|
31
|
+
*/
|
|
32
|
+
const isWindows = /^win/.test(process.platform);
|
|
33
|
+
const scriptFile = isWindows
|
|
34
|
+
? 'launchPackager.bat'
|
|
35
|
+
: 'launchPackager.command';
|
|
36
|
+
const packagerEnvFilename = isWindows ? '.packager.bat' : '.packager.env';
|
|
37
|
+
const packagerEnvFileExportContent = isWindows
|
|
38
|
+
? `set RCT_METRO_PORT=${port}\nset PROJECT_ROOT=${projectRoot}\nset REACT_NATIVE_PATH=${reactNativePath}`
|
|
39
|
+
: `export RCT_METRO_PORT=${port}\nexport PROJECT_ROOT=${projectRoot}\nexport REACT_NATIVE_PATH=${reactNativePath}`;
|
|
40
|
+
const nodeModulesPath = resolveNodeModuleDir(projectRoot, '.bin');
|
|
41
|
+
const cliPluginMetroPath = path.join(
|
|
42
|
+
path.dirname(
|
|
43
|
+
require.resolve('@react-native/community-cli-plugin/package.json'),
|
|
44
|
+
),
|
|
45
|
+
'build',
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set up the `.packager.(env|bat)` file to ensure the packager starts on the right port and in right directory.
|
|
50
|
+
*/
|
|
51
|
+
const packagerEnvFile = path.join(nodeModulesPath, `${packagerEnvFilename}`);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Set up the `launchPackager.(command|bat)` file.
|
|
55
|
+
* It lives next to `.packager.(bat|env)`
|
|
56
|
+
*/
|
|
57
|
+
const launchPackagerScript = path.join(nodeModulesPath, scriptFile);
|
|
58
|
+
const procConfig = {cwd: path.dirname(packagerEnvFile)};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Ensure we overwrite file by passing the `w` flag
|
|
62
|
+
*/
|
|
63
|
+
fs.writeFileSync(packagerEnvFile, packagerEnvFileExportContent, {
|
|
64
|
+
encoding: 'utf8',
|
|
65
|
+
flag: 'w',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Copy files into `node_modules/.bin`.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
if (isWindows) {
|
|
74
|
+
fs.copyFileSync(
|
|
75
|
+
path.join(cliPluginMetroPath, 'launchPackager.bat'),
|
|
76
|
+
path.join(nodeModulesPath, 'launchPackager.bat'),
|
|
77
|
+
);
|
|
78
|
+
} else {
|
|
79
|
+
fs.copyFileSync(
|
|
80
|
+
path.join(cliPluginMetroPath, 'launchPackager.command'),
|
|
81
|
+
path.join(nodeModulesPath, 'launchPackager.command'),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return new CLIError(
|
|
86
|
+
`Couldn't copy the script for running bundler. Please check if the "${scriptFile}" file exists in the "node_modules/@react-native/community-cli-plugin" folder and try again.`,
|
|
87
|
+
error,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (process.platform === 'darwin') {
|
|
92
|
+
try {
|
|
93
|
+
return execa.sync(
|
|
94
|
+
'open',
|
|
95
|
+
['-a', terminal, launchPackagerScript],
|
|
96
|
+
procConfig,
|
|
97
|
+
);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return execa.sync('open', [launchPackagerScript], procConfig);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (process.platform === 'linux') {
|
|
103
|
+
try {
|
|
104
|
+
return execa.sync(terminal, ['-e', `sh ${launchPackagerScript}`], {
|
|
105
|
+
...procConfig,
|
|
106
|
+
detached: true,
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
// By default, the child shell process will be attached to the parent
|
|
110
|
+
return execa.sync('sh', [launchPackagerScript], procConfig);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (isWindows) {
|
|
114
|
+
// Awaiting this causes the CLI to hang indefinitely, so this must execute without await.
|
|
115
|
+
return execa('cmd.exe', ['/C', launchPackagerScript], {
|
|
116
|
+
...procConfig,
|
|
117
|
+
detached: true,
|
|
118
|
+
stdio: 'ignore',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
logger.error(
|
|
122
|
+
`Cannot start the packager. Unknown platform ${process.platform}`,
|
|
123
|
+
);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _readline = _interopRequireDefault(require("readline"));
|
|
8
|
+
var _cliTools = require("@react-native-community/cli-tools");
|
|
9
|
+
var _execa = _interopRequireDefault(require("execa"));
|
|
10
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
+
function _interopRequireDefault(obj) {
|
|
12
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
* @format
|
|
22
|
+
* @oncall react_native
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function printWatchModeInstructions() {
|
|
26
|
+
_cliTools.logger.log(
|
|
27
|
+
`${_chalk.default.bold("r")} - reload the app\n${_chalk.default.bold(
|
|
28
|
+
"d"
|
|
29
|
+
)} - open developer menu\n${_chalk.default.bold(
|
|
30
|
+
"i"
|
|
31
|
+
)} - run on iOS\n${_chalk.default.bold("a")} - run on Android`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function enableWatchMode(messageSocket, ctx) {
|
|
35
|
+
// We need to set this to true to catch key presses individually.
|
|
36
|
+
// As a result we have to implement our own method for exiting
|
|
37
|
+
// and other commands (e.g. ctrl+c & ctrl+z)
|
|
38
|
+
// $FlowIgnore[method-unbinding]
|
|
39
|
+
if (!process.stdin.setRawMode) {
|
|
40
|
+
_cliTools.logger.debug("Watch mode is not supported in this environment");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
_readline.default.emitKeypressEvents(process.stdin);
|
|
44
|
+
|
|
45
|
+
// $FlowIgnore[prop-missing]
|
|
46
|
+
process.stdin.setRawMode(true);
|
|
47
|
+
|
|
48
|
+
// We have no way of knowing when the dependency graph is done loading
|
|
49
|
+
// except by hooking into stdout itself. We want to print instructions
|
|
50
|
+
// right after its done loading.
|
|
51
|
+
const restore = (0, _cliTools.hookStdout)((output) => {
|
|
52
|
+
// TODO(T160391951) Replace this string check with a suitable integration point
|
|
53
|
+
// in Metro
|
|
54
|
+
if (output.includes("Fast - Scalable - Integrated")) {
|
|
55
|
+
printWatchModeInstructions();
|
|
56
|
+
restore();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
process.stdin.on("keypress", (_key, data) => {
|
|
60
|
+
const { ctrl, name } = data;
|
|
61
|
+
if (ctrl === true) {
|
|
62
|
+
switch (name) {
|
|
63
|
+
case "c":
|
|
64
|
+
process.exit();
|
|
65
|
+
break;
|
|
66
|
+
case "z":
|
|
67
|
+
process.emit("SIGTSTP", "SIGTSTP");
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
} else if (name === "r") {
|
|
71
|
+
messageSocket.broadcast("reload", null);
|
|
72
|
+
_cliTools.logger.info("Reloading app...");
|
|
73
|
+
} else if (name === "d") {
|
|
74
|
+
messageSocket.broadcast("devMenu", null);
|
|
75
|
+
_cliTools.logger.info("Opening developer menu...");
|
|
76
|
+
} else if (name === "i" || name === "a") {
|
|
77
|
+
_cliTools.logger.info(
|
|
78
|
+
`Opening the app on ${name === "i" ? "iOS" : "Android"}...`
|
|
79
|
+
);
|
|
80
|
+
const params =
|
|
81
|
+
name === "i"
|
|
82
|
+
? ctx.project.ios?.watchModeCommandParams
|
|
83
|
+
: ctx.project.android?.watchModeCommandParams;
|
|
84
|
+
(0, _execa.default)("npx", [
|
|
85
|
+
"react-native",
|
|
86
|
+
name === "i" ? "run-ios" : "run-android",
|
|
87
|
+
...(params ?? []),
|
|
88
|
+
]).stdout?.pipe(process.stdout);
|
|
89
|
+
} else {
|
|
90
|
+
console.log(_key);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
var _default = enableWatchMode;
|
|
95
|
+
exports.default = _default;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type {Config} from '@react-native-community/cli-types';
|
|
13
|
+
|
|
14
|
+
import readline from 'readline';
|
|
15
|
+
import {logger, hookStdout} from '@react-native-community/cli-tools';
|
|
16
|
+
import execa from 'execa';
|
|
17
|
+
import chalk from 'chalk';
|
|
18
|
+
|
|
19
|
+
function printWatchModeInstructions() {
|
|
20
|
+
logger.log(
|
|
21
|
+
`${chalk.bold('r')} - reload the app\n${chalk.bold(
|
|
22
|
+
'd',
|
|
23
|
+
)} - open developer menu\n${chalk.bold('i')} - run on iOS\n${chalk.bold(
|
|
24
|
+
'a',
|
|
25
|
+
)} - run on Android`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function enableWatchMode(
|
|
30
|
+
messageSocket: $ReadOnly<{
|
|
31
|
+
broadcast: (type: string, params?: Record<string, mixed> | null) => void,
|
|
32
|
+
...
|
|
33
|
+
}>,
|
|
34
|
+
ctx: Config,
|
|
35
|
+
) {
|
|
36
|
+
// We need to set this to true to catch key presses individually.
|
|
37
|
+
// As a result we have to implement our own method for exiting
|
|
38
|
+
// and other commands (e.g. ctrl+c & ctrl+z)
|
|
39
|
+
// $FlowIgnore[method-unbinding]
|
|
40
|
+
if (!process.stdin.setRawMode) {
|
|
41
|
+
logger.debug('Watch mode is not supported in this environment');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
readline.emitKeypressEvents(process.stdin);
|
|
46
|
+
|
|
47
|
+
// $FlowIgnore[prop-missing]
|
|
48
|
+
process.stdin.setRawMode(true);
|
|
49
|
+
|
|
50
|
+
// We have no way of knowing when the dependency graph is done loading
|
|
51
|
+
// except by hooking into stdout itself. We want to print instructions
|
|
52
|
+
// right after its done loading.
|
|
53
|
+
const restore: () => void = hookStdout((output: string) => {
|
|
54
|
+
// TODO(T160391951) Replace this string check with a suitable integration point
|
|
55
|
+
// in Metro
|
|
56
|
+
if (output.includes('Fast - Scalable - Integrated')) {
|
|
57
|
+
printWatchModeInstructions();
|
|
58
|
+
restore();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
process.stdin.on(
|
|
63
|
+
'keypress',
|
|
64
|
+
(_key: string, data: {ctrl: boolean, name: string}) => {
|
|
65
|
+
const {ctrl, name} = data;
|
|
66
|
+
if (ctrl === true) {
|
|
67
|
+
switch (name) {
|
|
68
|
+
case 'c':
|
|
69
|
+
process.exit();
|
|
70
|
+
break;
|
|
71
|
+
case 'z':
|
|
72
|
+
process.emit('SIGTSTP', 'SIGTSTP');
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
} else if (name === 'r') {
|
|
76
|
+
messageSocket.broadcast('reload', null);
|
|
77
|
+
logger.info('Reloading app...');
|
|
78
|
+
} else if (name === 'd') {
|
|
79
|
+
messageSocket.broadcast('devMenu', null);
|
|
80
|
+
logger.info('Opening developer menu...');
|
|
81
|
+
} else if (name === 'i' || name === 'a') {
|
|
82
|
+
logger.info(
|
|
83
|
+
`Opening the app on ${name === 'i' ? 'iOS' : 'Android'}...`,
|
|
84
|
+
);
|
|
85
|
+
const params =
|
|
86
|
+
name === 'i'
|
|
87
|
+
? ctx.project.ios?.watchModeCommandParams
|
|
88
|
+
: ctx.project.android?.watchModeCommandParams;
|
|
89
|
+
execa('npx', [
|
|
90
|
+
'react-native',
|
|
91
|
+
name === 'i' ? 'run-ios' : 'run-android',
|
|
92
|
+
...(params ?? []),
|
|
93
|
+
]).stdout?.pipe(process.stdout);
|
|
94
|
+
} else {
|
|
95
|
+
console.log(_key);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default enableWatchMode;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "bundleCommand", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _bundle.default;
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ramBundleCommand", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _ramBundle.default;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "startCommand", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _start.default;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "unstable_buildBundleWithConfig", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _buildBundle.unstable_buildBundleWithConfig;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
var _bundle = _interopRequireDefault(require("./commands/bundle/bundle"));
|
|
31
|
+
var _ramBundle = _interopRequireDefault(require("./commands/bundle/ramBundle"));
|
|
32
|
+
var _start = _interopRequireDefault(require("./commands/start"));
|
|
33
|
+
var _buildBundle = require("./commands/bundle/buildBundle");
|
|
34
|
+
function _interopRequireDefault(obj) {
|
|
35
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export {default as bundleCommand} from './commands/bundle/bundle';
|
|
13
|
+
export {default as ramBundleCommand} from './commands/bundle/ramBundle';
|
|
14
|
+
export {default as startCommand} from './commands/start';
|
|
15
|
+
|
|
16
|
+
export {unstable_buildBundleWithConfig} from './commands/bundle/buildBundle';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/*::
|
|
13
|
+
export type * from './index.flow';
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
if (!process.env.BUILD_EXCLUDE_BABEL_REGISTER) {
|
|
17
|
+
require('../../../scripts/build/babel-register').registerForMonorepo();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = require('./index.flow');
|