Skip to content

Commit

Permalink
fix next cfg, add ios rn path injection, remove mandatory bootstrapQu…
Browse files Browse the repository at this point in the history
…estions
  • Loading branch information
mihaiblaga89 committed Nov 7, 2023
1 parent 6408eea commit e3b5521
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/app-harness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@rnv/engine-rn-next": "1.0.0-feat-metro-config.2",
"@rnv/engine-rn-tvos": "1.0.0-feat-metro-config.2",
"@rnv/engine-rn-web": "1.0.0-feat-metro-config.2",
"@rnv/template-starter": "1.0.0-feat-metro-config.2",
"@rnv/template-starter": "^1.0.0-feat-metro-config.2",
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"@types/react-native": "0.72.2",
Expand Down
3 changes: 0 additions & 3 deletions packages/core/jsonSchema/rnv.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@
"additionalProperties": false
}
},
"required": [
"bootstrapQuestions"
],
"additionalProperties": false,
"description": "Used in `renative.template.json` allows you to define template behaviour."
},
Expand Down
61 changes: 60 additions & 1 deletion packages/core/src/__tests__/fileutils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import { createPlatformBuild } from '../platforms';
import { createRnvApi } from '../api';
import { createRnvContext } from '../context';
import { sanitizeDynamicProps, getRelativePath } from '../system/fs';
import { RnvPlatform } from '../types';
import { getContext } from '../context/provider';
import { doResolve } from '../system/resolve';

jest.mock('../logger/index.ts');
jest.mock('../logger/index.ts', () => {
return {
logTask: jest.fn(),
logDebug: jest.fn(),
chalk: () => ({
red: jest.fn(),
white: jest.fn(),
}),
};
});

jest.mock('../system/fs.ts', () => {
const original = jest.requireActual('../system/fs.ts');

return {
...original,
copyFolderContentsRecursiveSync: jest.fn(),
}
})

describe('sanitizeDynamicProps', () => {
beforeAll(() => {
Expand Down Expand Up @@ -122,4 +144,41 @@ describe('getRelativePath', () => {
const result = getRelativePath(from, to);
expect(result).toEqual(expected);
});
});

describe('createPlatformBuild', () => {
// GIVEN
const platform: RnvPlatform = 'ios';
const c = getContext();
c.runtime.availablePlatforms = ['ios', 'android'];
c.paths.project.platformTemplatesDirs[platform] = '/path/to/pt';
const { copyFolderContentsRecursiveSync } = require('../system/fs');

it('should copy platform template files to app folder', async () => {

// WHEN
await createPlatformBuild(
c,
platform,
);

// THEN
expect(copyFolderContentsRecursiveSync).toHaveBeenCalledWith(
'/path/to/pt/ios',
'undefined_null', // TODO: fix this
false,
['/path/to/pt/ios/_privateConfig'],
false,
[
{
pattern: '{{PATH_REACT_NATIVE}}',
override: doResolve(c.runtime.runtimeExtraProps?.reactNativePackageName || 'react-native', true, {
forceForwardPaths: true,
}) || '',
},
],
undefined,
c
);
});
});
8 changes: 7 additions & 1 deletion packages/core/src/platforms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { RnvContext } from '../context/types';
import { generateOptions, inquirerPrompt } from '../api';
import type { RnvPlatform, RnvPlatformWithAll } from '../types';
import { updateProjectPlatforms } from '../configs/configProject';
import { doResolve } from '../system/resolve';

export const logErrorPlatform = (c: RnvContext) => {
logError(
Expand Down Expand Up @@ -65,7 +66,12 @@ export const createPlatformBuild = (c: RnvContext, platform: RnvPlatform) =>
false,
[path.join(ptPath, '_privateConfig')],
false,
[],
[{
pattern: '{{PATH_REACT_NATIVE}}',
override: doResolve(c.runtime.runtimeExtraProps?.reactNativePackageName || 'react-native', true, {
forceForwardPaths: true,
}) || '',
}],
getTimestampPathsConfig(c, platform),
c
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/schema/configFiles/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const RootTemplateSchema = z.object({
.array(z.string())
.describe('Defines list of all file/dir paths you want to include in template')
.optional(),
bootstrapQuestions: BootstrapQuestionsSchema,
bootstrapQuestions: z.optional(BootstrapQuestionsSchema),
packageTemplate: z.optional(
z.object({
dependencies: z.optional(NpmDep),
Expand Down
12 changes: 0 additions & 12 deletions packages/engine-rn-next/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
confirmActiveBundler,
getPlatformBuildDir,
fsExistsSync,
writeCleanFile,
copyFolderContentsRecursiveSync,
chalk,
logTask,
Expand All @@ -22,7 +21,6 @@ import {
getModuleConfigs,
RnvPlatform,
} from '@rnv/core';
import { NEXT_CONFIG_NAME } from './constants';
import { getDevServerHost, openBrowser, waitForHost } from '@rnv/sdk-utils';

export const configureNextIfRequired = async (c: RnvContext) => {
Expand All @@ -31,11 +29,6 @@ export const configureNextIfRequired = async (c: RnvContext) => {
if (!c.platform) return;

c.runtime.platformBuildsProjectPath = `${getPlatformBuildDir(c)}`;
const { platformTemplatesDirs, dir } = c.paths.project;

const supportFilesDir = path.join(platformTemplatesDirs[c.platform], '../../supportFiles');

const configFile = path.join(dir, NEXT_CONFIG_NAME);

await copyAssetsFolder(c, c.platform);

Expand All @@ -50,11 +43,6 @@ export const configureNextIfRequired = async (c: RnvContext) => {
const sourcePath = path.join(c.paths.appConfig.dir, `assets/${c.platform}`);
copyFolderContentsRecursiveSync(sourcePath, destPath);
}

// add config
if (!fsExistsSync(configFile)) {
writeCleanFile(path.join(supportFilesDir, NEXT_CONFIG_NAME), configFile, undefined, undefined, c);
}
};

export const runWebNext = async (c: RnvContext) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"../../../../node_modules/react-native-tvos/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../../../../node_modules/react-native-tvos/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"{{PATH_REACT_NATIVE}}/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"{{PATH_REACT_NATIVE}}/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
};
0D7507D506130F6246FD97BE /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\nREACT_NATIVE_FOLDER=$(node -p \"require.resolve('react-native').split('/').slice(0, -1).join('/')\")\nWITH_ENVIRONMENT=\"$REACT_NATIVE_FOLDER/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_FOLDER/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
shellScript = "set -e\nWITH_ENVIRONMENT=\"{{PATH_REACT_NATIVE}}/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"{{PATH_REACT_NATIVE}}/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
};
DF530FE9BA2EFAF0A1689966 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
9 changes: 0 additions & 9 deletions packages/sdk-android/src/__tests__/index.test.ts

This file was deleted.

18 changes: 14 additions & 4 deletions packages/template-starter/renative.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"metro.config.js",
".bundle",
"react-native.config.js",
"babel.config.js"
"babel.config.js",
"next.config.js",
"next-env.d.ts"
],
"packageTemplate": {
"devDependencies": {
Expand All @@ -23,8 +25,16 @@
"babel-loader": "9.1.3"
},
"browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"],
"development": ["last 1 chrome version", "last 1 firefox version", "last 1 safari version"]
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"resolutions": {
"@babel/traverse": "7.15.0",
Expand All @@ -35,4 +45,4 @@
"platforms": {},
"plugins": {},
"extendsTemplate": "@rnv/template-starter/renative.json"
}
}
2 changes: 1 addition & 1 deletion spec/other/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\nREACT_NATIVE_FOLDER=$(node -p \"require.resolve('react-native').split('/').slice(0, -1).join('/')\")\nWITH_ENVIRONMENT=\"$REACT_NATIVE_FOLDER/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_FOLDER/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
shellScript = "set -e\nWITH_ENVIRONMENT=\"{{PATH_REACT_NATIVE}}/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"{{PATH_REACT_NATIVE}}/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
};
DF530FE9BA2EFAF0A1689966 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
Expand Down

0 comments on commit e3b5521

Please sign in to comment.