PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / PageCreator / lib / processPatterns.js

processPatterns.js in Extendify trunk, at src/PageCreator/lib/processPatterns.js

44 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { getActivePlugins, processPlaceholders } from '@page-creator/api/WPApi';
2 import { recordPluginActivity } from '@shared/api/DataApi';
3 import { failedDependencies } from '@shared/lib/patterns';
4 import { sleep } from '@shared/lib/utils';
5
6 export const processPatterns = async (patterns) => {
7 const maxAttempts = 3;
8 const delay = 1000; // 1 second delay between retries
9
10 const activePlugins =
11 (await getActivePlugins())?.data?.map((path) => path.split('/')[0]) || [];
12
13 const pluginsActivity = patterns
14 .filter((p) => p.pluginDependency)
15 .map((p) => p.pluginDependency)
16 .filter((p) => !activePlugins.includes(p));
17
18 for (const plugin of pluginsActivity) {
19 recordPluginActivity({
20 slug: plugin,
21 source: 'page-creator',
22 });
23 }
24
25 for (let attempt = 1; attempt <= maxAttempts; attempt++) {
26 try {
27 const processed = await processPlaceholders(patterns);
28 if (!failedDependencies(processed).length || attempt === maxAttempts) {
29 return processed;
30 }
31 } catch (error) {
32 if (attempt === maxAttempts) {
33 console.error(
34 `Failed to process patterns after ${maxAttempts} attempts:`,
35 error,
36 );
37 return patterns;
38 }
39 }
40
41 await sleep(delay);
42 }
43 };
44