mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
16 lines
3.8 KiB
Markdown
16 lines
3.8 KiB
Markdown
---
|
|
id: version-0.50-understanding-cli
|
|
title: understanding-cli
|
|
original_id: understanding-cli
|
|
---
|
|
<a id="content"></a><h1><a class="anchor" name="understanding-the-cli"></a>Understanding the CLI <a class="hash-link" href="docs/understanding-cli.html#understanding-the-cli">#</a></h1><div class="banner-crna-ejected"><h3>Project with Native Code Required</h3><p>This page only applies to projects made with <code>react-native init</code> or to those made with Create React Native App which have since ejected. For more information about ejecting, please see the <a href="https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md" target="_blank">guide</a> on the Create React Native App repository.</p></div><div><p>Though you may have installed the <code>react-native-cli</code> via npm as a separate module, it is a shell for accessing the CLI embedded
|
|
in the React Native of each project. Your commands and their effects are dependent on the version of the module of <code>react-native</code>
|
|
in context of the project. This guide will give a brief overview of the CLI in the module.</p><h1><a class="anchor" name="the-local-cli"></a>The local CLI <a class="hash-link" href="docs/understanding-cli.html#the-local-cli">#</a></h1><p>React Native has a <a href="https://github.com/facebook/react-native/tree/master/local-cli" target="_blank"><code>local-cli</code></a> folder with a file named
|
|
<a href="https://github.com/facebook/react-native/blob/master/local-cli/cliEntry.js" target="_blank"><code>cliEntry.js</code></a>. Here, the commands are read
|
|
from <code>commands.js</code> and added as possible CLI commands. <em>E.G.</em> the <code>react-native link</code> command, exists in the
|
|
<a href="https://github.com/facebook/react-native/blob/master/local-cli/link/" target="_blank"><code>react-native/local-cli/link</code></a> folder, and is
|
|
required in <code>commands.js</code>, which will register it as a documented command to be exposed to the CLI.</p><h1><a class="anchor" name="command-definitions"></a>Command definitions <a class="hash-link" href="docs/understanding-cli.html#command-definitions">#</a></h1><p>At the end of each command entry is an export. The export is an object with a function to perform, description of the command, and the command name. The object structure for the <code>link</code> command looks like so:</p><div class="prism language-js">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
|
|
func<span class="token punctuation">:</span> link<span class="token punctuation">,</span>
|
|
description<span class="token punctuation">:</span> <span class="token string">'links all native dependencies'</span><span class="token punctuation">,</span>
|
|
name<span class="token punctuation">:</span> <span class="token string">'link [packageName]'</span><span class="token punctuation">,</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">;</span></div><h3><a class="anchor" name="parameters"></a>Parameters <a class="hash-link" href="docs/understanding-cli.html#parameters">#</a></h3><p>The command name identifies the parameters that a command would expect. When the command parameter is surrounded by greater-than, less-than symbols <code>< ></code>, this indicates that the parameter is expected. When a parameter is surrounded by brackets <code>[ ]</code>, this indicates that the parameter is optional.</p></div><div class="docs-prevnext"><a class="docs-prev btn" href="docs/testing.html#content">← Previous</a><a class="docs-next btn" href="docs/activityindicator.html#content">Continue Reading →</a></div><p class="edit-page-block"><a target="_blank" href="https://github.com/facebook/react-native/blob/master/docs/UnderstandingCLI.md">Improve this page</a> by sending a pull request!</p> |