Skip to content

Commit

Permalink
chore: simplify cli structure and common tools (#201)
Browse files Browse the repository at this point in the history
Summary:
---------

Cleaning up the `packages/cli` structure. This might be pretty disruptive to already open PRs :D.

- Renamed `core` -> `tools`
- Moved `util` to `tools`
- Flatten-out `server/util`
- Create `commands` dir and put all commands there

```
packages/cli/src
├── bin.js
├── cliEntry.js
├── commands
│   ├── bundle
│   ├── dependencies
│   ├── eject
│   ├── index.js
│   ├── info
│   ├── init
│   ├── install
│   ├── library
│   ├── link
│   ├── logAndroid
│   ├── logIOS
│   ├── runAndroid
│   ├── runIOS
│   ├── server
│   └── upgrade
├── index.js
└── tools
    ├── ...
``` 

Fixes #49

Test Plan:
----------

CI green
  • Loading branch information
thymikee authored and Esemesek committed Mar 5, 2019
1 parent 75c86c8 commit 8ef2a97
Show file tree
Hide file tree
Showing 260 changed files with 153 additions and 152 deletions.
13 changes: 0 additions & 13 deletions packages/cli/src/__mocks__/beeper.js

This file was deleted.

12 changes: 6 additions & 6 deletions packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import childProcess from 'child_process';
import commander from 'commander';
import minimist from 'minimist';
import path from 'path';
import type { CommandT, ContextT } from './core/types.flow';
import getCommands from './core/getCommands';
import getLegacyConfig from './core/getLegacyConfig';
import init from './init/init';
import assertRequiredOptions from './util/assertRequiredOptions';
import logger from './util/logger';
import type { CommandT, ContextT } from './tools/types.flow';
import getLegacyConfig from './tools/getLegacyConfig';
import { getCommands } from './commands';
import init from './commands/init/init';
import assertRequiredOptions from './tools/assertRequiredOptions';
import logger from './tools/logger';
import pkg from '../package.json';

commander
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import Server from 'metro/src/Server';
import outputBundle from 'metro/src/shared/output/bundle';
import path from 'path';
import type { CommandLineArgs } from './bundleCommandLineArgs';
import type { ContextT } from '../core/types.flow';
import type { ContextT } from '../../tools/types.flow';
import saveAssets from './saveAssets';
import loadMetroConfig from '../util/loadMetroConfig';
import logger from '../util/logger';
import loadMetroConfig from '../../tools/loadMetroConfig';
import logger from '../../tools/logger';

async function buildBundle(
args: CommandLineArgs,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import fs from 'fs';
import filterPlatformAssetScales from './filterPlatformAssetScales';
import getAssetDestPathAndroid from './getAssetDestPathAndroid';
import getAssetDestPathIOS from './getAssetDestPathIOS';
import logger from '../util/logger';
import logger from '../../tools/logger';

function saveAssets(assets, platform, assetsDest) {
if (!assetsDest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import path from 'path';
import fs from 'fs';
import copyProjectTemplateAndReplace from '../generator/copyProjectTemplateAndReplace';
import logger from '../util/logger';
import copyProjectTemplateAndReplace from '../../tools/generator/copyProjectTemplateAndReplace';
import logger from '../../tools/logger';

/**
* The eject command re-creates the `android` and `ios` native folders. Because native code can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@

import path from 'path';

import findPlugins from './findPlugins';
import logger from '../util/logger';
import findPlugins from '../tools/findPlugins';
import logger from '../tools/logger';

import type { CommandT, ProjectCommandT, LocalCommandT } from './types.flow';
import type {
CommandT,
ProjectCommandT,
LocalCommandT,
} 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';
import eject from '../eject/eject';
import link from '../link/link';
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 dependencies from '../dependencies/dependencies';
import info from '../info/info';
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';
import eject from './eject/eject';
import link from './link/link';
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 dependencies from './dependencies/dependencies';
import info from './info/info';

/**
* List of built-in commands
Expand Down Expand Up @@ -97,18 +101,20 @@ const loadProjectCommands = (root: string): Array<ProjectCommandT> => {
/**
* Loads all the commands inside a given `root` folder
*/
export default (root: string): Array<CommandT> => [
...loadLocalCommands,
{
name: 'init',
func: () => {
logger.warn(
[
'Looks like a React Native project already exists in the current',
'folder. Run this command from a different folder or remove node_modules/react-native',
].join('\n')
);
export function getCommands(root: string): Array<CommandT> {
return [
...loadLocalCommands,
{
name: 'init',
func: () => {
logger.warn(
[
'Looks like a React Native project already exists in the current',
'folder. Run this command from a different folder or remove node_modules/react-native',
].join('\n')
);
},
},
},
...loadProjectCommands(root),
];
...loadProjectCommands(root),
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import envinfo from 'envinfo';
import logger from '../util/logger';
import logger from '../../tools/logger';

const info = function getInfo(argv, ctx, options) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import fs from 'fs';
import minimist from 'minimist';
import path from 'path';
import process from 'process';
import printRunInstructions from '../generator/printRunInstructions';
import { createProjectFromTemplate } from '../generator/templates';
import PackageManager from '../util/PackageManager';
import logger from '../util/logger';
import printRunInstructions from '../../tools/generator/printRunInstructions';
import { createProjectFromTemplate } from '../../tools/generator/templates';
import PackageManager from '../../tools/PackageManager';
import logger from '../../tools/logger';

/**
* Creates the template for a React Native project given the provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @flow
*/

import type { ContextT } from '../core/types.flow';
import logger from '../util/logger';
import PackageManager from '../util/PackageManager';
import type { ContextT } from '../../tools/types.flow';
import logger from '../../tools/logger';
import PackageManager from '../../tools/PackageManager';
import link from '../link/link';

async function install(args: Array<string>, ctx: ContextT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @flow
*/

import type { ContextT } from '../core/types.flow';
import logger from '../util/logger';
import PackageManager from '../util/PackageManager';
import type { ContextT } from '../../tools/types.flow';
import logger from '../../tools/logger';
import PackageManager from '../../tools/PackageManager';
import link from '../link/unlink';

async function uninstall(args: Array<string>, ctx: ContextT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import fs from 'fs';
import path from 'path';
import copyAndReplace from '../util/copyAndReplace';
import isValidPackageName from '../util/isValidPackageName';
import walk from '../util/walk';
import logger from '../util/logger';
import copyAndReplace from '../../tools/copyAndReplace';
import isValidPackageName from '../../tools/isValidPackageName';
import walk from '../../tools/walk';
import logger from '../../tools/logger';

/**
* Creates a new native library with the given name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const platforms = {
},
};

jest.setMock('../../core/getPackageConfiguration', folder => {
jest.setMock('../../../tools/getPackageConfiguration', folder => {
if (folder === '/root/node_modules/abcd') {
throw new Error('Cannot require');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

jest.mock('chalk', () => ({ grey: str => str }));
jest.mock('../../util/logger');
jest.mock('../../../tools/logger');

const context = {
root: process.cwd(),
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('link', () => {
);
jest.doMock('../ios/registerNativeModule.js', () => jest.fn());

jest.doMock('../../core/getAssets', () => projectAssets);
jest.doMock('../../../tools/getAssets', () => projectAssets);

const copyAssets = jest.fn();

Expand All @@ -157,7 +157,7 @@ describe('link', () => {
link(['react-native-blur'], context, {}).then(() => {
expect(copyAssets.mock.calls).toHaveLength(2);
expect(copyAssets.mock.calls[0][0]).toEqual(dependencyAssets);
jest.unmock('../../core/getAssets');
jest.unmock('../../../tools/getAssets');
done();
});
});
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('link', () => {
commands: {},
}));

jest.doMock('../../core/getPlatforms', () => {
jest.doMock('../../../tools/getPlatforms', () => {
const fn = () => ({
ios: { linkConfig: require('../ios').default },
android: { linkConfig: require('../android').default },
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('link', () => {

it('should link only for specific platforms if --platforms is used', async () => {
jest.doMock('../getProjectDependencies', () => () => ['react-native-maps']);
jest.doMock('../../core/getPackageConfiguration', () => () => ({
jest.doMock('../../../tools/getPackageConfiguration', () => () => ({
assets: [],
}));

Expand All @@ -273,7 +273,7 @@ describe('link', () => {
register: registerIOSNativeModule,
});

jest.doMock('../../core/getPlatforms', () => {
jest.doMock('../../../tools/getPlatforms', () => {
const fn = () => ({
android: { linkConfig: genericAndroidLinkConfig },
ios: { linkConfig: genericIOSLinkConfig },
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import type {
PlatformsT,
ContextT,
DependenciesConfig,
} from '../core/types.flow';
} from '../../tools/types.flow';

import getPackageConfiguration from '../core/getPackageConfiguration';
import getParams from '../core/getParams';
import getHooks from '../core/getHooks';
import getAssets from '../core/getAssets';
import getPackageConfiguration from '../../tools/getPackageConfiguration';
import getParams from '../../tools/getParams';
import getHooks from '../../tools/getHooks';
import getAssets from '../../tools/getAssets';

export default function getDependencyConfig(
ctx: ContextT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
* @flow
*/

import type { PlatformsT, ContextT, ProjectConfigT } from '../core/types.flow';
import type {
PlatformsT,
ContextT,
ProjectConfigT,
} from '../../tools/types.flow';

import getPackageConfiguration from '../core/getPackageConfiguration';
import getPackageConfiguration from '../../tools/getPackageConfiguration';

export default function getProjectConfig(
ctx: ContextT,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @format
*/

import log from '../../util/logger';
import log from '../../../tools/logger';
import createGroup from './createGroup';
import getGroup from './getGroup';

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import fs from 'fs-extra';
import path from 'path';
import xcode from 'xcode';
import { difference } from 'lodash';
import log from '../../util/logger';
import log from '../../../tools/logger';

import groupFilesByType from '../groupFilesByType';
import getPlist from './getPlist';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
*/

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

import promiseWaterfall from './promiseWaterfall';
import logger from '../util/logger';
import logger from '../../tools/logger';
import getDependencyConfig from './getDependencyConfig';
import commandStub from './commandStub';
import promisify from './promisify';
import getProjectConfig from './getProjectConfig';
import linkDependency from './linkDependency';
import linkAssets from './linkAssets';
import linkAll from './linkAll';
import findReactNativeScripts from '../util/findReactNativeScripts';
import getPlatforms from '../core/getPlatforms';
import findReactNativeScripts from '../../tools/findReactNativeScripts';
import getPlatforms from '../../tools/getPlatforms';

type FlagsType = {
platforms?: Array<string>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import { uniqBy, flatten } from 'lodash';
import path from 'path';
import type { ContextT, PlatformsT, ProjectConfigT } from '../core/types.flow';
import logger from '../util/logger';
import getAssets from '../core/getAssets';
import type {
ContextT,
PlatformsT,
ProjectConfigT,
} from '../../tools/types.flow';
import logger from '../../tools/logger';
import getAssets from '../../tools/getAssets';
import getProjectDependencies from './getProjectDependencies';
import getDependencyConfig from './getDependencyConfig';
import promiseWaterfall from './promiseWaterfall';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow

import { isEmpty } from 'lodash';
import type { PlatformsT, ProjectConfigT } from '../core/types.flow';
import type { PlatformsT, ProjectConfigT } from '../../tools/types.flow';

import logger from '../util/logger';
import logger from '../../tools/logger';

const linkAssets = (
platforms: PlatformsT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type {
PlatformsT,
ProjectConfigT,
DependenciesConfig,
} from '../core/types.flow';
import logger from '../util/logger';
} from '../../tools/types.flow';
import logger from '../../tools/logger';
import pollParams from './pollParams';
import { getPlatformName } from '../core/getPlatforms';
import { getPlatformName } from '../../tools/getPlatforms';

const linkDependency = async (
platforms: PlatformsT,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8ef2a97

Please sign in to comment.