Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions packages/catalyst/src/cli/lib/project.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { z } from 'zod';

const projectListItemSchema = z.object({
uuid: z.string(),
name: z.string(),
});

const fetchProjectsSchema = z.object({
data: z.array(
z.object({
uuid: z.string(),
name: z.string(),
}),
),
data: z.array(projectListItemSchema),
});

export interface ProjectListItem {
uuid: string;
name: string;
}
export type ProjectListItem = z.infer<typeof projectListItemSchema>;

export async function fetchProjects(
storeHash: string,
Expand Down Expand Up @@ -46,21 +43,18 @@ export async function fetchProjects(
return data;
}

const createProjectResultSchema = z.object({
uuid: z.string(),
name: z.string(),
date_created: z.coerce.date(),
date_modified: z.coerce.date(),
});

const createProjectSchema = z.object({
data: z.object({
uuid: z.string(),
name: z.string(),
date_created: z.coerce.date(),
date_modified: z.coerce.date(),
}),
data: createProjectResultSchema,
});

export interface CreateProjectResult {
uuid: string;
name: string;
date_created: Date;
date_modified: Date;
}
export type CreateProjectResult = z.infer<typeof createProjectResultSchema>;

export async function createProject(
name: string,
Expand Down
26 changes: 10 additions & 16 deletions packages/create-catalyst/src/commands/integration.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { Command } from '@commander-js/extra-typings';
import { exec as execCb } from 'child_process';
import { parse } from 'dotenv';
import { parse as parseDotenv } from 'dotenv';
import { outputFileSync, writeJsonSync } from 'fs-extra/esm';
import kebabCase from 'lodash.kebabcase';
import { coerce, compare } from 'semver';
import { promisify } from 'util';
import { z } from 'zod';

const exec = promisify(execCb);

export const ManifestSchema = z.object({
name: z.string(),
dependencies: z.object({ add: z.array(z.string()) }),
devDependencies: z.object({ add: z.array(z.string()) }),
environmentVariables: z.array(z.string()),
});
import { type Manifest, ManifestSchema, PackageDependenciesSchema } from '../utils/parse';

type Manifest = z.infer<typeof ManifestSchema>;
const exec = promisify(execCb);

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

// Reference ManifestSchema so its export isn't tree-shaken if needed by consumers
void ManifestSchema;

await exec('git fetch --tags');

const { stdout: headRefStdOut } = await exec('git rev-parse --abbrev-ref HEAD');
Expand All @@ -57,27 +53,22 @@
})
.reverse();

const PackageDependenciesSchema = z.object({
dependencies: z.object({}).passthrough(),
devDependencies: z.object({}).passthrough(),
});

const getPackageDeps = async (ref: string) => {
const { stdout } = await exec(`git show ${ref}:core/package.json`);

return PackageDependenciesSchema.parse(JSON.parse(stdout));

Check failure on line 59 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe member access .parse on an `error` typed value

Check failure on line 59 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe call of a(n) `error` type typed value

Check failure on line 59 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe return of a value of type error
};

const integrationJson = await getPackageDeps(sourceRef);

Check failure on line 62 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe assignment of an error typed value
const latestCoreTagJson = await getPackageDeps(latestCoreTag);

Check failure on line 63 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe assignment of an error typed value

const diffObjectKeys = (a: Record<string, unknown>, b: Record<string, unknown>) => {
return Object.keys(a).filter((key) => !Object.keys(b).includes(key));
};

manifest.dependencies.add = diffObjectKeys(

Check failure on line 69 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe member access .dependencies on an `error` typed value
integrationJson.dependencies,

Check failure on line 70 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe member access .dependencies on an `error` typed value

Check failure on line 70 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe argument of type error typed assigned to a parameter of type `Record<string, unknown>`
latestCoreTagJson.dependencies,

Check failure on line 71 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe member access .dependencies on an `error` typed value

Check failure on line 71 in packages/create-catalyst/src/commands/integration.ts

View workflow job for this annotation

GitHub Actions / Lint, Typecheck, and gql.tada

Unsafe argument of type error typed assigned to a parameter of type `Record<string, unknown>`
);
manifest.devDependencies.add = diffObjectKeys(
integrationJson.devDependencies,
Expand All @@ -87,7 +78,10 @@
const { stdout: latestCoreEnv } = await exec(`git show ${latestCoreTag}:core/.env.example`);
const { stdout: integrationEnv } = await exec(`git show ${sourceRef}:core/.env.example`);

manifest.environmentVariables = diffObjectKeys(parse(integrationEnv), parse(latestCoreEnv));
manifest.environmentVariables = diffObjectKeys(
parseDotenv(integrationEnv),
parseDotenv(latestCoreEnv),
);

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