Skip to content

Commit

Permalink
Merge branch 'release/1.0' into chore/deps-update
Browse files Browse the repository at this point in the history
  • Loading branch information
pavjacko committed Jun 20, 2024
2 parents 8244fcc + ba59ff2 commit ef9b627
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/app-harness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"react-native-tvos": "0.73.6-0",
"react-native-web": "0.19.12",
"rn-fetch-blob": "0.12.0"
"dotenv": "16.4.5"
},
"devDependencies": {
"@flexn/assets-renative-outline": "0.3.5",
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/engines/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const generateEngineExtensions = (id: string, exts: Array<string>, engine
export const configureEngines = async (c: RnvContext) => {
logDefault('configureEngines');

const engines = _getFilteredEngines(c);
const engines = getFilteredEngines(c);
const devDependencies = c.files.project.package.devDependencies || {};
c.files.project.package.devDependencies = devDependencies;
let needsPackageUpdate = false;
Expand Down Expand Up @@ -348,7 +348,7 @@ export const loadEnginePackageDeps = async (engineConfigs: Array<RnvEngineInstal
// return addedDeps.length;
};

const _getFilteredEngines = (c: RnvContext) => {
export const getFilteredEngines = (c: RnvContext) => {
const engines = c.buildConfig?.engines;
if (!engines) {
logError('Engine configs missing in your renative.json. FIXING...DONE');
Expand Down Expand Up @@ -383,11 +383,11 @@ const _getFilteredEngines = (c: RnvContext) => {
return filteredEngines;
};

const getScopedVersion = (
export const getScopedVersion = (
c: RnvContext,
key: string,
val: RenativeConfigVersion,
sourceObjKey: 'engineTemplates' | 'plugins'
sourceObjKey: 'engineTemplates' | 'plugins' | 'pluginTemplates'
) => {
if (typeof val === 'string') {
if (val.startsWith('source:')) {
Expand All @@ -413,7 +413,7 @@ export const installEngines = async (failOnMissingDeps?: boolean): Promise<boole

if (!fsExistsSync(c.paths.project.config)) return true;

const filteredEngines: Record<string, string> = _getFilteredEngines(c);
const filteredEngines: Record<string, string> = getFilteredEngines(c);
const enginesToInstall: Array<RnvEngineInstallConfig> = [];
const readyEngines: Array<string> = [];
const engineConfigs: Array<RnvEngineInstallConfig> = [];
Expand Down
123 changes: 123 additions & 0 deletions packages/engine-core/src/tasks/bootstrap/questions/installEngines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import {
RnvEngineInstallConfig,
getFilteredEngines,
executeAsync,
fsExistsSync,
getContext,
getScopedVersion,
isYarnInstalled,
writeFileSync,
readObjectSync,
ConfigFileEngine,
RnvFileName,
getMergedPlugin,
RnvPlugin,
RnvPlatformKey,
inquirerPrompt,
} from '@rnv/core';
import type { NewProjectData } from '../types';
import path from 'path';

const _mergeDependencies = (target: Record<string, string>, source?: Record<string, string>) => {
if (source) {
Object.keys(source).forEach((dep) => {
if (!target[dep]) {
target[dep] = source[dep];
}
});
}
};

const _isPluginRequired = (plugin: RnvPlugin, supportedPlatforms: Array<RnvPlatformKey>) => {
if (!plugin.supportedPlatforms) return true;
return plugin.supportedPlatforms.some((platform) => supportedPlatforms.includes(platform));
};
const Question = async (data: NewProjectData) => {
const c = getContext();

if (!fsExistsSync(c.paths.project.config)) return true;
const { confirmInstallEngines } = await inquirerPrompt({
name: 'confirmInstallEngines',
type: 'confirm',
message: 'You do not have any engines installed. Do you want to install them now?',
});
if (!confirmInstallEngines) return true;

const filteredEngines: Record<string, string> = getFilteredEngines(c);
const enginesToInstall: Array<RnvEngineInstallConfig> = [];
const pkg = c.files.project.package;
const devDeps = pkg.devDependencies || {};
const deps = pkg.dependencies || {};
pkg.devDependencies = devDeps;
pkg.dependencies = deps;
const supportedPlatforms = data?.inputs?.supportedPlatforms;

Object.keys(filteredEngines).forEach((k) => {
const engVersion = getScopedVersion(c, k, filteredEngines[k], 'engineTemplates');
if (engVersion) {
enginesToInstall.push({
key: k,
version: engVersion,
});
}
});
if (enginesToInstall.length) {
const cwd = c.paths.project.dir;

for (const engine of enginesToInstall) {
const { key, version } = engine;
if (key && version) {
const installCommand = `${isYarnInstalled() ? 'yarn' : 'npm'} add ${key}@${version} --dev`;
await executeAsync(installCommand, {
cwd,
});
devDeps[key] = version;

const nmDir = path.join(cwd, 'node_modules');
const engineConfigPath = path.join(nmDir, key, RnvFileName.renativeEngine);
const engineConfig = readObjectSync<ConfigFileEngine>(engineConfigPath);

if (engineConfig && supportedPlatforms) {
supportedPlatforms.forEach((platform) => {
const npmDeps = engineConfig?.platforms?.[platform]?.npm;
if (npmDeps) {
_mergeDependencies(deps, npmDeps.dependencies);
_mergeDependencies(devDeps, npmDeps.devDependencies);
}
});
if (engineConfig?.npm) {
_mergeDependencies(deps, engineConfig.npm.dependencies);
_mergeDependencies(devDeps, engineConfig.npm.devDependencies);
}
}
}
}
}

const { plugins } = c.buildConfig;

if (plugins) {
Object.keys(plugins).forEach((k) => {
const plugin = getMergedPlugin(c, k);
if (!plugin) return;

const { version } = plugin;
if (supportedPlatforms) {
if (
plugin.disabled !== true &&
plugin.disableNpm !== true &&
_isPluginRequired(plugin, supportedPlatforms)
) {
if (version) {
if (!deps[k]) {
deps[k] = version;
}
}
}
}
});
}
writeFileSync(c.paths.project.package, c.files.project.package);
};

export default Question;
3 changes: 3 additions & 0 deletions packages/engine-core/src/tasks/bootstrap/taskNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import inquiryBookmarkTemplate from './questions/bookmarkTemplate';
import inquiryAppConfigs from './questions/appConfigs';
import inquiryConfigTemplates from './questions/configTemplates';
import inquiryProjectInstall from './questions/installProject';
import inquiryInstallEngines from './questions/installEngines';
import {
configureConfigOverrides,
generateProjectOverview,
Expand Down Expand Up @@ -73,8 +74,10 @@ export default createTask({
await configureTemplateFiles();
await generateLocalJsonSchemas();
await inquiryAppConfigs(payload);
await inquiryInstallEngines(payload);
// Telementry
await telemetryNewProject(payload);

await inquiryProjectInstall(payload);

logToSummary(generateProjectOverview(payload));
Expand Down
4 changes: 3 additions & 1 deletion packages/engine-rn-tvos/renative.engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"tvos": {
"engine": "engine-rn-tvos",
"npm": {
"devDependencies": {}
"dependencies": {
"dotenv": "16.4.5"
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/engine-rn/renative.engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
},
"platforms": {
"ios": {
"engine": "engine-rn"
"engine": "engine-rn",
"npm": {
"dependencies": {
"dotenv": "16.4.5"
}
}
},
"macos": {
"engine": "engine-rn"
Expand Down
7 changes: 4 additions & 3 deletions packages/template-starter/renative.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
},
{
"paths": ["Gemfile", "metro.config.js", ".bundle", "react-native.config.js"],

"platforms": ["ios", "android", "androidwear", "tvos", "firetv", "androidtv"]

},
{
"paths": ["next.config.js", "next-env.d.ts", "src/pages"],
"platforms": ["web"]
},
{
"paths": ["webpack.config.js"],

"platforms": [
"windows",
"macos",
Expand Down Expand Up @@ -58,9 +61,7 @@
"@rnv/cli": "1.0.0-rc.19",
"@rnv/adapter": "1.0.0-rc.19",
"@rnv/config-templates": "1.0.0-rc.19",
"babel-loader": "9.1.3",
"readable-stream": "4.5.2",
"dotenv": "16.4.5"
"babel-loader": "9.1.3"
},
"browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"],
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9714,16 +9714,16 @@ dotenv-expand@^5.1.0:
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==

dotenv@16.4.5, dotenv@^16.0.3, dotenv@^16.3.1:
version "16.4.5"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

dotenv@^10.0.0, dotenv@~10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

dotenv@^16.0.3, dotenv@^16.3.1:
version "16.4.5"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

dotenv@^9.0.2:
version "9.0.2"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-9.0.2.tgz#dacc20160935a37dea6364aa1bef819fb9b6ab05"
Expand Down

0 comments on commit ef9b627

Please sign in to comment.