Skip to content

Commit

Permalink
fix(cli): Update filters within generator upgrade to appropriately ta… (
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Sep 2, 2024
1 parent 07332e8 commit 42fe106
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/cli/cli/src/commands/upgrade/upgradeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export async function loadAndUpdateGenerators({
context.logger.debug(`Groups found: ${generatorGroups.toString()}`);

for (const groupBlock of generatorGroups.items) {
const groupName = groupBlock.key;
// The typing appears to be off in this lib, but BLOCK.key.value is meant to always be available
// https://eemeli.org/yaml/#creating-nodes
const groupName = (groupBlock.key as any).value as string;

Check warning on line 55 in packages/cli/cli/src/commands/upgrade/upgradeGenerator.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments
const group = groupBlock.value as YAML.YAMLMap<string, YAML.YAMLSeq<YAML.YAMLMap<unknown, unknown>>>;
if (!YAML.isMap(group)) {
Expand All @@ -60,7 +62,8 @@ export async function loadAndUpdateGenerators({
continue;
}

if (groupFilter != null && group.get("name") !== groupName) {
if (groupFilter != null && groupFilter !== groupName) {
context.logger.debug(`Skipping group ${groupName} as it does not match the filter: ${groupFilter}`);
continue;
}

Expand All @@ -79,11 +82,15 @@ export async function loadAndUpdateGenerators({
`Expected generator in group ${groupName} to be a map in ${path.relative(process.cwd(), filepath)}`
);
}
if (generatorFilter != null && generator.get("name") !== generatorFilter) {
const generatorName = generator.get("name") as string;

if (generatorFilter != null && generatorName !== generatorFilter) {
context.logger.debug(
`Skipping generator ${generatorName} as it does not match the filter: ${generatorFilter}`
);
continue;
}

const generatorName = generator.get("name") as string;
const normalizedGeneratorName = generatorsYml.getGeneratorNameOrThrow(generatorName, context);

const currentGeneratorVersion = generator.get("version") as string;
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- changelog_entry:
- summary: `fern generator upgrade` respects the `--group` flag and only upgrades generators within a particular group.
type: fix
created_at: '2024-09-02'
ir_version: 53
version: 0.40.3

- changelog_entry:
- summary: Release IR v53.9.0 which includes a publishing configuration.
type: internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ describe("fern generator upgrade", () => {
expect(javaVersion.stdout).toEqual("0.0.1");
}, 60_000);

it("fern generator upgrade with filters", async () => {
// Create tmpdir and copy contents
const tmpDir = await tmp.dir();
const directory = AbsoluteFilePath.of(tmpDir.path);

await cp(FIXTURES_DIR, directory, { recursive: true });

await runFernCli(["generator", "upgrade", "--group", "python-sdk", "--generator", "fernapi/fern-python-sdk"], {
cwd: directory
});

const pythonVersion = await runFernCli(
["generator", "get", "--group", "python-sdk", "--generator", "fernapi/fern-python-sdk", "--version"],
{
cwd: directory
}
);

expect(pythonVersion.stdout).not.toEqual("0.0.0");
}, 60_000);

it("fern generator help commands", async () => {
// Create tmpdir and copy contents
const tmpDir = await tmp.dir();
Expand Down

0 comments on commit 42fe106

Please sign in to comment.