Skip to content

Commit 780ad3e

Browse files
committed
feat: Improved init experience (always new project for init)
1 parent 5d9b8be commit 780ad3e

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/common/initialize-plugins.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface InitializeArgs {
1717
verbosityLevel?: number;
1818
transformProject?: (project: Project) => Project | Promise<Project>;
1919
allowEmptyProject?: boolean;
20+
forceEmptyProject?: boolean;
2021
}
2122

2223
export interface InitializationResult {
@@ -30,14 +31,10 @@ export class PluginInitOrchestrator {
3031
args: InitializeArgs,
3132
reporter: Reporter,
3233
): Promise<InitializationResult> {
33-
const codifyPath = await PluginInitOrchestrator.resolveCodifyRootPath(args, reporter);
34-
35-
let project = await PluginInitOrchestrator.parse(
36-
codifyPath,
34+
const project = await PluginInitOrchestrator.parseProject(
35+
args,
36+
reporter
3737
);
38-
if (args.transformProject) {
39-
project = await args.transformProject(project);
40-
}
4138

4239
ctx.subprocessStarted(SubProcessName.INITIALIZE_PLUGINS)
4340
const pluginManager = new PluginManager();
@@ -47,18 +44,28 @@ export class PluginInitOrchestrator {
4744
return { resourceDefinitions, pluginManager, project };
4845
}
4946

50-
private static async parse(
51-
fileOrDir: string | undefined,
47+
private static async parseProject(
48+
args: InitializeArgs,
49+
reporter: Reporter,
5250
): Promise<Project> {
51+
if (args.forceEmptyProject) {
52+
return Project.empty();
53+
}
54+
55+
const codifyPath = await PluginInitOrchestrator.resolveCodifyRootPath(args, reporter);
5356
ctx.subprocessStarted(SubProcessName.PARSE);
5457

55-
const project = fileOrDir
56-
? await CodifyParser.parse(fileOrDir)
58+
const project = codifyPath
59+
? await CodifyParser.parse(codifyPath)
5760
: Project.empty()
5861

5962
ctx.subprocessFinished(SubProcessName.PARSE);
6063

61-
return project
64+
if (args.transformProject) {
65+
return args.transformProject(project);
66+
}
67+
68+
return project;
6269
}
6370

6471
/** Resolve the root codify file to run.

src/orchestrators/init.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export const InitializeOrchestrator = {
2424
await reporter.displayProgress();
2525

2626

27-
const { pluginManager, resourceDefinitions } = await PluginInitOrchestrator.run(args, reporter);
27+
const { pluginManager, resourceDefinitions } = await PluginInitOrchestrator.run({
28+
...args,
29+
forceEmptyProject: true,
30+
}, reporter);
2831

2932
ctx.subprocessStarted(SubProcessName.IMPORT_RESOURCE)
3033

0 commit comments

Comments
 (0)