Skip to content

Commit 51ed202

Browse files
committed
Cleaned up apply and plan orchastrators
1 parent c8b0727 commit 51ed202

21 files changed

Lines changed: 71 additions & 93 deletions

src/commands/apply/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Args, Command, Flags } from '@oclif/core'
22
import path from 'node:path';
3-
4-
import { ApplyOrchestrator } from './orchestrator.js';
3+
import { ApplyOrchestrator } from '../../orchestrators/apply.js';
54

65
export default class Apply extends Command {
76
static args = {

src/commands/apply/orchestrator.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/commands/plan/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Args, Command, Flags } from '@oclif/core'
22
import * as path from 'node:path';
3-
4-
import { PlanOrchestrator } from './orchestrator.js';
3+
import { PlanOrchestrator } from '../../orchestrators/plan.js';
54

65
export default class Plan extends Command {
76
static args = {

src/commands/plan/orchestrator.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/entities/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigClass } from '../config-parser/language-definition.js';
1+
import { ConfigClass } from '../parser/language-definition.js';
22

33
export interface ConfigBlock {
44
configClass: ConfigClass;

src/entities/project-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ProjectSchema } from 'codify-schemas';
22

3-
import { ConfigClass } from '../config-parser/language-definition.js';
3+
import { ConfigClass } from '../parser/language-definition.js';
44
import { ajv } from '../utils/ajv.js';
55
import { RemoveMethods } from '../utils/types.js';
66
import { ConfigBlock } from './index.js';

src/entities/resource-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ResourceSchema } from 'codify-schemas';
22

3-
import { ConfigClass } from '../config-parser/language-definition.js';
3+
import { ConfigClass } from '../parser/language-definition.js';
44
import { ajv } from '../utils/ajv.js';
55
import { RemoveMethods } from '../utils/types.js';
66
import { ConfigBlock } from './index.js';

src/orchestrators/apply.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import readline from 'node:readline';
2+
3+
import { PlanOrchestrator } from './plan.js';
4+
5+
const rl = readline.createInterface(process.stdin, process.stdout);
6+
7+
export const ApplyOrchestrator = {
8+
async run(rootDirectory: string): Promise<void> {
9+
const { plan, pluginCollection } = await PlanOrchestrator.run(rootDirectory, false);
10+
11+
const response = await new Promise((resolve) => {
12+
rl.question('Is this okay?\n', (answer) => resolve(answer));
13+
});
14+
if (response !== 'yes') {
15+
return;
16+
}
17+
18+
await pluginCollection.apply(plan);
19+
await pluginCollection.destroy();
20+
},
21+
};

src/orchestrators/plan.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { PlanResponseData } from 'codify-schemas';
2+
3+
import { Project } from '../entities/project.js';
4+
import { Parser } from '../parser/index.js';
5+
import { PluginCollection } from '../plugins/plugin-collection.js';
6+
7+
interface PlanOchestratorResponse {
8+
plan: PlanResponseData[],
9+
pluginCollection: PluginCollection;
10+
project: Project;
11+
}
12+
13+
export const PlanOrchestrator = {
14+
async run(rootDirectory: string, destroyPlugins = true): Promise<PlanOchestratorResponse> {
15+
const project = await Parser.parseProject(rootDirectory);
16+
17+
const pluginCollection = new PluginCollection();
18+
const dependencyMap = await pluginCollection.initialize(project);
19+
project.validateWithResourceMap(dependencyMap);
20+
project.resolveResourceDependencies(dependencyMap);
21+
22+
const validationResults = await pluginCollection.validate(project);
23+
project.handlePluginResourceValidationResults(validationResults);
24+
project.calculateEvaluationOrder();
25+
26+
const plan = await pluginCollection.getPlan(project);
27+
console.log(JSON.stringify(plan, null, 2));
28+
29+
if (destroyPlugins) {
30+
await pluginCollection.destroy();
31+
}
32+
33+
return {
34+
plan,
35+
pluginCollection,
36+
project,
37+
};
38+
},
39+
};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { JsonFileParser } from './parser/json/file-parser.js';
88
import { ProjectReader } from './reader/index.js';
99
import { ConfigBlock } from '../entities/index.js';
1010

11-
export class ConfigParser {
11+
export class Parser {
1212

1313
static readonly supportedParsers: Record<string, FileParser> = {
1414
'json': new JsonFileParser(),
@@ -19,7 +19,7 @@ export class ConfigParser {
1919
const loadedProject = await configReader.readProject(directory);
2020

2121
const configBlocksResult = await Promise.all(loadedProject.files.map((file) => {
22-
const parser = ConfigParser.supportedParsers[file.fileType];
22+
const parser = Parser.supportedParsers[file.fileType];
2323
if (!parser) {
2424
throw new InternalError(`Unsupported file format loaded into parser: ${file.fileName}`);
2525
}
@@ -28,7 +28,7 @@ export class ConfigParser {
2828
}));
2929

3030
const configBlocks = configBlocksResult.flat(1);
31-
const projectConfig = ConfigParser.findProjectConfig(configBlocks);
31+
const projectConfig = Parser.findProjectConfig(configBlocks);
3232

3333
return new Project(
3434
projectConfig,

0 commit comments

Comments
 (0)