Skip to content

Commit

Permalink
fix program options to support both hyphenated and camelCase values
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaDiachenko committed Jun 20, 2024
1 parent f660719 commit 54d1689
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 56 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/tasks/creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ type TaskOptionsMap<OKey> = Record<Extract<OKey, string>, RnvTaskOption<OKey>>;
export const createTaskOptionsMap = <OKey>(opts: ReadonlyArray<RnvTaskOption<OKey>>) => {
const map: Partial<TaskOptionsMap<OKey>> = {};
opts.forEach((opt) => {
map[opt.key] = opt;
if (opt.altKey) {
map[opt.altKey] = opt;
} else {
map[opt.key] = opt;
}
});
return map as TaskOptionsMap<OKey>;
};
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/tasks/taskHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export const generateStringFromTaskOption = (opt: RnvTaskOption) => {
cmd += `-${opt.shortcut}, `;
}
cmd += `--${opt.key}`;
if (opt.altKey) {
cmd += `, --${opt.altKey}`;
}
if (opt.isVariadic) {
if (opt.isRequired) {
cmd += ` <value...>`;
Expand Down
60 changes: 30 additions & 30 deletions packages/core/src/tasks/taskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const RnvTaskOptions = createTaskOptionsMap([
description: 'Show full debug Info',
},
{
key: 'printExec',
// altKey: 'printExec',
key: 'print-exec',
altKey: 'printExec',
description: 'Print exec commands in full',
},
{
Expand All @@ -25,8 +25,8 @@ export const RnvTaskOptions = createTaskOptionsMap([
description: 'select specific Platform',
},
{
key: 'skipTasks',
// key: 'skip-tasks',
key: 'skip-tasks',
altKey: 'skipTasks',
isValueType: true,
isRequired: true,
description: 'List tasks which you want to skip during rnv execution',
Expand All @@ -46,8 +46,8 @@ export const RnvTaskOptions = createTaskOptionsMap([
description: 'Monochrome console output without chalk',
},
{
key: 'maxErrorLength',
// key: 'max-error-length',
key: 'max-error-length',
altKey: 'maxErrorLength',
isValueType: true,
isRequired: true,
description: 'Specify how many characters each error should display. Default 200',
Expand All @@ -61,52 +61,52 @@ export const RnvTaskOptions = createTaskOptionsMap([
description: 'Default all prompts to yes',
},
{
key: 'telemetryDebug',
// key: 'telemetry-debug',
key: 'telemetry-debug',
altKey: 'telemetryDebug',
description: 'If you have telemetry enabled, will print out exactly what is being collected into the console',
},
// OTHERS 1st --------------------------------
// Still present in core
{
key: 'packageManager',
// key: 'package-manager',
key: 'package-manager',
altKey: 'packageManager',
isValueType: true,
isRequired: true,
// options: ['yarn', 'npm'],
description: 'Set specific package manager to use',
examples: ['--packageManager yarn', '--packageManager npm'],
},
{
key: 'npxMode',
// key: 'npx-mode',
key: 'npx-mode',
altKey: 'npxMode',
description: 'Ensures you can use local npx rnv version after the command is done',
},
{
key: 'unlinked',
description: 'Force engines to be loaded from node_modules rather than locally',
},
{
key: 'configName',
// key: 'config-name',
key: 'config-name',
altKey: 'configName',
isValueType: true,
isRequired: true,
description: 'Use custom name for ./renative.json. (applies only at root level)',
},
{
key: 'skipDependencyCheck',
// key: 'skip-dependency-check',
key: 'skip-dependency-check',
altKey: 'skipDependencyCheck',
description: 'Skips auto update of npm dependencies if mismatch found',
},
{
key: 'appConfigID',
// key: 'app-config-id',
key: 'app-config-id',
altKey: 'appConfigID',
shortcut: 'c',
isValueType: true,
description: 'select specific app Config id',
},
{
key: 'skipRnvCheck',
// key: 'skip-rnv-check',
key: 'skip-rnv-check',
altKey: 'skipRnvCheck',
description: 'Skips auto update of rnv dependencies if mismatch found',
},
{
Expand All @@ -123,8 +123,8 @@ export const RnvTaskOptions = createTaskOptionsMap([
description: 'engine to be used ie "engine-rn"',
},
{
key: 'exeMethod',
// key: 'exe-method',
key: 'exe-method',
altKey: 'exeMethod',
shortcut: 'x',
isValueType: true,
description: 'eXecutable method in buildHooks',
Expand All @@ -135,14 +135,14 @@ export const RnvTaskOptions = createTaskOptionsMap([
description: 'also perform reset of platform build',
},
{
key: 'resetHard',
// key: 'reset-hard',
key: 'reset-hard',
altKey: 'resetHard',
shortcut: 'R',
description: 'also perform reset of platform platform and platform assets',
},
{
key: 'resetAssets',
// key: 'reset-assets',
key: 'reset-assets',
altKey: 'resetAssets',
shortcut: 'a',
description: 'also perform reset of platform assets',
},
Expand All @@ -153,8 +153,8 @@ export const RnvTaskOptions = createTaskOptionsMap([
// OTHERS 2nd --------------------------------
// Still present in core but ONLY in runtime defaults
{
// key: 'host-ip',
key: 'hostIp',
key: 'host-ip',
altKey: 'hostIp',
isValueType: true,
isRequired: true,
description: 'Custom IP override',
Expand Down Expand Up @@ -191,8 +191,8 @@ export const RnvTaskOptions = createTaskOptionsMap([
},
// SDK-WEBPACK --------------------------------
{
// key: 'debug-ip',
key: 'debugIp',
key: 'debug-ip',
altKey: 'debugIp',
isValueType: true,
isRequired: true,
description: '(optional) overwrite the ip to which the remote debugger will connect',
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tasks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type TaskPromptOption = {
export type RnvTaskOption<OKey = string> = {
shortcut?: string;
key: OKey extends string ? OKey : never;
altKey?: OKey extends string ? OKey : never;
isRequired?: boolean;
isValueType?: boolean;
isVariadic?: boolean;
Expand Down
15 changes: 10 additions & 5 deletions packages/engine-core/src/taskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const TaskOptions = createTaskOptionsMap([
description: 'Pass the key/password',
},
{
key: 'gitEnabled',
key: 'git-enabled',
altKey: 'gitEnabled',
description: 'Enable git in your newly created project',
isValueType: true,
},
Expand All @@ -33,17 +34,20 @@ export const TaskOptions = createTaskOptionsMap([
description: 'select specific template',
},
{
key: 'projectName',
key: 'project-name',
altKey: 'projectName',
isValueType: true,
description: 'select the name of the new project',
},
{
key: 'projectTemplate',
key: 'project-template',
altKey: 'projectTemplate',
isValueType: true,
description: 'select the template of new project',
},
{
key: 'templateVersion',
key: 'template-version',
altKey: 'templateVersion',
isValueType: true,
description: 'select the template version',
},
Expand All @@ -53,7 +57,8 @@ export const TaskOptions = createTaskOptionsMap([
description: 'select the title of the app',
},
{
key: 'appVersion',
key: 'app-version',
altKey: 'appVersion',
isValueType: true,
description: 'select the version of the app',
},
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk-android/src/taskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { createTaskOptionsMap } from '@rnv/core';

export const TaskOptions = createTaskOptionsMap([
{
// key: 'skip-target-check',
key: 'skipTargetCheck',
key: 'skip-target-check',
altKey: 'skipTargetCheck',
description: 'Skip Android target check, just display the raw adb devices to choose from',
},
{
Expand All @@ -14,8 +14,8 @@ export const TaskOptions = createTaskOptionsMap([
description: 'Filter value',
},
{
// key: 'reset-adb',
key: 'resetAdb',
key: 'reset-adb',
altKey: 'resetAdb',
description: 'Forces to reset android adb',
},
]);
32 changes: 16 additions & 16 deletions packages/sdk-apple/src/taskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { createTaskOptionsMap, createTaskOptionsPreset } from '@rnv/core';

export const TaskOptions = createTaskOptionsMap([
{
key: 'updatePods',
// key: 'update-pods',
key: 'update-pods',
altKey: 'updatePods',
shortcut: 'u',
description: 'Force update dependencies (iOS only)',
},
Expand All @@ -14,50 +14,50 @@ export const TaskOptions = createTaskOptionsMap([
description: 'Name of the keychain',
},
{
key: 'provisioningStyle',
// key: 'provisioning-style',
key: 'provisioning-style',
altKey: 'provisioningStyle',
isValueType: true,
isRequired: true,
description: 'Set provisioningStyle (Automatic | Manual)',
},
{
key: 'codeSignIdentity',
// key: 'code-sign-identity',
key: 'code-sign-identity',
altKey: 'codeSignIdentity',
isValueType: true,
isRequired: true,
description: 'Set codeSignIdentity (ie iPhone Distribution)',
},
{
key: 'provisionProfileSpecifier',
// key: 'provision-profile-specifier',
key: 'provision-profile-specifier',
altKey: 'provisionProfileSpecifier',
isValueType: true,
isRequired: true,
description: 'Name of provisionProfile',
},
{
key: 'xcodebuildArgs',
// key: 'xcodebuild-args',
key: 'xcodebuild-args',
altKey: 'xcodebuildArgs',
isValueType: true,
isRequired: true,
description: 'pass down custom xcodebuild arguments',
},
{
key: 'xcodebuildArchiveArgs',
// key: 'xcodebuild-archive-args',
key: 'xcodebuild-archive-args',
altKey: 'xcodebuildArchiveArgs',
isValueType: true,
isRequired: true,
description: 'pass down custom xcodebuild arguments',
},
{
key: 'xcodebuildExportArgs',
// key: 'xcodebuild-export-args',
key: 'xcodebuild-export-args',
altKey: 'xcodebuildExportArgs',
isValueType: true,
isRequired: true,
description: 'pass down custom xcodebuild arguments',
},
{
// key: 'skip-target-check',
key: 'skipTargetCheck',
key: 'skip-target-check',
altKey: 'skipTargetCheck',
description: 'Skip ios target check, just display the raw sims to choose from',
},
{
Expand Down

0 comments on commit 54d1689

Please sign in to comment.