diff --git a/lib/schemas/src/tasks.ts b/lib/schemas/src/tasks.ts index 80b20ba62..5643a78d0 100644 --- a/lib/schemas/src/tasks.ts +++ b/lib/schemas/src/tasks.ts @@ -14,6 +14,7 @@ import { SmokeTestSchema } from './tasks/n-test' import { CypressSchema } from './tasks/cypress' import { HerokuProductionSchema } from './tasks/heroku-production' import { ServerlessRunSchema } from './tasks/serverless-run' +import { WorkspaceCommandSchema } from './tasks/workspace-command' import { z } from 'zod' export const TaskSchemas = { @@ -40,7 +41,8 @@ export const TaskSchemas = { ServerlessTeardown: z.object({}).describe('Tear down existing serverless functions'), TypeScript: TypeScriptSchema, UploadAssetsToS3: UploadAssetsToS3Schema, - Webpack: WebpackSchema + Webpack: WebpackSchema, + WorkspaceCommand: WorkspaceCommandSchema } export type TaskOptions = InferSchemaOptions diff --git a/lib/schemas/src/tasks/workspace-command.ts b/lib/schemas/src/tasks/workspace-command.ts new file mode 100644 index 000000000..f309844b9 --- /dev/null +++ b/lib/schemas/src/tasks/workspace-command.ts @@ -0,0 +1,9 @@ +import { z } from 'zod' + +export const WorkspaceCommandSchema = z.object({ + command: z.string().optional() +}) + +export type WorkspaceCommandOptions = z.infer + +export const Schema = WorkspaceCommandSchema diff --git a/package-lock.json b/package-lock.json index 6943f5884..57aeb8add 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32317,6 +32317,7 @@ "version": "0.1.0", "license": "ISC", "dependencies": { + "@dotcom-tool-kit/schemas": "^1.0.0", "@npmcli/map-workspaces": "^3.0.6" }, "devDependencies": { diff --git a/plugins/monorepo/package.json b/plugins/monorepo/package.json index bc95cd7f4..36fc974c8 100644 --- a/plugins/monorepo/package.json +++ b/plugins/monorepo/package.json @@ -28,6 +28,7 @@ "dotcom-tool-kit": "3.x" }, "dependencies": { + "@dotcom-tool-kit/schemas": "^1.0.0", "@npmcli/map-workspaces": "^3.0.6" }, "devDependencies": { diff --git a/plugins/monorepo/src/tasks/workspace-command.ts b/plugins/monorepo/src/tasks/workspace-command.ts index 0cbbb7990..026975332 100644 --- a/plugins/monorepo/src/tasks/workspace-command.ts +++ b/plugins/monorepo/src/tasks/workspace-command.ts @@ -5,8 +5,9 @@ import path from 'path' import { loadConfig } from 'dotcom-tool-kit/lib/config' import { runTasksFromConfig } from 'dotcom-tool-kit/lib/tasks' import { ToolKitError } from '@dotcom-tool-kit/error' +import { WorkspaceCommandSchema } from '@dotcom-tool-kit/schemas/lib/tasks/workspace-command' -export default class WorkspaceCommand extends Task { +export default class WorkspaceCommand extends Task<{ task: typeof WorkspaceCommandSchema }> { async runPackageCommand(packageId: string, packagePath: string, command: string, files?: string[]) { const config = await loadConfig(this.logger, { root: packagePath }) @@ -20,7 +21,9 @@ export default class WorkspaceCommand extends Task { const workspaces = await mapWorkspaces({ cwd, pkg }) const results = await Promise.allSettled( - Array.from(workspaces, ([id, packagePath]) => this.runPackageCommand(id, packagePath, command, files)) + Array.from(workspaces, ([id, packagePath]) => + this.runPackageCommand(id, packagePath, this.options.command ?? command, files) + ) ) const erroredCommands = results.filter( @@ -29,7 +32,7 @@ export default class WorkspaceCommand extends Task { if (erroredCommands.length) { // TODO improve error messages - const error = new ToolKitError(`error running workspace command ${command}`) + const error = new ToolKitError(`error running workspace command ${this.options.command ?? command}`) error.details = erroredCommands.map((result) => result.reason.toString()).join('\n\n') throw error } diff --git a/plugins/monorepo/tsconfig.json b/plugins/monorepo/tsconfig.json index 5ec64d916..65a97dec3 100644 --- a/plugins/monorepo/tsconfig.json +++ b/plugins/monorepo/tsconfig.json @@ -7,6 +7,9 @@ "references": [ { "path": "../../lib/base" + }, + { + "path": "../../lib/schemas" } ], "include": ["src/**/*"]