Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add offline mode option #1680

Merged
merged 2 commits into from
Sep 4, 2024
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
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';
Loading