Skip to content

Commit

Permalink
feat(cli): run plugin hooks (#7499)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jun 11, 2024
1 parent cca0b80 commit 3b847ea
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
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

0 comments on commit 3b847ea

Please sign in to comment.