Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): run plugin hooks #7499

Merged
merged 2 commits into from
Jun 11, 2024
Merged
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
15 changes: 15 additions & 0 deletions cli/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import c from './colors';
import type { Config, PackageJson } from './definitions';
import { fatal } from './errors';
import { output, logger } from './log';
import { getPlugins } from './plugin';
import { findNXMonorepoRoot, isNXMonorepo } from './util/monorepotools';
import { resolveNode } from './util/node';
import { runCommand } from './util/subprocess';
Expand Down Expand Up @@ -162,6 +163,20 @@ export async function wait(time: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, time));
}

export async function runHooks(
config: Config,
platformName: string,
dir: string,
hook: string,
): Promise<void> {
await runPlatformHook(config, platformName, dir, hook);

const allPlugins = await getPlugins(config, platformName);
allPlugins.forEach(async p => {
await runPlatformHook(config, platformName, p.rootPath, hook);
});
}

export async function runPlatformHook(
config: Config,
platformName: string,
Expand Down
5 changes: 3 additions & 2 deletions cli/src/tasks/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import c from '../colors';
import {
checkWebDir,
resolvePlatform,
runHooks,
runPlatformHook,
runTask,
isValidPlatform,
Expand Down Expand Up @@ -70,7 +71,7 @@ export async function copy(
throw result;
}

await runPlatformHook(
await runHooks(
config,
platformName,
config.app.rootDir,
Expand Down Expand Up @@ -190,7 +191,7 @@ export async function copy(
}
});

await runPlatformHook(
await runHooks(
config,
platformName,
config.app.rootDir,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/tasks/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
checkWebDir,
selectPlatforms,
isValidPlatform,
runPlatformHook,
runHooks,
} from '../common';
import type { Config } from '../definitions';
import { fatal, isFatal } from '../errors';
Expand Down Expand Up @@ -63,7 +63,7 @@ export async function sync(
deployment: boolean,
inline = false,
): Promise<void> {
await runPlatformHook(
await runHooks(
config,
platformName,
config.app.rootDir,
Expand All @@ -77,7 +77,7 @@ export async function sync(
}
await update(config, platformName, deployment);

await runPlatformHook(
await runHooks(
config,
platformName,
config.app.rootDir,
Expand Down
5 changes: 3 additions & 2 deletions cli/src/tasks/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
check,
checkPackage,
resolvePlatform,
runHooks,
runPlatformHook,
runTask,
selectPlatforms,
Expand Down Expand Up @@ -84,7 +85,7 @@ export async function update(
deployment: boolean,
): Promise<void> {
await runTask(c.success(c.strong(`update ${platformName}`)), async () => {
await runPlatformHook(
await runHooks(
config,
platformName,
config.app.rootDir,
Expand All @@ -97,7 +98,7 @@ export async function update(
await updateAndroid(config);
}

await runPlatformHook(
await runHooks(
config,
platformName,
config.app.rootDir,
Expand Down