Skip to content

Commit

Permalink
Merge pull request #1498 from flexn-io/fix/lightningjs_port
Browse files Browse the repository at this point in the history
added check for available port - lightningjs
  • Loading branch information
pavjacko authored Apr 9, 2024
2 parents 4e63bd8 + 46e83ea commit fb9f073
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"overrides": {
"build/bin.js": {
"require(\"./tools/gracefulifyFs\");": "require(\"./tools/gracefulifyFs\"/*RNV*/); var dotenv = require('dotenv'); if(dotenv) dotenv.config();"
}
}
}
1 change: 1 addition & 0 deletions packages/config-templates/renative.templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@
"version": "0.5.9"
},
"@react-native-community/cli": {
"disableNpm": true,
"version": "^6.0.0"
},
"@react-native-community/cli-platform-android": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const Question = async (data: NewProjectData) => {
}
}

const nmDir = path.join(c.paths.project.dir, RnvFolderName.dotRnv, RnvFolderName.npmCache);
const npmCacheDir = path.join(c.paths.project.dir, RnvFolderName.dotRnv, RnvFolderName.npmCache);

if (localTemplatePath) {
if (!fsExistsSync(localTemplatePath)) {
Expand All @@ -112,7 +112,7 @@ const Question = async (data: NewProjectData) => {
}
const pkg = readObjectSync<NpmPackageFile>(localTemplatePkgPath);

mkdirSync(nmDir);
mkdirSync(npmCacheDir);
if (!pkg?.name) {
return Promise.reject(`Invalid package ${localTemplatePkgPath} missing name field`);
}
Expand All @@ -123,7 +123,7 @@ const Question = async (data: NewProjectData) => {

if (!inputs.template) return;

const nmTemplatePath = path.join(nmDir, pkg?.name);
const nmTemplatePath = path.join(npmCacheDir, pkg?.name);

logInfo(`Found local template: ${pkg.name}@${pkg.version}`);

Expand Down Expand Up @@ -189,6 +189,7 @@ const Question = async (data: NewProjectData) => {
}
);
// Check if node_modules folder exists
const nmDir = path.join(c.paths.project.dir, 'node_modules');
if (!fsExistsSync(nmDir)) {
return Promise.reject(
`${isYarnInstalled() ? 'yarn' : 'npm'} add ${inputs.template.packageName}@${
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-lightning/src/sdk/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const EnvVars = {
LNG_SERVE_PORT: () => {
const ctx = getContext();
return {
LNG_SERVE_PORT: ctx.runtime.currentPlatform?.defaultPort,
LNG_SERVE_PORT: ctx.runtime.port,
};
},
LNG_DIST_FOLDER: () => {
Expand Down
50 changes: 38 additions & 12 deletions packages/engine-lightning/src/sdk/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ import semver from 'semver';

import { runTizenSimOrDevice, CLI_TIZEN } from '@rnv/sdk-tizen';
import { CLI_WEBOS_ARES_PACKAGE, runWebosSimOrDevice } from '@rnv/sdk-webos';
import { getAppVersion, getAppTitle, getAppId, getAppDescription, addSystemInjects } from '@rnv/sdk-utils';
import {
getAppVersion,
getAppTitle,
getAppId,
getAppDescription,
addSystemInjects,
checkPortInUse,
confirmActiveBundler,
} from '@rnv/sdk-utils';
import { EnvVars } from './env';

export const runLightningProject = async () => {
Expand All @@ -34,17 +42,35 @@ export const runLightningProject = async () => {
const isHosted = hosted && !getConfigProp('bundleAssets');

if (isHosted) {
await executeAsync('lng dev', {
stdio: 'inherit',
silent: false,
env: {
...CoreEnvVars.BASE(),
...CoreEnvVars.RNV_EXTENSIONS(),
...EnvVars.LNG_BUILD_FOLDER(),
...EnvVars.LNG_ENTRY_FILE(),
...EnvVars.LNG_SERVE_PORT(),
},
});
const isPortActive = await checkPortInUse(c.runtime.port);
if (isPortActive) {
const resetCompleted = await confirmActiveBundler();
if (resetCompleted) {
await executeAsync('lng dev', {
stdio: 'inherit',
silent: false,
env: {
...CoreEnvVars.BASE(),
...CoreEnvVars.RNV_EXTENSIONS(),
...EnvVars.LNG_BUILD_FOLDER(),
...EnvVars.LNG_ENTRY_FILE(),
...EnvVars.LNG_SERVE_PORT(),
},
});
}
} else {
await executeAsync('lng dev', {
stdio: 'inherit',
silent: false,
env: {
...CoreEnvVars.BASE(),
...CoreEnvVars.RNV_EXTENSIONS(),
...EnvVars.LNG_BUILD_FOLDER(),
...EnvVars.LNG_ENTRY_FILE(),
...EnvVars.LNG_SERVE_PORT(),
},
});
}
} else {
await buildLightningProject();
if (platform === 'tizen') {
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk-android/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {
composeDevicesArray,
} from './deviceManager';
import { ANDROID_COLORS, ANDROID_STRINGS, ANDROID_STYLES, CLI_ANDROID_ADB } from './constants';
import { runReactNativeAndroid, packageReactNativeAndroid } from '@rnv/sdk-react-native';
import { runReactNativeAndroid, packageReactNativeAndroid, generateEnvVarsFile } from '@rnv/sdk-react-native';
import { getEntryFile } from '@rnv/sdk-utils';

export const packageAndroid = async () => {
Expand Down Expand Up @@ -361,6 +361,7 @@ export const configureGradleProject = async () => {
await configureAndroidProperties();
await configureProject();
await copyBuildsFolder();
await generateEnvVarsFile();
return true;
};

Expand Down
34 changes: 33 additions & 1 deletion packages/sdk-react-native/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { doResolve, getConfigProp, getContext, getRelativePath, parsePlugins } from '@rnv/core';
import {
CoreEnvVars,
doResolve,
fsWriteFileSync,
getAppFolder,
getConfigProp,
getContext,
getRelativePath,
parsePlugins,
} from '@rnv/core';
import { getAppId } from '@rnv/sdk-utils';
import path from 'path';

export const EnvVars = {
RCT_METRO_PORT: () => {
Expand Down Expand Up @@ -57,3 +67,25 @@ export const EnvVars = {
return {};
},
};

export const generateEnvVarsFile = async () => {
const destDir = getAppFolder();
const destPath = path.join(destDir, '.env');
const envVars: Record<string, any> = {
...CoreEnvVars.BASE(),
RNV_EXTENSIONS: CoreEnvVars.RNV_EXTENSIONS().RNV_EXTENSIONS.join(', '),
...EnvVars.RCT_METRO_PORT(),
...EnvVars.RNV_REACT_NATIVE_PATH(),
...EnvVars.RCT_NO_LAUNCH_PACKAGER(),
...EnvVars.RNV_APP_ID(),
...EnvVars.RCT_NEW_ARCH_ENABLED(),
...EnvVars.RNV_FLIPPER_ENABLED(),
...EnvVars.RNV_SKIP_LINKING(),
};
let env = '';
Object.keys(envVars).forEach((key) => {
env += `${key}=${envVars[key]}\n`;
});

fsWriteFileSync(destPath, env);
};
29 changes: 8 additions & 21 deletions packages/template-starter/renative.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
"minSdkVersion": 21,
"extendPlatform": "android",
"engine": "engine-rn-tvos",
"includedPermissions": [
"INTERNET"
]
"includedPermissions": ["INTERNET"]
},
"web": {
"engine": "engine-rn-next"
Expand Down Expand Up @@ -114,31 +112,20 @@
"react-dom": "source:rnv",
"react-native-gesture-handler": "source:rnv",
"@react-native-community/cli-platform-ios": {
"supportedPlatforms": [
"tvos",
"ios"
]
"supportedPlatforms": ["tvos", "ios"]
},
"@react-native-community/cli": {
"supportedPlatforms": ["tvos", "ios"]
},
"react-native": "source:rnv",
"next": {
"supportedPlatforms": [
"web"
]
"supportedPlatforms": ["web"]
},
"react-native-web": {
"supportedPlatforms": [
"web",
"tizen",
"webos",
"macos"
]
"supportedPlatforms": ["web", "tizen", "webos", "macos"]
},
"react-native-tvos": {
"supportedPlatforms": [
"tvos",
"firetv",
"androidtv"
]
"supportedPlatforms": ["tvos", "firetv", "androidtv"]
}
},
"permissions": {
Expand Down

0 comments on commit fb9f073

Please sign in to comment.