From 98c1ce95d4f33e0c2a8cb9f6a32234e7c270280b Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Thu, 18 Apr 2019 16:59:49 +0200 Subject: [PATCH] Support functions in default --- packages/cli/src/cliEntry.js | 2 +- packages/cli/src/tools/config/schema.js | 4 +++- packages/platform-android/src/commands/runAndroid/index.js | 2 +- packages/platform-ios/src/commands/runIOS/index.js | 2 +- types/index.js | 6 +++++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/cliEntry.js b/packages/cli/src/cliEntry.js index 3d5a9ea0e..ad3eae7d5 100644 --- a/packages/cli/src/cliEntry.js +++ b/packages/cli/src/cliEntry.js @@ -125,7 +125,7 @@ const addCommand = (command: CommandT, ctx: ConfigT) => { opt.command, opt.description, opt.parse || defaultOptParser, - opt.default, + typeof opt.default === 'function' ? opt.default(ctx) : opt.default, ), ); }; diff --git a/packages/cli/src/tools/config/schema.js b/packages/cli/src/tools/config/schema.js index 094c4e335..c55015d17 100644 --- a/packages/cli/src/tools/config/schema.js +++ b/packages/cli/src/tools/config/schema.js @@ -22,7 +22,9 @@ const command = t.object({ command: t.string().required(), description: t.string(), parse: t.func(), - default: t.alternatives().try([t.bool(), t.number(), t.string()]), + default: t + .alternatives() + .try([t.bool(), t.number(), t.string(), t.func()]), }), ), examples: t.array().items( diff --git a/packages/platform-android/src/commands/runAndroid/index.js b/packages/platform-android/src/commands/runAndroid/index.js index e3e37b5ad..f1553c51d 100644 --- a/packages/platform-android/src/commands/runAndroid/index.js +++ b/packages/platform-android/src/commands/runAndroid/index.js @@ -362,7 +362,7 @@ export default { command: '--terminal [string]', description: 'Launches the Metro Bundler in a new window using the specified terminal path.', - default: getDefaultUserTerminal(), + default: getDefaultUserTerminal, }, ], }; diff --git a/packages/platform-ios/src/commands/runIOS/index.js b/packages/platform-ios/src/commands/runIOS/index.js index 777090cd3..5786c204c 100644 --- a/packages/platform-ios/src/commands/runIOS/index.js +++ b/packages/platform-ios/src/commands/runIOS/index.js @@ -452,7 +452,7 @@ export default { command: '--terminal [string]', description: 'Launches the Metro Bundler in a new window using the specified terminal path.', - default: getDefaultUserTerminal(), + default: getDefaultUserTerminal, }, ], }; diff --git a/types/index.js b/types/index.js index d90cb35f6..feef6bcd2 100644 --- a/types/index.js +++ b/types/index.js @@ -10,7 +10,11 @@ export type CommandT = { command: string, description?: string, parse?: (val: string) => any, - default?: string | boolean | number, + default?: + | string + | boolean + | number + | ((ctx: ConfigT) => string | boolean | number), }>, examples?: Array<{ desc: string,