From 789c4f7429c7fabb4202ac4deb6cdee2e0fe6a50 Mon Sep 17 00:00:00 2001 From: Dominic Sudy <99014187+doosuu@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:46:09 +0100 Subject: [PATCH] fix: Support multiple setup components for sync (#210) --- src/commands/sync/index.ts | 4 ++-- src/modules/component.ts | 8 +++++--- src/modules/package.ts | 8 ++------ test/commands/sync/sync.test.ts | 6 +++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/commands/sync/index.ts b/src/commands/sync/index.ts index 97fa77f7..e7293c38 100644 --- a/src/commands/sync/index.ts +++ b/src/commands/sync/index.ts @@ -22,7 +22,7 @@ export default class Sync extends Command { static description = 'Syncs Velocitas components into your repo.'; static examples = [ - `$ velocitas update MyAwesomeApp --lang cpp + `$ velocitas sync Syncing Velocitas components! ... syncing 'devenv-github-workflows' ... syncing 'devenv-github-templates'`, @@ -33,7 +33,7 @@ Syncing Velocitas components! const projectConfig = ProjectConfig.read(`v${this.config.version}`); const setupComponents = findComponentsByType(projectConfig, ComponentType.setup); for (const setupComponent of setupComponents) { - this.log(`... syncing '${setupComponent[0].getPackageName()}'`); + this.log(`... syncing '${setupComponent[2].id}'`); const componentConfig = getComponentConfig(setupComponent[0], setupComponent[2].id); const variables = VariableCollection.build(projectConfig, setupComponent[0], componentConfig, setupComponent[2]); diff --git a/src/modules/component.ts b/src/modules/component.ts index d01219cf..55c9900c 100644 --- a/src/modules/component.ts +++ b/src/modules/component.ts @@ -12,7 +12,7 @@ // // SPDX-License-Identifier: Apache-2.0 -import { getComponentByType, PackageConfig, PackageManifest } from './package'; +import { getComponentsByType, PackageConfig, PackageManifest } from './package'; import { ComponentConfig, ProjectConfig } from './project-config'; import { VariableDefinition } from './variables'; @@ -105,9 +105,11 @@ export function findComponentsByType( ): Array<[PackageConfig, PackageManifest, TComponentType]> { const result = new Array<[PackageConfig, PackageManifest, TComponentType]>(); for (const packageConfig of projectConfig.packages) { - const componentManifest = packageConfig.readPackageManifest(); + const packageManifest = packageConfig.readPackageManifest(); try { - result.push([packageConfig, componentManifest, getComponentByType(componentManifest, type) as TComponentType]); + for(const component of getComponentsByType(packageManifest, type)) { + result.push([packageConfig, packageManifest, component as TComponentType]); + } } catch (e) {} } diff --git a/src/modules/package.ts b/src/modules/package.ts index 2f386b90..91eb9e16 100644 --- a/src/modules/package.ts +++ b/src/modules/package.ts @@ -132,10 +132,6 @@ function getPackageFolderPath(): string { return join(getVelocitasRoot(), 'packages'); } -export function getComponentByType(packageManifest: PackageManifest, type: ComponentType): Component { - const component = packageManifest.components.find((component: Component) => component.type === type); - if (component === undefined) { - throw new TypeError(`No Subcomponent with type "${type}" found!`); - } - return component; +export function getComponentsByType(packageManifest: PackageManifest, type: ComponentType): Component[] { + return packageManifest.components.filter((component: Component) => component.type === type); } diff --git a/test/commands/sync/sync.test.ts b/test/commands/sync/sync.test.ts index e68440fb..e55f8eae 100644 --- a/test/commands/sync/sync.test.ts +++ b/test/commands/sync/sync.test.ts @@ -13,7 +13,7 @@ // SPDX-License-Identifier: Apache-2.0 import { expect, test } from '@oclif/test'; -import { velocitasConfigMock } from '../../utils/mockConfig'; +import { runtimeComponentManifestMock, setupComponentManifestMock, velocitasConfigMock } from '../../utils/mockConfig'; import { mockFolders, mockRestore } from '../../utils/mockfs'; describe('sync', () => { @@ -27,7 +27,7 @@ describe('sync', () => { .command(['sync']) .it('syncing components into project directory', (ctx) => { expect(ctx.stdout).to.contain('Syncing Velocitas components!'); - expect(ctx.stdout).to.contain(`... syncing '${velocitasConfigMock.packages[1].name}'`); - expect(ctx.stdout).to.not.contain(`... syncing '${velocitasConfigMock.packages[0].name}'`); + expect(ctx.stdout).to.contain(`... syncing '${setupComponentManifestMock.components[0].id}'`); + expect(ctx.stdout).to.not.contain(`... syncing '${runtimeComponentManifestMock.components[0].id}'`); }); });