@wordpress-flow/cli 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/block-build-worker.js +4385 -0
- package/dist/index.js +158 -35
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -116534,7 +116534,7 @@ var watch = (paths, options) => {
|
|
|
116534
116534
|
var $watch = watch;
|
|
116535
116535
|
|
|
116536
116536
|
// src/commands/dev-command.ts
|
|
116537
|
-
import * as
|
|
116537
|
+
import * as path16 from "path";
|
|
116538
116538
|
import * as fs14 from "fs";
|
|
116539
116539
|
|
|
116540
116540
|
// src/build/block-scanner.ts
|
|
@@ -117319,7 +117319,7 @@ class MDXDependencyTracker {
|
|
|
117319
117319
|
}
|
|
117320
117320
|
|
|
117321
117321
|
// src/commands/build-command.ts
|
|
117322
|
-
import * as
|
|
117322
|
+
import * as path15 from "path";
|
|
117323
117323
|
|
|
117324
117324
|
// src/build/php-generator.ts
|
|
117325
117325
|
import * as fs13 from "fs";
|
|
@@ -117403,6 +117403,108 @@ add_action('enqueue_block_assets', 'wordpress_flow_enqueue_block_scripts');
|
|
|
117403
117403
|
}
|
|
117404
117404
|
}
|
|
117405
117405
|
|
|
117406
|
+
// src/build/worker-pool.ts
|
|
117407
|
+
import { Worker } from "worker_threads";
|
|
117408
|
+
import * as path14 from "path";
|
|
117409
|
+
import * as os from "os";
|
|
117410
|
+
var __dirname = "/Users/pkrasinski/Clients/RekinySukcesu.pl/wordpress-test/packages/cli/src/build";
|
|
117411
|
+
|
|
117412
|
+
class WorkerPool {
|
|
117413
|
+
concurrency;
|
|
117414
|
+
outputDir;
|
|
117415
|
+
webpackConfigPath;
|
|
117416
|
+
scriptsPath;
|
|
117417
|
+
workerPath;
|
|
117418
|
+
constructor(options) {
|
|
117419
|
+
this.concurrency = options.concurrency ?? Math.max(1, os.cpus().length - 1);
|
|
117420
|
+
this.outputDir = options.outputDir;
|
|
117421
|
+
this.webpackConfigPath = options.webpackConfigPath;
|
|
117422
|
+
this.scriptsPath = options.scriptsPath;
|
|
117423
|
+
const distDir = __dirname.replace(/\/src\/build$/, "/dist/build");
|
|
117424
|
+
this.workerPath = path14.join(distDir, "block-build-worker.js");
|
|
117425
|
+
}
|
|
117426
|
+
async buildAll(blocks, onProgress) {
|
|
117427
|
+
const results = [];
|
|
117428
|
+
const queue = [...blocks];
|
|
117429
|
+
let completed = 0;
|
|
117430
|
+
const total = blocks.length;
|
|
117431
|
+
let activeWorkers = 0;
|
|
117432
|
+
logger.info(`Building ${total} block(s) with ${this.concurrency} worker(s)`);
|
|
117433
|
+
return new Promise((resolve5, reject) => {
|
|
117434
|
+
const processNext = () => {
|
|
117435
|
+
while (activeWorkers < this.concurrency && queue.length > 0) {
|
|
117436
|
+
const block = queue.shift();
|
|
117437
|
+
activeWorkers++;
|
|
117438
|
+
this.buildBlockInWorker(block).then((result2) => {
|
|
117439
|
+
results.push(result2);
|
|
117440
|
+
completed++;
|
|
117441
|
+
activeWorkers--;
|
|
117442
|
+
onProgress?.(completed, total, result2.blockName, result2.success);
|
|
117443
|
+
if (queue.length > 0) {
|
|
117444
|
+
processNext();
|
|
117445
|
+
} else if (activeWorkers === 0) {
|
|
117446
|
+
resolve5(results);
|
|
117447
|
+
}
|
|
117448
|
+
}).catch((error) => {
|
|
117449
|
+
const result2 = {
|
|
117450
|
+
success: false,
|
|
117451
|
+
blockName: block.name,
|
|
117452
|
+
error: error.message || String(error)
|
|
117453
|
+
};
|
|
117454
|
+
results.push(result2);
|
|
117455
|
+
completed++;
|
|
117456
|
+
activeWorkers--;
|
|
117457
|
+
onProgress?.(completed, total, block.name, false);
|
|
117458
|
+
if (queue.length > 0) {
|
|
117459
|
+
processNext();
|
|
117460
|
+
} else if (activeWorkers === 0) {
|
|
117461
|
+
resolve5(results);
|
|
117462
|
+
}
|
|
117463
|
+
});
|
|
117464
|
+
}
|
|
117465
|
+
};
|
|
117466
|
+
processNext();
|
|
117467
|
+
});
|
|
117468
|
+
}
|
|
117469
|
+
buildBlockInWorker(block) {
|
|
117470
|
+
return new Promise((resolve5, reject) => {
|
|
117471
|
+
const tempDir = path14.join(process.cwd(), ".wordpress-flow-temp", `worker-${block.name}-${Date.now()}`);
|
|
117472
|
+
const workerData = {
|
|
117473
|
+
block: {
|
|
117474
|
+
name: block.name,
|
|
117475
|
+
filePath: block.filePath,
|
|
117476
|
+
scripts: block.scripts
|
|
117477
|
+
},
|
|
117478
|
+
outputDir: this.outputDir,
|
|
117479
|
+
webpackConfigPath: this.webpackConfigPath,
|
|
117480
|
+
scriptsPath: this.scriptsPath,
|
|
117481
|
+
tempDir
|
|
117482
|
+
};
|
|
117483
|
+
const worker = new Worker(this.workerPath, { workerData });
|
|
117484
|
+
const timeout = setTimeout(() => {
|
|
117485
|
+
worker.terminate();
|
|
117486
|
+
reject(new Error(`Worker timeout for block: ${block.name}`));
|
|
117487
|
+
}, 5 * 60 * 1000);
|
|
117488
|
+
worker.on("message", (result2) => {
|
|
117489
|
+
clearTimeout(timeout);
|
|
117490
|
+
worker.terminate();
|
|
117491
|
+
resolve5(result2);
|
|
117492
|
+
});
|
|
117493
|
+
worker.on("error", (error) => {
|
|
117494
|
+
clearTimeout(timeout);
|
|
117495
|
+
worker.terminate();
|
|
117496
|
+
reject(error);
|
|
117497
|
+
});
|
|
117498
|
+
worker.on("exit", (code2) => {
|
|
117499
|
+
clearTimeout(timeout);
|
|
117500
|
+
if (code2 !== 0) {
|
|
117501
|
+
reject(new Error(`Worker exited with code ${code2} for block: ${block.name}`));
|
|
117502
|
+
}
|
|
117503
|
+
});
|
|
117504
|
+
});
|
|
117505
|
+
}
|
|
117506
|
+
}
|
|
117507
|
+
|
|
117406
117508
|
// src/commands/build-command.ts
|
|
117407
117509
|
class BuildCommand {
|
|
117408
117510
|
configManager;
|
|
@@ -117456,28 +117558,48 @@ class BuildCommand {
|
|
|
117456
117558
|
} else {
|
|
117457
117559
|
logger.info(`Found ${blocks.length} block(s): ${blocks.map((b) => b.name).join(", ")}`);
|
|
117458
117560
|
}
|
|
117459
|
-
|
|
117460
|
-
|
|
117461
|
-
|
|
117462
|
-
|
|
117463
|
-
|
|
117464
|
-
|
|
117465
|
-
|
|
117561
|
+
const workerPool = new WorkerPool({
|
|
117562
|
+
concurrency: options.concurrency,
|
|
117563
|
+
outputDir,
|
|
117564
|
+
webpackConfigPath: webpackConfig,
|
|
117565
|
+
scriptsPath
|
|
117566
|
+
});
|
|
117567
|
+
const results = await workerPool.buildAll(blocks, (completed, total, blockName, success) => {
|
|
117568
|
+
if (success) {
|
|
117569
|
+
logger.success(`✅ Built: ${blockName} [${completed}/${total}]`);
|
|
117570
|
+
} else {
|
|
117571
|
+
logger.error(`❌ Failed: ${blockName} [${completed}/${total}]`);
|
|
117572
|
+
}
|
|
117573
|
+
});
|
|
117574
|
+
for (const block of blocks) {
|
|
117575
|
+
if (block.scripts && block.scripts.length > 0) {
|
|
117576
|
+
const result2 = results.find((r) => r.blockName === block.name);
|
|
117577
|
+
if (result2?.success) {
|
|
117578
|
+
const scriptPaths = block.scripts.map((script) => `scripts/${path15.basename(script).replace(/\.ts$/, ".js")}`);
|
|
117466
117579
|
this.blockScripts.set(block.name, scriptPaths);
|
|
117467
117580
|
}
|
|
117468
|
-
|
|
117469
|
-
|
|
117470
|
-
|
|
117471
|
-
|
|
117472
|
-
|
|
117581
|
+
}
|
|
117582
|
+
}
|
|
117583
|
+
const failures = results.filter((r) => !r.success);
|
|
117584
|
+
if (failures.length > 0) {
|
|
117585
|
+
logger.error(`
|
|
117586
|
+
Failed to build ${failures.length} block(s):`);
|
|
117587
|
+
for (const failure of failures) {
|
|
117588
|
+
logger.error(` - ${failure.blockName}: ${failure.error}`);
|
|
117473
117589
|
}
|
|
117474
117590
|
}
|
|
117475
117591
|
if (this.blockScripts.size > 0) {
|
|
117476
|
-
const phpPath =
|
|
117592
|
+
const phpPath = path15.join(path15.dirname(outputDir), "functions-blocks-scripts.php");
|
|
117477
117593
|
this.phpGenerator.generateScriptRegistrationPHP(this.blockScripts, phpPath);
|
|
117478
117594
|
}
|
|
117479
117595
|
await this.generateTypeDefinitions(outputDir);
|
|
117480
|
-
|
|
117596
|
+
const successCount = results.filter((r) => r.success).length;
|
|
117597
|
+
if (failures.length > 0) {
|
|
117598
|
+
logger.warn(`Build completed with errors. Built ${successCount}/${blocks.length} block(s).`);
|
|
117599
|
+
process.exit(1);
|
|
117600
|
+
} else {
|
|
117601
|
+
logger.success(`Build completed successfully! Built ${successCount} block(s).`);
|
|
117602
|
+
}
|
|
117481
117603
|
} catch (error) {
|
|
117482
117604
|
logger.error("Build operation failed");
|
|
117483
117605
|
process.exit(1);
|
|
@@ -117491,7 +117613,7 @@ class BuildCommand {
|
|
|
117491
117613
|
logger.warn("No blocks found for type generation");
|
|
117492
117614
|
return;
|
|
117493
117615
|
}
|
|
117494
|
-
const typesPath =
|
|
117616
|
+
const typesPath = path15.join(outputDir, "blocks.d.ts");
|
|
117495
117617
|
await this.typeGenerator.generateDefinitions(blocks, typesPath);
|
|
117496
117618
|
logger.success(`✅ Generated TypeScript definitions for ${blocks.length} block(s)`);
|
|
117497
117619
|
} catch (error) {
|
|
@@ -117658,7 +117780,7 @@ class DevCommand {
|
|
|
117658
117780
|
return new Promise(() => {});
|
|
117659
117781
|
}
|
|
117660
117782
|
handleFileEvent(eventType, filePath2, options) {
|
|
117661
|
-
const fullPath =
|
|
117783
|
+
const fullPath = path16.resolve(this.configManager.resolvePath(this.configManager.getConfig().paths.mdxOutputDir), filePath2);
|
|
117662
117784
|
logger.debug(`File ${eventType}: ${filePath2}`);
|
|
117663
117785
|
if (eventType === "unlink") {
|
|
117664
117786
|
logger.warn(`File deleted: ${filePath2} - Manual WordPress cleanup may be required`);
|
|
@@ -117677,7 +117799,7 @@ class DevCommand {
|
|
|
117677
117799
|
}
|
|
117678
117800
|
async handleLocalFileChange(filePath2, options) {
|
|
117679
117801
|
try {
|
|
117680
|
-
logger.info(`\uD83D\uDD04 Processing local file change: ${
|
|
117802
|
+
logger.info(`\uD83D\uDD04 Processing local file change: ${path16.relative(process.cwd(), filePath2)}`);
|
|
117681
117803
|
await this.pushCommand.execute({
|
|
117682
117804
|
files: [filePath2],
|
|
117683
117805
|
force: options.conflictResolution === "local-wins",
|
|
@@ -117727,13 +117849,13 @@ class DevCommand {
|
|
|
117727
117849
|
handleBlockFileEvent(eventType, filePath2, options) {
|
|
117728
117850
|
const config2 = this.configManager.getConfig();
|
|
117729
117851
|
const blocksDir = this.configManager.resolvePath(config2.build?.blocksDir || "./theme/blocks");
|
|
117730
|
-
const fullPath =
|
|
117852
|
+
const fullPath = path16.resolve(blocksDir, filePath2);
|
|
117731
117853
|
logger.debug(`Block file ${eventType}: ${filePath2}`);
|
|
117732
117854
|
if (eventType === "unlink") {
|
|
117733
117855
|
logger.warn(`Block file deleted: ${filePath2} - Manual cleanup may be required`);
|
|
117734
117856
|
return;
|
|
117735
117857
|
}
|
|
117736
|
-
const blockName =
|
|
117858
|
+
const blockName = path16.basename(filePath2, path16.extname(filePath2));
|
|
117737
117859
|
this.buildQueue.add(blockName);
|
|
117738
117860
|
const debounceKey = `block-${blockName}`;
|
|
117739
117861
|
const existingTimer = this.debounceTimers.get(debounceKey);
|
|
@@ -117803,8 +117925,8 @@ class DevCommand {
|
|
|
117803
117925
|
const sourceBlocks = await this.blockScanner.scanBlocks(this.configManager.resolvePath(config2.build?.blocksDir || "./theme/blocks"));
|
|
117804
117926
|
const missingBuilds = [];
|
|
117805
117927
|
for (const block of sourceBlocks) {
|
|
117806
|
-
const blockBuildDir =
|
|
117807
|
-
const blockJsonPath =
|
|
117928
|
+
const blockBuildDir = path16.join(outputDir, block.name);
|
|
117929
|
+
const blockJsonPath = path16.join(blockBuildDir, "block.json");
|
|
117808
117930
|
if (!fs14.existsSync(blockJsonPath)) {
|
|
117809
117931
|
missingBuilds.push(block.name);
|
|
117810
117932
|
}
|
|
@@ -117859,7 +117981,7 @@ class DevCommand {
|
|
|
117859
117981
|
if (blocks.length === 0) {
|
|
117860
117982
|
return;
|
|
117861
117983
|
}
|
|
117862
|
-
const typesPath =
|
|
117984
|
+
const typesPath = path16.join(outputDir, "blocks.d.ts");
|
|
117863
117985
|
await this.typeGenerator.generateDefinitions(blocks, typesPath);
|
|
117864
117986
|
logger.debug(`\uD83D\uDD27 Updated TypeScript definitions for ${blocks.length} block(s)`);
|
|
117865
117987
|
} catch (error) {
|
|
@@ -117882,7 +118004,7 @@ class DevCommand {
|
|
|
117882
118004
|
return;
|
|
117883
118005
|
}
|
|
117884
118006
|
logger.info(`\uD83D\uDCC4 Found ${dependentFiles.size} content file(s) that depend on changed blocks`);
|
|
117885
|
-
logger.debug(`Dependent files: ${Array.from(dependentFiles).map((f) =>
|
|
118007
|
+
logger.debug(`Dependent files: ${Array.from(dependentFiles).map((f) => path16.basename(f)).join(", ")}`);
|
|
117886
118008
|
const config2 = this.configManager.getConfig();
|
|
117887
118009
|
const contentDir = this.configManager.resolvePath(config2.paths.mdxOutputDir);
|
|
117888
118010
|
await this.mdxDependencyTracker.scanMDXDependencies(contentDir);
|
|
@@ -117917,7 +118039,7 @@ class DevCommand {
|
|
|
117917
118039
|
|
|
117918
118040
|
// src/commands/build-templates-command.ts
|
|
117919
118041
|
import * as fs15 from "fs";
|
|
117920
|
-
import * as
|
|
118042
|
+
import * as path17 from "path";
|
|
117921
118043
|
class BuildTemplatesCommand {
|
|
117922
118044
|
configManager;
|
|
117923
118045
|
constructor() {
|
|
@@ -117959,8 +118081,8 @@ class BuildTemplatesCommand {
|
|
|
117959
118081
|
let errorCount = 0;
|
|
117960
118082
|
for (let i2 = 0;i2 < templateFiles.length; i2++) {
|
|
117961
118083
|
const templateFile = templateFiles[i2];
|
|
117962
|
-
const relativePath =
|
|
117963
|
-
const templateName =
|
|
118084
|
+
const relativePath = path17.relative(templatesDir, templateFile);
|
|
118085
|
+
const templateName = path17.basename(templateFile, ".mdx");
|
|
117964
118086
|
logger.step(i2 + 1, templateFiles.length, `Building template: ${relativePath}`);
|
|
117965
118087
|
try {
|
|
117966
118088
|
await this.buildTemplate(templateFile, templateName, outputDir, renderer);
|
|
@@ -117984,15 +118106,15 @@ class BuildTemplatesCommand {
|
|
|
117984
118106
|
const cleanContent = this.removeFrontmatter(mdxContent);
|
|
117985
118107
|
const html5 = await renderer.renderMDXToHTML(cleanContent);
|
|
117986
118108
|
const cleanHTML = renderer.postProcessHTML(html5);
|
|
117987
|
-
const outputPath =
|
|
118109
|
+
const outputPath = path17.join(outputDir, `${templateName}.html`);
|
|
117988
118110
|
fs15.writeFileSync(outputPath, cleanHTML, "utf8");
|
|
117989
|
-
logger.info(`✓ Generated: ${
|
|
118111
|
+
logger.info(`✓ Generated: ${path17.relative(process.cwd(), outputPath)}`);
|
|
117990
118112
|
}
|
|
117991
118113
|
findMDXFiles(dir) {
|
|
117992
118114
|
const files = [];
|
|
117993
118115
|
const entries = fs15.readdirSync(dir, { withFileTypes: true });
|
|
117994
118116
|
for (const entry of entries) {
|
|
117995
|
-
const fullPath =
|
|
118117
|
+
const fullPath = path17.join(dir, entry.name);
|
|
117996
118118
|
if (entry.isDirectory()) {
|
|
117997
118119
|
files.push(...this.findMDXFiles(fullPath));
|
|
117998
118120
|
} else if (entry.isFile() && entry.name.endsWith(".mdx")) {
|
|
@@ -118009,7 +118131,7 @@ class BuildTemplatesCommand {
|
|
|
118009
118131
|
// package.json
|
|
118010
118132
|
var package_default = {
|
|
118011
118133
|
name: "@wordpress-flow/cli",
|
|
118012
|
-
version: "1.0.
|
|
118134
|
+
version: "1.0.5",
|
|
118013
118135
|
type: "module",
|
|
118014
118136
|
description: "TypeScript-based WordPress block creation system",
|
|
118015
118137
|
main: "dist/index.js",
|
|
@@ -118017,7 +118139,7 @@ var package_default = {
|
|
|
118017
118139
|
"wordpress-flow": "./dist/index.js"
|
|
118018
118140
|
},
|
|
118019
118141
|
scripts: {
|
|
118020
|
-
build: "bun build ./src/index.ts --outdir ./dist --target node"
|
|
118142
|
+
build: "bun build ./src/index.ts --outdir ./dist --target node && bun build ./src/build/block-build-worker.ts --outfile ./dist/build/block-build-worker.js --target node"
|
|
118021
118143
|
},
|
|
118022
118144
|
dependencies: {
|
|
118023
118145
|
"@babel/core": "^7.28.4",
|
|
@@ -118080,7 +118202,7 @@ program2.command("setup").description("Run the configuration wizard").action(asy
|
|
|
118080
118202
|
process.exit(1);
|
|
118081
118203
|
}
|
|
118082
118204
|
});
|
|
118083
|
-
program2.command("build").description("Build WordPress blocks for Gutenberg").option("--blocks-dir <dir>", "Source directory for blocks").option("--output-dir <dir>", "Output directory for built blocks").option("--webpack-config <path>", "Path to webpack config file").option("--watch", "Watch mode for development").option("-b, --blocks <names...>", "Specific block names to build").action(async (options) => {
|
|
118205
|
+
program2.command("build").description("Build WordPress blocks for Gutenberg").option("--blocks-dir <dir>", "Source directory for blocks").option("--output-dir <dir>", "Output directory for built blocks").option("--webpack-config <path>", "Path to webpack config file").option("--watch", "Watch mode for development").option("-b, --blocks <names...>", "Specific block names to build").option("-c, --concurrency <number>", "Number of parallel workers (default: CPU cores - 1)").action(async (options) => {
|
|
118084
118206
|
try {
|
|
118085
118207
|
await ensureConfiguration();
|
|
118086
118208
|
const command = new BuildCommand;
|
|
@@ -118089,7 +118211,8 @@ program2.command("build").description("Build WordPress blocks for Gutenberg").op
|
|
|
118089
118211
|
outputDir: options.outputDir,
|
|
118090
118212
|
webpackConfig: options.webpackConfig,
|
|
118091
118213
|
watch: options.watch || false,
|
|
118092
|
-
blocks: options.blocks
|
|
118214
|
+
blocks: options.blocks,
|
|
118215
|
+
concurrency: options.concurrency ? parseInt(options.concurrency, 10) : undefined
|
|
118093
118216
|
});
|
|
118094
118217
|
logger.info("Build command completed successfully");
|
|
118095
118218
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress-flow/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TypeScript-based WordPress block creation system",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"wordpress-flow": "./dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "bun build ./src/index.ts --outdir ./dist --target node"
|
|
11
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node && bun build ./src/build/block-build-worker.ts --outfile ./dist/build/block-build-worker.js --target node"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@babel/core": "^7.28.4",
|