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] add support for dynamic plugin fonts #914

Merged
merged 2 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rnv/src/__tests__/startup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Bootstrapping the CLI', () => {

it('should create C variable correctly', async () => {
const cKeys = Object.keys(c).sort();
const expectKeys = ['api', 'buildConfig', 'cli', 'command', 'configPropsInjects', 'files', 'paths', 'platform', 'process', 'program', 'runtime', 'subCommand'];
const expectKeys = ['_renativePluginCache', 'api', 'buildConfig', 'cli', 'command', 'configPropsInjects', 'files', 'paths', 'platform', 'process', 'program', 'runtime', 'subCommand'];
expect(cKeys).toEqual(expectKeys);
});

Expand Down
1 change: 1 addition & 0 deletions packages/rnv/src/core/configManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ export const parseRenativeConfigs = async (c) => {

export const createRnvConfig = (program, process, cmd, subCmd, { projectRoot } = {}) => {
const c = {
_renativePluginCache: {},
cli: {},
api: {
fsExistsSync,
Expand Down
8 changes: 8 additions & 0 deletions packages/rnv/src/core/pluginManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ const _getMergedPlugin = (c, plugin, pluginKey, parentScope, scopes, skipSanitiz
});
}
const mergedObj = mergeObjects(c, parentPlugin, currentPlugin, true, true);
if (c._renativePluginCache[pluginKey]) {
mergedObj.config = c._renativePluginCache[pluginKey];
}

// IMPORTANT: only final top level merge should be sanitized
const obj = skipSanitize ? mergedObj : sanitizeDynamicProps(mergedObj, {
files: c.files,
Expand Down Expand Up @@ -727,6 +731,10 @@ export const checkForPluginDependencies = async (c) => {
Object.keys(c.buildConfig.plugins).forEach((pluginName) => {
const renativePluginConfig = _getPluginConfiguration(c, pluginName);

if (renativePluginConfig) {
c._renativePluginCache[pluginName] = renativePluginConfig;
}

if (renativePluginConfig?.plugins) {
// we have dependencies for this plugin
Object.keys(renativePluginConfig.plugins).forEach((p) => {
Expand Down
26 changes: 18 additions & 8 deletions packages/rnv/src/core/projectManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { INJECTABLE_CONFIG_PROPS, RN_BABEL_CONFIG_NAME, RENATIVE_CONFIG_TEMPLATE_NAME } from '../constants';
import { getEngineRunnerByPlatform } from '../engineManager';
import { isPlatformActive } from '../platformManager';
import { copyTemplatePluginsSync } from '../pluginManager';
import { copyTemplatePluginsSync, parsePlugins } from '../pluginManager';
import {
cleanFolder,
copyFolderContentsRecursiveSync,
Expand Down Expand Up @@ -374,17 +374,27 @@ export const parseFonts = (c, callback) => {
if (callback) callback(font, c.paths.appConfig.fontsDir);
});
}
const fontSources = getConfigProp(c, c.platform, 'fontSources', []).map(v => _resolvePackage(c, v));
fontSources.forEach((fontSourceDir) => {
if (fsExistsSync(fontSourceDir)) {
fsReaddirSync(fontSourceDir).forEach((font) => {
if (callback) callback(font, fontSourceDir);
});
_parseFontSources(c, getConfigProp(c, c.platform, 'fontSources', []), callback);
// PLUGIN FONTS
parsePlugins(c, c.platform, (plugin) => {
if (plugin.config?.fontSources) {
_parseFontSources(c, plugin.config?.fontSources, callback);
}
});
}, true);
}
};

const _parseFontSources = (c, fontSourcesArr, callback) => {
const fontSources = fontSourcesArr.map(v => _resolvePackage(c, v));
fontSources.forEach((fontSourceDir) => {
if (fsExistsSync(fontSourceDir)) {
fsReaddirSync(fontSourceDir).forEach((font) => {
if (callback) callback(font, fontSourceDir);
});
}
});
};

const _resolvePackage = (c, v) => {
if (v?.startsWith?.('./')) {
return path.join(c.paths.project.dir, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export const taskRnvProjectConfigure = async (c, parentTask, originTask) => {
// await configureEntryPoints(c);
await generateRuntimeConfig(c);
await overrideTemplatePlugins(c);
await configureFonts(c);
// NOTE: this is needed to ensure missing rnv plugin sub-deps are caught
await checkForPluginDependencies(c);
await configureFonts(c);
}

return true;
Expand Down