Skip to content

Commit

Permalink
added withRnvRNConfig, added missing files to template
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiblaga89 committed Oct 10, 2023
1 parent 8d2b938 commit 68b1b06
Show file tree
Hide file tree
Showing 19 changed files with 345 additions and 147 deletions.
18 changes: 18 additions & 0 deletions packages/engine-rn-macos/src/adapters/babelAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const withRNVBabel = (cnf: any) => {
const plugins = cnf?.plugins || [];

return {
retainLines: true,
presets: ['module:metro-react-native-babel-preset'],
...cnf,
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: [process.env.RNV_MONO_ROOT || '.'],
},
],
...plugins,
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,3 @@ export const withRNVMetro = (config: any) => {

return cnf;
};

export const withRNVBabel = (cnf: any) => {
const plugins = cnf?.plugins || [];

return {
retainLines: true,
presets: ['module:metro-react-native-babel-preset'],
...cnf,
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: [process.env.RNV_MONO_ROOT || '.'],
},
],
...plugins,
],
};
};
64 changes: 64 additions & 0 deletions packages/engine-rn-macos/src/adapters/rnConfigAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import merge from 'deepmerge';

const getApplicationId = () => {
const appId = process.env.RNV_APP_ID;
return appId;
};

const getAppFolderRelative = () => {
const pth = process.env.RNV_APP_BUILD_DIR;
if (pth) {
return pth;
} else {
const cwd = process.cwd();
if (cwd.includes('platformBuilds/')) {
const dir = process.cwd().split('platformBuilds/')[1];

return `platformBuilds/${dir}`;
} else {
return undefined;
}
}
};

const getReactNativePathRelative = () => {
const rnPath = process.env.RNV_REACT_NATIVE_PATH;
return rnPath;
};

const getProjectRoot = () => {
//env: PROJECT_ROOT
const rnPath = process.env.RNV_PROJECT_ROOT;
return rnPath;
};

export const withRNVRNConfig = (config: any) => {
const cnfRnv = {
root: getProjectRoot(),
//Required to support 2 react native instances
reactNativePath: getReactNativePathRelative(),
dependencies: {
// Required for Expo CLI to be used with platforms (such as Apple TV) that are not supported in Expo SDK
expo: {
platforms: {
android: null,
ios: null,
macos: null,
},
},
},
project: {
ios: {
sourceDir: getAppFolderRelative(),
},
android: {
appName: 'app',
sourceDir: getAppFolderRelative(),
packageName: getApplicationId(),
},
},
};

const cnf = merge(cnfRnv, config);
return cnf;
};
6 changes: 4 additions & 2 deletions packages/engine-rn-macos/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { generateEngineExtensions, generateEngineTasks, RnvEngine } from '@rnv/core';
import { withRNVBabel, withRNVMetro } from './adapter';
import { withRNVMetro } from './adapters/metroAdapter';
import { withRNVBabel } from './adapters/babelAdapter';
import { withRNVRNConfig } from './adapters/rnConfigAdapter';
//@ts-ignore
import CNF from '../renative.engine.json';
import taskRnvRun from './tasks/task.rnv.run';
Expand Down Expand Up @@ -45,6 +47,6 @@ const Engine: RnvEngine = {
// Backward compatibility
const withRNV = withRNVMetro;

export { withRNV, withRNVMetro, withRNVBabel };
export { withRNV, withRNVMetro, withRNVBabel, withRNVRNConfig };

export default Engine;
18 changes: 18 additions & 0 deletions packages/engine-rn-next/src/adapters/babelAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const withRNVBabel = (cnf: any) => {
const plugins = cnf?.plugins || [];

return {
retainLines: true,
presets: ['module:babel-preset-expo'],
...cnf,
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: [process.env.RNV_MONO_ROOT || '.'],
},
],
...plugins,
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,3 @@ export const withRNVNext = (config: any, opts: any) => {

return cnf1;
};

export const withRNVBabel = (cnf: any) => {
const plugins = cnf?.plugins || [];

return {
retainLines: true,
presets: ['module:babel-preset-expo'],
...cnf,
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: [process.env.RNV_MONO_ROOT || '.'],
},
],
...plugins,
],
};
};
3 changes: 2 additions & 1 deletion packages/engine-rn-next/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { generateEngineExtensions, generateEngineTasks, RnvEngine } from '@rnv/core';
import { withRNVNext, withRNVBabel } from './adapter';
import { withRNVNext } from './adapters/nextAdapter';
import { withRNVBabel } from './adapters/babelAdapter';
//@ts-ignore
import CNF from '../renative.engine.json';
import taskRnvRun from './tasks/task.rnv.run';
Expand Down
64 changes: 64 additions & 0 deletions packages/engine-rn-tvos/src/adapters/rnConfigAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import merge from 'deepmerge';

const getApplicationId = () => {
const appId = process.env.RNV_APP_ID;
return appId;
};

const getAppFolderRelative = () => {
const pth = process.env.RNV_APP_BUILD_DIR;
if (pth) {
return pth;
} else {
const cwd = process.cwd();
if (cwd.includes('platformBuilds/')) {
const dir = process.cwd().split('platformBuilds/')[1];

return `platformBuilds/${dir}`;
} else {
return undefined;
}
}
};

const getReactNativePathRelative = () => {
const rnPath = process.env.RNV_REACT_NATIVE_PATH;
return rnPath;
};

const getProjectRoot = () => {
//env: PROJECT_ROOT
const rnPath = process.env.RNV_PROJECT_ROOT;
return rnPath;
};

export const withRNVRNConfig = (config: any) => {
const cnfRnv = {
root: getProjectRoot(),
//Required to support 2 react native instances
reactNativePath: getReactNativePathRelative(),
dependencies: {
// Required for Expo CLI to be used with platforms (such as Apple TV) that are not supported in Expo SDK
expo: {
platforms: {
android: null,
ios: null,
macos: null,
},
},
},
project: {
ios: {
sourceDir: getAppFolderRelative(),
},
android: {
appName: 'app',
sourceDir: getAppFolderRelative(),
packageName: getApplicationId(),
},
},
};

const cnf = merge(cnfRnv, config);
return cnf;
};
3 changes: 2 additions & 1 deletion packages/engine-rn-tvos/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import taskRnvLog from './tasks/task.rnv.log';
import CNF from '../renative.engine.json';
import { withRNVBabel } from './adapters/babelAdapter';
import { withRNVMetro } from './adapters/metroAdapter';
import { withRNVRNConfig } from './adapters/rnConfigAdapter';

const Engine: RnvEngine = {
// initializeRuntimeConfig: (c) => Context.initializeConfig(c),
Expand Down Expand Up @@ -68,6 +69,6 @@ const Engine: RnvEngine = {

const withRNV = withRNVMetro;

export { withRNVMetro, withRNV, withRNVBabel };
export { withRNVMetro, withRNV, withRNVBabel, withRNVRNConfig };

export default Engine;
18 changes: 18 additions & 0 deletions packages/engine-rn-windows/src/adapters/babelAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const withRNVBabel = (cnf: any) => {
const plugins = cnf?.plugins || [];

return {
retainLines: true,
presets: ['module:metro-react-native-babel-preset'],
...cnf,
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: [process.env.RNV_MONO_ROOT || '.'],
},
],
...plugins,
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,3 @@ export const withRNVMetro = (config: any) => {
return cnf;
};

export const withRNVBabel = (cnf: any) => {
const plugins = cnf?.plugins || [];

return {
retainLines: true,
presets: ['module:metro-react-native-babel-preset'],
...cnf,
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
{
root: [process.env.RNV_MONO_ROOT || '.'],
},
],
...plugins,
],
};
};
64 changes: 64 additions & 0 deletions packages/engine-rn-windows/src/adapters/rnConfigAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import merge from 'deepmerge';

const getApplicationId = () => {
const appId = process.env.RNV_APP_ID;
return appId;
};

const getAppFolderRelative = () => {
const pth = process.env.RNV_APP_BUILD_DIR;
if (pth) {
return pth;
} else {
const cwd = process.cwd();
if (cwd.includes('platformBuilds/')) {
const dir = process.cwd().split('platformBuilds/')[1];

return `platformBuilds/${dir}`;
} else {
return undefined;
}
}
};

const getReactNativePathRelative = () => {
const rnPath = process.env.RNV_REACT_NATIVE_PATH;
return rnPath;
};

const getProjectRoot = () => {
//env: PROJECT_ROOT
const rnPath = process.env.RNV_PROJECT_ROOT;
return rnPath;
};

export const withRNVRNConfig = (config: any) => {
const cnfRnv = {
root: getProjectRoot(),
//Required to support 2 react native instances
reactNativePath: getReactNativePathRelative(),
dependencies: {
// Required for Expo CLI to be used with platforms (such as Apple TV) that are not supported in Expo SDK
expo: {
platforms: {
android: null,
ios: null,
macos: null,
},
},
},
project: {
ios: {
sourceDir: getAppFolderRelative(),
},
android: {
appName: 'app',
sourceDir: getAppFolderRelative(),
packageName: getApplicationId(),
},
},
};

const cnf = merge(cnfRnv, config);
return cnf;
};
6 changes: 4 additions & 2 deletions packages/engine-rn-windows/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { RnvEngine, generateEngineTasks, generateEngineExtensions } from '@rnv/core';
import { withRNVBabel, withRNVMetro } from './adapter';
import { withRNVMetro } from './adapters/metroAdapter';
import { withRNVBabel } from './adapters/babelAdapter';
import { withRNVRNConfig } from './adapters/rnConfigAdapter';
//@ts-ignore
import CNF from '../renative.engine.json';
import taskRnvBuild from './tasks/task.rnv.build';
Expand Down Expand Up @@ -43,6 +45,6 @@ const Engine: RnvEngine = {
// Backward compatibility
const withRNV = withRNVMetro;

export { withRNV, withRNVMetro, withRNVBabel };
export { withRNV, withRNVMetro, withRNVBabel, withRNVRNConfig };

export default Engine;
Loading

0 comments on commit 68b1b06

Please sign in to comment.