@wordpress-flow/cli 1.0.21 → 1.0.23
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 +29 -20
- package/dist/index.js +97 -113
- package/package.json +2 -2
|
@@ -1835,7 +1835,7 @@ import { parentPort, workerData } from "worker_threads";
|
|
|
1835
1835
|
import * as path from "path";
|
|
1836
1836
|
import * as fs from "fs";
|
|
1837
1837
|
import * as esbuild from "esbuild";
|
|
1838
|
-
import
|
|
1838
|
+
import webpack from "webpack";
|
|
1839
1839
|
async function buildBlock() {
|
|
1840
1840
|
const { block, outputDir, webpackConfigPath, scriptsPath, tempDir } = workerData;
|
|
1841
1841
|
try {
|
|
@@ -2002,26 +2002,35 @@ function parseBlockJsonFromSource(block) {
|
|
|
2002
2002
|
};
|
|
2003
2003
|
}
|
|
2004
2004
|
async function runWebpackBuild(entryPoint, outputDir, webpackConfigPath) {
|
|
2005
|
-
|
|
2006
|
-
const
|
|
2007
|
-
const
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
path.join(process.cwd(), "node_modules", ".bin", "webpack")
|
|
2018
|
-
];
|
|
2019
|
-
for (const webpackPath of possiblePaths) {
|
|
2020
|
-
if (fs.existsSync(webpackPath)) {
|
|
2021
|
-
return webpackPath;
|
|
2005
|
+
delete __require.cache[__require.resolve(webpackConfigPath)];
|
|
2006
|
+
const configModule = __require(webpackConfigPath);
|
|
2007
|
+
const configFactory = configModule.default || configModule;
|
|
2008
|
+
const env = { entry: entryPoint, output: outputDir };
|
|
2009
|
+
const baseConfig = typeof configFactory === "function" ? configFactory(env) : configFactory;
|
|
2010
|
+
const config = {
|
|
2011
|
+
...baseConfig,
|
|
2012
|
+
mode: "production",
|
|
2013
|
+
entry: entryPoint,
|
|
2014
|
+
output: {
|
|
2015
|
+
...baseConfig.output,
|
|
2016
|
+
path: outputDir
|
|
2022
2017
|
}
|
|
2023
|
-
}
|
|
2024
|
-
return
|
|
2018
|
+
};
|
|
2019
|
+
return new Promise((resolve2, reject) => {
|
|
2020
|
+
webpack(config, (err, stats) => {
|
|
2021
|
+
if (err) {
|
|
2022
|
+
reject(err);
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
if (stats?.hasErrors()) {
|
|
2026
|
+
const info = stats.toJson();
|
|
2027
|
+
reject(new Error(info.errors?.map((e) => e.message).join(`
|
|
2028
|
+
`) || "Webpack build failed"));
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
resolve2();
|
|
2032
|
+
});
|
|
2033
|
+
});
|
|
2025
2034
|
}
|
|
2026
2035
|
function verifyBuildOutput(outputDir) {
|
|
2027
2036
|
const requiredFiles = ["block.json", "index.js", "ssr.js"];
|
package/dist/index.js
CHANGED
|
@@ -114193,7 +114193,7 @@ var watch = (paths, options) => {
|
|
|
114193
114193
|
var $watch = watch;
|
|
114194
114194
|
|
|
114195
114195
|
// src/commands/dev-command.ts
|
|
114196
|
-
import * as
|
|
114196
|
+
import * as path15 from "path";
|
|
114197
114197
|
import * as fs14 from "fs";
|
|
114198
114198
|
|
|
114199
114199
|
// src/build/block-scanner.ts
|
|
@@ -114258,17 +114258,12 @@ class BlockScanner {
|
|
|
114258
114258
|
|
|
114259
114259
|
// src/build/block-builder.ts
|
|
114260
114260
|
import * as fs10 from "fs";
|
|
114261
|
-
import * as
|
|
114261
|
+
import * as path9 from "path";
|
|
114262
114262
|
|
|
114263
114263
|
// src/build/webpack-runner.ts
|
|
114264
|
-
import * as path8 from "path";
|
|
114265
114264
|
import * as fs8 from "fs";
|
|
114266
|
-
import
|
|
114267
|
-
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
114265
|
+
import webpack from "webpack";
|
|
114268
114266
|
var import_chalk3 = __toESM(require_source(), 1);
|
|
114269
|
-
var __filename2 = fileURLToPath4(import.meta.url);
|
|
114270
|
-
var __dirname2 = path8.dirname(__filename2);
|
|
114271
|
-
|
|
114272
114267
|
class WebpackRunner {
|
|
114273
114268
|
async runBuild(entryPoint, outputDir, webpackConfigPath) {
|
|
114274
114269
|
logger.debug(`Running webpack build for: ${entryPoint}`);
|
|
@@ -114287,85 +114282,74 @@ class WebpackRunner {
|
|
|
114287
114282
|
throw new Error(error);
|
|
114288
114283
|
}
|
|
114289
114284
|
fs8.mkdirSync(outputDir, { recursive: true });
|
|
114290
|
-
const webpackBinary = this.findWebpackBinary();
|
|
114291
|
-
logger.debug(`Using webpack binary: ${webpackBinary}`);
|
|
114292
|
-
const envVars = {
|
|
114293
|
-
entry: entryPoint,
|
|
114294
|
-
output: outputDir
|
|
114295
|
-
};
|
|
114296
|
-
const envString = Object.entries(envVars).map(([key, value]) => `--env ${key}="${value}"`).join(" ");
|
|
114297
|
-
const command = `${webpackBinary} --config "${webpackConfigPath}" ${envString} --mode production`;
|
|
114298
|
-
logger.debug(`Full command: ${command}`);
|
|
114299
114285
|
try {
|
|
114300
|
-
|
|
114301
|
-
|
|
114302
|
-
const
|
|
114303
|
-
|
|
114304
|
-
|
|
114305
|
-
|
|
114286
|
+
delete __require.cache[__require.resolve(webpackConfigPath)];
|
|
114287
|
+
const configModule = __require(webpackConfigPath);
|
|
114288
|
+
const configFactory = configModule.default || configModule;
|
|
114289
|
+
const env2 = { entry: entryPoint, output: outputDir };
|
|
114290
|
+
const baseConfig = typeof configFactory === "function" ? configFactory(env2) : configFactory;
|
|
114291
|
+
const config2 = {
|
|
114292
|
+
...baseConfig,
|
|
114293
|
+
mode: "production",
|
|
114294
|
+
entry: entryPoint,
|
|
114295
|
+
output: {
|
|
114296
|
+
...baseConfig.output,
|
|
114297
|
+
path: outputDir
|
|
114298
|
+
}
|
|
114299
|
+
};
|
|
114300
|
+
logger.debug(`Running webpack with config for: ${entryPoint}`);
|
|
114301
|
+
await new Promise((resolve4, reject) => {
|
|
114302
|
+
webpack(config2, (err, stats) => {
|
|
114303
|
+
if (err) {
|
|
114304
|
+
reject(err);
|
|
114305
|
+
return;
|
|
114306
|
+
}
|
|
114307
|
+
if (stats?.hasErrors()) {
|
|
114308
|
+
const info = stats.toJson();
|
|
114309
|
+
reject(new Error(info.errors?.map((e) => e.message).join(`
|
|
114310
|
+
`) || "Webpack build failed"));
|
|
114311
|
+
return;
|
|
114312
|
+
}
|
|
114313
|
+
if (stats?.hasWarnings()) {
|
|
114314
|
+
const info = stats.toJson();
|
|
114315
|
+
info.warnings?.forEach((w) => logger.debug(`Webpack warning: ${w.message}`));
|
|
114316
|
+
}
|
|
114317
|
+
resolve4();
|
|
114318
|
+
});
|
|
114306
114319
|
});
|
|
114307
114320
|
logger.debug("Webpack build completed successfully");
|
|
114308
|
-
logger.debug(`Output: ${output2}`);
|
|
114309
114321
|
} catch (error) {
|
|
114310
114322
|
console.error("");
|
|
114311
114323
|
console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
|
|
114312
114324
|
console.error(import_chalk3.default.red.bold(" WEBPACK BUILD FAILED"));
|
|
114313
114325
|
console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
|
|
114314
114326
|
console.error("");
|
|
114315
|
-
console.error(import_chalk3.default.yellow("
|
|
114316
|
-
console.error(import_chalk3.default.gray(
|
|
114327
|
+
console.error(import_chalk3.default.yellow("Entry point:"));
|
|
114328
|
+
console.error(import_chalk3.default.gray(entryPoint));
|
|
114317
114329
|
console.error("");
|
|
114318
|
-
console.error(import_chalk3.default.yellow("
|
|
114319
|
-
console.error(import_chalk3.default.gray(
|
|
114330
|
+
console.error(import_chalk3.default.yellow("Output directory:"));
|
|
114331
|
+
console.error(import_chalk3.default.gray(outputDir));
|
|
114332
|
+
console.error("");
|
|
114333
|
+
console.error(import_chalk3.default.yellow("Error message:"));
|
|
114334
|
+
console.error(import_chalk3.default.gray(error.message));
|
|
114320
114335
|
console.error("");
|
|
114321
|
-
if (error.stdout && error.stdout.trim()) {
|
|
114322
|
-
console.error(import_chalk3.default.yellow("Standard output:"));
|
|
114323
|
-
console.error(error.stdout);
|
|
114324
|
-
console.error("");
|
|
114325
|
-
}
|
|
114326
|
-
if (error.stderr && error.stderr.trim()) {
|
|
114327
|
-
console.error(import_chalk3.default.yellow("Error output:"));
|
|
114328
|
-
console.error(error.stderr);
|
|
114329
|
-
console.error("");
|
|
114330
|
-
}
|
|
114331
|
-
if (!error.stdout && !error.stderr) {
|
|
114332
|
-
console.error(import_chalk3.default.yellow("Error message:"));
|
|
114333
|
-
console.error(error.message);
|
|
114334
|
-
console.error("");
|
|
114335
|
-
}
|
|
114336
114336
|
console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
|
|
114337
114337
|
console.error("");
|
|
114338
|
-
throw new Error(`Webpack build failed`);
|
|
114339
|
-
}
|
|
114340
|
-
}
|
|
114341
|
-
findWebpackBinary() {
|
|
114342
|
-
const possiblePaths = [
|
|
114343
|
-
path8.join(process.cwd(), "packages", "block", "node_modules", ".bin", "webpack"),
|
|
114344
|
-
path8.join(process.cwd(), "node_modules", ".bin", "webpack"),
|
|
114345
|
-
path8.join(__dirname2, "..", "..", "..", "node_modules", ".bin", "webpack"),
|
|
114346
|
-
path8.join(process.cwd(), "..", "node_modules", ".bin", "webpack")
|
|
114347
|
-
];
|
|
114348
|
-
for (const webpackPath of possiblePaths) {
|
|
114349
|
-
if (fs8.existsSync(webpackPath)) {
|
|
114350
|
-
logger.debug(`Found webpack at: ${webpackPath}`);
|
|
114351
|
-
return webpackPath;
|
|
114352
|
-
}
|
|
114338
|
+
throw new Error(`Webpack build failed: ${error.message}`);
|
|
114353
114339
|
}
|
|
114354
|
-
logger.debug("Using npx webpack as fallback");
|
|
114355
|
-
return "npx webpack";
|
|
114356
114340
|
}
|
|
114357
114341
|
}
|
|
114358
114342
|
|
|
114359
114343
|
// src/build/script-builder.ts
|
|
114360
114344
|
import * as fs9 from "fs";
|
|
114361
|
-
import * as
|
|
114345
|
+
import * as path8 from "path";
|
|
114362
114346
|
import * as esbuild from "esbuild";
|
|
114363
114347
|
class ScriptBuilder {
|
|
114364
114348
|
async buildScript(scriptPath, outputDir, scriptName) {
|
|
114365
114349
|
try {
|
|
114366
114350
|
logger.debug(`Building script: ${scriptName}`);
|
|
114367
114351
|
fs9.mkdirSync(outputDir, { recursive: true });
|
|
114368
|
-
const outputPath =
|
|
114352
|
+
const outputPath = path8.join(outputDir, scriptName.replace(/\.ts$/, ".js"));
|
|
114369
114353
|
await esbuild.build({
|
|
114370
114354
|
entryPoints: [scriptPath],
|
|
114371
114355
|
outfile: outputPath,
|
|
@@ -114395,19 +114379,19 @@ class ScriptBuilder {
|
|
|
114395
114379
|
async buildScripts(scripts, scriptsPath, outputDir) {
|
|
114396
114380
|
const outputPaths = [];
|
|
114397
114381
|
for (const script of scripts) {
|
|
114398
|
-
const scriptPath =
|
|
114382
|
+
const scriptPath = path8.resolve(scriptsPath, script);
|
|
114399
114383
|
if (!fs9.existsSync(scriptPath)) {
|
|
114400
114384
|
logger.warn(`Script not found: ${scriptPath}`);
|
|
114401
114385
|
continue;
|
|
114402
114386
|
}
|
|
114403
|
-
const scriptName =
|
|
114387
|
+
const scriptName = path8.basename(script);
|
|
114404
114388
|
const outputPath = await this.buildScript(scriptPath, outputDir, scriptName);
|
|
114405
114389
|
outputPaths.push(outputPath);
|
|
114406
114390
|
}
|
|
114407
114391
|
return outputPaths;
|
|
114408
114392
|
}
|
|
114409
114393
|
getRelativeScriptPath(blockDistPath, scriptPath) {
|
|
114410
|
-
const relativePath =
|
|
114394
|
+
const relativePath = path8.relative(blockDistPath, scriptPath);
|
|
114411
114395
|
return relativePath.replace(/\\/g, "/");
|
|
114412
114396
|
}
|
|
114413
114397
|
}
|
|
@@ -114421,7 +114405,7 @@ class BlockBuilder {
|
|
|
114421
114405
|
constructor() {
|
|
114422
114406
|
this.webpackRunner = new WebpackRunner;
|
|
114423
114407
|
this.scriptBuilder = new ScriptBuilder;
|
|
114424
|
-
this.tempDir =
|
|
114408
|
+
this.tempDir = path9.join(process.cwd(), ".wordpress-flow-temp");
|
|
114425
114409
|
}
|
|
114426
114410
|
async buildBlock(block, outputDir, webpackConfigPath, scriptsPath) {
|
|
114427
114411
|
logger.debug(`Building block: ${block.name}`);
|
|
@@ -114430,7 +114414,7 @@ class BlockBuilder {
|
|
|
114430
114414
|
logger.debug(`[1/6] Generating entry point...`);
|
|
114431
114415
|
const entryPoint = await this.generateEntryPoint(block);
|
|
114432
114416
|
logger.debug(`[2/6] Creating output directory...`);
|
|
114433
|
-
const blockOutputDir =
|
|
114417
|
+
const blockOutputDir = path9.join(outputDir, block.name);
|
|
114434
114418
|
fs10.mkdirSync(blockOutputDir, { recursive: true });
|
|
114435
114419
|
let scriptPaths = [];
|
|
114436
114420
|
if (block.scripts && block.scripts.length > 0 && scriptsPath) {
|
|
@@ -114458,7 +114442,7 @@ class BlockBuilder {
|
|
|
114458
114442
|
}
|
|
114459
114443
|
}
|
|
114460
114444
|
async buildBlockScripts(scripts, scriptsPath, outputDir) {
|
|
114461
|
-
const scriptsOutputDir =
|
|
114445
|
+
const scriptsOutputDir = path9.join(path9.dirname(outputDir), "scripts");
|
|
114462
114446
|
return await this.scriptBuilder.buildScripts(scripts, scriptsPath, scriptsOutputDir);
|
|
114463
114447
|
}
|
|
114464
114448
|
async generateEntryPoint(block) {
|
|
@@ -114482,14 +114466,14 @@ if (document.readyState === 'loading') {
|
|
|
114482
114466
|
blockInstance.register();
|
|
114483
114467
|
}
|
|
114484
114468
|
`;
|
|
114485
|
-
const entryPath =
|
|
114469
|
+
const entryPath = path9.join(this.tempDir, `${block.name}-entry.js`);
|
|
114486
114470
|
fs10.writeFileSync(entryPath, entryContent, "utf8");
|
|
114487
114471
|
return entryPath;
|
|
114488
114472
|
}
|
|
114489
114473
|
async generateSSRVersion(block, outputDir) {
|
|
114490
114474
|
try {
|
|
114491
114475
|
logger.debug(`Generating SSR version for ${block.name} using esbuild`);
|
|
114492
|
-
const ssrPath =
|
|
114476
|
+
const ssrPath = path9.join(outputDir, "ssr.js");
|
|
114493
114477
|
await esbuild2.build({
|
|
114494
114478
|
entryPoints: [block.filePath],
|
|
114495
114479
|
outfile: ssrPath,
|
|
@@ -114529,7 +114513,7 @@ if (document.readyState === 'loading') {
|
|
|
114529
114513
|
throw new Error(`Block ${block.name} must export a valid block instance with toBlockJson() method`);
|
|
114530
114514
|
}
|
|
114531
114515
|
const blockJson = blockInstance.toBlockJson();
|
|
114532
|
-
const blockJsonPath =
|
|
114516
|
+
const blockJsonPath = path9.join(outputDir, "block.json");
|
|
114533
114517
|
fs10.writeFileSync(blockJsonPath, JSON.stringify(blockJson, null, 2), "utf8");
|
|
114534
114518
|
logger.debug(`Generated block.json for ${block.name}`);
|
|
114535
114519
|
} catch (error) {
|
|
@@ -114553,7 +114537,7 @@ if (document.readyState === 'loading') {
|
|
|
114553
114537
|
editorStyle: "file:./index.css",
|
|
114554
114538
|
style: "file:./style-index.css"
|
|
114555
114539
|
};
|
|
114556
|
-
const blockJsonPath =
|
|
114540
|
+
const blockJsonPath = path9.join(outputDir, "block.json");
|
|
114557
114541
|
fs10.writeFileSync(blockJsonPath, JSON.stringify(fallbackBlockJson, null, 2), "utf8");
|
|
114558
114542
|
logger.warn(`Used fallback block.json for ${block.name}`);
|
|
114559
114543
|
}
|
|
@@ -114566,7 +114550,7 @@ if (document.readyState === 'loading') {
|
|
|
114566
114550
|
}
|
|
114567
114551
|
async compileAndImport(filePath2) {
|
|
114568
114552
|
try {
|
|
114569
|
-
const tempFile =
|
|
114553
|
+
const tempFile = path9.join(this.tempDir, `${path9.basename(filePath2, path9.extname(filePath2))}-compiled.js`);
|
|
114570
114554
|
logger.debug(`Compiling ${filePath2} to ${tempFile}`);
|
|
114571
114555
|
if (typeof global.React === "undefined") {
|
|
114572
114556
|
global.React = require_react();
|
|
@@ -114596,7 +114580,7 @@ if (document.readyState === 'loading') {
|
|
|
114596
114580
|
}
|
|
114597
114581
|
parseBlockFromSource(filePath2) {
|
|
114598
114582
|
const content4 = fs10.readFileSync(filePath2, "utf8");
|
|
114599
|
-
const blockName =
|
|
114583
|
+
const blockName = path9.basename(filePath2, ".tsx");
|
|
114600
114584
|
const blockData = this.extractBlockDataFromSource(content4, filePath2);
|
|
114601
114585
|
return {
|
|
114602
114586
|
toBlockJson: () => {
|
|
@@ -114706,13 +114690,13 @@ if (document.readyState === 'loading') {
|
|
|
114706
114690
|
const requiredFiles = ["block.json", "index.js", "ssr.js"];
|
|
114707
114691
|
const optionalFiles = ["index.asset.php", "index.css", "style-index.css"];
|
|
114708
114692
|
for (const file of requiredFiles) {
|
|
114709
|
-
const filePath2 =
|
|
114693
|
+
const filePath2 = path9.join(outputDir, file);
|
|
114710
114694
|
if (!fs10.existsSync(filePath2)) {
|
|
114711
114695
|
throw new Error(`Required build output file missing: ${file}`);
|
|
114712
114696
|
}
|
|
114713
114697
|
}
|
|
114714
114698
|
for (const file of optionalFiles) {
|
|
114715
|
-
const filePath2 =
|
|
114699
|
+
const filePath2 = path9.join(outputDir, file);
|
|
114716
114700
|
if (fs10.existsSync(filePath2)) {
|
|
114717
114701
|
logger.debug(`Generated optional file: ${file}`);
|
|
114718
114702
|
}
|
|
@@ -114731,12 +114715,12 @@ if (document.readyState === 'loading') {
|
|
|
114731
114715
|
|
|
114732
114716
|
// src/build/type-definition-generator.ts
|
|
114733
114717
|
import * as fs11 from "fs";
|
|
114734
|
-
import * as
|
|
114718
|
+
import * as path10 from "path";
|
|
114735
114719
|
class TypeDefinitionGenerator {
|
|
114736
114720
|
async generateDefinitions(blocks, outputPath) {
|
|
114737
114721
|
logger.debug(`Generating TypeScript definitions for ${blocks.length} blocks`);
|
|
114738
114722
|
const content4 = this.generateDefinitionContent(blocks);
|
|
114739
|
-
const outputDir =
|
|
114723
|
+
const outputDir = path10.dirname(outputPath);
|
|
114740
114724
|
if (!fs11.existsSync(outputDir)) {
|
|
114741
114725
|
fs11.mkdirSync(outputDir, { recursive: true });
|
|
114742
114726
|
}
|
|
@@ -114842,7 +114826,7 @@ export {};
|
|
|
114842
114826
|
const blockDirs = fs11.readdirSync(distDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
114843
114827
|
for (const blockDir of blockDirs) {
|
|
114844
114828
|
try {
|
|
114845
|
-
const blockJsonPath =
|
|
114829
|
+
const blockJsonPath = path10.join(distDir, blockDir, "block.json");
|
|
114846
114830
|
if (fs11.existsSync(blockJsonPath)) {
|
|
114847
114831
|
const blockJson = JSON.parse(fs11.readFileSync(blockJsonPath, "utf8"));
|
|
114848
114832
|
const blockInfo = {
|
|
@@ -114874,7 +114858,7 @@ export {};
|
|
|
114874
114858
|
|
|
114875
114859
|
// src/build/mdx-dependency-tracker.ts
|
|
114876
114860
|
import * as fs12 from "fs";
|
|
114877
|
-
import * as
|
|
114861
|
+
import * as path11 from "path";
|
|
114878
114862
|
class MDXDependencyTracker {
|
|
114879
114863
|
dependencies = new Map;
|
|
114880
114864
|
reverseDependencies = new Map;
|
|
@@ -114886,7 +114870,7 @@ class MDXDependencyTracker {
|
|
|
114886
114870
|
}
|
|
114887
114871
|
this.dependencies.clear();
|
|
114888
114872
|
this.reverseDependencies.clear();
|
|
114889
|
-
const pattern =
|
|
114873
|
+
const pattern = path11.join(contentDir, "**/*.mdx");
|
|
114890
114874
|
const mdxFiles = await glob(pattern);
|
|
114891
114875
|
logger.debug(`Found ${mdxFiles.length} MDX files`);
|
|
114892
114876
|
for (const filePath2 of mdxFiles) {
|
|
@@ -114925,7 +114909,7 @@ class MDXDependencyTracker {
|
|
|
114925
114909
|
blocks.push(componentName);
|
|
114926
114910
|
}
|
|
114927
114911
|
}
|
|
114928
|
-
logger.debug(`File ${
|
|
114912
|
+
logger.debug(`File ${path11.basename(filePath2)} uses blocks: ${blocks.join(", ")}`);
|
|
114929
114913
|
return blocks;
|
|
114930
114914
|
}
|
|
114931
114915
|
getDependentFiles(blockName) {
|
|
@@ -114960,13 +114944,13 @@ class MDXDependencyTracker {
|
|
|
114960
114944
|
printDependencies() {
|
|
114961
114945
|
logger.info("=== MDX Dependencies ===");
|
|
114962
114946
|
for (const [filePath2, blocks] of this.dependencies.entries()) {
|
|
114963
|
-
const fileName =
|
|
114947
|
+
const fileName = path11.basename(filePath2);
|
|
114964
114948
|
logger.info(`${fileName}: [${blocks.join(", ")}]`);
|
|
114965
114949
|
}
|
|
114966
114950
|
logger.info(`
|
|
114967
114951
|
=== Reverse Dependencies ===`);
|
|
114968
114952
|
for (const [blockName, files] of this.reverseDependencies.entries()) {
|
|
114969
|
-
const fileNames = files.map((f) =>
|
|
114953
|
+
const fileNames = files.map((f) => path11.basename(f));
|
|
114970
114954
|
logger.info(`${blockName}: [${fileNames.join(", ")}]`);
|
|
114971
114955
|
}
|
|
114972
114956
|
const stats = this.getStats();
|
|
@@ -114980,17 +114964,17 @@ class MDXDependencyTracker {
|
|
|
114980
114964
|
}
|
|
114981
114965
|
|
|
114982
114966
|
// src/commands/build-command.ts
|
|
114983
|
-
import * as
|
|
114967
|
+
import * as path14 from "path";
|
|
114984
114968
|
|
|
114985
114969
|
// src/build/php-generator.ts
|
|
114986
114970
|
import * as fs13 from "fs";
|
|
114987
|
-
import * as
|
|
114971
|
+
import * as path12 from "path";
|
|
114988
114972
|
class PHPGenerator {
|
|
114989
114973
|
generateScriptRegistrationPHP(scripts, outputPath) {
|
|
114990
114974
|
const registrations = [];
|
|
114991
114975
|
scripts.forEach((scriptPaths, blockName) => {
|
|
114992
114976
|
scriptPaths.forEach((scriptPath, index2) => {
|
|
114993
|
-
const scriptName =
|
|
114977
|
+
const scriptName = path12.basename(scriptPath, ".js");
|
|
114994
114978
|
const handle = `${blockName.toLowerCase()}-${scriptName}-script`;
|
|
114995
114979
|
registrations.push({
|
|
114996
114980
|
blockName,
|
|
@@ -115053,7 +115037,7 @@ add_action('enqueue_block_assets', 'wordpress_flow_enqueue_block_scripts');
|
|
|
115053
115037
|
generateSingleRegistration(reg) {
|
|
115054
115038
|
const deps = reg.dependencies.map((d) => `'${d}'`).join(", ");
|
|
115055
115039
|
const scriptPath = reg.scriptPath.includes("dist/") ? reg.scriptPath : `dist/${reg.scriptPath}`;
|
|
115056
|
-
return ` // ${reg.blockName} - ${
|
|
115040
|
+
return ` // ${reg.blockName} - ${path12.basename(reg.scriptPath)}
|
|
115057
115041
|
wp_register_script(
|
|
115058
115042
|
'${reg.scriptHandle}',
|
|
115059
115043
|
get_template_directory_uri() . '/${scriptPath}',
|
|
@@ -115066,11 +115050,11 @@ add_action('enqueue_block_assets', 'wordpress_flow_enqueue_block_scripts');
|
|
|
115066
115050
|
|
|
115067
115051
|
// src/build/worker-pool.ts
|
|
115068
115052
|
import { Worker } from "worker_threads";
|
|
115069
|
-
import * as
|
|
115053
|
+
import * as path13 from "path";
|
|
115070
115054
|
import * as os from "os";
|
|
115071
|
-
import { fileURLToPath as
|
|
115072
|
-
var
|
|
115073
|
-
var
|
|
115055
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
115056
|
+
var __filename2 = fileURLToPath4(import.meta.url);
|
|
115057
|
+
var __dirname2 = path13.dirname(__filename2);
|
|
115074
115058
|
|
|
115075
115059
|
class WorkerPool {
|
|
115076
115060
|
concurrency;
|
|
@@ -115083,7 +115067,7 @@ class WorkerPool {
|
|
|
115083
115067
|
this.outputDir = options.outputDir;
|
|
115084
115068
|
this.webpackConfigPath = options.webpackConfigPath;
|
|
115085
115069
|
this.scriptsPath = options.scriptsPath;
|
|
115086
|
-
this.workerPath =
|
|
115070
|
+
this.workerPath = path13.join(__dirname2, "build", "block-build-worker.js");
|
|
115087
115071
|
}
|
|
115088
115072
|
async buildAll(blocks, onProgress) {
|
|
115089
115073
|
const results = [];
|
|
@@ -115130,7 +115114,7 @@ class WorkerPool {
|
|
|
115130
115114
|
}
|
|
115131
115115
|
buildBlockInWorker(block) {
|
|
115132
115116
|
return new Promise((resolve5, reject) => {
|
|
115133
|
-
const tempDir =
|
|
115117
|
+
const tempDir = path13.join(process.cwd(), ".wordpress-flow-temp", `worker-${block.name}-${Date.now()}`);
|
|
115134
115118
|
const workerData = {
|
|
115135
115119
|
block: {
|
|
115136
115120
|
name: block.name,
|
|
@@ -115237,7 +115221,7 @@ class BuildCommand {
|
|
|
115237
115221
|
if (block.scripts && block.scripts.length > 0) {
|
|
115238
115222
|
const result2 = results.find((r) => r.blockName === block.name);
|
|
115239
115223
|
if (result2?.success) {
|
|
115240
|
-
const scriptPaths = block.scripts.map((script) => `scripts/${
|
|
115224
|
+
const scriptPaths = block.scripts.map((script) => `scripts/${path14.basename(script).replace(/\.ts$/, ".js")}`);
|
|
115241
115225
|
this.blockScripts.set(block.name, scriptPaths);
|
|
115242
115226
|
}
|
|
115243
115227
|
}
|
|
@@ -115251,7 +115235,7 @@ Failed to build ${failures.length} block(s):`);
|
|
|
115251
115235
|
}
|
|
115252
115236
|
}
|
|
115253
115237
|
if (this.blockScripts.size > 0) {
|
|
115254
|
-
const phpPath =
|
|
115238
|
+
const phpPath = path14.join(path14.dirname(outputDir), "functions-blocks-scripts.php");
|
|
115255
115239
|
this.phpGenerator.generateScriptRegistrationPHP(this.blockScripts, phpPath);
|
|
115256
115240
|
}
|
|
115257
115241
|
await this.generateTypeDefinitions(outputDir);
|
|
@@ -115275,7 +115259,7 @@ Failed to build ${failures.length} block(s):`);
|
|
|
115275
115259
|
logger.warn("No blocks found for type generation");
|
|
115276
115260
|
return;
|
|
115277
115261
|
}
|
|
115278
|
-
const typesPath =
|
|
115262
|
+
const typesPath = path14.join(outputDir, "blocks.d.ts");
|
|
115279
115263
|
await this.typeGenerator.generateDefinitions(blocks, typesPath);
|
|
115280
115264
|
logger.success(`✅ Generated TypeScript definitions for ${blocks.length} block(s)`);
|
|
115281
115265
|
} catch (error) {
|
|
@@ -115442,7 +115426,7 @@ class DevCommand {
|
|
|
115442
115426
|
return new Promise(() => {});
|
|
115443
115427
|
}
|
|
115444
115428
|
handleFileEvent(eventType, filePath2, options) {
|
|
115445
|
-
const fullPath =
|
|
115429
|
+
const fullPath = path15.resolve(this.configManager.resolvePath(this.configManager.getConfig().paths.mdxOutputDir), filePath2);
|
|
115446
115430
|
logger.debug(`File ${eventType}: ${filePath2}`);
|
|
115447
115431
|
if (eventType === "unlink") {
|
|
115448
115432
|
logger.warn(`File deleted: ${filePath2} - Manual WordPress cleanup may be required`);
|
|
@@ -115461,7 +115445,7 @@ class DevCommand {
|
|
|
115461
115445
|
}
|
|
115462
115446
|
async handleLocalFileChange(filePath2, options) {
|
|
115463
115447
|
try {
|
|
115464
|
-
logger.info(`\uD83D\uDD04 Processing local file change: ${
|
|
115448
|
+
logger.info(`\uD83D\uDD04 Processing local file change: ${path15.relative(process.cwd(), filePath2)}`);
|
|
115465
115449
|
await this.pushCommand.execute({
|
|
115466
115450
|
files: [filePath2],
|
|
115467
115451
|
force: options.conflictResolution === "local-wins",
|
|
@@ -115511,13 +115495,13 @@ class DevCommand {
|
|
|
115511
115495
|
handleBlockFileEvent(eventType, filePath2, options) {
|
|
115512
115496
|
const config2 = this.configManager.getConfig();
|
|
115513
115497
|
const blocksDir = this.configManager.resolvePath(config2.build?.blocksDir || "./theme/blocks");
|
|
115514
|
-
const fullPath =
|
|
115498
|
+
const fullPath = path15.resolve(blocksDir, filePath2);
|
|
115515
115499
|
logger.debug(`Block file ${eventType}: ${filePath2}`);
|
|
115516
115500
|
if (eventType === "unlink") {
|
|
115517
115501
|
logger.warn(`Block file deleted: ${filePath2} - Manual cleanup may be required`);
|
|
115518
115502
|
return;
|
|
115519
115503
|
}
|
|
115520
|
-
const blockName =
|
|
115504
|
+
const blockName = path15.basename(filePath2, path15.extname(filePath2));
|
|
115521
115505
|
this.buildQueue.add(blockName);
|
|
115522
115506
|
const debounceKey = `block-${blockName}`;
|
|
115523
115507
|
const existingTimer = this.debounceTimers.get(debounceKey);
|
|
@@ -115587,8 +115571,8 @@ class DevCommand {
|
|
|
115587
115571
|
const sourceBlocks = await this.blockScanner.scanBlocks(this.configManager.resolvePath(config2.build?.blocksDir || "./theme/blocks"));
|
|
115588
115572
|
const missingBuilds = [];
|
|
115589
115573
|
for (const block of sourceBlocks) {
|
|
115590
|
-
const blockBuildDir =
|
|
115591
|
-
const blockJsonPath =
|
|
115574
|
+
const blockBuildDir = path15.join(outputDir, block.name);
|
|
115575
|
+
const blockJsonPath = path15.join(blockBuildDir, "block.json");
|
|
115592
115576
|
if (!fs14.existsSync(blockJsonPath)) {
|
|
115593
115577
|
missingBuilds.push(block.name);
|
|
115594
115578
|
}
|
|
@@ -115643,7 +115627,7 @@ class DevCommand {
|
|
|
115643
115627
|
if (blocks.length === 0) {
|
|
115644
115628
|
return;
|
|
115645
115629
|
}
|
|
115646
|
-
const typesPath =
|
|
115630
|
+
const typesPath = path15.join(outputDir, "blocks.d.ts");
|
|
115647
115631
|
await this.typeGenerator.generateDefinitions(blocks, typesPath);
|
|
115648
115632
|
logger.debug(`\uD83D\uDD27 Updated TypeScript definitions for ${blocks.length} block(s)`);
|
|
115649
115633
|
} catch (error) {
|
|
@@ -115666,7 +115650,7 @@ class DevCommand {
|
|
|
115666
115650
|
return;
|
|
115667
115651
|
}
|
|
115668
115652
|
logger.info(`\uD83D\uDCC4 Found ${dependentFiles.size} content file(s) that depend on changed blocks`);
|
|
115669
|
-
logger.debug(`Dependent files: ${Array.from(dependentFiles).map((f) =>
|
|
115653
|
+
logger.debug(`Dependent files: ${Array.from(dependentFiles).map((f) => path15.basename(f)).join(", ")}`);
|
|
115670
115654
|
const config2 = this.configManager.getConfig();
|
|
115671
115655
|
const contentDir = this.configManager.resolvePath(config2.paths.mdxOutputDir);
|
|
115672
115656
|
await this.mdxDependencyTracker.scanMDXDependencies(contentDir);
|
|
@@ -115701,7 +115685,7 @@ class DevCommand {
|
|
|
115701
115685
|
|
|
115702
115686
|
// src/commands/build-templates-command.ts
|
|
115703
115687
|
import * as fs15 from "fs";
|
|
115704
|
-
import * as
|
|
115688
|
+
import * as path16 from "path";
|
|
115705
115689
|
class BuildTemplatesCommand {
|
|
115706
115690
|
configManager;
|
|
115707
115691
|
constructor() {
|
|
@@ -115743,8 +115727,8 @@ class BuildTemplatesCommand {
|
|
|
115743
115727
|
let errorCount = 0;
|
|
115744
115728
|
for (let i2 = 0;i2 < templateFiles.length; i2++) {
|
|
115745
115729
|
const templateFile = templateFiles[i2];
|
|
115746
|
-
const relativePath =
|
|
115747
|
-
const templateName =
|
|
115730
|
+
const relativePath = path16.relative(templatesDir, templateFile);
|
|
115731
|
+
const templateName = path16.basename(templateFile, ".mdx");
|
|
115748
115732
|
logger.step(i2 + 1, templateFiles.length, `Building template: ${relativePath}`);
|
|
115749
115733
|
try {
|
|
115750
115734
|
await this.buildTemplate(templateFile, templateName, outputDir, renderer);
|
|
@@ -115768,15 +115752,15 @@ class BuildTemplatesCommand {
|
|
|
115768
115752
|
const cleanContent = this.removeFrontmatter(mdxContent);
|
|
115769
115753
|
const html5 = await renderer.renderMDXToHTML(cleanContent);
|
|
115770
115754
|
const cleanHTML = renderer.postProcessHTML(html5);
|
|
115771
|
-
const outputPath =
|
|
115755
|
+
const outputPath = path16.join(outputDir, `${templateName}.html`);
|
|
115772
115756
|
fs15.writeFileSync(outputPath, cleanHTML, "utf8");
|
|
115773
|
-
logger.info(`✓ Generated: ${
|
|
115757
|
+
logger.info(`✓ Generated: ${path16.relative(process.cwd(), outputPath)}`);
|
|
115774
115758
|
}
|
|
115775
115759
|
findMDXFiles(dir) {
|
|
115776
115760
|
const files = [];
|
|
115777
115761
|
const entries = fs15.readdirSync(dir, { withFileTypes: true });
|
|
115778
115762
|
for (const entry of entries) {
|
|
115779
|
-
const fullPath =
|
|
115763
|
+
const fullPath = path16.join(dir, entry.name);
|
|
115780
115764
|
if (entry.isDirectory()) {
|
|
115781
115765
|
files.push(...this.findMDXFiles(fullPath));
|
|
115782
115766
|
} else if (entry.isFile() && entry.name.endsWith(".mdx")) {
|
|
@@ -115793,7 +115777,7 @@ class BuildTemplatesCommand {
|
|
|
115793
115777
|
// package.json
|
|
115794
115778
|
var package_default = {
|
|
115795
115779
|
name: "@wordpress-flow/cli",
|
|
115796
|
-
version: "1.0.
|
|
115780
|
+
version: "1.0.23",
|
|
115797
115781
|
type: "module",
|
|
115798
115782
|
description: "TypeScript-based WordPress block creation system",
|
|
115799
115783
|
main: "dist/index.js",
|
|
@@ -115801,7 +115785,7 @@ var package_default = {
|
|
|
115801
115785
|
"wordpress-flow": "./dist/index.js"
|
|
115802
115786
|
},
|
|
115803
115787
|
scripts: {
|
|
115804
|
-
build: "bun build ./src/index.ts --outdir ./dist --target node --external esbuild && bun build ./src/build/block-build-worker.ts --outfile ./dist/build/block-build-worker.js --target node --external esbuild"
|
|
115788
|
+
build: "bun build ./src/index.ts --outdir ./dist --target node --external esbuild --external webpack && bun build ./src/build/block-build-worker.ts --outfile ./dist/build/block-build-worker.js --target node --external esbuild --external webpack"
|
|
115805
115789
|
},
|
|
115806
115790
|
dependencies: {
|
|
115807
115791
|
"@babel/core": "^7.28.4",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress-flow/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
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 --external esbuild && bun build ./src/build/block-build-worker.ts --outfile ./dist/build/block-build-worker.js --target node --external esbuild"
|
|
11
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node --external esbuild --external webpack && bun build ./src/build/block-build-worker.ts --outfile ./dist/build/block-build-worker.js --target node --external esbuild --external webpack"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@babel/core": "^7.28.4",
|