Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into tools-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Esemesek committed Apr 10, 2019
2 parents 998bb75 + 6343e2a commit c6f31ee
Show file tree
Hide file tree
Showing 63 changed files with 1,508 additions and 1,258 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ flow-typed
[options]
emoji=true

esproposal.export_star_as=enable
esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
Expand Down
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// added for Jest inline snapshots to not use default Prettier config
module.exports = {
bracketSpacing: false,
trailingComma: "all"
}
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "3.10.6",
"version": "2.0.0-alpha.3",
"version": "2.0.0-alpha.5",
"npmClient": "yarn",
"useWorkspaces": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
"chalk": "^2.4.2",
"eslint": "^5.10.0",
"execa": "^1.0.0",
"flow-bin": "^0.95.1",
"flow-bin": "^0.96.0",
"flow-typed": "^2.5.1",
"glob": "^7.1.3",
"jest": "^24.6.0",
"lerna": "^3.13.1",
"metro-memory-fs": "^0.53.1",
"micromatch": "^3.1.10",
"mkdirp": "^0.5.1",
"string-length": "^2.0.0"
Expand Down
17 changes: 5 additions & 12 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-community/cli",
"version": "2.0.0-alpha.3",
"version": "2.0.0-alpha.5",
"description": "React Native CLI",
"license": "MIT",
"main": "build/index.js",
Expand All @@ -19,19 +19,17 @@
"testEnvironment": "node"
},
"dependencies": {
"@react-native-community/cli-platform-ios": "2.0.0-alpha.3",
"@react-native-community/cli-platform-android": "2.0.0-alpha.3",
"@react-native-community/cli-tools": "2.0.0-alpha.3",
"@react-native-community/cli-platform-android": "^2.0.0-alpha.5",
"@react-native-community/cli-platform-ios": "^2.0.0-alpha.5",
"@react-native-community/cli-tools": "^2.0.0-alpha.5",
"chalk": "^1.1.1",
"commander": "^2.19.0",
"compression": "^1.7.1",
"connect": "^3.6.5",
"cosmiconfig": "^5.1.0",
"deepmerge": "^3.2.0",
"denodeify": "^1.2.1",
"envinfo": "^7.1.0",
"errorhandler": "^1.5.0",
"escape-string-regexp": "^1.0.5",
"execa": "^1.0.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.1",
Expand All @@ -42,9 +40,7 @@
"metro": "^0.53.1",
"metro-config": "^0.53.1",
"metro-core": "^0.53.1",
"metro-memory-fs": "^0.53.1",
"metro-react-native-babel-transformer": "^0.53.1",
"mime": "^1.3.4",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"morgan": "^1.9.0",
Expand All @@ -56,10 +52,7 @@
"semver": "^5.0.3",
"serve-static": "^1.13.1",
"shell-quote": "1.6.1",
"slash": "^2.0.0",
"ws": "^1.1.0",
"xcode": "^2.0.0",
"xmldoc": "^0.4.0"
"ws": "^1.1.0"
},
"peerDependencies": {
"react-native": "^0.60.0"
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import childProcess from 'child_process';
import commander from 'commander';
import path from 'path';

import type {CommandT, ContextT} from './tools/types.flow';
import type {CommandT, ConfigT} from './tools/config/types.flow';

import {getCommands} from './commands';
import commands from './commands';
import init from './commands/init/initCompat';
import assertRequiredOptions from './tools/assertRequiredOptions';
import {logger} from '@react-native-community/cli-tools';
Expand Down Expand Up @@ -95,7 +95,7 @@ function printUnknownCommand(cmdName) {
}
}

const addCommand = (command: CommandT, ctx: ContextT) => {
const addCommand = (command: CommandT, ctx: ConfigT) => {
const options = command.options || [];

const cmd = commander
Expand Down Expand Up @@ -162,9 +162,7 @@ async function setupAndRun() {

setProjectDir(ctx.root);

const commands = getCommands(ctx);

commands.forEach(command => addCommand(command, ctx));
[...commands, ...ctx.commands].forEach(command => addCommand(command, ctx));

commander.parse(process.argv);

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import outputBundle from 'metro/src/shared/output/bundle';
import path from 'path';
import chalk from 'chalk';
import type {CommandLineArgs} from './bundleCommandLineArgs';
import type {ContextT} from '../../tools/types.flow';
import type {ConfigT} from '../../tools/config/types.flow';
import saveAssets from './saveAssets';
import loadMetroConfig from '../../tools/loadMetroConfig';
import {logger} from '@react-native-community/cli-tools';

async function buildBundle(
args: CommandLineArgs,
ctx: ContextT,
ctx: ConfigT,
output: typeof outputBundle = outputBundle,
) {
const config = await loadMetroConfig(ctx, {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/config/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @flow
*/
import {type ContextT} from '../../tools/types.flow';
import {type ConfigT} from '../../tools/config/types.flow';
export default {
name: 'config',
description: 'Print CLI configuration',
func: async (argv: string[], ctx: ContextT) => {
func: async (argv: string[], ctx: ConfigT) => {
console.log(JSON.stringify(ctx, null, 2));
},
};
78 changes: 3 additions & 75 deletions packages/cli/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
/**
* @flow
*/
import {type CommandT} from '../tools/config/types.flow';

import path from 'path';
import type {
CommandT,
ProjectCommandT,
LocalCommandT,
} from '../tools/types.flow';

import {type ContextT} from '../tools/types.flow';
import server from './server/server';
import runIOS from './runIOS/runIOS';
import runAndroid from './runAndroid/runAndroid';
import library from './library/library';
import bundle from './bundle/bundle';
import ramBundle from './bundle/ramBundle';
Expand All @@ -21,20 +12,12 @@ import unlink from './link/unlink';
import install from './install/install';
import uninstall from './install/uninstall';
import upgrade from './upgrade/upgrade';
import logAndroid from './logAndroid/logAndroid';
import logIOS from './logIOS/logIOS';
import info from './info/info';
import config from './config/config';
import init from './init';

/**
* List of built-in commands
*/

const loadLocalCommands: Array<LocalCommandT> = [
export default ([
server,
runIOS,
runAndroid,
library,
bundle,
ramBundle,
Expand All @@ -43,62 +26,7 @@ const loadLocalCommands: Array<LocalCommandT> = [
install,
uninstall,
upgrade,
logAndroid,
logIOS,
info,
config,
init,
];

/**
* Returns an array of commands that are defined in the project.
*
* This checks all CLI plugins for presence of 3rd party packages that define commands
* and loads them
*/
const loadProjectCommands = ({
root,
commands,
}: ContextT): Array<ProjectCommandT> => {
return commands.reduce((acc: Array<ProjectCommandT>, cmdPath: string) => {
/**
* `pathToCommand` is a path to a file where commands are defined, relative to `node_modules`
* folder.
*
* Following code gets the name of the package name out of the path, taking scope
* into consideration.
*/
const name =
cmdPath[0] === '@'
? cmdPath
.split(path.sep)
.slice(0, 2)
.join(path.sep)
: cmdPath.split(path.sep)[0];

const pkg = require(path.join(root, 'node_modules', name, 'package.json'));

const requiredCommands:
| ProjectCommandT
| Array<ProjectCommandT> = require(path.join(
root,
'node_modules',
cmdPath,
));

if (Array.isArray(requiredCommands)) {
return acc.concat(
requiredCommands.map(requiredCommand => ({...requiredCommand, pkg})),
);
}

return acc.concat({...requiredCommands, pkg});
}, []);
};

/**
* Loads all the commands inside a given `root` folder
*/
export function getCommands(ctx: ContextT): Array<CommandT> {
return [...loadLocalCommands, ...loadProjectCommands(ctx)];
}
]: CommandT[]);
4 changes: 2 additions & 2 deletions packages/cli/src/commands/info/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

import envinfo from 'envinfo';
import {logger} from '@react-native-community/cli-tools';
import type {ContextT} from '../../tools/types.flow';
import type {ConfigT} from '../../tools/config/types.flow';

const info = async function getInfo(
argv: Array<string>,
ctx: ContextT,
ctx: ConfigT,
options: {},
) {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'fs-extra';
import minimist from 'minimist';
import semver from 'semver';
import type {ContextT} from '../../tools/types.flow';
import type {ConfigT} from '../../tools/config/types.flow';
import {validateProjectName} from './validate';
import DirectoryAlreadyExistsError from './errors/DirectoryAlreadyExistsError';
import printRunInstructions from './printRunInstructions';
Expand Down Expand Up @@ -153,7 +153,7 @@ function createProject(projectName: string, options: Options, version: string) {

export default (async function initialize(
[projectName]: Array<string>,
_context: ContextT,
_context: ConfigT,
options: Options,
) {
validateProjectName(projectName);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/install/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* @flow
*/

import type {ContextT} from '../../tools/types.flow';
import type {ConfigT} from '../../tools/config/types.flow';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import link from '../link/link';
import loadConfig from '../../tools/config';

async function install(args: Array<string>, ctx: ContextT) {
async function install(args: Array<string>, ctx: ConfigT) {
const name = args[0];

logger.info(`Installing "${name}"...`);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/install/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* @flow
*/

import type {ContextT} from '../../tools/types.flow';
import type {ConfigT} from '../../tools/config/types.flow';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import link from '../link/unlink';

async function uninstall(args: Array<string>, ctx: ContextT) {
async function uninstall(args: Array<string>, ctx: ConfigT) {
const name = args[0];

logger.info(`Unlinking "${name}"...`);
Expand Down
11 changes: 4 additions & 7 deletions packages/cli/src/commands/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
*/

import {pick} from 'lodash';
import dedent from 'dedent';

import {type ContextT} from '../../tools/types.flow';

import {CLIError} from '../../tools/errors';
import {type ConfigT} from '../../tools/config/types.flow';

import promiseWaterfall from './promiseWaterfall';
import {logger} from '@react-native-community/cli-tools';
import {logger, CLIError} from '@react-native-community/cli-tools';
import commandStub from './commandStub';
import promisify from './promisify';
import getPlatformName from './getPlatformName';
Expand All @@ -34,7 +31,7 @@ type FlagsType = {
* @param args If optional argument [packageName] is provided,
* only that package is processed.
*/
function link([rawPackageName]: Array<string>, ctx: ContextT, opts: FlagsType) {
function link([rawPackageName]: Array<string>, ctx: ConfigT, opts: FlagsType) {
let platforms = ctx.platforms;
let project = ctx.project;

Expand All @@ -61,7 +58,7 @@ function link([rawPackageName]: Array<string>, ctx: ContextT, opts: FlagsType) {
const packageName = rawPackageName.replace(/^(.+?)(@.+?)$/gi, '$1');

if (!Object.keys(ctx.dependencies).includes(packageName)) {
throw new CLIError(dedent`
throw new CLIError(`
Unknown dependency. Make sure that the package you are trying to link is
already installed in your "node_modules" and present in your "package.json" dependencies.
`);
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/link/linkAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import {uniqBy, flatMap} from 'lodash';
import path from 'path';

import type {ConfigT, PlatformsT} from '../../tools/config/types.flow';
import {CLIError} from '../../tools/errors';
import type {ConfigT} from '../../tools/config/types.flow';

import promiseWaterfall from './promiseWaterfall';
import commandStub from './commandStub';
Expand All @@ -15,6 +14,8 @@ import promisify from './promisify';
import linkAssets from './linkAssets';
import linkDependency from './linkDependency';

import {CLIError} from '@react-native-community/cli-tools';

const dedupeAssets = (assets: Array<string>): Array<string> =>
uniqBy(assets, asset => path.basename(asset));

Expand Down
Loading

0 comments on commit c6f31ee

Please sign in to comment.