Skip to content

Commit ccbe144

Browse files
committed
Added additional plugin integration and fixed build
1 parent 3c56fed commit ccbe144

10 files changed

Lines changed: 60 additions & 22 deletions

File tree

codify-core/README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@ describe the command here
134134

135135
```
136136
USAGE
137-
$ codify plan [FILE] [-f] [-n <value>]
137+
$ codify plan [FILE] [-f] [-n <value>] [-p <value>]
138138
139139
ARGUMENTS
140140
FILE file to read
141141
142142
FLAGS
143143
-f, --force
144144
-n, --name=<value> name to print
145+
-p, --path=<value> path to project
145146
146147
DESCRIPTION
147148
describe the command here
@@ -150,7 +151,7 @@ EXAMPLES
150151
$ codify plan
151152
```
152153

153-
_See code: [src/commands/plan.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/plan.ts)_
154+
_See code: [src/commands/plan/index.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/plan/index.ts)_
154155

155156
## `codify plugins`
156157

@@ -173,7 +174,7 @@ EXAMPLES
173174
$ codify plugins
174175
```
175176

176-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/index.ts)_
177+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/index.ts)_
177178

178179
## `codify plugins:install PLUGIN...`
179180

@@ -238,7 +239,7 @@ EXAMPLES
238239
$ codify plugins:inspect myplugin
239240
```
240241

241-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/inspect.ts)_
242+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/inspect.ts)_
242243

243244
## `codify plugins:install PLUGIN...`
244245

@@ -278,7 +279,7 @@ EXAMPLES
278279
$ codify plugins:install someuser/someplugin
279280
```
280281

281-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/install.ts)_
282+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/install.ts)_
282283

283284
## `codify plugins:link PLUGIN`
284285

@@ -292,8 +293,9 @@ ARGUMENTS
292293
PATH [default: .] path to plugin
293294
294295
FLAGS
295-
-h, --help Show CLI help.
296+
-h, --help Show CLI help.
296297
-v, --verbose
298+
--[no-]install Install dependencies after linking the plugin.
297299
298300
DESCRIPTION
299301
Links a plugin into the CLI for development.
@@ -307,7 +309,7 @@ EXAMPLES
307309
$ codify plugins:link myplugin
308310
```
309311

310-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/link.ts)_
312+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/link.ts)_
311313

312314
## `codify plugins:uninstall PLUGIN...`
313315

@@ -355,7 +357,8 @@ ALIASES
355357
$ codify plugins remove
356358
```
357359

358-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/uninstall.ts)_
360+
_See
361+
code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/uninstall.ts)_
359362

360363
## `codify plugins:uninstall PLUGIN...`
361364

@@ -396,5 +399,5 @@ DESCRIPTION
396399
Update installed plugins.
397400
```
398401

399-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.8.4/src/commands/plugins/update.ts)_
402+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/update.ts)_
400403
<!-- commandsstop -->

codify-core/src/commands/plan/orchestrator.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import { ConfigCompiler } from '../../config-compiler';
22
import { PluginCollection } from '../../plugins/plugin-collection';
33

44
export const PlanOrchestrator = {
5-
async run(rootDirectory: string): Promise<void> {
5+
async run(rootDirectory: string): Promise<string> {
66
const project = await ConfigCompiler.parseProject(rootDirectory);
77

88
const pluginCollection = await PluginCollection.create(project);
99
const resourceDefinitions = await pluginCollection.getAllResourceDefinitions();
1010

1111
await ConfigCompiler.analyzeProject(project, resourceDefinitions);
12-
await pluginCollection.getPlan(project);
13-
14-
// console.log(project.coreModule.configBlocks);
12+
const plan = await pluginCollection.getPlan(project);
1513

1614
await pluginCollection.destroy();
15+
return JSON.stringify(plan, null, 2);
1716
},
1817
};

codify-core/src/plugins/plugin-collection.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { ConfigBlockType } from '../config-compiler/language-definition';
12
import { ParsedProject } from '../config-compiler/parser/entities';
3+
import { ResourceConfig } from '../config-compiler/parser/entities/resource';
24
import { ResourceDefinition } from '../entities/resource-definition';
35
import { Plugin } from './entities/plugin';
46
import { PluginResolver } from './resolver';
5-
import { ConfigBlockType } from '../config-compiler/language-definition';
6-
import { ResourceConfig } from '../config-compiler/parser/entities/resource';
77

88
type PluginName = string;
99

@@ -56,7 +56,8 @@ export class PluginCollection {
5656
return result;
5757
}
5858

59-
async getPlan(project: ParsedProject): Promise<void> {
59+
async getPlan(project: ParsedProject): Promise<Array<string>> {
60+
const result = new Array<string>();
6061
for (const config of project.coreModule.configBlocks) {
6162
if (config.configType !== ConfigBlockType.RESOURCE) {
6263
continue;
@@ -73,9 +74,10 @@ export class PluginCollection {
7374
}
7475

7576
// eslint-disable-next-line no-await-in-loop
76-
const result = await plugin.generateResourcePlan(config as ResourceConfig);
77-
console.log(result);
77+
result.push(await plugin.generateResourcePlan(config as ResourceConfig) as string);
7878
}
79+
80+
return result;
7981
}
8082

8183
async destroy(): Promise<void> {

codify-core/src/plugins/resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class PluginResolver {
1919
private static async resolveDefaultPlugin(name: string, _version: string): Promise<Plugin> {
2020
const pluginName = name.match(DEFAULT_PLUGIN_REGEX)![0]
2121

22-
const defaultPluginDir = '../plugins';
22+
const defaultPluginDir = '/Users/kevinwang/Projects/codify/plugins';
2323
const pluginDirFiles = await fs.readdir(defaultPluginDir);
2424
if (!pluginDirFiles.includes(pluginName)) {
2525
throw new Error(`Unable to find default plugin: ${name}`)

codify-core/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
"strict": true,
88
"target": "es2022"
99
},
10-
"include": ["src/**/*"]
10+
"include": [
11+
"src/**/*"
12+
],
13+
"exclude": [
14+
"src/**/*.test.ts"
15+
]
1116
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "main",
33
"parameters": {
4-
"directory": "string"
4+
"version": "string",
5+
"taps": "array",
6+
"formulae": "object",
7+
"cask": "array"
58
}
69
}

plugins/homebrew/src/library/entities/plan.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
import { Resource } from "./resource";
2+
13
export enum PlanOperation {
24
NO_CHANGE = 'no_change',
35
ADD = 'add',
46
DELETE = 'delete',
57
MODIFY = 'modify'
68
}
79

10+
export interface ResourcePlan {
11+
resourceName: string;
12+
operation: PlanOperation;
13+
14+
parameters: Array<ResourceParameterPlan>;
15+
}
16+
817
export interface ResourceParameterPlan {
918
parameterName: string;
1019
previousValue: any;

plugins/homebrew/src/library/entities/plugin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Resource } from "./resource";
22
import { Message } from "../ipc/entities";
3+
import { PlanOperation, ResourcePlan } from "./plan";
34

45
export abstract class Plugin {
56

@@ -15,6 +16,17 @@ export abstract class Plugin {
1516
return definitions.flat(1);
1617
}
1718

19+
async generateResourcePlan(message: Message): Promise<ResourcePlan> {
20+
// @ts-ignore
21+
const { type } = message.data;
22+
23+
return {
24+
resourceName: type,
25+
operation: PlanOperation.NO_CHANGE,
26+
parameters: [],
27+
}
28+
}
29+
1830
async onDestroy(): Promise<void> {}
1931

2032
}

plugins/homebrew/src/library/entities/resource-definition.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export interface ResourceDefinition {
55

66
type ResourceParameter = [] | boolean | null | number | object | string
77

8-
98
export interface ResourceParameterDefinition {
109
name: string;
1110
type: ResourceParameterType

plugins/homebrew/src/library/ipc/message-handlers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {validateMessage} from "../utils/validators";
44

55
const MESSAGE_HANDLERS: Record<string, (plugin: Plugin, message: Message) => Promise<void>> = {
66
'getResourceDefinitions': getResourceDefinitions,
7+
'generateResourcePlan': generateResourcePlan,
78
}
89

910
export async function onMessage(plugin: Plugin, message: unknown) {
@@ -21,3 +22,8 @@ async function getResourceDefinitions(plugin: Plugin, message: Message): Promise
2122
const data = await plugin.getResourceDefinitions(message);
2223
process.send!({ cmd: message.cmd + 'Result', data });
2324
}
25+
26+
async function generateResourcePlan(plugin: Plugin, message: Message): Promise<void> {
27+
const data = await plugin.generateResourcePlan(message);
28+
process.send!({ cmd: message.cmd + 'Result', data });
29+
}

0 commit comments

Comments
 (0)