Skip to content

Commit 403e8f3

Browse files
authored
Merge pull request #3 from builtnorth/dev
Dev
2 parents 3d9634d + d5a65f0 commit 403e8f3

File tree

2 files changed

+153
-17
lines changed

2 files changed

+153
-17
lines changed

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"name": "@builtnorth/wp-theme-json-compiler",
3-
"version": "0.2.0",
4-
"description": "A modular theme.json compiler for WordPress themes.",
5-
"main": "src/index.js",
6-
"bin": {
7-
"wp-theme-json-compiler": "src/index.js"
8-
},
9-
"scripts": {
10-
"compile": "node src/index.js compile",
11-
"split": "node src/index.js split",
12-
"watch": "node src/index.js watch"
13-
},
14-
"author": "Built North",
15-
"license": "MIT",
16-
"dependencies": {
17-
"chokidar": "^3.6.0"
18-
}
2+
"name": "@builtnorth/wp-theme-json-compiler",
3+
"version": "1.0.0",
4+
"description": "A modular theme.json compiler for WordPress themes.",
5+
"main": "src/index.js",
6+
"bin": {
7+
"wp-theme-json-compiler": "src/index.js"
8+
},
9+
"scripts": {
10+
"compile": "node src/index.js compile",
11+
"split": "node src/index.js split",
12+
"watch": "node src/index.js watch"
13+
},
14+
"author": "Built North",
15+
"license": "MIT",
16+
"dependencies": {
17+
"chokidar": "^3.6.0"
18+
}
1919
}

src/index.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,138 @@ function mergeDeep(target, source) {
4949
return target;
5050
}
5151

52+
function expandWildcardBlocks(blocksConfig) {
53+
if (!blocksConfig || typeof blocksConfig !== "object") {
54+
return blocksConfig;
55+
}
56+
57+
const expanded = {};
58+
const wildcardConfig = blocksConfig["*"];
59+
60+
// Common block patterns that should receive wildcard settings
61+
const commonBlocks = [
62+
// Core blocks
63+
"core/paragraph",
64+
"core/heading",
65+
"core/list",
66+
"core/list-item",
67+
"core/quote",
68+
"core/audio",
69+
"core/button",
70+
"core/buttons",
71+
"core/columns",
72+
"core/column",
73+
"core/cover",
74+
"core/file",
75+
"core/gallery",
76+
"core/group",
77+
"core/image",
78+
"core/media-text",
79+
"core/more",
80+
"core/nextpage",
81+
"core/preformatted",
82+
"core/pullquote",
83+
"core/separator",
84+
"core/shortcode",
85+
"core/spacer",
86+
"core/table",
87+
"core/verse",
88+
"core/video",
89+
"core/code",
90+
"core/details",
91+
"core/freeform",
92+
"core/html",
93+
"core/search",
94+
"core/social-links",
95+
"core/site-logo",
96+
"core/navigation",
97+
"core/post-template",
98+
"core/post-title",
99+
"core/post-excerpt",
100+
"core/post-content",
101+
"core/post-featured-image",
102+
"core/post-comments",
103+
"core/post-comments-form",
104+
"core/post-comments-count",
105+
"core/post-comments-link",
106+
"core/post-date",
107+
"core/post-author",
108+
"core/post-terms",
109+
"core/post-navigation-link",
110+
"core/query",
111+
"core/query-title",
112+
"core/query-pagination",
113+
"core/query-pagination-next",
114+
"core/query-pagination-previous",
115+
"core/query-pagination-numbers",
116+
"core/query-no-results",
117+
"core/read-more",
118+
"core/site-tagline",
119+
"core/site-title",
120+
"core/archives",
121+
"core/calendar",
122+
"core/categories",
123+
"core/latest-comments",
124+
"core/latest-posts",
125+
"core/page-list",
126+
"core/rss",
127+
"core/social-link",
128+
"core/tag-cloud",
129+
"core/home-link",
130+
"core/loginout",
131+
"core/term-description",
132+
"core/query-loop",
133+
"core/template-part",
134+
"core/avatar",
135+
"core/post-author-biography",
136+
"core/comment-author-avatar",
137+
"core/comment-author-name",
138+
"core/comment-content",
139+
"core/comment-date",
140+
"core/comment-edit-link",
141+
"core/comment-reply-link",
142+
"core/comment-template",
143+
"core/comments",
144+
"core/comments-pagination",
145+
"core/comments-pagination-next",
146+
"core/comments-pagination-numbers",
147+
"core/comments-pagination-previous",
148+
"core/comments-title",
149+
"core/embed",
150+
"core/block",
151+
"core/text",
152+
"core/row",
153+
"core/grid",
154+
// Polaris blocks
155+
"polaris/accordion",
156+
"polaris/business-card",
157+
"polaris/section",
158+
"polaris/container",
159+
// Compass blocks
160+
"compass/single-details",
161+
"compass/single-features",
162+
"compass/single-pricing",
163+
];
164+
165+
// Apply wildcard config to common blocks if it exists
166+
if (wildcardConfig) {
167+
for (const blockName of commonBlocks) {
168+
if (!blocksConfig[blockName]) {
169+
expanded[blockName] = wildcardConfig;
170+
}
171+
}
172+
}
173+
174+
// Add all explicit block configurations (these override wildcard settings)
175+
for (const [blockName, config] of Object.entries(blocksConfig)) {
176+
if (blockName !== "*") {
177+
expanded[blockName] = config;
178+
}
179+
}
180+
181+
return expanded;
182+
}
183+
52184
function compileDirectory(dirPath, excludeDirs = []) {
53185
if (!fs.existsSync(dirPath)) return {};
54186
const files = fs.readdirSync(dirPath).filter((f) => f.endsWith(".js"));
@@ -307,6 +439,10 @@ function compileThemeJson({ skipBackup = false } = {}) {
307439
path.join(THEME_CONFIG_DIR, "settings"),
308440
);
309441
if (Object.keys(settingsData).length) {
442+
// Expand wildcard blocks if they exist
443+
if (settingsData.blocks) {
444+
settingsData.blocks = expandWildcardBlocks(settingsData.blocks);
445+
}
310446
compiled.settings = settingsData;
311447
}
312448

0 commit comments

Comments
 (0)