Skip to content

Commit

Permalink
improvement(new), warn for deprecated starter (#9161)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfirst authored Aug 30, 2024
1 parent 3ab2db4 commit 5a70ac7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions scopes/generator/generator/generator.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TrackerAspect, TrackerMain } from '@teambit/tracker';
import { NewComponentHelperAspect, NewComponentHelperMain } from '@teambit/new-component-helper';
import { compact, uniq } from 'lodash';
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
import { DeprecationAspect, DeprecationMain } from '@teambit/deprecation';
import { ComponentTemplate } from './component-template';
import { GeneratorAspect } from './generator.aspect';
import { CreateCmd, CreateOptions } from './create.cmd';
Expand Down Expand Up @@ -90,7 +91,8 @@ export class GeneratorMain {
private tracker: TrackerMain,
private logger: Logger,
private git: GitMain,
private wsConfigFiles: WorkspaceConfigFilesMain
private wsConfigFiles: WorkspaceConfigFilesMain,
private deprecation: DeprecationMain
) {}

/**
Expand Down Expand Up @@ -380,10 +382,20 @@ the reason is that after refactoring, the code will have this invalid class: "cl

if (!workspaceTemplate) throw new BitError(`template "${templateName}" was not found`);
const workspaceGenerator = new WorkspaceGenerator(workspaceName, workspacePath, options, workspaceTemplate, aspect);
await this.warnAboutDeprecation(aspect);
await workspaceGenerator.generate();
return { workspacePath, appName: workspaceTemplate.appName };
}

private async warnAboutDeprecation(aspect?: Component) {
if (!aspect) return;
const deprecationInfo = await this.deprecation.getDeprecationInfo(aspect);
if (deprecationInfo.isDeprecate) {
const newStarterMsg = deprecationInfo.newId ? `, use "${deprecationInfo.newId.toString()}" instead` : '';
this.logger.consoleWarning(`the starter "${aspect?.id.toString()}" is deprecated${newStarterMsg}`);
}
}

private async getAllComponentTemplatesDescriptorsFlattened(aspectId?: string): Promise<Array<TemplateDescriptor>> {
const envTemplates = await this.listEnvComponentTemplateDescriptors([], aspectId);
if (envTemplates && envTemplates.length) {
Expand Down Expand Up @@ -541,6 +553,7 @@ the reason is that after refactoring, the code will have this invalid class: "cl
LoggerAspect,
GitAspect,
WorkspaceConfigFilesAspect,
DeprecationAspect,
];

static runtime = MainRuntime;
Expand All @@ -558,6 +571,7 @@ the reason is that after refactoring, the code will have this invalid class: "cl
loggerMain,
git,
wsConfigFiles,
deprecation,
]: [
Workspace,
CLIMain,
Expand All @@ -569,7 +583,8 @@ the reason is that after refactoring, the code will have this invalid class: "cl
TrackerMain,
LoggerMain,
GitMain,
WorkspaceConfigFilesMain
WorkspaceConfigFilesMain,
DeprecationMain
],
config: GeneratorConfig,
[componentTemplateSlot, workspaceTemplateSlot, onComponentCreateSlot]: [
Expand All @@ -592,7 +607,8 @@ the reason is that after refactoring, the code will have this invalid class: "cl
tracker,
logger,
git,
wsConfigFiles
wsConfigFiles,
deprecation
);
const commands = [new CreateCmd(generator), new TemplatesCmd(generator), new NewCmd(generator)];
cli.register(...commands);
Expand Down

0 comments on commit 5a70ac7

Please sign in to comment.