Skip to content

Commit a28068d

Browse files
committed
feat: Moved validation to a separate orchestrator and added validation for improts
1 parent 95f23e9 commit a28068d

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

src/orchestrators/import.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { FileModificationCalculator, ModificationType } from '../utils/file-modi
1313
import { groupBy, sleep } from '../utils/index.js';
1414
import { wildCardMatch } from '../utils/wild-card-match.js';
1515
import { InitializationResult, InitializeOrchestrator } from './initialize.js';
16+
import { ValidateOrchestrator } from './validate.js';
1617

1718
export type ImportResult = { result: ResourceConfig[], errors: string[] }
1819

@@ -57,7 +58,13 @@ export class ImportOrchestrator {
5758
throw new Error('At least one resource [type] must be specified. Ex: "codify import homebrew". Or the import command must be run in a directory with a valid codify file')
5859
}
5960

60-
await (!typeIds || typeIds.length === 0 ? ImportOrchestrator.runExistingProject(reporter, initializationResult) : ImportOrchestrator.runNewImport(typeIds, reporter, initializationResult));
61+
await ValidateOrchestrator.run({ existing: initializationResult }, reporter);
62+
63+
if (!typeIds || typeIds.length === 0) {
64+
await ImportOrchestrator.runExistingProject(reporter, initializationResult);
65+
} else {
66+
await ImportOrchestrator.runNewImport(typeIds, reporter, initializationResult)
67+
}
6168
}
6269

6370
/** Import new resources. Type ids supplied. This will ask for any required parameters */

src/orchestrators/plan.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DependencyMap, PluginManager } from '../plugins/plugin-manager.js';
55
import { Reporter } from '../ui/reporters/reporter.js';
66
import { createStartupShellScriptsIfNotExists } from '../utils/file.js';
77
import { InitializeOrchestrator } from './initialize.js';
8+
import { ValidateOrchestrator } from './validate.js';
89

910
export interface PlanArgs {
1011
path?: string;
@@ -21,13 +22,14 @@ export class PlanOrchestrator {
2122
static async run(args: PlanArgs, reporter: Reporter): Promise<PlanOrchestratorResponse> {
2223
ctx.processStarted(ProcessName.PLAN)
2324

24-
const { typeIdsToDependenciesMap, pluginManager, project } = await InitializeOrchestrator.run({
25+
const initializationResult = await InitializeOrchestrator.run({
2526
...args,
2627
}, reporter);
28+
const { typeIdsToDependenciesMap, pluginManager, project } = initializationResult;
2729

2830
await createStartupShellScriptsIfNotExists();
2931

30-
await PlanOrchestrator.validate(project, pluginManager, typeIdsToDependenciesMap)
32+
await ValidateOrchestrator.run({ existing: initializationResult }, reporter);
3133
project.resolveDependenciesAndCalculateEvalOrder(typeIdsToDependenciesMap);
3234
project.addXCodeToolsConfig(); // We have to add xcode-tools config always since almost every resource depends on it
3335

@@ -46,16 +48,6 @@ export class PlanOrchestrator {
4648
};
4749
}
4850

49-
private static async validate(project: Project, pluginManager: PluginManager, dependencyMap: DependencyMap) {
50-
ctx.subprocessStarted(SubProcessName.VALIDATE)
51-
52-
project.validateTypeIds(dependencyMap);
53-
const validationResults = await pluginManager.validate(project);
54-
project.handlePluginResourceValidationResults(validationResults);
55-
56-
ctx.subprocessFinished(SubProcessName.VALIDATE)
57-
}
58-
5951
private static async plan(project: Project, pluginManager: PluginManager): Promise<Plan> {
6052
ctx.subprocessStarted(SubProcessName.GENERATE_PLAN)
6153
const plan = await pluginManager.plan(project);

src/orchestrators/validate.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ctx, SubProcessName } from '../events/context.js';
2+
import { DependencyMap, PluginManager } from '../plugins/plugin-manager.js';
3+
import { Project } from '../entities/project.js';
4+
import { InitializationResult, InitializeOrchestrator } from './initialize.js';
5+
import { Reporter } from '../ui/reporters/reporter.js';
6+
7+
export interface ValidateArgs {
8+
existing?: InitializationResult;
9+
path?: string;
10+
}
11+
12+
export class ValidateOrchestrator {
13+
14+
static async run(
15+
args: ValidateArgs,
16+
reporter: Reporter
17+
): Promise<void> {
18+
const {
19+
project,
20+
typeIdsToDependenciesMap: dependencyMap,
21+
pluginManager,
22+
} = args.existing ?? await InitializeOrchestrator.run(args, reporter)
23+
24+
if (args.existing) {
25+
ctx.subprocessStarted(SubProcessName.VALIDATE)
26+
} else {
27+
ctx.processStarted(SubProcessName.VALIDATE)
28+
}
29+
30+
project.validateTypeIds(dependencyMap);
31+
const validationResults = await pluginManager.validate(project);
32+
project.handlePluginResourceValidationResults(validationResults);
33+
34+
if (args.existing) {
35+
ctx.subprocessFinished(SubProcessName.VALIDATE)
36+
} else {
37+
ctx.processFinished(SubProcessName.VALIDATE)
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)