Skip to content

Commit 1383f3d

Browse files
author
dennismeister93
authored
feat: slim project config (#246)
* slim project config --------- Signed-off-by: Dennis Meister <[email protected]>
1 parent 1e19b14 commit 1383f3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1457
-629
lines changed

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,24 @@ An exemplary project configuration (`.velocitas.json`) looks like this:
6767

6868
```json
6969
{
70-
"packages": [
71-
{
72-
"repo": "package-A",
73-
"version": "v1.0.0"
74-
},
75-
{
76-
"repo": "package-B",
77-
"version": "v2.3.1-dev"
78-
}
79-
],
70+
"packages": {
71+
"package-A": "v1.0.0",
72+
"package-B": "v2.3.1-dev"
73+
},
74+
"components": [ "component-A", "component-B" ],
8075
"variables": {
8176
"repoUrl": "https://github.com/eclipse-velocitas/cli",
8277
"copyrightYear": 2023,
83-
"autoGenerateVehicleModel": true
78+
"autoGenerateVehicleModel": true,
79+
"variableA@package-A": "variableA",
80+
"variableB@component-B": "variableB",
8481
}
8582
}
8683
```
8784

88-
As mentioned previously, a package simply is a git repository. The `repo` attribute of a package is used to identify the git repository which holds the package. `repo` is currently resolved to `https://github.com/eclipse-velocitas/<name>`. Alternatively, you can also supply a fully qualified Git repo URL e.g. `https://<your-host>/<your-repo>.git` or `git@<your-host>/<your-repo>.git`. Credentials for HTTPs and SSH based git repos are provided by your local git configuration (CLI is using Git under the hood). The `version` attribute specifies a tag, a branch or a SHA of the repository.
85+
As mentioned previously, a package simply is a git repository. The key inside the packages is used to identify the git repository which holds the package. It is currently resolved to `https://github.com/eclipse-velocitas/<name>`. Alternatively, you can also supply a fully qualified Git repo URL e.g. `https://<your-host>/<your-repo>.git` or `git@<your-host>/<your-repo>.git`. Credentials for HTTPs and SSH based git repos are provided by your local git configuration (CLI is using Git under the hood). The value of the package attribute specifies a tag, a branch or a SHA of the repository.
8986

90-
The `variables` block holds user configured values for the packages and their contained components. It is a global variable definition. Should two components share the same variable name, both can be set with one line in this global block. Package-wide or component-wide variable configuration to avoid name clashes is also possible.
87+
The `variables` block holds configured values for a specific scope (project, package or component). A variable without separator acts as a global variable. Should two components share the same variable name, both can be set with one line in this global block. Package-wide or component-wide variable configuration can be used to avoid name clashes. For a package or component scope the variable needs to be assigned with an '@' followed by either package or component ID. In the example above, `variableA@package-A` and `variableB@component-B` showcase such a usage.
9188

9289
Click [here](./docs/PROJECT-CONFIG.md) for an in-depth overview of the project configuration.
9390

docs/PROJECT-CONFIG.md

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
# Project configuration
22

3-
The project configuration describes which packages your project is using and in which version. The versions of the referenced packages can be upgraded using the `upgrade` command. If you only want to see which new versions are available use `upgrade --dry-run` or `upgrade --dry-run --ignore-bounds`. Each package may expose variables which need to be set from the project configuration. If multiple different packages all expose the same named variable `foo`, setting this variable once in the project configuration will pass the value to all packages.
3+
The project configuration describes which packages your project is using and in which version. The versions of the referenced packages can be upgraded using the `upgrade` command. If you only want to see which new versions are available use `upgrade --dry-run` or `upgrade --dry-run --ignore-bounds`. Each package may expose variables which need to be set from the project configuration. If multiple different packages all expose the same named variable `foo`, setting this variable once in the project configuration will pass the value to all packages. If a package or even a component exposes a variable which is only needed within its scope it can be set with `"variableA@package-A": "variableA"`.
44

55
Read more about variables [here](./features/VARIABLES.md).
66

77
```json
88
{
9-
"packages": [
10-
{
11-
"repo": "package-A",
12-
"version": "v1.0.0"
13-
},
14-
{
15-
"repo": "package-B",
16-
"version": "v2.3.1-dev"
17-
}
18-
],
9+
"packages": {
10+
"package-A": "v1.0.0",
11+
"package-B": "v2.3.1-dev"
12+
},
13+
"components": [ "component-A", "component-B" ],
1914
"variables": {
2015
"repoUrl": "https://github.com/eclipse-velocitas/cli",
2116
"copyrightYear": 2023,
22-
"autoGenerateVehicleModel": true
17+
"autoGenerateVehicleModel": true,
18+
"variableA@package-A": "variableA",
19+
"variableB@component-B": "variableB",
2320
}
2421
}
2522
```
@@ -32,24 +29,11 @@ By default, all components of a package will be used, but if desired the used co
3229

3330
```json
3431
{
35-
"packages": [
36-
{
37-
"repo": "package-A",
38-
"version": "v1.0.0"
39-
},
40-
{
41-
"repo": "package-B",
42-
"version": "v2.3.1-dev"
43-
}
44-
],
45-
"components": [
46-
{
47-
"id": "component-exposed-by-pkg-a"
48-
},
49-
{
50-
"id": "component-exposed-by-pkg-b"
51-
},
52-
],
32+
"packages": {
33+
"package-A": "v1.0.0",
34+
"package-B": "v2.3.1-dev"
35+
},
36+
"components": [ "component-exposed-by-pkg-a", "component-exposed-by-pkg-b" ],
5337
"variables": {
5438
"repoUrl": "https://github.com/eclipse-velocitas/cli",
5539
"copyrightYear": 2023,
@@ -62,23 +46,25 @@ The project above will only use the components `component-exposed-by-pkg-a` and
6246

6347
## File Structure
6448

65-
### `packages` - Array[[`PackageConfig`](#packageconfig)]
49+
### `packages` - Map[string, string]
50+
51+
A key-value configuration of packages, where key is the package [repo](#repo) and value is the [version](#version).
6652

67-
Array of packages used in the project.
53+
### `components` - string[]
54+
55+
An array of used components.
6856

6957
### `variables` - Map[string, any]
7058

71-
Project-wide key-value variable configuration.
59+
Project-wide key-value [variable](#variables) configuration.
7260

7361
# Types
7462

75-
## `PackageConfig`
76-
77-
### `repo` - string
63+
## `repo`
7864

7965
The name of the package or URL to the package git repository. A simple name is currently resolved to `https://github.com/eclipse-velocitas/<name>`. Alternatively, you can also supply a fully qualified Git repo URL e.g. `https://<your-host>/<your-repo>.git` or `git@<your-host>/<your-repo>.git`. Credentials for HTTPs and SSH based git repos are provided by your local git configuration (CLI is using Git under the hood).
8066

81-
### `version` - string
67+
## `version`
8268

8369
The version of the package to use.
8470
| Literal | Behaviour | Example |
@@ -88,20 +74,10 @@ The version of the package to use.
8874
| branch (prefixed with an '@') | Refers to the latest commit in a specific branch | `"@main"` |
8975
| latest | Refers to the latest tag if available else to the highest version tag | `"latest"` |
9076

91-
### `variables` - Map[string, any]
92-
93-
Package-wide variable configuration.
94-
95-
### `components` - Array[[`ComponentConfig`](#componentconfig)]
96-
97-
Per-component configuration.
98-
99-
## `ComponentConfig`
100-
101-
### `id` - string
102-
103-
Unique ID of the component within the package.
104-
105-
### `variables` - Map[string, any]
77+
## `variables`
10678

107-
Component-wide key-value variable configuration
79+
| Scope | Example |
80+
|-------|---------|
81+
| Global | `"projectVariable": "A project wide variable"` |
82+
| Package | `"packageVariable@pkg-a": "A package wide variable"` |
83+
| Component | `"componentVariable@component-exposed-by-pkg-a": "A component wide variable"` |

src/commands/cache/clear.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import { Command } from '@oclif/core';
1616
import { ProjectCache } from '../../modules/project-cache';
17-
import { ProjectConfig } from '../../modules/project-config';
17+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
1818

1919
export default class Clear extends Command {
2020
static description = "Clean a project's cache.";
@@ -26,7 +26,7 @@ export default class Clear extends Command {
2626

2727
// although we are not reading the project config, we want to
2828
// ensure the command is run in a project directory only.
29-
ProjectConfig.read(`v${this.config.version}`);
29+
ProjectConfigIO.read(`v${this.config.version}`);
3030
const cache = ProjectCache.read();
3131
cache.clear();
3232
cache.write();

src/commands/cache/get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import { Args, Command } from '@oclif/core';
1616
import { mapReplacer } from '../../modules/helpers';
1717
import { ProjectCache } from '../../modules/project-cache';
18-
import { ProjectConfig } from '../../modules/project-config';
18+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
1919

2020
export default class Get extends Command {
2121
static description = 'Get the complete cache contents as JSON string or the value of a single key.';
@@ -36,7 +36,7 @@ bar`,
3636

3737
// although we are not reading the project config, we want to
3838
// ensure the command is run in a project directory only.
39-
ProjectConfig.read(`v${this.config.version}`);
39+
ProjectConfigIO.read(`v${this.config.version}`);
4040

4141
const cache = ProjectCache.read();
4242

src/commands/cache/set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import { Args, Command } from '@oclif/core';
1616
import { ProjectCache } from '../../modules/project-cache';
17-
import { ProjectConfig } from '../../modules/project-config';
17+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
1818

1919
export default class Set extends Command {
2020
static description = 'Set the cache value of an entry.';
@@ -31,7 +31,7 @@ export default class Set extends Command {
3131

3232
// although we are not reading the project config, we want to
3333
// ensure the command is run in a project directory only.
34-
ProjectConfig.read(`v${this.config.version}`);
34+
ProjectConfigIO.read(`v${this.config.version}`);
3535

3636
const cache = ProjectCache.read();
3737
cache.set(args.key, args.value);

src/commands/component/add.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
// SPDX-License-Identifier: Apache-2.0
1414

1515
import { Args, Command } from '@oclif/core';
16-
import { ProjectConfig } from '../../modules/project-config';
16+
import { ComponentContext } from '../../modules/component';
17+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
1718

1819
export default class Add extends Command {
1920
static description = 'Add project components.';
@@ -27,8 +28,10 @@ export default class Add extends Command {
2728
async run(): Promise<void> {
2829
const { args } = await this.parse(Add);
2930

30-
const projectConfig = ProjectConfig.read(`v${this.config.version}`);
31-
const foundComponent = projectConfig.getComponents(false).find((compContext) => compContext.manifest.id === args.id);
31+
const projectConfig = ProjectConfigIO.read(`v${this.config.version}`);
32+
const foundComponent = projectConfig
33+
.getComponentContexts(false)
34+
.find((compContext: ComponentContext) => compContext.manifest.id === args.id);
3235

3336
if (!foundComponent) {
3437
throw Error(
@@ -41,6 +44,6 @@ export default class Add extends Command {
4144
}
4245

4346
projectConfig.addComponent(foundComponent?.manifest.id);
44-
projectConfig.write();
47+
ProjectConfigIO.write(projectConfig);
4548
}
4649
}

src/commands/component/list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// SPDX-License-Identifier: Apache-2.0
1414

1515
import { Command, Flags } from '@oclif/core';
16-
import { ProjectConfig } from '../../modules/project-config';
16+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
1717

1818
export default class List extends Command {
1919
static description = 'List project components.';
@@ -35,10 +35,10 @@ export default class List extends Command {
3535
async run(): Promise<void> {
3636
const { flags } = await this.parse(List);
3737

38-
const projectConfig = ProjectConfig.read(`v${this.config.version}`);
38+
const projectConfig = ProjectConfigIO.read(`v${this.config.version}`);
3939
const onlyUsed = !flags.all && !flags.unused;
4040

41-
for (const componentContext of projectConfig.getComponents(onlyUsed)) {
41+
for (const componentContext of projectConfig.getComponentContexts(onlyUsed)) {
4242
if (flags.unused && componentContext.usedInProject) {
4343
continue;
4444
}

src/commands/component/remove.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
// SPDX-License-Identifier: Apache-2.0
1414

1515
import { Args, Command } from '@oclif/core';
16-
import { ProjectConfig } from '../../modules/project-config';
16+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
1717

1818
export default class Remove extends Command {
1919
static description = 'Remove project components.';
2020

2121
static examples = [`$ velocitas component remove <id>`];
2222

2323
static args = {
24-
id: Args.string({ description: 'ID of the component to add', required: true }),
24+
id: Args.string({ description: 'ID of the component to remove', required: true }),
2525
};
2626

2727
async run(): Promise<void> {
2828
const { args } = await this.parse(Remove);
2929

30-
const projectConfig = ProjectConfig.read(`v${this.config.version}`);
30+
const projectConfig = ProjectConfigIO.read(`v${this.config.version}`);
3131

32-
const foundComponent = projectConfig.getComponents(false).find((compContext) => compContext.manifest.id === args.id);
32+
const foundComponent = projectConfig.getComponentContexts(false).find((compContext) => compContext.manifest.id === args.id);
3333

3434
if (!foundComponent) {
3535
throw Error(
@@ -42,6 +42,6 @@ export default class Remove extends Command {
4242
}
4343

4444
projectConfig.removeComponent(foundComponent?.manifest.id);
45-
projectConfig.write();
45+
ProjectConfigIO.write(projectConfig);
4646
}
4747
}

src/commands/create/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { Command, Flags } from '@oclif/core';
1616
import { AppManifest, AppManifestInterfaceAttributes } from '../../modules/app-manifest';
1717
import { InteractiveMode } from '../../modules/create-interactive';
1818
import { CoreComponent, CoreOptions, DescribedId, ExtensionComponent, PackageIndex, Parameter } from '../../modules/package-index';
19-
import { ProjectConfig } from '../../modules/project-config';
19+
import { ProjectConfig } from '../../modules/projectConfig/projectConfig';
20+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
2021
// eslint-disable-next-line @typescript-eslint/naming-convention
2122
import Exec from '../exec';
2223
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -228,7 +229,9 @@ export default class Create extends Command {
228229
} else {
229230
createData = await this._parseFlags(packageIndex, flags);
230231
}
231-
await ProjectConfig.create(createData.componentIds, packageIndex, this.config.version);
232+
const projectConfig = await ProjectConfig.create(createData.componentIds, packageIndex, this.config.version);
233+
ProjectConfigIO.write(projectConfig);
234+
232235
createData.appManifest.write();
233236

234237
this.log(`... Project for Vehicle Application '${createData.name}' created!`);

src/commands/exec/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Args, Command, Flags } from '@oclif/core';
1616
import { APP_MANIFEST_PATH_VARIABLE, AppManifest } from '../../modules/app-manifest';
1717
import { ExecSpec } from '../../modules/component';
1818
import { ExecExitError, runExecSpec } from '../../modules/exec';
19-
import { ProjectConfig } from '../../modules/project-config';
19+
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
2020
import { createEnvVars } from '../../modules/variables';
2121

2222
export default class Exec extends Command {
@@ -75,7 +75,7 @@ export default class Exec extends Command {
7575
const programArgsAndFlags = this._extractProgramArgsAndFlags();
7676
const { args, flags } = await this.parse(Exec);
7777

78-
const projectConfig = ProjectConfig.read(`v${this.config.version}`);
78+
const projectConfig = ProjectConfigIO.read(`v${this.config.version}`);
7979

8080
const execSpec: ExecSpec = {
8181
ref: args.ref,

0 commit comments

Comments
 (0)