Skip to content

Commit 1ae2e19

Browse files
committed
Fixed dependency-graph-resolver bugs. Added tests for dependency-graph-resolver. Added xcode-tools config by default for all plans and applies. Made all other resource blocks depend on xcode-tools. Renamed config file from index.ts to config.ts.
1 parent 6a50aa4 commit 1ae2e19

14 files changed

Lines changed: 103 additions & 210 deletions

README.md

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ USAGE
2828
# Commands
2929
<!-- commands -->
3030
* [`codify apply [FILE]`](#codify-apply-file)
31-
* [`codify hello PERSON`](#codify-hello-person)
32-
* [`codify hello world`](#codify-hello-world)
3331
* [`codify help [COMMANDS]`](#codify-help-commands)
3432
* [`codify plan [FILE]`](#codify-plan-file)
3533
* [`codify plugins`](#codify-plugins)
@@ -41,21 +39,27 @@ USAGE
4139
* [`codify plugins:uninstall PLUGIN...`](#codify-pluginsuninstall-plugin-1)
4240
* [`codify plugins:uninstall PLUGIN...`](#codify-pluginsuninstall-plugin-2)
4341
* [`codify plugins update`](#codify-plugins-update)
44-
* [`codify uninstall RESOURCES`](#codify-uninstall-resources)
42+
* [`codify uninstall`](#codify-uninstall)
4543

4644
## `codify apply [FILE]`
4745

4846
describe the command here
4947

5048
```
5149
USAGE
52-
$ codify apply [FILE] [-p <value>]
50+
$ codify apply [FILE] [--json] [-o plain|default|debug|json] [--debug] [-p <value>]
5351
5452
ARGUMENTS
5553
FILE file to read
5654
5755
FLAGS
58-
-p, --path=<value> path to project
56+
-o, --output=<option> [default: default]
57+
<options: plain|default|debug|json>
58+
-p, --path=<value> path to project
59+
--debug
60+
61+
GLOBAL FLAGS
62+
--json Format output as json.
5963
6064
DESCRIPTION
6165
describe the command here
@@ -67,48 +71,6 @@ EXAMPLES
6771
_See
6872
code: [src/commands/apply/index.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/apply/index.ts)_
6973

70-
## `codify hello PERSON`
71-
72-
Say hello
73-
74-
```
75-
USAGE
76-
$ codify hello PERSON -f <value>
77-
78-
ARGUMENTS
79-
PERSON Person to say hello to
80-
81-
FLAGS
82-
-f, --from=<value> (required) Who is saying hello
83-
84-
DESCRIPTION
85-
Say hello
86-
87-
EXAMPLES
88-
$ oex hello friend --from oclif
89-
hello friend from oclif! (./src/commands/hello/index.ts)
90-
```
91-
92-
_See code: [src/commands/hello/index.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/hello/index.ts)_
93-
94-
## `codify hello world`
95-
96-
Say hello world
97-
98-
```
99-
USAGE
100-
$ codify hello world
101-
102-
DESCRIPTION
103-
Say hello world
104-
105-
EXAMPLES
106-
$ codify hello world
107-
hello world! (./src/commands/hello/world.ts)
108-
```
109-
110-
_See code: [src/commands/hello/world.ts](https://github.com/kevinwang5658/codify/blob/v0.0.0/src/commands/hello/world.ts)_
111-
11274
## `codify help [COMMANDS]`
11375

11476
Display help for codify.
@@ -135,15 +97,21 @@ describe the command here
13597

13698
```
13799
USAGE
138-
$ codify plan [FILE] [-f] [-n <value>] [-p <value>]
100+
$ codify plan [FILE] [--json] [-o plain|default|debug|json] [--debug] [-f] [-n <value>] [-p <value>]
139101
140102
ARGUMENTS
141103
FILE file to read
142104
143105
FLAGS
144106
-f, --force
145-
-n, --name=<value> name to print
146-
-p, --path=<value> path to project
107+
-n, --name=<value> name to print
108+
-o, --output=<option> [default: default]
109+
<options: plain|default|debug|json>
110+
-p, --path=<value> path to project
111+
--debug
112+
113+
GLOBAL FLAGS
114+
--json Format output as json.
147115
148116
DESCRIPTION
149117
describe the command here
@@ -402,16 +370,21 @@ DESCRIPTION
402370

403371
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.4/src/commands/plugins/update.ts)_
404372

405-
## `codify uninstall RESOURCES`
373+
## `codify uninstall`
406374

407375
describe the command here
408376

409377
```
410378
USAGE
411-
$ codify uninstall RESOURCES...
379+
$ codify uninstall [--json] [-o plain|default|debug|json] [--debug]
412380
413-
ARGUMENTS
414-
RESOURCES... A resource typeId for uninstalling. Ex: "codify uninstall homebrew"
381+
FLAGS
382+
-o, --output=<option> [default: default]
383+
<options: plain|default|debug|json>
384+
--debug
385+
386+
GLOBAL FLAGS
387+
--json Format output as json.
415388
416389
DESCRIPTION
417390
describe the command here

src/common/orchestrator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export const CommonOrchestrator = {
1313
ctx.subprocessFinished(SubProcessName.INITIALIZE_PLUGINS)
1414

1515
return { dependencyMap, pluginCollection };
16-
}
16+
},
1717
};

src/entities/project-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ProjectSchema } from 'codify-schemas';
33
import { ConfigClass } from '../parser/language-definition.js';
44
import { ajv } from '../utils/ajv.js';
55
import { RemoveMethods } from '../utils/types.js';
6-
import { ConfigBlock } from './index.js';
6+
import { ConfigBlock } from './config.js';
77

88
/** Project JSON supported format
99
* {

src/entities/project.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidateResponseData } from 'codify-schemas';
22

3+
import { ctx } from '../events/context.js';
34
import { DependencyMap } from '../plugins/plugin-collection.js';
45
import { DependencyGraphResolver } from '../utils/dependency-graph-resolver.js';
56
import { ProjectConfig } from './project-config.js';
@@ -19,6 +20,12 @@ export class Project {
1920
return this.resourceConfigs.length === 0;
2021
}
2122

23+
addXCodeToolsConfig() {
24+
this.resourceConfigs.unshift(new ResourceConfig({
25+
type: 'xcode-tools'
26+
}));
27+
}
28+
2229
validateWithResourceMap(resourceMap: Map<string, string[]>) {
2330
const invalidConfigs = this.resourceConfigs.filter((c) => !resourceMap.get(c.type));
2431
if (invalidConfigs.length > 0) {
@@ -31,7 +38,7 @@ export class Project {
3138
resolveResourceDependencies(dependencyMap: DependencyMap) {
3239
const resourceMap = new Map(this.resourceConfigs.map((r) => [r.id, r] as const));
3340

34-
this.resourceConfigs.forEach((r) => {
41+
for (const r of this.resourceConfigs) {
3542
// User specified dependencies are hard dependencies. They must be present.
3643
r.addDependenciesBasedOnParameters((id) => resourceMap.has(id));
3744

@@ -40,7 +47,13 @@ export class Project {
4047
?.filter((id) => resourceMap.has(id))
4148
?? []
4249
);
43-
})
50+
51+
// Add this to ensure that the default config xcode-tools gets applied first
52+
// TODO: remove this in the future with required dependencies
53+
if (r.type !== 'xcode-tools') {
54+
r.addDependencies(['xcode-tools'])
55+
}
56+
}
4457
}
4558

4659
handlePluginResourceValidationResults(results: ValidateResponseData[]) {
@@ -65,5 +78,7 @@ ${JSON.stringify(
6578
(r) => r.id,
6679
(r) => r.dependencyIds
6780
);
81+
82+
ctx.debug(`Resource Evaluation Order:\n${JSON.stringify(this.evaluationOrder, null, 2)}`);
6883
}
6984
}

src/entities/resource-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ResourceSchema } from 'codify-schemas';
33
import { ConfigClass } from '../parser/language-definition.js';
44
import { ajv } from '../utils/ajv.js';
55
import { RemoveMethods } from '../utils/types.js';
6-
import { ConfigBlock } from './index.js';
6+
import { ConfigBlock } from './config.js';
77

88
/** Resource JSON supported format
99
* {

src/orchestrators/plan.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export const PlanOrchestrator = {
1919

2020
ctx.subprocessStarted(SubProcessName.PARSE);
2121
const project = await Parser.parseProject(path);
22+
23+
// Always add xcode tools as a dependency to make sure it's installed. This may be temporary if required dependencies get added.
24+
project.addXCodeToolsConfig();
2225
ctx.subprocessFinished(SubProcessName.PARSE);
2326

2427
const { dependencyMap, pluginCollection } = await CommonOrchestrator.initializePlugins(project);
@@ -33,7 +36,6 @@ export const PlanOrchestrator = {
3336
project.calculateEvaluationOrder();
3437
ctx.subprocessFinished(SubProcessName.VALIDATE)
3538

36-
3739
ctx.subprocessStarted(SubProcessName.GENERATE_PLAN)
3840
const plan = await pluginCollection.getPlan(project);
3941
ctx.subprocessFinished(SubProcessName.GENERATE_PLAN)

src/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigBlock } from '../entities/index.js';
1+
import { ConfigBlock } from '../entities/config.js';
22
import { Project } from '../entities/project.js';
33
import { ProjectConfig } from '../entities/project-config.js';
44
import { ResourceConfig } from '../entities/resource-config.js';

src/parser/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigBlock } from '../../entities/index.js';
1+
import { ConfigBlock } from '../../entities/config.js';
22
import { File } from '../reader/entities/file.js';
33

44
export interface FileParser {

src/parser/parser/json/config-block-factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigBlock } from '../../../entities/index.js';
1+
import { ConfigBlock } from '../../../entities/config.js';
22
import { ProjectConfig } from '../../../entities/project-config.js';
33
import { ResourceConfig } from '../../../entities/resource-config.js';
44
import { SyntaxError } from '../../../utils/errors.js';

0 commit comments

Comments
 (0)