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(workspace-generator): add context to fork & import functions #7553

Merged
merged 1 commit into from
Jun 21, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions scopes/generator/generator/workspace-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,21 @@ export class WorkspaceGenerator {
await uiMain.createRuntime({});
}

/**
* writes the generated template files to the default directory set in the workspace config
*/
private async writeWorkspaceFiles(): Promise<void> {
const workspaceContext: WorkspaceContext = {
private getWorkspaceContext(): WorkspaceContext {
return {
name: this.workspaceName,
defaultScope: this.options.defaultScope,
empty: this.options.empty,
aspectComponent: this.aspectComponent,
template: this.template,
};
}

/**
* writes the generated template files to the default directory set in the workspace config
*/
private async writeWorkspaceFiles(): Promise<void> {
const workspaceContext = this.getWorkspaceContext();
const templateFiles = await this.template.generateFiles(workspaceContext);
await Promise.all(
templateFiles.map(async (templateFile) => {
Expand All @@ -119,7 +123,9 @@ export class WorkspaceGenerator {

private async forkComponentsFromRemote() {
if (this.options.empty) return;
const componentsToFork = this.template?.importComponents?.() || this.template?.fork?.() || [];
const workspaceContext = this.getWorkspaceContext();
const componentsToFork =
this.template?.importComponents?.(workspaceContext) || this.template?.fork?.(workspaceContext) || [];
if (!componentsToFork.length) return;
const componentsToForkRestructured = componentsToFork.map(({ id, targetName, path }) => ({
sourceId: id,
Expand All @@ -137,7 +143,8 @@ export class WorkspaceGenerator {

private async importComponentsFromRemote() {
if (this.options.empty) return;
const componentsToImport = this.template?.import?.() || [];
const workspaceContext = this.getWorkspaceContext();
const componentsToImport = this.template?.import?.(workspaceContext) || [];

if (!componentsToImport.length) return;

Expand Down
6 changes: 3 additions & 3 deletions scopes/generator/generator/workspace-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ export interface WorkspaceTemplate {
* @deprecated use `fork()` or `import()` instead
* this is working similarly to `fork()`
*/
importComponents?: () => ForkComponentInfo[];
importComponents?: (context: WorkspaceContext) => ForkComponentInfo[];

/**
* import components into the new workspace, don't change their source code.
*/
import?: () => ImportComponentInfo[];
import?: (context: WorkspaceContext) => ImportComponentInfo[];

/**
* populate existing components into the new workspace and add them as new components.
* change their source code and update the dependency names according to the new component names.
*/
fork?: () => ForkComponentInfo[];
fork?: (context: WorkspaceContext) => ForkComponentInfo[];
}