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

Context generics, types name refactor #1496

Merged
merged 38 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1436681
add fail sdk test
Marius456 Mar 13, 2024
aeaecea
Bump follow-redirects from 1.15.5 to 1.15.6
dependabot[bot] Mar 17, 2024
ad634a6
add success test
Marius456 Mar 19, 2024
0bb4f5b
fix android styles, colors
ElenaDiachenko Mar 19, 2024
7a57a5c
fix all android based platforms
ElenaDiachenko Mar 19, 2024
51ac1c4
update tests
Marius456 Mar 19, 2024
223f6b0
add variations of test
Marius456 Mar 19, 2024
aab7c89
update test
Marius456 Mar 20, 2024
9a6c9cd
fix target not found test
Marius456 Mar 20, 2024
b64c92b
add isSystem to context
Marius456 Mar 20, 2024
444d8e3
Merge branch 'release/1.0' into chore/UT_sdk_webos_device_manager
Marius456 Mar 20, 2024
33bfd3d
small fix
Marius456 Mar 20, 2024
930c080
fix UT due to migration to getContext DI
Marius456 Mar 20, 2024
bf3eb39
Bump webpack-dev-middleware from 5.3.3 to 5.3.4
dependabot[bot] Mar 23, 2024
e43aad4
add styles_xml generating
ElenaDiachenko Mar 23, 2024
b1ef487
fix _parseNode func, add strings_xml and colors_xml generating
ElenaDiachenko Mar 24, 2024
98d915d
fix schema
ElenaDiachenko Mar 24, 2024
b6fe66c
fix all strings_xml and colors_xml for android based platforms
ElenaDiachenko Mar 25, 2024
4dc38f2
clean code
ElenaDiachenko Mar 25, 2024
b213320
fix android e2e
Marius456 Mar 26, 2024
8866e8d
refactor getConfigProp to be extendable trough context generics
pavjacko Apr 7, 2024
c59b806
Merge branch 'release/1.0' of github.com:flexn-io/renative into relea…
pavjacko Apr 7, 2024
5e21159
migrate to new contextProps
pavjacko Apr 7, 2024
b7bcd58
Merge branch 'fix/android_resources' into chore/config_generics
pavjacko Apr 7, 2024
b469347
update type names, pathNames, merge fixes
pavjacko Apr 7, 2024
2dff97e
Merge branch 'chore/UT_sdk_webos_device_manager' into chore/config_ge…
pavjacko Apr 7, 2024
de979bc
cleanup core mocks, fix UTs
pavjacko Apr 7, 2024
7e0ba5d
cleanup test structure
pavjacko Apr 7, 2024
09a34be
Merge pull request #1480 from flexn-io/dependabot/npm_and_yarn/webpac…
pavjacko Apr 7, 2024
a09c627
Merge pull request #1472 from flexn-io/dependabot/npm_and_yarn/follow…
pavjacko Apr 7, 2024
9551175
update buildConfig merges
pavjacko Apr 8, 2024
4a1da61
fix private configs
pavjacko Apr 8, 2024
6d0828e
fix asset copy, cleanup resources
pavjacko Apr 8, 2024
38c9059
add multi-folder resources support spec
pavjacko Apr 8, 2024
51d3df7
Merge branch 'chore/config_generics' of github.com:flexn-io/renative …
pavjacko Apr 8, 2024
99365b5
update, fix schema
pavjacko Apr 8, 2024
7bb4296
cleanup
pavjacko Apr 8, 2024
70c4da6
fix manifest merging
pavjacko Apr 8, 2024
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
Prev Previous commit
Next Next commit
fix _parseNode func, add strings_xml and colors_xml generating
  • Loading branch information
ElenaDiachenko committed Mar 24, 2024
commit b1ef487fa65926426c3d21972a15f1c9c9cd65bb
10 changes: 10 additions & 0 deletions packages/app-harness/renative.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
]
}
]
},
"colors_xml": {
"tag": "resources",
"children": [
{
"tag": "color",
"name": "bg_line",
"value": "#E7E7E7"
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<color name="bg">{{PLUGIN_COLORS_BG}}</color>
</resources>
<!--
Generate by ReNative (https://renative.org)
BASE: packages/sdk-android/supportFiles/colors_xml.json
-->
{{PLUGIN_COLORS_XML_FILE}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- HARDCODED -->
<resources>
<string name="app_name">ReNative</string>
</resources>
<!--
Generate by ReNative (https://renative.org)
BASE: packages/sdk-android/supportFiles/strings_xml.json
-->
{{PLUGIN_STRINGS_XML_FILE}}
28 changes: 19 additions & 9 deletions packages/sdk-android/src/manifestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,26 @@ const _parseNode = <T extends AndroidManifestNode | AndroidResourcesNode>(n: T,
if (!SYSTEM_TAGS.includes(v)) nodeKeysCount++;
});
const isSingleLine = nodeKeysCount < 2;

let closedTag = false;
if (!n.tag) {
logWarning('Each node must have tag key!');
return;
}

if (n) {
const endLine = isSingleLine ? ' ' : '\n';
output += `${space}<${n.tag}${endLine}`;
Object.keys(n).forEach((k) => {
if (!SYSTEM_TAGS.includes(k)) {
output += `${isSingleLine ? '' : `${space} `}${k}="${n[k as keyof T]}"${endLine}`;
}
});
if ('value' in n) {
closedTag = true;
output += `${space} <${n.tag} name="${(n as AndroidResourcesNode).name}">${n.value}`;
} else {
closedTag = false;
const endLine = isSingleLine ? ' ' : '\n';
output += `${space}<${n.tag}${endLine}`;
Object.keys(n).forEach((k) => {
if (!SYSTEM_TAGS.includes(k)) {
output += `${isSingleLine ? '' : `${space} `}${k}="${n[k as keyof T]}"${endLine}`;
}
});
}
}
// else {
// output += `${space}<${n.tag}`;
Expand All @@ -98,7 +104,11 @@ const _parseNode = <T extends AndroidManifestNode | AndroidResourcesNode>(n: T,
});
output += `${space}</${n.tag}>\n`;
} else {
output += `${isSingleLine ? '' : space}/>\n`;
if (isSingleLine) {
output += '/>\n';
} else {
output += !closedTag ? `${space}/>\n` : `</${n.tag}>\n`;
}
}
return output;
};
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk-android/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ import {
} from './gradleParser';
import { parseGradleWrapperSync } from './gradleWrapperParser';
import {
parseValuesStringsSync,
injectPluginXmlValuesSync,
parseValuesColorsSync,
// injectPluginXmlValuesSync,
parseValuesXml,
} from './xmlValuesParser';
import { ejectGradleProject } from './ejector';
Expand Down Expand Up @@ -456,7 +454,7 @@ export const configureProject = async () => {
injectPluginGradleSync(plugin, pluginPlat, key);
injectPluginKotlinSync(pluginPlat, key, pluginPlat.package);
injectPluginManifestSync();
injectPluginXmlValuesSync(pluginPlat);
// injectPluginXmlValuesSync(pluginPlat);
});

c.payload.pluginConfigAndroid.pluginPackages = c.payload.pluginConfigAndroid.pluginPackages.substring(
Expand Down Expand Up @@ -496,10 +494,12 @@ export const configureProject = async () => {
parseMainActivitySync();
parseMainApplicationSync();
parseSplashActivitySync();
parseValuesStringsSync();
// parseValuesStringsSync();
parseValuesXml('strings_xml', true);
parseValuesXml('styles_xml');
parseValuesXml('colors_xml', true);
// parseValuesStylesSync();
parseValuesColorsSync();
// parseValuesColorsSync();
parseAndroidManifestSync();
parseGradlePropertiesSync();
// parseFlipperSync(c, 'debug');
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-android/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ export type TemplateAndroid = Required<Required<RenativeConfigPluginPlatform>['t
// export type AndroidManifestJSON = AndroidManifestJSONNode & {
// package?: string;
// };
export type TargetResourceFile = 'styles_xml' | 'strings_xml' | 'colors_xml';
134 changes: 33 additions & 101 deletions packages/sdk-android/src/xmlValuesParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
RenativeConfigPluginPlatform,
getAppFolder,
getConfigProp,
writeFileSync,
writeCleanFile,
getContext,
OverridesOptions,
logDefault,
readObjectSync,
AndroidResources,
Expand All @@ -15,92 +13,20 @@ import {
getFlavouredProp,
} from '@rnv/core';
import { getBuildFilePath, getAppTitle, sanitizeColor, addSystemInjects } from '@rnv/sdk-utils';
import { Payload, ResourceStyles, TemplateAndroid } from './types';
import { _convertToXML, _mergeNodeChildren, _mergeNodeParameters, getConfigPropArray } from './manifestParser';
import { TargetResourceFile } from './types';

export const parseValuesStringsSync = () => {
const c = getContext<Payload>();
const appFolder = getAppFolder();
const templateAndroid = getConfigProp('templateAndroid', {});

const resourceStrings = templateAndroid?.strings_xml?.children;
if (resourceStrings) {
resourceStrings.forEach((obj) => {
c.payload.pluginConfigAndroid.resourceStrings.push(obj);
});
}
const stringsPath = 'app/src/main/res/values/strings.xml';
let strings = '<resources>\n';
strings += ` <string name="app_name">${getAppTitle()}</string>\n`;
c.payload.pluginConfigAndroid.resourceStrings.forEach((v) => {
strings += ` <${v.tag} name="${v.name}">${v.child_value}</${v.tag}>\n`;
});
strings += '</resources>';
writeFileSync(path.join(appFolder, stringsPath), strings);
};
export const parseValuesStylesSync = () => {
const c = getContext<Payload>();
const appFolder = getAppFolder();
const templateAndroid = getConfigProp('templateAndroid', {});

const resourceStylesValues = templateAndroid?.styles_xml;

if (resourceStylesValues) {
Object.entries(resourceStylesValues).forEach(([key, values]) => {
const xmlStringObject: Partial<ResourceStyles> = {};
Object.entries(values).forEach(([childKey, children]) => {
let string = '';
children.forEach((child) => {
string += `<${child.tag} name="${child.name}">${child.child_value}</${child.tag}>\n`;
});
xmlStringObject[childKey as keyof ResourceStyles] = string;
});

if (key === 'values') {
c.payload.pluginConfigAndroid.resourceStylesValue = xmlStringObject as ResourceStyles;
} else if (key === 'values_v28') {
c.payload.pluginConfigAndroid.resourceStylesValueV28 = xmlStringObject as ResourceStyles;
}
});
}

const injects: OverridesOptions = [
{
pattern: '{{VALUES_STYLES_APP}}',
override: c.payload.pluginConfigAndroid.resourceStylesValue.app_children || '',
},
{
pattern: '{{VALUES_STYLES_SPLASH}}',
override: c.payload.pluginConfigAndroid.resourceStylesValue.splash_children || '',
},

{
pattern: '{{VALUES_V28_STYLES_APP}}',
override: c.payload.pluginConfigAndroid.resourceStylesValueV28.app_children || '',
},

{
pattern: '{{VALUES_V28_STYLES_SPLASH}}',
override: c.payload.pluginConfigAndroid.resourceStylesValueV28.splash_children || '',
},
];

addSystemInjects(injects);
const stylePath1 = 'app/src/main/res/values/styles.xml';
const stylePath2 = 'app/src/main/res/values-v28/styles.xml';
writeCleanFile(getBuildFilePath(stylePath1), path.join(appFolder, stylePath1), injects, undefined, c);
writeCleanFile(getBuildFilePath(stylePath2), path.join(appFolder, stylePath2), injects, undefined, c);
};
export const parseValuesXml = (targetRes: 'styles_xml' | 'strings_xml' | 'colors_xml') => {
export const parseValuesXml = (targetRes: TargetResourceFile, injectValue?: boolean) => {
const c = getContext();
logDefault('parseValuesStylesSync');
logDefault(`parseValuesXml: ${targetRes}`);
const { platform } = c;

const appFolder = getAppFolder();
if (!platform) return;

try {
const baseResoutcesFilePath = path.join(__dirname, `../supportFiles/${targetRes}.json`);
const baseResourcesFile = readObjectSync<AndroidResources>(baseResoutcesFilePath);
const resourceFile = `app/src/main/res/values/${targetRes.replace('_', '.')}`;

if (!baseResourcesFile) {
return;
Expand Down Expand Up @@ -130,45 +56,51 @@ export const parseValuesXml = (targetRes: 'styles_xml' | 'strings_xml' | 'colors
});

const resourceXml = _convertToXML(baseResourcesFile);
const resourceFile = `app/src/main/res/values/${targetRes.replace('_', '.')}`;
const getPattern = (): string => {
return `{{PLUGIN_${targetRes.toUpperCase()}_FILE}}`;
};
const injects = [{ pattern: getPattern(), override: resourceXml || '' }];

addSystemInjects(injects);
const injects = [{ pattern: _getPattern(targetRes), override: resourceXml || '' }];

const appFolder = getAppFolder();
writeCleanFile(getBuildFilePath(resourceFile), path.join(appFolder, resourceFile), injects, undefined, c);
addSystemInjects(injects);
const buildFilePath = getBuildFilePath(resourceFile);
const projectFilePath = path.join(appFolder, resourceFile);

if (!injectValue) {
writeCleanFile(buildFilePath, projectFilePath, injects, undefined, c);
} else {
writeCleanFile(buildFilePath, projectFilePath, injects, undefined, c);
_overrideDynamicValue(projectFilePath);
}

return;
} catch (e) {
logError(e);
}
};
export const parseValuesColorsSync = () => {

const _getPattern = (targetRes: TargetResourceFile): string => {
return `{{PLUGIN_${targetRes.toUpperCase()}_FILE}}`;
};
const _overrideDynamicValue = (stringsPath: string) => {
const c = getContext();
const appFolder = getAppFolder();
const stringsPath = 'app/src/main/res/values/colors.xml';

const injects = [
{
pattern: '{{PLUGIN_COLORS_BG}}',
override: sanitizeColor(getConfigProp('backgroundColor'), 'backgroundColor').hex,
override: sanitizeColor(getConfigProp('backgroundColor'), 'backgroundColor').hex || '#FFFFFF',
},
{ pattern: '{{APP_TITLE}}', override: getAppTitle() || '' },
];

addSystemInjects(injects);

writeCleanFile(getBuildFilePath(stringsPath), path.join(appFolder, stringsPath), injects, undefined, c);
writeCleanFile(stringsPath, stringsPath, injects, undefined, c);
};

export const injectPluginXmlValuesSync = (plugin: RenativeConfigPluginPlatform) => {
const rStrings = plugin.templateAndroid?.strings_xml?.children;
if (rStrings) {
const c = getContext();
rStrings.forEach((obj) => {
c.payload.pluginConfigAndroid.resourceStrings.push(obj);
});
}
};
// export const injectPluginXmlValuesSync = (plugin: RenativeConfigPluginPlatform) => {
// const rStrings = plugin.templateAndroid?.strings_xml?.children;
// if (rStrings) {
// const c = getContext();
// rStrings.forEach((obj) => {
// c.payload.pluginConfigAndroid.resourceStrings.push(obj);
// });
// }
// };
10 changes: 10 additions & 0 deletions packages/sdk-android/supportFiles/colors_xml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tag": "resources",
"children": [
{
"tag": "color",
"name": "bg",
"value": "{{PLUGIN_COLORS_BG}}"
}
]
}
10 changes: 10 additions & 0 deletions packages/sdk-android/supportFiles/strings_xml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tag": "resources",
"children": [
{
"tag": "string",
"name": "app_name",
"value": "{{APP_TITLE}}"
}
]
}