Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/plugins support #721

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/rnv/src/core/pluginManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ package.json will be overriden`
if (hasPackageChanged && !c.runtime.skipPackageUpdate) {
_updatePackage(c, { dependencies: newDeps, devDependencies: newDevDeps });
}

return true;
};

Expand Down Expand Up @@ -660,8 +661,66 @@ export const installPackageDependenciesAndPlugins = async (c) => {

await installPackageDependencies(c);
await overrideTemplatePlugins(c);
await _checkForPluginDependencies(c);
};

const _getPluginConfiguration = (c, pluginName) => {
let renativePluginPath;
try {
renativePluginPath = require.resolve(`${pluginName}/renative.plugin.json`, { paths: [c.paths.project.dir] });
} catch {
//
}

if (renativePluginPath) {
return readObjectSync(renativePluginPath);
}
return null;
};

const _checkForPluginDependencies = async (c) => {
const toAdd = {};
Object.keys(c.buildConfig.plugins).forEach((pluginName) => {
const renativePluginConfig = _getPluginConfiguration(c, pluginName);

if (renativePluginConfig?.plugins) {
// we have dependencies for this plugin
Object.keys(renativePluginConfig.plugins).forEach((p) => {
if (!c.buildConfig.plugins[p] && c.buildConfig.plugins[pluginName].plugins?.[p] !== null) {
logWarning(`Plugin ${p} is not installed yet.`);
toAdd[p] = renativePluginConfig.plugins[p];
c.buildConfig.plugins[p] = renativePluginConfig.plugins[p];
}
});
}
});

if (Object.keys(toAdd).length) {
// ask the user
let install = false;
if (!c.program.ci) {
const answer = await inquirerPrompt({
type: 'confirm',
message: `Install ${Object.keys(toAdd).join(', ')}?`,
warningMessage: `One or more dependencies are not installed: ${chalk().white(Object.keys(toAdd).join(', '))}`
});
install = answer.confirm;
} else {
logWarning('CI detected. Automatically installing dependencies');
install = true;
}

if (install) {
c.files.project.config.plugins = {
...c.files.project.config.plugins,
...toAdd
};
writeRenativeConfigFile(c, c.paths.project.config, c.files.project.config);
await configurePlugins(c);
await installPackageDependenciesAndPlugins(c);
}
}
};

export const overrideTemplatePlugins = async (c) => {
logTask('overrideTemplatePlugins');
Expand Down