Skip to content

Commit

Permalink
feat(cli): add inline option to copy command (#5901)
Browse files Browse the repository at this point in the history
* feat(cli): add inline option to copy command

* chore: fix update default passed to copy

* chore: make inlines optional with false default
  • Loading branch information
IT-MikeS authored Sep 7, 2022
1 parent d84352d commit 17fbabb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
9 changes: 7 additions & 2 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,17 @@ export function runProgram(config: Config): void {
program
.command('copy [platform]')
.description('copies the web app build into the native app')
.option(
'--inline',
'Optional: if true, all source maps will be inlined for easier debugging on mobile devices',
false,
)
.action(
wrapAction(
telemetryAction(config, async platform => {
telemetryAction(config, async (platform, { inline }) => {
checkExternalConfig(config.app);
const { copyCommand } = await import('./tasks/copy');
await copyCommand(config, platform);
await copyCommand(config, platform, inline);
}),
),
);
Expand Down
9 changes: 8 additions & 1 deletion cli/src/tasks/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import { getPlugins } from '../plugin';
import { allSerial } from '../util/promise';
import { copyWeb } from '../web/copy';

import { inlineSourceMaps } from './sourcemaps';

export async function copyCommand(
config: Config,
selectedPlatformName: string,
inline = false,
): Promise<void> {
if (selectedPlatformName && !(await isValidPlatform(selectedPlatformName))) {
const platformDir = resolvePlatform(config, selectedPlatformName);
Expand All @@ -43,7 +46,7 @@ export async function copyCommand(
const platforms = await selectPlatforms(config, selectedPlatformName);
try {
await allSerial(
platforms.map(platformName => () => copy(config, platformName)),
platforms.map(platformName => () => copy(config, platformName, inline)),
);
} catch (e) {
if (isFatal(e)) {
Expand All @@ -58,6 +61,7 @@ export async function copyCommand(
export async function copy(
config: Config,
platformName: string,
inline = false,
): Promise<void> {
await runTask(c.success(c.strong(`copy ${platformName}`)), async () => {
const result = await checkWebDir(config);
Expand Down Expand Up @@ -134,6 +138,9 @@ export async function copy(
} else {
throw `Platform ${platformName} is not valid.`;
}
if (inline) {
await inlineSourceMaps(config, platformName);
}
});

await runPlatformHook(
Expand Down
12 changes: 4 additions & 8 deletions cli/src/tasks/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { logger } from '../log';
import { allSerial } from '../util/promise';

import { copy, copyCommand } from './copy';
import { inlineSourceMaps } from './sourcemaps';
import { update, updateChecks, updateCommand } from './update';

/**
Expand All @@ -22,11 +21,11 @@ export async function syncCommand(
config: Config,
selectedPlatformName: string,
deployment: boolean,
inline: boolean,
inline = false,
): Promise<void> {
if (selectedPlatformName && !(await isValidPlatform(selectedPlatformName))) {
try {
await copyCommand(config, selectedPlatformName);
await copyCommand(config, selectedPlatformName, inline);
} catch (e) {
logger.error(e.stack ?? e);
}
Expand Down Expand Up @@ -62,7 +61,7 @@ export async function sync(
config: Config,
platformName: string,
deployment: boolean,
inline: boolean,
inline = false,
): Promise<void> {
await runPlatformHook(
config,
Expand All @@ -72,10 +71,7 @@ export async function sync(
);

try {
await copy(config, platformName);
if (inline) {
await inlineSourceMaps(config, platformName);
}
await copy(config, platformName, inline);
} catch (e) {
logger.error(e.stack ?? e);
}
Expand Down

0 comments on commit 17fbabb

Please sign in to comment.