Skip to content

Commit 2a20b19

Browse files
committed
feat: Added importing of resources and selection flow
1 parent 0f29c04 commit 2a20b19

File tree

24 files changed

+318
-49
lines changed

24 files changed

+318
-49
lines changed

package-lock.json

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
"ajv": "^8.12.0",
1515
"ajv-formats": "^3.0.1",
1616
"chalk": "^5.3.0",
17-
"codify-schemas": "^1.0.73",
17+
"codify-schemas": "^1.0.74",
1818
"debug": "^4.3.4",
1919
"detect-indent": "^7.0.1",
2020
"diff": "^7.0.0",
2121
"ink": "^5.1.0",
2222
"ink-big-text": "^2.0.0",
2323
"ink-gradient": "^3.0.0",
2424
"ink-select-input": "^6.0.0",
25-
"@fforres/ink-quicksearch-input": "^1.0.1",
2625
"jotai": "^2.11.1",
2726
"js-yaml": "^4.1.0",
2827
"js-yaml-source-map": "^0.2.2",

src/commands/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs/promises';
22

33
import { BaseCommand } from '../common/base-command.js';
4+
import { InitializeOrchestrator } from '../orchestrators/initialize.js';
45
import { ShellUtils } from '../utils/shell.js';
56

67
export default class Init extends BaseCommand {
@@ -35,7 +36,7 @@ Codify will try to smartly insert new configs by following existing spacing and
3536
public async run(): Promise<void> {
3637
const { raw, flags } = await this.parse(Init)
3738

38-
this.reporter.displayInitBanner()
39+
await InitializeOrchestrator.run(this.reporter);
3940

4041
// if (flags.path) {
4142
// this.log(`Applying Codify from: ${flags.path}`);

src/events/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export enum ProcessName {
2222
PLAN = 'plan',
2323
DESTROY = 'destroy',
2424
IMPORT = 'import',
25+
INIT = 'init',
2526
}
2627

2728
export enum SubProcessName {

src/orchestrators/destroy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ProcessName, SubProcessName, ctx } from '../events/context.js';
55
import { DependencyMap, PluginManager } from '../plugins/plugin-manager.js';
66
import { Reporter } from '../ui/reporters/reporter.js';
77
import { getTypeAndNameFromId } from '../utils/index.js';
8-
import { InitializeOrchestrator } from './initialize-plugins.js';
8+
import { PluginInitOrchestrator } from './initialize-plugins.js';
99

1010
export interface DestroyArgs {
1111
ids: string[];
@@ -23,7 +23,7 @@ export class DestroyOrchestrator {
2323

2424
ctx.processStarted(ProcessName.DESTROY)
2525

26-
const { typeIdsToDependenciesMap, pluginManager, project } = await InitializeOrchestrator.run({
26+
const { typeIdsToDependenciesMap, pluginManager, project } = await PluginInitOrchestrator.run({
2727
...args,
2828
allowEmptyProject: true,
2929
transformProject(project) {

src/orchestrators/import.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { FileUtils } from '../utils/file.js';
1212
import { FileModificationCalculator, ModificationType } from '../utils/file-modification-calculator.js';
1313
import { groupBy, sleep } from '../utils/index.js';
1414
import { wildCardMatch } from '../utils/wild-card-match.js';
15-
import { InitializationResult, InitializeOrchestrator } from './initialize-plugins.js';
15+
import { InitializationResult, PluginInitOrchestrator } from './initialize-plugins.js';
1616

1717
export type ImportResult = { result: ResourceConfig[], errors: string[] }
1818

@@ -47,7 +47,7 @@ export class ImportOrchestrator {
4747
const typeIds = args.typeIds?.filter(Boolean)
4848
ctx.processStarted(ProcessName.IMPORT)
4949

50-
const initializationResult = await InitializeOrchestrator.run(
50+
const initializationResult = await PluginInitOrchestrator.run(
5151
{ ...args, allowEmptyProject: true },
5252
reporter
5353
);

src/orchestrators/initialize-plugins.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ export interface InitializationResult {
2121
project: Project,
2222
}
2323

24-
export class InitializeOrchestrator {
24+
export class PluginInitOrchestrator {
2525
static async run(
2626
args: InitializeArgs,
2727
reporter: Reporter,
2828
): Promise<InitializationResult> {
29-
let project = await InitializeOrchestrator.parse(
29+
let project = await PluginInitOrchestrator.parse(
3030
args.path,
3131
args.allowEmptyProject ?? false,
3232
reporter
@@ -51,7 +51,7 @@ export class InitializeOrchestrator {
5151
ctx.subprocessStarted(SubProcessName.PARSE);
5252

5353
const pathToParse = (fileOrDir === undefined)
54-
? await InitializeOrchestrator.findCodifyJson()
54+
? await PluginInitOrchestrator.findCodifyJson()
5555
: fileOrDir
5656

5757
if (!pathToParse && !allowEmptyProject) {

src/orchestrators/initialize.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ProcessName, ctx } from '../events/context.js';
2+
import { Reporter } from '../ui/reporters/reporter.js';
3+
import { PluginInitOrchestrator } from './initialize-plugins.js';
4+
5+
export const InitializeOrchestrator = {
6+
7+
async run(reporter: Reporter) {
8+
await reporter.displayInitBanner()
9+
10+
ctx.processStarted(ProcessName.INIT)
11+
await reporter.displayProgress();
12+
13+
14+
const { pluginManager, typeIdsToDependenciesMap } = await PluginInitOrchestrator.run({}, reporter);
15+
16+
const importResults = await Promise.all([...typeIdsToDependenciesMap.keys()].map(async (typeId) => {
17+
try {
18+
return await pluginManager.importResource({
19+
core: { type: typeId },
20+
parameters: {}
21+
}, true);
22+
} catch {
23+
return null;
24+
}
25+
}))
26+
27+
const flattenedResults = importResults.filter(Boolean).flatMap(p => p?.result).filter(Boolean)
28+
29+
const userSelectedTypes = await reporter.promptInitResultSelection([...new Set(flattenedResults.map((r) => r!.core.type))])
30+
31+
ctx.processFinished(ProcessName.INIT);
32+
33+
console.log(JSON.stringify(flattenedResults, null, 2));
34+
},
35+
36+
37+
};

src/orchestrators/plan.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Plan } from '../entities/plan.js';
22
import { Project } from '../entities/project.js';
33
import { ProcessName, SubProcessName, ctx } from '../events/context.js';
4-
import { DependencyMap, PluginManager } from '../plugins/plugin-manager.js';
4+
import { PluginManager } from '../plugins/plugin-manager.js';
55
import { Reporter } from '../ui/reporters/reporter.js';
66
import { createStartupShellScriptsIfNotExists } from '../utils/file.js';
7-
import { InitializeOrchestrator } from './initialize-plugins.js';
7+
import { PluginInitOrchestrator } from './initialize-plugins.js';
88
import { ValidateOrchestrator } from './validate.js';
99

1010
export interface PlanArgs {
@@ -22,7 +22,7 @@ export class PlanOrchestrator {
2222
static async run(args: PlanArgs, reporter: Reporter): Promise<PlanOrchestratorResponse> {
2323
ctx.processStarted(ProcessName.PLAN)
2424

25-
const initializationResult = await InitializeOrchestrator.run({
25+
const initializationResult = await PluginInitOrchestrator.run({
2626
...args,
2727
}, reporter);
2828
const { typeIdsToDependenciesMap, pluginManager, project } = initializationResult;

src/orchestrators/validate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SubProcessName, ctx } from '../events/context.js';
22
import { Reporter } from '../ui/reporters/reporter.js';
3-
import { InitializationResult, InitializeOrchestrator } from './initialize-plugins.js';
3+
import { InitializationResult, PluginInitOrchestrator } from './initialize-plugins.js';
44

55
export interface ValidateArgs {
66
existing?: InitializationResult;
@@ -17,7 +17,7 @@ export const ValidateOrchestrator = {
1717
project,
1818
typeIdsToDependenciesMap: dependencyMap,
1919
pluginManager,
20-
} = args.existing ?? await InitializeOrchestrator.run(args, reporter)
20+
} = args.existing ?? await PluginInitOrchestrator.run(args, reporter)
2121

2222
if (args.existing) {
2323
ctx.subprocessStarted(SubProcessName.VALIDATE)

0 commit comments

Comments
 (0)