Skip to content

Commit

Permalink
Merge branch 'release/1.0' into fix/windows-link
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardasN committed Jun 21, 2024
2 parents 83a756f + ba59ff2 commit 4af86ac
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 33 deletions.
3 changes: 2 additions & 1 deletion packages/app-harness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"react-native-splash-screen": "3.3.0",
"react-native-tvos": "0.73.6-0",
"react-native-web": "0.19.9",
"rn-fetch-blob": "0.12.0"
"rn-fetch-blob": "0.12.0",
"dotenv": "16.4.5"
},
"devDependencies": {
"@flexn/assets-renative-outline": "0.3.5",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/configs/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
fsExistsSync,
formatBytes,
mkdirSync,
writeFileSync,
writeFileSync
} from '../system/fs';
import { chalk, logDefault, logWarning, logDebug } from '../logger';
import { getContext } from '../context/provider';
Expand Down Expand Up @@ -49,7 +49,6 @@ export const generateBuildConfig = () => {
logDebug('generateBuildConfig');

const c = getContext();

const extraPlugins = getEnginesPluginDelta();

const mergePathsPublic = [
Expand Down Expand Up @@ -109,7 +108,6 @@ export const generateBuildConfig = () => {

const _generateBuildConfig = (mergePaths: string[], mergeFiles: Array<object | undefined>) => {
const c = getContext();

const cleanPaths = mergePaths.filter((v) => v);
const existsPaths = cleanPaths.filter((v) => {
const exists = fsExistsSync(v);
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
2 changes: 1 addition & 1 deletion packages/core/src/system/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const execCLI = (cli: string, command: string, opts: ExecOptions = {}) => {
c.buildConfig?.sdks
);
return Promise.reject(
`Location of your cli ${chalk().bold(p)} does not exists. check your ${chalk().bold(
`Location of your cli ${chalk().bold(p)} does not exist. check your ${chalk().bold(
c.paths.workspace.config
)} file if your ${chalk().bold('sdks')} paths are correct`
);
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
3 changes: 2 additions & 1 deletion packages/engine-rn-web/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createRnvEngine, GetContextType } from '@rnv/core';
import ModuleSDKWebOS from '@rnv/sdk-webos';
import ModuleSDKTizen from '@rnv/sdk-tizen';
import ModuleSDKKaios from '@rnv/sdk-kaios';
import { withRNVBabel, withRNVWebpack } from './adapter';
import taskRun from './tasks/taskRun';
import taskBuild from './tasks/taskBuild';
Expand All @@ -10,7 +11,7 @@ import taskDebug from './tasks/taskDebug';
import { Config } from './config';

const Engine = createRnvEngine({
extendModules: [ModuleSDKWebOS, ModuleSDKTizen],
extendModules: [ModuleSDKWebOS, ModuleSDKTizen, ModuleSDKKaios],
tasks: [taskRun, taskBuild, taskConfigure, taskStart, taskDebug] as const,
config: Config,
platforms: {
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
36 changes: 35 additions & 1 deletion packages/sdk-kaios/src/deviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
getContext,
executeAsync,
ExecOptionsPresets,
logToSummary,
logWarning,
chalk,
} from '@rnv/core';
import path from 'path';

Expand All @@ -24,14 +27,22 @@ export const launchKaiOSSimulator = async (target: string | boolean) => {
(directory) => directory.toLowerCase().indexOf('kaios') !== -1
);

if (typeof target !== 'string' || !availableSimulatorVersions.includes(target)) {
if (target === true) {
const { selectedSimulator } = await inquirerPrompt({
name: 'selectedSimulator',
type: 'list',
message: 'What simulator would you like to launch?',
choices: availableSimulatorVersions,
});
target = selectedSimulator;
} else if (typeof target === 'string' && !availableSimulatorVersions.includes(target)) {
logWarning(
`Target with name ${chalk().red(target)} does not exist. You can update it here: ${chalk().cyan(
c.paths.dotRnv.config
)}`
);
await launchKaiOSSimulator(true);
return true;
}

const simulatorPath = path.join(kaiosSdkPath, `${target}/kaiosrt/kaiosrt`);
Expand All @@ -44,4 +55,27 @@ export const launchKaiOSSimulator = async (target: string | boolean) => {
cwd: `${kaiosSdkPath}/${target}/kaiosrt`,
...ExecOptionsPresets.NO_SPINNER_FULL_ERROR_SUMMARY,
});
return Promise.reject(`The Simulator can't be launched because it is already in use.`);
};

export const listKaiosTargets = async () => {
const c = getContext();

const kaiosSdkPath = getRealPath(c.buildConfig?.sdks?.KAIOS_SDK);

if (!kaiosSdkPath) {
return Promise.reject(`c.buildConfig.sdks.KAIOS_SDK undefined`);
}

const availableSimulatorVersions = getDirectories(kaiosSdkPath).filter(
(directory) => directory.toLowerCase().indexOf('kaios') !== -1
);

// availableSimulatorVersions.map((a) => {
// deviceArray.push(` [${deviceArray.length + 1}]> ${chalk().bold(a)} | simulator`);
// });

logToSummary(`Kaios Targets:\n${availableSimulatorVersions.join('\n')}`);

return true;
};
3 changes: 2 additions & 1 deletion packages/sdk-kaios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ export * from './constants';

import { GetContextType, createRnvModule } from '@rnv/core';
import taskTargetLaunch from './tasks/taskTargetLaunch';
import taskTargetList from './tasks/taskTargetList';

const RnvModule = createRnvModule({
tasks: [taskTargetLaunch] as const,
tasks: [taskTargetLaunch, taskTargetList] as const,
name: '@rnv/sdk-kaios',
type: 'internal',
});
Expand Down
15 changes: 15 additions & 0 deletions packages/sdk-kaios/src/tasks/taskTargetList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createTask, RnvTaskName, RnvTaskOptions } from '@rnv/core';
import { listKaiosTargets } from '../deviceManager';
import { SdkPlatforms } from '../constants';

export default createTask({
description: 'List all available targets for specific platform',
dependsOn: [RnvTaskName.workspaceConfigure],
fn: async () => {
return listKaiosTargets();
},
task: RnvTaskName.targetList,
options: [RnvTaskOptions.target],
platforms: SdkPlatforms,
isGlobalScope: true,
});
11 changes: 7 additions & 4 deletions packages/sdk-tizen/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const _isSdkInstalled = (c: RnvContext) => {
return fsExistsSync(getRealPath(sdkPath));
};

const _attemptAutoFix = async (c: RnvContext) => {
const _attemptAutoFix = async (c: RnvContext, shouldThrow?: boolean) => {
logDefault('_attemptAutoFix');

if (!c.files.workspace.config) return;
Expand Down Expand Up @@ -98,15 +98,18 @@ const _attemptAutoFix = async (c: RnvContext) => {
}
}

logDefault(`_attemptAutoFix: no sdks found. searched at: ${getSdkLocations().join(', ')}`);

if (shouldThrow) {
throw new Error(`_attemptAutoFix: no sdks found. searched at: ${getSdkLocations().join(', ')}`);
} else logDefault(`_attemptAutoFix: no sdks found. searched at: ${getSdkLocations().join(', ')}`);

// const setupInstance = PlatformSetup(c);
// await setupInstance.askToInstallSDK(sdkPlatform);
generateBuildConfig();
return true;
};

export const checkTizenSdk = async () => {
export const checkTizenSdk = async (shouldThrow?: boolean) => {
const c = getContext();

logDefault('checkTizenSdk');
Expand All @@ -116,7 +119,7 @@ export const checkTizenSdk = async () => {
c.paths.workspace.config
)} does not exist: ${chalk().bold(_getCurrentSdkPath(c))}`
);
return _attemptAutoFix(c);
return _attemptAutoFix(c, shouldThrow);
}
return true;
};
Loading

0 comments on commit 4af86ac

Please sign in to comment.