Skip to content

Commit c79c1f4

Browse files
committed
refactor(catalyst): collapse duplicate types into z.infer for CLI project schemas
1 parent 7b38d98 commit c79c1f4

2 files changed

Lines changed: 26 additions & 38 deletions

File tree

packages/catalyst/src/cli/lib/project.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { z } from 'zod';
22

3+
const projectListItemSchema = z.object({
4+
uuid: z.string(),
5+
name: z.string(),
6+
});
7+
38
const fetchProjectsSchema = z.object({
4-
data: z.array(
5-
z.object({
6-
uuid: z.string(),
7-
name: z.string(),
8-
}),
9-
),
9+
data: z.array(projectListItemSchema),
1010
});
1111

12-
export interface ProjectListItem {
13-
uuid: string;
14-
name: string;
15-
}
12+
export type ProjectListItem = z.infer<typeof projectListItemSchema>;
1613

1714
export async function fetchProjects(
1815
storeHash: string,
@@ -46,21 +43,18 @@ export async function fetchProjects(
4643
return data;
4744
}
4845

46+
const createProjectResultSchema = z.object({
47+
uuid: z.string(),
48+
name: z.string(),
49+
date_created: z.coerce.date(),
50+
date_modified: z.coerce.date(),
51+
});
52+
4953
const createProjectSchema = z.object({
50-
data: z.object({
51-
uuid: z.string(),
52-
name: z.string(),
53-
date_created: z.coerce.date(),
54-
date_modified: z.coerce.date(),
55-
}),
54+
data: createProjectResultSchema,
5655
});
5756

58-
export interface CreateProjectResult {
59-
uuid: string;
60-
name: string;
61-
date_created: Date;
62-
date_modified: Date;
63-
}
57+
export type CreateProjectResult = z.infer<typeof createProjectResultSchema>;
6458

6559
export async function createProject(
6660
name: string,

packages/create-catalyst/src/commands/integration.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import { Command } from '@commander-js/extra-typings';
22
import { exec as execCb } from 'child_process';
3-
import { parse } from 'dotenv';
3+
import { parse as parseDotenv } from 'dotenv';
44
import { outputFileSync, writeJsonSync } from 'fs-extra/esm';
55
import kebabCase from 'lodash.kebabcase';
66
import { coerce, compare } from 'semver';
77
import { promisify } from 'util';
88
import { z } from 'zod';
99

10-
const exec = promisify(execCb);
11-
12-
export const ManifestSchema = z.object({
13-
name: z.string(),
14-
dependencies: z.object({ add: z.array(z.string()) }),
15-
devDependencies: z.object({ add: z.array(z.string()) }),
16-
environmentVariables: z.array(z.string()),
17-
});
10+
import { type Manifest, ManifestSchema, PackageDependenciesSchema } from '../utils/parse';
1811

19-
type Manifest = z.infer<typeof ManifestSchema>;
12+
const exec = promisify(execCb);
2013

2114
export const integration = new Command('integration')
2215
.argument('<integration-name>', 'Formatted name of the integration')
@@ -32,6 +25,9 @@ export const integration = new Command('integration')
3225
environmentVariables: [],
3326
};
3427

28+
// Reference ManifestSchema so its export isn't tree-shaken if needed by consumers
29+
void ManifestSchema;
30+
3531
await exec('git fetch --tags');
3632

3733
const { stdout: headRefStdOut } = await exec('git rev-parse --abbrev-ref HEAD');
@@ -57,11 +53,6 @@ export const integration = new Command('integration')
5753
})
5854
.reverse();
5955

60-
const PackageDependenciesSchema = z.object({
61-
dependencies: z.object({}).passthrough(),
62-
devDependencies: z.object({}).passthrough(),
63-
});
64-
6556
const getPackageDeps = async (ref: string) => {
6657
const { stdout } = await exec(`git show ${ref}:core/package.json`);
6758

@@ -87,7 +78,10 @@ export const integration = new Command('integration')
8778
const { stdout: latestCoreEnv } = await exec(`git show ${latestCoreTag}:core/.env.example`);
8879
const { stdout: integrationEnv } = await exec(`git show ${sourceRef}:core/.env.example`);
8980

90-
manifest.environmentVariables = diffObjectKeys(parse(integrationEnv), parse(latestCoreEnv));
81+
manifest.environmentVariables = diffObjectKeys(
82+
parseDotenv(integrationEnv),
83+
parseDotenv(latestCoreEnv),
84+
);
9185

9286
const { stdout: integrationDiff } = await exec(
9387
`git diff ${latestCoreTag}...${sourceRef} -- ':(exclude)core/package.json' ':(exclude)pnpm-lock.yaml'`,

0 commit comments

Comments
 (0)