Skip to content

Commit

Permalink
refactor remote component generator config
Browse files Browse the repository at this point in the history
  • Loading branch information
maaaathis committed Jan 6, 2025
1 parent e8dbd2b commit 392a4fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dev/remote-components-generator/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const remoteComponentGeneratorConfig = {
ignoreComponents: ["ActionStateContext"],
components: {},
ignoreProps: ["tunnelId", "ref", "key"],
};
31 changes: 24 additions & 7 deletions dev/remote-components-generator/generateRemoteComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import jetpack from "fs-jetpack";
import { prepareTypeScriptOutput } from "./generation/prepareTypeScriptOutput";
import { generateRemoteElementFile } from "./generation/generateRemoteElementFile";
import { remoteComponentGeneratorConfig } from "./config";
import type { RemoteComponentGeneratorConfig } from "./types/config";

const componentFileLoader = new ComponentFileLoader();
const componentFileContentLoader = new ComponentFileContentLoader(
componentFileLoader,
);

async function generate() {
const config = remoteComponentGeneratorConfig;
const config: RemoteComponentGeneratorConfig = remoteComponentGeneratorConfig;

console.log("🤓 Read component specification file");
const componentSpecificationFile = await componentFileLoader.loadFile();
Expand All @@ -29,12 +30,28 @@ async function generate() {
console.log("✅ Done");
console.log("");

console.log("💣 Remove ignored components");
config.ignoreComponents.map((ignoredComponent) => {
components = components.filter(
(item) => item.displayName != ignoredComponent,
);
});
console.log("💣 Remove ignored components and props");
for (const [componentName, componentConfig] of Object.entries(
config.components,
)) {
if (componentConfig.ignore) {
console.log(` .. removing "${componentName}"`);
components = components.filter(
(item) => item.displayName != componentName,
);
}
if (componentConfig.ignoreProps) {
const component = components.find(
(item) => item.displayName == componentName,
);
if (component?.props) {
componentConfig.ignoreProps.map((ignoredProp) => {
console.log(` .. removing ${componentName}'s "${ignoredProp}" prop`);
delete component.props[ignoredProp];
});
}
}
}
console.log("✅ Done");
console.log("");

Expand Down
9 changes: 9 additions & 0 deletions dev/remote-components-generator/types/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface RemoteComponentGeneratorConfigComponent {
ignore?: boolean;
ignoreProps?: string[];
}

export interface RemoteComponentGeneratorConfig {
components: Record<string, RemoteComponentGeneratorConfigComponent>;
ignoreProps: string[];
}

0 comments on commit 392a4fa

Please sign in to comment.