@wordpress-flow/cli 1.2.0 → 1.2.2

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.
@@ -1837,7 +1837,7 @@ import * as fs from "fs";
1837
1837
  import * as esbuild from "esbuild";
1838
1838
  import { execSync } from "child_process";
1839
1839
  async function buildBlock() {
1840
- const { block, outputDir, webpackConfigPath, scriptsPath, tempDir } = workerData;
1840
+ const { block, outputDir, scriptsOutputDir, webpackConfigPath, scriptsPath, tempDir } = workerData;
1841
1841
  try {
1842
1842
  fs.mkdirSync(tempDir, { recursive: true });
1843
1843
  const entryPoint = await generateEntryPoint(block, tempDir);
@@ -1845,7 +1845,7 @@ async function buildBlock() {
1845
1845
  fs.mkdirSync(blockOutputDir, { recursive: true });
1846
1846
  let scriptPaths = [];
1847
1847
  if (block.scripts && block.scripts.length > 0 && scriptsPath) {
1848
- scriptPaths = await buildBlockScripts(block.scripts, scriptsPath, outputDir);
1848
+ scriptPaths = await buildBlockScripts(block.scripts, scriptsPath, scriptsOutputDir);
1849
1849
  }
1850
1850
  await generateBlockJson(block, blockOutputDir, tempDir);
1851
1851
  await generateSSRVersion(block, blockOutputDir);
@@ -1859,10 +1859,22 @@ async function buildBlock() {
1859
1859
  };
1860
1860
  } catch (error) {
1861
1861
  cleanupTempFiles(tempDir);
1862
+ let errorMessage = "Unknown error";
1863
+ if (error instanceof Error) {
1864
+ errorMessage = error.message;
1865
+ if (error.stack) {
1866
+ errorMessage += `
1867
+ ${error.stack}`;
1868
+ }
1869
+ } else if (typeof error === "string") {
1870
+ errorMessage = error;
1871
+ } else if (error) {
1872
+ errorMessage = JSON.stringify(error);
1873
+ }
1862
1874
  return {
1863
1875
  success: false,
1864
1876
  blockName: block.name,
1865
- error: error.message || String(error)
1877
+ error: errorMessage
1866
1878
  };
1867
1879
  }
1868
1880
  }
@@ -1889,29 +1901,33 @@ if (document.readyState === 'loading') {
1889
1901
  fs.writeFileSync(entryPath, entryContent, "utf8");
1890
1902
  return entryPath;
1891
1903
  }
1892
- async function buildBlockScripts(scripts, scriptsPath, outputDir) {
1893
- const scriptsOutputDir = path.join(outputDir, "scripts");
1904
+ async function buildBlockScripts(scripts, scriptsPath, scriptsOutputDir) {
1894
1905
  fs.mkdirSync(scriptsOutputDir, { recursive: true });
1895
1906
  const outputPaths = [];
1896
1907
  for (const script of scripts) {
1897
1908
  const scriptPath = path.resolve(scriptsPath, script);
1898
1909
  if (!fs.existsSync(scriptPath)) {
1899
- continue;
1910
+ throw new Error(`Script file not found: ${scriptPath}`);
1900
1911
  }
1901
1912
  const scriptName = path.basename(script);
1902
1913
  const outputPath = path.join(scriptsOutputDir, scriptName.replace(/\.ts$/, ".js"));
1903
- await esbuild.build({
1904
- entryPoints: [scriptPath],
1905
- outfile: outputPath,
1906
- bundle: true,
1907
- minify: true,
1908
- platform: "browser",
1909
- target: "es2015",
1910
- format: "iife",
1911
- external: ["react", "react-dom", "@wordpress/*", "jquery"],
1912
- define: { "process.env.NODE_ENV": '"production"' },
1913
- logLevel: "warning"
1914
- });
1914
+ try {
1915
+ await esbuild.build({
1916
+ entryPoints: [scriptPath],
1917
+ outfile: outputPath,
1918
+ bundle: true,
1919
+ minify: true,
1920
+ platform: "browser",
1921
+ target: "es2015",
1922
+ format: "iife",
1923
+ external: ["react", "react-dom", "@wordpress/*", "jquery"],
1924
+ define: { "process.env.NODE_ENV": '"production"' },
1925
+ logLevel: "warning",
1926
+ allowOverwrite: true
1927
+ });
1928
+ } catch (err) {
1929
+ throw new Error(`Failed to build script ${script}: ${err.message}`);
1930
+ }
1915
1931
  outputPaths.push(outputPath);
1916
1932
  }
1917
1933
  return outputPaths;
package/dist/index.js CHANGED
@@ -81015,13 +81015,16 @@ class ConfigManager {
81015
81015
  const theme = raw.paths?.theme || DEFAULTS.paths.theme;
81016
81016
  const content2 = raw.paths?.content || DEFAULTS.paths.content;
81017
81017
  const plugins = raw.paths?.plugins || DEFAULTS.paths.plugins;
81018
+ const dist = `${theme}/dist`;
81018
81019
  return {
81019
81020
  paths: {
81020
81021
  theme,
81021
81022
  content: content2,
81022
81023
  plugins,
81023
81024
  blocks: `${theme}/blocks`,
81024
- dist: `${theme}/dist`,
81025
+ dist,
81026
+ blocksDist: `${dist}/blocks`,
81027
+ scriptsDist: `${dist}/scripts`,
81025
81028
  scripts: `${theme}/scripts`,
81026
81029
  templates: `${content2}/templates`,
81027
81030
  templateParts: `${content2}/parts`,
@@ -81167,7 +81170,7 @@ class ConfigManager {
81167
81170
  },
81168
81171
  build: {
81169
81172
  blocksDir: config.paths.blocks,
81170
- outputDir: config.paths.dist,
81173
+ outputDir: config.paths.blocksDist,
81171
81174
  scriptsPath: config.paths.scripts
81172
81175
  },
81173
81176
  templates: {
@@ -113058,7 +113061,7 @@ class PushCommand {
113058
113061
  this.blockRegistry = blockRegistry;
113059
113062
  } else {
113060
113063
  const config = this.configManager.getConfig();
113061
- const buildOutputDir = this.configManager.resolvePath(config.paths.dist);
113064
+ const buildOutputDir = this.configManager.resolvePath(config.paths.blocksDist);
113062
113065
  this.blockRegistry = new BlockRegistry(buildOutputDir);
113063
113066
  }
113064
113067
  }
@@ -114740,6 +114743,7 @@ import * as os from "os";
114740
114743
  class AbortableWorkerPool {
114741
114744
  concurrency;
114742
114745
  outputDir;
114746
+ scriptsOutputDir;
114743
114747
  webpackConfigPath;
114744
114748
  scriptsPath;
114745
114749
  workerPath;
@@ -114747,6 +114751,7 @@ class AbortableWorkerPool {
114747
114751
  constructor(options) {
114748
114752
  this.concurrency = options.concurrency ?? Math.max(1, os.cpus().length - 1);
114749
114753
  this.outputDir = options.outputDir;
114754
+ this.scriptsOutputDir = options.scriptsOutputDir;
114750
114755
  this.webpackConfigPath = options.webpackConfigPath;
114751
114756
  this.scriptsPath = options.scriptsPath;
114752
114757
  this.workerPath = path9.join(import.meta.dirname, "build", "block-build-worker.js");
@@ -114808,22 +114813,23 @@ class AbortableWorkerPool {
114808
114813
  results.push(result2);
114809
114814
  completed++;
114810
114815
  activeCount--;
114811
- onProgress?.(completed, total, result2.blockName, result2.success, result2.aborted || false);
114816
+ onProgress?.(completed, total, result2.blockName, result2.success, result2.error);
114812
114817
  if (queue.length > 0) {
114813
114818
  processNext();
114814
114819
  } else if (activeCount === 0) {
114815
114820
  resolve4(results);
114816
114821
  }
114817
114822
  }).catch((error) => {
114823
+ const errorMsg = error.message || String(error);
114818
114824
  const result2 = {
114819
114825
  success: false,
114820
114826
  blockName: block.name,
114821
- error: error.message || String(error)
114827
+ error: errorMsg
114822
114828
  };
114823
114829
  results.push(result2);
114824
114830
  completed++;
114825
114831
  activeCount--;
114826
- onProgress?.(completed, total, block.name, false, false);
114832
+ onProgress?.(completed, total, block.name, false, errorMsg);
114827
114833
  if (queue.length > 0) {
114828
114834
  processNext();
114829
114835
  } else if (activeCount === 0) {
@@ -114845,6 +114851,7 @@ class AbortableWorkerPool {
114845
114851
  scripts: block.scripts
114846
114852
  },
114847
114853
  outputDir: this.outputDir,
114854
+ scriptsOutputDir: this.scriptsOutputDir,
114848
114855
  webpackConfigPath: this.webpackConfigPath,
114849
114856
  scriptsPath: this.scriptsPath,
114850
114857
  tempDir
@@ -116261,7 +116268,7 @@ class DockerEnvManager {
116261
116268
  // package.json
116262
116269
  var package_default = {
116263
116270
  name: "@wordpress-flow/cli",
116264
- version: "1.2.0",
116271
+ version: "1.2.2",
116265
116272
  type: "module",
116266
116273
  description: "TypeScript-based WordPress block creation system",
116267
116274
  main: "dist/index.js",
@@ -116338,6 +116345,7 @@ class DevModeOrchestrator {
116338
116345
  isRunning = false;
116339
116346
  blocksDir;
116340
116347
  outputDir;
116348
+ scriptsOutputDir;
116341
116349
  templatesDir;
116342
116350
  templatesOutputDir;
116343
116351
  templatePartsDir;
@@ -116458,7 +116466,8 @@ class DevModeOrchestrator {
116458
116466
  async initializeConfig() {
116459
116467
  const config = this.configManager.getConfig();
116460
116468
  this.blocksDir = this.configManager.resolvePath(config.paths.blocks);
116461
- this.outputDir = this.configManager.resolvePath(config.paths.dist);
116469
+ this.outputDir = this.configManager.resolvePath(config.paths.blocksDist);
116470
+ this.scriptsOutputDir = this.configManager.resolvePath(config.paths.scriptsDist);
116462
116471
  this.webpackConfig = path17.join(__dirname2, "..", "webpack.config.cjs");
116463
116472
  this.scriptsPath = this.configManager.resolvePath(config.paths.scripts);
116464
116473
  this.contentDir = this.configManager.resolvePath(config.paths.content);
@@ -116469,11 +116478,15 @@ class DevModeOrchestrator {
116469
116478
  if (!fs15.existsSync(this.outputDir)) {
116470
116479
  fs15.mkdirSync(this.outputDir, { recursive: true });
116471
116480
  }
116481
+ if (!fs15.existsSync(this.scriptsOutputDir)) {
116482
+ fs15.mkdirSync(this.scriptsOutputDir, { recursive: true });
116483
+ }
116472
116484
  }
116473
116485
  initializeManagers() {
116474
116486
  this.workerPool = new AbortableWorkerPool({
116475
116487
  concurrency: this.options.concurrency,
116476
116488
  outputDir: this.outputDir,
116489
+ scriptsOutputDir: this.scriptsOutputDir,
116477
116490
  webpackConfigPath: this.webpackConfig,
116478
116491
  scriptsPath: this.scriptsPath
116479
116492
  });
@@ -116552,12 +116565,12 @@ class DevModeOrchestrator {
116552
116565
  let successCount = 0;
116553
116566
  let failCount = 0;
116554
116567
  const blockScripts = new Map;
116555
- const results = await this.workerPool.buildAll(blocksToRebuild, (completed, total, blockName, success) => {
116568
+ const results = await this.workerPool.buildAll(blocksToRebuild, (completed, total, blockName, success, error) => {
116556
116569
  if (success) {
116557
116570
  console.log(` ✅ ${blockName} [${completed}/${total}]`);
116558
116571
  successCount++;
116559
116572
  } else {
116560
- console.log(` ❌ ${blockName} failed [${completed}/${total}]`);
116573
+ console.log(` ❌ ${blockName} failed [${completed}/${total}]: ${error || "unknown error"}`);
116561
116574
  failCount++;
116562
116575
  }
116563
116576
  });
@@ -116575,7 +116588,8 @@ class DevModeOrchestrator {
116575
116588
  }
116576
116589
  }
116577
116590
  if (blockScripts.size > 0) {
116578
- const phpPath = path17.join(path17.dirname(this.outputDir), "functions-blocks-scripts.php");
116591
+ const distDir = path17.dirname(this.outputDir);
116592
+ const phpPath = path17.join(distDir, "functions-blocks-scripts.php");
116579
116593
  this.phpGenerator.generateScriptRegistrationPHP(blockScripts, phpPath);
116580
116594
  }
116581
116595
  await this.generateTypeDefinitions();
@@ -117610,12 +117624,14 @@ import * as os2 from "os";
117610
117624
  class WorkerPool {
117611
117625
  concurrency;
117612
117626
  outputDir;
117627
+ scriptsOutputDir;
117613
117628
  webpackConfigPath;
117614
117629
  scriptsPath;
117615
117630
  workerPath;
117616
117631
  constructor(options) {
117617
117632
  this.concurrency = options.concurrency ?? Math.max(1, os2.cpus().length - 1);
117618
117633
  this.outputDir = options.outputDir;
117634
+ this.scriptsOutputDir = options.scriptsOutputDir;
117619
117635
  this.webpackConfigPath = options.webpackConfigPath;
117620
117636
  this.scriptsPath = options.scriptsPath;
117621
117637
  this.workerPath = path21.join(import.meta.dirname, "build", "block-build-worker.js");
@@ -117636,7 +117652,7 @@ class WorkerPool {
117636
117652
  results.push(result2);
117637
117653
  completed++;
117638
117654
  activeWorkers--;
117639
- onProgress?.(completed, total, result2.blockName, result2.success);
117655
+ onProgress?.(completed, total, result2.blockName, result2.success, result2.error);
117640
117656
  if (queue.length > 0) {
117641
117657
  processNext();
117642
117658
  } else if (activeWorkers === 0) {
@@ -117651,7 +117667,7 @@ class WorkerPool {
117651
117667
  results.push(result2);
117652
117668
  completed++;
117653
117669
  activeWorkers--;
117654
- onProgress?.(completed, total, block.name, false);
117670
+ onProgress?.(completed, total, block.name, false, result2.error);
117655
117671
  if (queue.length > 0) {
117656
117672
  processNext();
117657
117673
  } else if (activeWorkers === 0) {
@@ -117673,6 +117689,7 @@ class WorkerPool {
117673
117689
  scripts: block.scripts
117674
117690
  },
117675
117691
  outputDir: this.outputDir,
117692
+ scriptsOutputDir: this.scriptsOutputDir,
117676
117693
  webpackConfigPath: this.webpackConfigPath,
117677
117694
  scriptsPath: this.scriptsPath,
117678
117695
  tempDir
@@ -117726,7 +117743,7 @@ class BuildCommand {
117726
117743
  try {
117727
117744
  const config = this.configManager.getConfig();
117728
117745
  const blocksDir = this.configManager.resolvePath(options.blocksDir || config.paths.blocks);
117729
- const outputDir = this.configManager.resolvePath(options.outputDir || config.paths.dist);
117746
+ const outputDir = this.configManager.resolvePath(options.outputDir || config.paths.blocksDist);
117730
117747
  let webpackConfig;
117731
117748
  if (options.webpackConfig) {
117732
117749
  webpackConfig = this.configManager.resolvePath(options.webpackConfig);
@@ -117763,17 +117780,19 @@ class BuildCommand {
117763
117780
  } else {
117764
117781
  logger.info(`Found ${blocks.length} block(s): ${blocks.map((b) => b.name).join(", ")}`);
117765
117782
  }
117783
+ const scriptsOutputDir = this.configManager.resolvePath(config.paths.scriptsDist);
117766
117784
  const workerPool = new WorkerPool({
117767
117785
  concurrency: options.concurrency,
117768
117786
  outputDir,
117787
+ scriptsOutputDir,
117769
117788
  webpackConfigPath: webpackConfig,
117770
117789
  scriptsPath
117771
117790
  });
117772
- const results = await workerPool.buildAll(blocks, (completed, total, blockName, success) => {
117791
+ const results = await workerPool.buildAll(blocks, (completed, total, blockName, success, error) => {
117773
117792
  if (success) {
117774
117793
  logger.success(`✅ Built: ${blockName} [${completed}/${total}]`);
117775
117794
  } else {
117776
- logger.error(`❌ Failed: ${blockName} [${completed}/${total}]`);
117795
+ logger.error(`❌ Failed: ${blockName} [${completed}/${total}]: ${error || "unknown error"}`);
117777
117796
  }
117778
117797
  });
117779
117798
  for (const block of blocks) {
@@ -117794,7 +117813,8 @@ Failed to build ${failures.length} block(s):`);
117794
117813
  }
117795
117814
  }
117796
117815
  if (this.blockScripts.size > 0) {
117797
- const phpPath = path22.join(path22.dirname(outputDir), "functions-blocks-scripts.php");
117816
+ const distDir = path22.dirname(outputDir);
117817
+ const phpPath = path22.join(distDir, "functions-blocks-scripts.php");
117798
117818
  this.phpGenerator.generateScriptRegistrationPHP(this.blockScripts, phpPath);
117799
117819
  }
117800
117820
  await this.generateTypeDefinitions(outputDir);
@@ -117849,7 +117869,7 @@ class BuildTemplatesCommand {
117849
117869
  return;
117850
117870
  }
117851
117871
  fs19.mkdirSync(outputDir, { recursive: true });
117852
- const blocksOutputDir = this.configManager.resolvePath(config.paths.dist);
117872
+ const blocksOutputDir = this.configManager.resolvePath(config.paths.blocksDist);
117853
117873
  const blockRegistry = new BlockRegistry(blocksOutputDir);
117854
117874
  await blockRegistry.loadBuiltBlocks();
117855
117875
  logger.info(`Loaded ${blockRegistry.getAllComponentMappings().length} built blocks`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress-flow/cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "description": "TypeScript-based WordPress block creation system",
6
6
  "main": "dist/index.js",