@wordpress-flow/cli 1.0.3 → 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/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 path15 from "path";
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 path14 from "path";
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;
@@ -117432,34 +117534,72 @@ class BuildCommand {
117432
117534
  if (scriptsPath) {
117433
117535
  logger.info(`Scripts directory: ${scriptsPath}`);
117434
117536
  }
117435
- const blocks = await this.blockScanner.scanBlocks(blocksDir);
117537
+ let blocks = await this.blockScanner.scanBlocks(blocksDir);
117436
117538
  if (blocks.length === 0) {
117437
117539
  logger.warn("No blocks found in the specified directory");
117438
117540
  return;
117439
117541
  }
117440
- logger.info(`Found ${blocks.length} block(s): ${blocks.map((b) => b.name).join(", ")}`);
117441
- for (let i2 = 0;i2 < blocks.length; i2++) {
117442
- const block = blocks[i2];
117443
- logger.step(i2 + 1, blocks.length, `Building block: ${block.name}`);
117444
- try {
117445
- await this.blockBuilder.buildBlock(block, outputDir, webpackConfig, scriptsPath);
117446
- if (block.scripts && block.scripts.length > 0) {
117447
- const scriptPaths = block.scripts.map((script) => `scripts/${path14.basename(script).replace(/\.ts$/, ".js")}`);
117542
+ if (options.blocks && options.blocks.length > 0) {
117543
+ const requestedBlocks = options.blocks;
117544
+ const allBlockNames = blocks.map((b) => b.name);
117545
+ const filteredBlocks = blocks.filter((block) => requestedBlocks.includes(block.name));
117546
+ const foundBlockNames = filteredBlocks.map((b) => b.name);
117547
+ const notFoundBlocks = requestedBlocks.filter((name2) => !foundBlockNames.includes(name2));
117548
+ if (notFoundBlocks.length > 0) {
117549
+ logger.warn(`Requested blocks not found: ${notFoundBlocks.join(", ")}`);
117550
+ logger.info(`Available blocks: ${allBlockNames.join(", ")}`);
117551
+ }
117552
+ if (filteredBlocks.length === 0) {
117553
+ logger.warn("No matching blocks found to build");
117554
+ return;
117555
+ }
117556
+ blocks = filteredBlocks;
117557
+ logger.info(`Building ${blocks.length} specified block(s): ${blocks.map((b) => b.name).join(", ")}`);
117558
+ } else {
117559
+ logger.info(`Found ${blocks.length} block(s): ${blocks.map((b) => b.name).join(", ")}`);
117560
+ }
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")}`);
117448
117579
  this.blockScripts.set(block.name, scriptPaths);
117449
117580
  }
117450
- logger.success(`Built: ${block.name}`);
117451
- } catch (error) {
117452
- logger.error(`Failed to build block: ${block.name}`);
117453
- logger.error(`Block file: ${block.filePath}`);
117454
- throw error;
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}`);
117455
117589
  }
117456
117590
  }
117457
117591
  if (this.blockScripts.size > 0) {
117458
- const phpPath = path14.join(path14.dirname(outputDir), "functions-blocks-scripts.php");
117592
+ const phpPath = path15.join(path15.dirname(outputDir), "functions-blocks-scripts.php");
117459
117593
  this.phpGenerator.generateScriptRegistrationPHP(this.blockScripts, phpPath);
117460
117594
  }
117461
117595
  await this.generateTypeDefinitions(outputDir);
117462
- logger.success(`Build completed successfully! Built ${blocks.length} block(s).`);
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
+ }
117463
117603
  } catch (error) {
117464
117604
  logger.error("Build operation failed");
117465
117605
  process.exit(1);
@@ -117473,7 +117613,7 @@ class BuildCommand {
117473
117613
  logger.warn("No blocks found for type generation");
117474
117614
  return;
117475
117615
  }
117476
- const typesPath = path14.join(outputDir, "blocks.d.ts");
117616
+ const typesPath = path15.join(outputDir, "blocks.d.ts");
117477
117617
  await this.typeGenerator.generateDefinitions(blocks, typesPath);
117478
117618
  logger.success(`✅ Generated TypeScript definitions for ${blocks.length} block(s)`);
117479
117619
  } catch (error) {
@@ -117640,7 +117780,7 @@ class DevCommand {
117640
117780
  return new Promise(() => {});
117641
117781
  }
117642
117782
  handleFileEvent(eventType, filePath2, options) {
117643
- const fullPath = path15.resolve(this.configManager.resolvePath(this.configManager.getConfig().paths.mdxOutputDir), filePath2);
117783
+ const fullPath = path16.resolve(this.configManager.resolvePath(this.configManager.getConfig().paths.mdxOutputDir), filePath2);
117644
117784
  logger.debug(`File ${eventType}: ${filePath2}`);
117645
117785
  if (eventType === "unlink") {
117646
117786
  logger.warn(`File deleted: ${filePath2} - Manual WordPress cleanup may be required`);
@@ -117659,7 +117799,7 @@ class DevCommand {
117659
117799
  }
117660
117800
  async handleLocalFileChange(filePath2, options) {
117661
117801
  try {
117662
- logger.info(`\uD83D\uDD04 Processing local file change: ${path15.relative(process.cwd(), filePath2)}`);
117802
+ logger.info(`\uD83D\uDD04 Processing local file change: ${path16.relative(process.cwd(), filePath2)}`);
117663
117803
  await this.pushCommand.execute({
117664
117804
  files: [filePath2],
117665
117805
  force: options.conflictResolution === "local-wins",
@@ -117709,13 +117849,13 @@ class DevCommand {
117709
117849
  handleBlockFileEvent(eventType, filePath2, options) {
117710
117850
  const config2 = this.configManager.getConfig();
117711
117851
  const blocksDir = this.configManager.resolvePath(config2.build?.blocksDir || "./theme/blocks");
117712
- const fullPath = path15.resolve(blocksDir, filePath2);
117852
+ const fullPath = path16.resolve(blocksDir, filePath2);
117713
117853
  logger.debug(`Block file ${eventType}: ${filePath2}`);
117714
117854
  if (eventType === "unlink") {
117715
117855
  logger.warn(`Block file deleted: ${filePath2} - Manual cleanup may be required`);
117716
117856
  return;
117717
117857
  }
117718
- const blockName = path15.basename(filePath2, path15.extname(filePath2));
117858
+ const blockName = path16.basename(filePath2, path16.extname(filePath2));
117719
117859
  this.buildQueue.add(blockName);
117720
117860
  const debounceKey = `block-${blockName}`;
117721
117861
  const existingTimer = this.debounceTimers.get(debounceKey);
@@ -117785,8 +117925,8 @@ class DevCommand {
117785
117925
  const sourceBlocks = await this.blockScanner.scanBlocks(this.configManager.resolvePath(config2.build?.blocksDir || "./theme/blocks"));
117786
117926
  const missingBuilds = [];
117787
117927
  for (const block of sourceBlocks) {
117788
- const blockBuildDir = path15.join(outputDir, block.name);
117789
- const blockJsonPath = path15.join(blockBuildDir, "block.json");
117928
+ const blockBuildDir = path16.join(outputDir, block.name);
117929
+ const blockJsonPath = path16.join(blockBuildDir, "block.json");
117790
117930
  if (!fs14.existsSync(blockJsonPath)) {
117791
117931
  missingBuilds.push(block.name);
117792
117932
  }
@@ -117841,7 +117981,7 @@ class DevCommand {
117841
117981
  if (blocks.length === 0) {
117842
117982
  return;
117843
117983
  }
117844
- const typesPath = path15.join(outputDir, "blocks.d.ts");
117984
+ const typesPath = path16.join(outputDir, "blocks.d.ts");
117845
117985
  await this.typeGenerator.generateDefinitions(blocks, typesPath);
117846
117986
  logger.debug(`\uD83D\uDD27 Updated TypeScript definitions for ${blocks.length} block(s)`);
117847
117987
  } catch (error) {
@@ -117864,7 +118004,7 @@ class DevCommand {
117864
118004
  return;
117865
118005
  }
117866
118006
  logger.info(`\uD83D\uDCC4 Found ${dependentFiles.size} content file(s) that depend on changed blocks`);
117867
- logger.debug(`Dependent files: ${Array.from(dependentFiles).map((f) => path15.basename(f)).join(", ")}`);
118007
+ logger.debug(`Dependent files: ${Array.from(dependentFiles).map((f) => path16.basename(f)).join(", ")}`);
117868
118008
  const config2 = this.configManager.getConfig();
117869
118009
  const contentDir = this.configManager.resolvePath(config2.paths.mdxOutputDir);
117870
118010
  await this.mdxDependencyTracker.scanMDXDependencies(contentDir);
@@ -117899,7 +118039,7 @@ class DevCommand {
117899
118039
 
117900
118040
  // src/commands/build-templates-command.ts
117901
118041
  import * as fs15 from "fs";
117902
- import * as path16 from "path";
118042
+ import * as path17 from "path";
117903
118043
  class BuildTemplatesCommand {
117904
118044
  configManager;
117905
118045
  constructor() {
@@ -117941,8 +118081,8 @@ class BuildTemplatesCommand {
117941
118081
  let errorCount = 0;
117942
118082
  for (let i2 = 0;i2 < templateFiles.length; i2++) {
117943
118083
  const templateFile = templateFiles[i2];
117944
- const relativePath = path16.relative(templatesDir, templateFile);
117945
- const templateName = path16.basename(templateFile, ".mdx");
118084
+ const relativePath = path17.relative(templatesDir, templateFile);
118085
+ const templateName = path17.basename(templateFile, ".mdx");
117946
118086
  logger.step(i2 + 1, templateFiles.length, `Building template: ${relativePath}`);
117947
118087
  try {
117948
118088
  await this.buildTemplate(templateFile, templateName, outputDir, renderer);
@@ -117966,15 +118106,15 @@ class BuildTemplatesCommand {
117966
118106
  const cleanContent = this.removeFrontmatter(mdxContent);
117967
118107
  const html5 = await renderer.renderMDXToHTML(cleanContent);
117968
118108
  const cleanHTML = renderer.postProcessHTML(html5);
117969
- const outputPath = path16.join(outputDir, `${templateName}.html`);
118109
+ const outputPath = path17.join(outputDir, `${templateName}.html`);
117970
118110
  fs15.writeFileSync(outputPath, cleanHTML, "utf8");
117971
- logger.info(`✓ Generated: ${path16.relative(process.cwd(), outputPath)}`);
118111
+ logger.info(`✓ Generated: ${path17.relative(process.cwd(), outputPath)}`);
117972
118112
  }
117973
118113
  findMDXFiles(dir) {
117974
118114
  const files = [];
117975
118115
  const entries = fs15.readdirSync(dir, { withFileTypes: true });
117976
118116
  for (const entry of entries) {
117977
- const fullPath = path16.join(dir, entry.name);
118117
+ const fullPath = path17.join(dir, entry.name);
117978
118118
  if (entry.isDirectory()) {
117979
118119
  files.push(...this.findMDXFiles(fullPath));
117980
118120
  } else if (entry.isFile() && entry.name.endsWith(".mdx")) {
@@ -117988,10 +118128,63 @@ class BuildTemplatesCommand {
117988
118128
  return content4.replace(frontmatterRegex, "").trim();
117989
118129
  }
117990
118130
  }
118131
+ // package.json
118132
+ var package_default = {
118133
+ name: "@wordpress-flow/cli",
118134
+ version: "1.0.5",
118135
+ type: "module",
118136
+ description: "TypeScript-based WordPress block creation system",
118137
+ main: "dist/index.js",
118138
+ bin: {
118139
+ "wordpress-flow": "./dist/index.js"
118140
+ },
118141
+ scripts: {
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"
118143
+ },
118144
+ dependencies: {
118145
+ "@babel/core": "^7.28.4",
118146
+ "@babel/preset-react": "^7.27.1",
118147
+ "@mdx-js/mdx": "^3.1.1",
118148
+ "@mdx-js/react": "^3.1.1",
118149
+ "@types/react": "^18.3.24",
118150
+ "@types/wordpress__block-editor": "^11.5.17",
118151
+ "@wordpress/block-editor": "^15.4.0",
118152
+ "@wordpress/block-serialization-default-parser": "^5.33.0",
118153
+ "@wordpress/blocks": "^15.6.0",
118154
+ "@wordpress/element": "^6.33.0",
118155
+ ajv: "^8.17.1",
118156
+ axios: "^1.12.2",
118157
+ chalk: "^4.1.2",
118158
+ chokidar: "^3.5.3",
118159
+ commander: "^11.0.0",
118160
+ dotenv: "^17.2.3",
118161
+ esbuild: "^0.19.0",
118162
+ glob: "^11.0.3",
118163
+ mysql2: "^3.15.2",
118164
+ react: "^18.3.1",
118165
+ "react-dom": "^18.3.1"
118166
+ },
118167
+ devDependencies: {
118168
+ "@types/glob": "^9.0.0",
118169
+ "@types/mysql": "^2.15.27",
118170
+ "@types/node": "^20.0.0",
118171
+ "@wordpress/scripts": "^30.24.0",
118172
+ typescript: "^5.0.0",
118173
+ "webpack-cli": "^6.0.1"
118174
+ },
118175
+ keywords: [
118176
+ "wordpress",
118177
+ "blocks",
118178
+ "cli",
118179
+ "typescript"
118180
+ ],
118181
+ author: "Przemysław Krasiński",
118182
+ license: "MIT"
118183
+ };
117991
118184
 
117992
118185
  // src/index.ts
117993
118186
  var program2 = new Command;
117994
- program2.name("wordpress-flow").description("Build WordPress sites with React, TypeScript, and MDX - A content-first development framework").version("0.0.1");
118187
+ program2.name("wordpress-flow").description("Build WordPress sites with React, TypeScript, and MDX - A content-first development framework").version(package_default.version);
117995
118188
  program2.option("-v, --verbose", "Enable verbose logging").option("-q, --quiet", "Suppress non-error output").hook("preAction", (thisCommand) => {
117996
118189
  const opts = thisCommand.opts();
117997
118190
  if (opts.verbose) {
@@ -118009,7 +118202,7 @@ program2.command("setup").description("Run the configuration wizard").action(asy
118009
118202
  process.exit(1);
118010
118203
  }
118011
118204
  });
118012
- 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").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) => {
118013
118206
  try {
118014
118207
  await ensureConfiguration();
118015
118208
  const command = new BuildCommand;
@@ -118017,7 +118210,9 @@ program2.command("build").description("Build WordPress blocks for Gutenberg").op
118017
118210
  blocksDir: options.blocksDir,
118018
118211
  outputDir: options.outputDir,
118019
118212
  webpackConfig: options.webpackConfig,
118020
- watch: options.watch || false
118213
+ watch: options.watch || false,
118214
+ blocks: options.blocks,
118215
+ concurrency: options.concurrency ? parseInt(options.concurrency, 10) : undefined
118021
118216
  });
118022
118217
  logger.info("Build command completed successfully");
118023
118218
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress-flow/cli",
3
- "version": "1.0.3",
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",