Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion __e2e__/legacyInit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ afterEach(() => {
test('legacy init through react-native-cli', () => {
const templateFiles = [
'.buckconfig',
'.eslintrc.js',
'.flowconfig',
'.gitattributes',
'.gitignore',
Expand Down Expand Up @@ -64,7 +65,7 @@ test('legacy init through react-native-cli', () => {
name: 'TestApp',
private: true,
scripts: {
start: 'node node_modules/react-native/local-cli/cli.js start',
start: 'react-native start',
test: 'jest',
},
});
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,16 @@ async function setupAndRun() {
}
}

// when we run `config`, we don't want to output anything to the console. We
// expect it to return valid JSON
if (process.argv.includes('config')) {
logger.disable();
}

const ctx = loadConfig();

logger.enable();

setProjectDir(ctx.root);

[...commands, ...ctx.commands].forEach(command => addCommand(command, ctx));
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-android/native_modules.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class ReactNativeModules {

def cmdProcess
def root = getReactNativeProjectRoot()
def command = "node ./node_modules/.bin/react-native config"
def command = "./node_modules/.bin/react-native config"

try {
cmdProcess = Runtime.getRuntime().exec(command, null, root)
Expand Down
13 changes: 3 additions & 10 deletions packages/platform-ios/native_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#
def use_native_modules!(root = "..", packages = nil)
if (!packages)
command = "node"
args = ["./node_modules/.bin/react-native", "config"]
command = "./node_modules/.bin/react-native"
args = ["config"]
output = ""
# Make sure `react-native config` is ran from your project root
Dir.chdir(root) do
Expand All @@ -15,14 +15,7 @@ def use_native_modules!(root = "..", packages = nil)

json = []
output.each_line do |line|
case line
when /^warn\s(.+)/
Pod::UI.warn($1)
when /^(success|info|error|debug)\s(.+)/
Pod::UI.message($1)
else
json << line
end
json << line
end
config = JSON.parse(json.join("\n"))
packages = config["dependencies"]
Expand Down
33 changes: 27 additions & 6 deletions packages/tools/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,45 @@ import chalk from 'chalk';
const SEPARATOR = ', ';

let verbose = false;
let disabled = false;

const formatMessages = (messages: Array<string>) =>
chalk.reset(messages.join(SEPARATOR));

const success = (...messages: Array<string>) => {
console.log(`${chalk.green.bold('success')} ${formatMessages(messages)}`);
if (!disabled) {
console.log(`${chalk.green.bold('success')} ${formatMessages(messages)}`);
}
};

const info = (...messages: Array<string>) => {
console.log(`${chalk.cyan.bold('info')} ${formatMessages(messages)}`);
if (!disabled) {
console.log(`${chalk.cyan.bold('info')} ${formatMessages(messages)}`);
}
};

const warn = (...messages: Array<string>) => {
console.warn(`${chalk.yellow.bold('warn')} ${formatMessages(messages)}`);
if (!disabled) {
console.warn(`${chalk.yellow.bold('warn')} ${formatMessages(messages)}`);
}
};

const error = (...messages: Array<string>) => {
console.error(`${chalk.red.bold('error')} ${formatMessages(messages)}`);
if (!disabled) {
console.error(`${chalk.red.bold('error')} ${formatMessages(messages)}`);
}
};

const debug = (...messages: Array<string>) => {
if (verbose) {
if (verbose && !disabled) {
console.log(`${chalk.gray.bold('debug')} ${formatMessages(messages)}`);
}
};

const log = (...messages: Array<string>) => {
console.log(`${formatMessages(messages)}`);
if (!disabled) {
console.log(`${formatMessages(messages)}`);
}
};

const setVerbose = (level: boolean) => {
Expand All @@ -39,6 +50,14 @@ const setVerbose = (level: boolean) => {

const isVerbose = () => verbose;

const disable = () => {
disabled = true;
};

const enable = () => {
disabled = false;
};

export default {
success,
info,
Expand All @@ -48,4 +67,6 @@ export default {
log,
setVerbose,
isVerbose,
disable,
enable,
};