Skip to content

Commit

Permalink
Merge pull request #1680 from flexn-io/chore/cherry-pick-offline-mode…
Browse files Browse the repository at this point in the history
…-option

add offline mode option
  • Loading branch information
kasinskas authored Sep 4, 2024
2 parents 9da8f0d + c54f160 commit 0858f77
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/tasks/taskOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export const RnvTaskOptions = createTaskOptionsMap([
altKey: 'skipDependencyCheck',
description: 'Skips auto update of npm dependencies if mismatch found',
},
{
key: 'offline',
description: 'Run without connecting to the internet whenever possible',
},
{
key: 'app-config-ID',
altKey: 'appConfigID',
Expand Down Expand Up @@ -232,6 +236,7 @@ export const RnvTaskCoreOptionPresets = createTaskOptionsPreset({
RnvTaskOptions.json,
RnvTaskOptions.noSummary,
RnvTaskOptions.noIntro,
RnvTaskOptions.offline,
RnvTaskOptions.skipDependencyCheck,
],
});
Expand Down
11 changes: 9 additions & 2 deletions packages/engine-core/src/taskHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {
getContext,
installPackageDependencies,
logDefault,
logInfo,
overrideTemplatePlugins,
} from '@rnv/core';
import { configureFonts } from '@rnv/sdk-utils';
import { configureFonts, isOfflineMode } from '@rnv/sdk-utils';

export const installPackageDependenciesAndPlugins = async () => {
logDefault('installPackageDependenciesAndPlugins');
Expand All @@ -21,7 +22,13 @@ export const installPackageDependenciesAndPlugins = async () => {

export const checkAndInstallIfRequired = async () => {
const ctx = getContext();
if (ctx.program.opts().skipDependencyCheck) return true;
if (isOfflineMode('install package dependencies and plugins')) {
return true;
}
if (ctx.program.opts().skipDependencyCheck) {
logInfo(`Skipping installing package dependencies and plugins due to --skip-dependency-check option`);
return true;
}
const isNmInstalled = areNodeModulesInstalled();
if (isNmInstalled && !ctx._requiresNpmInstall) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk-react-native/src/iosRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { EnvVars } from './env';
import shellQuote from 'shell-quote';
import path from 'path';
import crypto from 'crypto';
import { isOfflineMode } from '@rnv/sdk-utils';

export const packageReactNativeIOS = (isDev = false) => {
const c = getContext();
Expand Down Expand Up @@ -126,6 +127,9 @@ const checkIfPodsIsRequired = (
c: RnvContext,
forceUpdatePods: boolean
): { result: boolean; reason: string; code: number } => {
if (isOfflineMode()) {
return { result: false, reason: 'You passed --offline option', code: 7 };
}
if (c.runtime._skipNativeDepResolutions) {
return { result: false, reason: `Command ${getCurrentCommand(true)} explicitly skips pod checks`, code: 1 };
}
Expand Down
12 changes: 12 additions & 0 deletions packages/sdk-utils/src/getCliOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getContext, logInfo } from '@rnv/core';

export const isOfflineMode = (logMessage?: string) => {
if (getContext().program.opts().offline) {
if (logMessage) {
logInfo(`Skipping "${logMessage}" due to --offline option`);
}
return true;
} else {
return false;
}
};
1 change: 1 addition & 0 deletions packages/sdk-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './ipUtils';
export * from './utils';
export * from './target';
export * from './axiosUtils';
export * from './getCliOptions';

0 comments on commit 0858f77

Please sign in to comment.