Skip to content

Commit

Permalink
feat: use common logger part 1
Browse files Browse the repository at this point in the history
Introduce logger to bundle core and eject
  • Loading branch information
Esemesek authored and thymikee committed Jan 23, 2019
1 parent 802e4ec commit 7ca57a5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 47 deletions.
5 changes: 2 additions & 3 deletions packages/cli/src/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const Server = require('metro/src/Server');

const outputBundle = require('metro/src/shared/output/bundle');
const path = require('path');
const log = require('./log').out('bundle');
const saveAssets = require('./saveAssets');

const loadMetroConfig = require('../util/loadMetroConfig');
const logger = require('../util/logger');

async function buildBundle(
args: CommandLineArgs,
Expand Down Expand Up @@ -51,7 +50,7 @@ async function buildBundle(
try {
const bundle = await output.build(server, requestOpts);

await output.save(bundle, args, log);
await output.save(bundle, args, logger.info);

// Save the assets of the bundle
const outputAssets = await server.getAssets({
Expand Down
5 changes: 0 additions & 5 deletions packages/cli/src/bundle/bundleCommandLineArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ module.exports = [
description:
'Directory name where to store assets referenced in the bundle',
},
{
command: '--verbose',
description: 'Enables logging',
default: false,
},
{
command: '--reset-cache',
description: 'Removes cached files',
Expand Down
28 changes: 0 additions & 28 deletions packages/cli/src/bundle/log.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/cli/src/bundle/saveAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const fs = require('fs');
const filterPlatformAssetScales = require('./filterPlatformAssetScales');
const getAssetDestPathAndroid = require('./getAssetDestPathAndroid');
const getAssetDestPathIOS = require('./getAssetDestPathIOS');
const log = require('./log').out('bundle');
const logger = require('../util/logger');

function saveAssets(assets, platform, assetsDest) {
if (!assetsDest) {
console.warn('Assets destination folder is not set, skipping...');
logger.warn('Assets destination folder is not set, skipping...');
return Promise.resolve();
}

Expand Down Expand Up @@ -49,15 +49,15 @@ function copyAll(filesToCopy) {
return Promise.resolve();
}

log(`Copying ${queue.length} asset files`);
logger.info(`Copying ${queue.length} asset files`);
return new Promise((resolve, reject) => {
const copyNext = error => {
if (error) {
reject(error);
return;
}
if (queue.length === 0) {
log('Done copying assets');
logger.info('Done copying assets');
resolve();
} else {
const src = queue.shift();
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/core/getCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { CommandT, ProjectCommandT, LocalCommandT } from './types.flow';

const path = require('path');
const findPlugins = require('./findPlugins');
const logger = require('../util/logger');

/**
* List of built-in commands
Expand Down Expand Up @@ -84,7 +85,7 @@ module.exports = (root: string): Array<CommandT> => [
{
name: 'init',
func: () => {
console.log(
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',
Expand Down
13 changes: 7 additions & 6 deletions packages/cli/src/eject/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const path = require('path');
const fs = require('fs');
const copyProjectTemplateAndReplace = require('../generator/copyProjectTemplateAndReplace');
const logger = require('../util/logger');

/**
* The eject command re-creates the `android` and `ios` native folders. Because native code can be
Expand All @@ -26,7 +27,7 @@ function eject() {
const doesIOSExist = fs.existsSync(path.resolve('ios'));
const doesAndroidExist = fs.existsSync(path.resolve('android'));
if (doesIOSExist && doesAndroidExist) {
console.error(
logger.error(
'Both the iOS and Android folders already exist! Please delete `ios` and/or `android` ' +
'before ejecting.'
);
Expand All @@ -37,7 +38,7 @@ function eject() {
try {
appConfig = require(path.resolve('app.json'));
} catch (e) {
console.error(
logger.error(
'Eject requires an `app.json` config file to be located at ' +
`${path.resolve(
'app.json'
Expand All @@ -49,7 +50,7 @@ function eject() {

const appName = appConfig.name;
if (!appName) {
console.error(
logger.error(
'App `name` must be defined in the `app.json` config file to define the project name. ' +
'It must not contain any spaces or dashes.'
);
Expand All @@ -59,7 +60,7 @@ function eject() {
// eslint-disable-next-line prefer-destructuring
const displayName = appConfig.displayName;
if (!displayName) {
console.error(
logger.error(
'App `displayName` must be defined in the `app.json` config file, to define the label ' +
'of the app on the home screen.'
);
Expand All @@ -69,7 +70,7 @@ function eject() {
const templateOptions = { displayName };

if (!doesIOSExist) {
console.log('Generating the iOS folder.');
logger.info('Generating the iOS folder.');
copyProjectTemplateAndReplace(
path.resolve(
'node_modules',
Expand All @@ -87,7 +88,7 @@ function eject() {
}

if (!doesAndroidExist) {
console.log('Generating the Android folder.');
logger.info('Generating the Android folder.');
copyProjectTemplateAndReplace(
path.resolve(
'node_modules',
Expand Down

0 comments on commit 7ca57a5

Please sign in to comment.