wp-typia 0.23.1 → 0.24.1
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/README.md +1 -0
- package/bin/routing-metadata.generated.js +9 -0
- package/dist-bunli/.bunli/commands.gen.js +9587 -7600
- package/dist-bunli/{cli-ymecd15q.js → cli-1xt99e09.js} +85 -10
- package/dist-bunli/{cli-y7w3pybs.js → cli-4ah8dawy.js} +982 -944
- package/dist-bunli/{cli-add-xjaaa01x.js → cli-add-mr731xtv.js} +8607 -7688
- package/dist-bunli/{cli-43mx1vfb.js → cli-bajwv85z.js} +2 -1
- package/dist-bunli/{cli-doctor-19e8313m.js → cli-doctor-kf9gwdhh.js} +98 -12
- package/dist-bunli/{cli-epsczb1c.js → cli-fzhkqzc7.js} +1 -1
- package/dist-bunli/{cli-nvs5atj1.js → cli-gaq29kzp.js} +1 -1
- package/dist-bunli/{cli-k5q5v8g6.js → cli-h2v72j8q.js} +1338 -893
- package/dist-bunli/{cli-init-2b4yn2cc.js → cli-init-557vq109.js} +3 -3
- package/dist-bunli/{cli-scaffold-4tjw4jk5.js → cli-scaffold-bt1ttnkg.js} +6 -6
- package/dist-bunli/cli-z48frc8t.js +229 -0
- package/dist-bunli/{cli-fp16mntv.js → cli-zjw3eqfj.js} +16 -9
- package/dist-bunli/cli.js +3 -3
- package/dist-bunli/{command-list-vme7dr5v.js → command-list-bd2582k1.js} +197 -29
- package/dist-bunli/{migrations-pb5vvtdp.js → migrations-ky53fj2h.js} +3 -3
- package/dist-bunli/node-cli.js +339 -75
- package/package.json +2 -2
- package/dist-bunli/cli-j8et6jvr.js +0 -123
|
@@ -14,10 +14,11 @@ import {
|
|
|
14
14
|
isOmittableBuiltInTemplateLayerDir,
|
|
15
15
|
resolveBuiltInTemplateSource,
|
|
16
16
|
resolveBuiltInTemplateSourceFromLayerDirs
|
|
17
|
-
} from "./cli-
|
|
17
|
+
} from "./cli-gaq29kzp.js";
|
|
18
18
|
import {
|
|
19
|
+
DEFAULT_WORDPRESS_ENV_VERSION,
|
|
19
20
|
getPackageVersions
|
|
20
|
-
} from "./cli-
|
|
21
|
+
} from "./cli-zjw3eqfj.js";
|
|
21
22
|
import {
|
|
22
23
|
BUILTIN_BLOCK_METADATA_VERSION,
|
|
23
24
|
COMPOUND_CHILD_BLOCK_METADATA_DEFAULTS,
|
|
@@ -35,7 +36,7 @@ import {
|
|
|
35
36
|
} from "./cli-8hxf9qw6.js";
|
|
36
37
|
import {
|
|
37
38
|
seedProjectMigrations
|
|
38
|
-
} from "./cli-
|
|
39
|
+
} from "./cli-fzhkqzc7.js";
|
|
39
40
|
import {
|
|
40
41
|
ensureMigrationDirectories,
|
|
41
42
|
isPlainObject,
|
|
@@ -62,7 +63,7 @@ import {
|
|
|
62
63
|
toTitleCase,
|
|
63
64
|
validateBlockSlug,
|
|
64
65
|
validateNamespace
|
|
65
|
-
} from "./cli-
|
|
66
|
+
} from "./cli-h2v72j8q.js";
|
|
66
67
|
import {
|
|
67
68
|
createManagedTempRoot
|
|
68
69
|
} from "./cli-t73q5aqz.js";
|
|
@@ -824,7 +825,7 @@ async function applyGeneratedProjectDxPackageJson({
|
|
|
824
825
|
} : {}
|
|
825
826
|
};
|
|
826
827
|
if (withWpEnv || withTestPreset) {
|
|
827
|
-
packageJson.devDependencies["@wordpress/env"] =
|
|
828
|
+
packageJson.devDependencies["@wordpress/env"] = DEFAULT_WORDPRESS_ENV_VERSION;
|
|
828
829
|
}
|
|
829
830
|
if (withTestPreset) {
|
|
830
831
|
packageJson.devDependencies["@playwright/test"] = "^1.54.2";
|
|
@@ -2307,72 +2308,169 @@ async function withEphemeralScaffoldNodeModules(targetDir, callback) {
|
|
|
2307
2308
|
}
|
|
2308
2309
|
|
|
2309
2310
|
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-integration-env.ts
|
|
2311
|
+
import path7 from "path";
|
|
2312
|
+
|
|
2313
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-integration-env-files.ts
|
|
2310
2314
|
import { promises as fsp4 } from "fs";
|
|
2311
2315
|
import path5 from "path";
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
class WorkspaceMutationRollbackError extends Error {
|
|
2320
|
-
mutationError;
|
|
2321
|
-
rollbackError;
|
|
2322
|
-
constructor(mutationError, rollbackError) {
|
|
2323
|
-
super("Workspace mutation failed and rollback also failed.");
|
|
2324
|
-
this.name = "WorkspaceMutationRollbackError";
|
|
2325
|
-
this.mutationError = mutationError;
|
|
2326
|
-
this.rollbackError = rollbackError;
|
|
2316
|
+
async function appendMissingLines(filePath, lines) {
|
|
2317
|
+
const current = await readOptionalUtf8File(filePath) ?? "";
|
|
2318
|
+
const existingLines = new Set(current.split(/\r?\n/u));
|
|
2319
|
+
const missingLines = lines.filter((line) => !existingLines.has(line));
|
|
2320
|
+
if (missingLines.length === 0) {
|
|
2321
|
+
return;
|
|
2327
2322
|
}
|
|
2323
|
+
const separator = current.length === 0 || current.endsWith(`
|
|
2324
|
+
`) ? "" : `
|
|
2325
|
+
`;
|
|
2326
|
+
await fsp4.mkdir(path5.dirname(filePath), { recursive: true });
|
|
2327
|
+
await fsp4.writeFile(filePath, `${current}${separator}${missingLines.join(`
|
|
2328
|
+
`)}
|
|
2329
|
+
`, "utf8");
|
|
2328
2330
|
}
|
|
2329
|
-
async function
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
targetPaths = []
|
|
2331
|
+
async function writeFileIfAbsent({
|
|
2332
|
+
filePath,
|
|
2333
|
+
source,
|
|
2334
|
+
warnings
|
|
2334
2335
|
}) {
|
|
2335
|
-
|
|
2336
|
-
fileSources: await snapshotWorkspaceFiles(filePaths),
|
|
2337
|
-
snapshotDirs: [...snapshotDirs],
|
|
2338
|
-
targetPaths: [...targetPaths]
|
|
2339
|
-
};
|
|
2336
|
+
await fsp4.mkdir(path5.dirname(filePath), { recursive: true });
|
|
2340
2337
|
try {
|
|
2341
|
-
|
|
2338
|
+
await fsp4.writeFile(filePath, source, { encoding: "utf8", flag: "wx" });
|
|
2342
2339
|
} catch (error) {
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
throw new WorkspaceMutationRollbackError(error, rollbackError);
|
|
2340
|
+
if (error.code === "EEXIST") {
|
|
2341
|
+
warnings.push(`Preserved existing ${path5.basename(filePath)}; review it manually if you need different local integration settings.`);
|
|
2342
|
+
return;
|
|
2347
2343
|
}
|
|
2348
2344
|
throw error;
|
|
2349
2345
|
}
|
|
2350
2346
|
}
|
|
2351
|
-
function
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2347
|
+
async function writeNewScaffoldFile(filePath, source) {
|
|
2348
|
+
await fsp4.mkdir(path5.dirname(filePath), { recursive: true });
|
|
2349
|
+
try {
|
|
2350
|
+
await fsp4.writeFile(filePath, source, { encoding: "utf8", flag: "wx" });
|
|
2351
|
+
} catch (error) {
|
|
2352
|
+
if (error.code === "EEXIST") {
|
|
2353
|
+
throw new Error(`An integration environment scaffold already exists at ${filePath}. Choose a different name.`);
|
|
2357
2354
|
}
|
|
2355
|
+
throw error;
|
|
2358
2356
|
}
|
|
2359
|
-
return `${source.trimEnd()}
|
|
2360
|
-
${snippet}
|
|
2361
|
-
`;
|
|
2362
2357
|
}
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2358
|
+
|
|
2359
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-integration-env-package-json.ts
|
|
2360
|
+
import { promises as fsp5 } from "fs";
|
|
2361
|
+
import path6 from "path";
|
|
2362
|
+
function addScriptIfMissing({
|
|
2363
|
+
scriptName,
|
|
2364
|
+
scripts,
|
|
2365
|
+
scriptValue,
|
|
2366
|
+
warnings
|
|
2367
|
+
}) {
|
|
2368
|
+
if (scripts[scriptName] === undefined) {
|
|
2369
|
+
scripts[scriptName] = scriptValue;
|
|
2370
|
+
return;
|
|
2368
2371
|
}
|
|
2369
|
-
|
|
2370
|
-
${
|
|
2371
|
-
|
|
2372
|
+
if (scripts[scriptName] !== scriptValue) {
|
|
2373
|
+
warnings.push(`Preserved existing package script "${scriptName}"; add "${scriptValue}" manually if you want the generated integration command.`);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
async function mutateIntegrationEnvPackageJson(projectDir, mutate) {
|
|
2377
|
+
const packageJsonPath = path6.join(projectDir, "package.json");
|
|
2378
|
+
const packageJson = await readJsonFile(packageJsonPath, {
|
|
2379
|
+
context: "integration env package manifest"
|
|
2380
|
+
});
|
|
2381
|
+
mutate(packageJson);
|
|
2382
|
+
await fsp5.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, "\t")}
|
|
2383
|
+
`, "utf8");
|
|
2384
|
+
}
|
|
2385
|
+
function addIntegrationEnvPackageJsonEntries({
|
|
2386
|
+
integrationEnvSlug,
|
|
2387
|
+
packageManager,
|
|
2388
|
+
packageJson,
|
|
2389
|
+
withReleaseZip,
|
|
2390
|
+
service,
|
|
2391
|
+
warnings,
|
|
2392
|
+
withWpEnv
|
|
2393
|
+
}) {
|
|
2394
|
+
const devDependencies = {
|
|
2395
|
+
...packageJson.devDependencies ?? {}
|
|
2396
|
+
};
|
|
2397
|
+
if (withWpEnv && devDependencies["@wordpress/env"] === undefined) {
|
|
2398
|
+
devDependencies["@wordpress/env"] = DEFAULT_WORDPRESS_ENV_VERSION;
|
|
2399
|
+
}
|
|
2400
|
+
packageJson.devDependencies = devDependencies;
|
|
2401
|
+
const scripts = {
|
|
2402
|
+
...packageJson.scripts ?? {}
|
|
2403
|
+
};
|
|
2404
|
+
addScriptIfMissing({
|
|
2405
|
+
scriptName: `smoke:${integrationEnvSlug}`,
|
|
2406
|
+
scriptValue: `node scripts/integration-smoke/${integrationEnvSlug}.mjs`,
|
|
2407
|
+
scripts,
|
|
2408
|
+
warnings
|
|
2409
|
+
});
|
|
2410
|
+
addScriptIfMissing({
|
|
2411
|
+
scriptName: "smoke:integration",
|
|
2412
|
+
scriptValue: formatRunScript(packageManager, `smoke:${integrationEnvSlug}`),
|
|
2413
|
+
scripts,
|
|
2414
|
+
warnings
|
|
2415
|
+
});
|
|
2416
|
+
if (withWpEnv) {
|
|
2417
|
+
addScriptIfMissing({
|
|
2418
|
+
scriptName: "wp-env:start",
|
|
2419
|
+
scriptValue: "wp-env start",
|
|
2420
|
+
scripts,
|
|
2421
|
+
warnings
|
|
2422
|
+
});
|
|
2423
|
+
addScriptIfMissing({
|
|
2424
|
+
scriptName: "wp-env:stop",
|
|
2425
|
+
scriptValue: "wp-env stop",
|
|
2426
|
+
scripts,
|
|
2427
|
+
warnings
|
|
2428
|
+
});
|
|
2429
|
+
addScriptIfMissing({
|
|
2430
|
+
scriptName: "wp-env:reset",
|
|
2431
|
+
scriptValue: "wp-env destroy all && wp-env start",
|
|
2432
|
+
scripts,
|
|
2433
|
+
warnings
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
if (withReleaseZip) {
|
|
2437
|
+
addScriptIfMissing({
|
|
2438
|
+
scriptName: "release:zip",
|
|
2439
|
+
scriptValue: `${formatRunScript(packageManager, "sync-rest:package")} && ${formatRunScript(packageManager, "build")} && wp-scripts plugin-zip`,
|
|
2440
|
+
scripts,
|
|
2441
|
+
warnings
|
|
2442
|
+
});
|
|
2443
|
+
addScriptIfMissing({
|
|
2444
|
+
scriptName: "release:zip:check",
|
|
2445
|
+
scriptValue: `${formatRunScript(packageManager, "sync-rest:package:check")} && ${formatRunScript(packageManager, "build")}`,
|
|
2446
|
+
scripts,
|
|
2447
|
+
warnings
|
|
2448
|
+
});
|
|
2449
|
+
addScriptIfMissing({
|
|
2450
|
+
scriptName: "qa:check",
|
|
2451
|
+
scriptValue: `${formatRunScript(packageManager, "wp-typia:doctor:workspace")} && ${formatRunScript(packageManager, "release:zip:check")}`,
|
|
2452
|
+
scripts,
|
|
2453
|
+
warnings
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
if (service === "docker-compose") {
|
|
2457
|
+
addScriptIfMissing({
|
|
2458
|
+
scriptName: "service:start",
|
|
2459
|
+
scriptValue: "docker compose -f docker-compose.integration.yml up -d",
|
|
2460
|
+
scripts,
|
|
2461
|
+
warnings
|
|
2462
|
+
});
|
|
2463
|
+
addScriptIfMissing({
|
|
2464
|
+
scriptName: "service:stop",
|
|
2465
|
+
scriptValue: "docker compose -f docker-compose.integration.yml down",
|
|
2466
|
+
scripts,
|
|
2467
|
+
warnings
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
packageJson.scripts = scripts;
|
|
2372
2471
|
}
|
|
2373
2472
|
|
|
2374
|
-
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-integration-env.ts
|
|
2375
|
-
var WP_ENV_PACKAGE_VERSION = "^11.2.0";
|
|
2473
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-integration-env-source-emitters.ts
|
|
2376
2474
|
function buildWpEnvConfigSource() {
|
|
2377
2475
|
return `${JSON.stringify({
|
|
2378
2476
|
$schema: "https://schemas.wp.org/trunk/wp-env.json",
|
|
@@ -2465,6 +2563,11 @@ function getEnv(name, fallback) {
|
|
|
2465
2563
|
return process.env[name] ?? envFile[name] ?? fallback;
|
|
2466
2564
|
}
|
|
2467
2565
|
|
|
2566
|
+
function getPositiveIntegerEnv(name, fallback) {
|
|
2567
|
+
const value = Number.parseInt(getEnv(name, String(fallback)), 10);
|
|
2568
|
+
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2468
2571
|
function resolveEndpointUrl(baseUrl, endpointPath) {
|
|
2469
2572
|
const normalizedBaseUrl = new URL(baseUrl);
|
|
2470
2573
|
if (!normalizedBaseUrl.pathname.endsWith("/")) {
|
|
@@ -2476,10 +2579,15 @@ function resolveEndpointUrl(baseUrl, endpointPath) {
|
|
|
2476
2579
|
}
|
|
2477
2580
|
|
|
2478
2581
|
async function assertJsonEndpoint(label, url) {
|
|
2582
|
+
const requestTimeoutMs = getPositiveIntegerEnv(
|
|
2583
|
+
"WP_TYPIA_SMOKE_TIMEOUT_MS",
|
|
2584
|
+
30_000,
|
|
2585
|
+
);
|
|
2479
2586
|
const response = await fetch(url, {
|
|
2480
2587
|
headers: {
|
|
2481
2588
|
accept: "application/json",
|
|
2482
2589
|
},
|
|
2590
|
+
signal: AbortSignal.timeout(requestTimeoutMs),
|
|
2483
2591
|
});
|
|
2484
2592
|
|
|
2485
2593
|
if (!response.ok) {
|
|
@@ -2529,6 +2637,7 @@ function buildEnvExampleSource(service) {
|
|
|
2529
2637
|
"WP_TYPIA_SMOKE_BASE_URL=http://localhost:8888",
|
|
2530
2638
|
"WP_TYPIA_SMOKE_USERNAME=admin",
|
|
2531
2639
|
"WP_TYPIA_SMOKE_PASSWORD=password",
|
|
2640
|
+
"WP_TYPIA_SMOKE_TIMEOUT_MS=30000",
|
|
2532
2641
|
...service === "docker-compose" ? [
|
|
2533
2642
|
"",
|
|
2534
2643
|
"# Optional docker-compose integration service starter.",
|
|
@@ -2590,150 +2699,69 @@ ${setupSteps.map((step, index) => `${index + 1}. ${step}`).join(`
|
|
|
2590
2699
|
${withReleaseZip ? "- Treat `release:zip:check` as a CI guard before packaging release artifacts.\n" : ""}
|
|
2591
2700
|
`;
|
|
2592
2701
|
}
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2702
|
+
|
|
2703
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-mutation.ts
|
|
2704
|
+
var DEFAULT_PHP_SNIPPET_INSERTION_ANCHORS = [
|
|
2705
|
+
/add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
|
|
2706
|
+
/\?>\s*$/u
|
|
2707
|
+
];
|
|
2708
|
+
|
|
2709
|
+
class WorkspaceMutationRollbackError extends Error {
|
|
2710
|
+
mutationError;
|
|
2711
|
+
rollbackError;
|
|
2712
|
+
constructor(mutationError, rollbackError) {
|
|
2713
|
+
super("Workspace mutation failed and rollback also failed.");
|
|
2714
|
+
this.name = "WorkspaceMutationRollbackError";
|
|
2715
|
+
this.mutationError = mutationError;
|
|
2716
|
+
this.rollbackError = rollbackError;
|
|
2599
2717
|
}
|
|
2600
|
-
const separator = current.length === 0 || current.endsWith(`
|
|
2601
|
-
`) ? "" : `
|
|
2602
|
-
`;
|
|
2603
|
-
await fsp4.mkdir(path5.dirname(filePath), { recursive: true });
|
|
2604
|
-
await fsp4.writeFile(filePath, `${current}${separator}${missingLines.join(`
|
|
2605
|
-
`)}
|
|
2606
|
-
`, "utf8");
|
|
2607
2718
|
}
|
|
2608
|
-
async function
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2719
|
+
async function executeWorkspaceMutationPlan({
|
|
2720
|
+
filePaths,
|
|
2721
|
+
run,
|
|
2722
|
+
snapshotDirs = [],
|
|
2723
|
+
targetPaths = []
|
|
2612
2724
|
}) {
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2725
|
+
const mutationSnapshot = {
|
|
2726
|
+
fileSources: await snapshotWorkspaceFiles(filePaths),
|
|
2727
|
+
snapshotDirs: [...snapshotDirs],
|
|
2728
|
+
targetPaths: [...targetPaths]
|
|
2729
|
+
};
|
|
2730
|
+
try {
|
|
2731
|
+
return await run();
|
|
2732
|
+
} catch (error) {
|
|
2733
|
+
try {
|
|
2734
|
+
await rollbackWorkspaceMutation(mutationSnapshot);
|
|
2735
|
+
} catch (rollbackError) {
|
|
2736
|
+
throw new WorkspaceMutationRollbackError(error, rollbackError);
|
|
2737
|
+
}
|
|
2738
|
+
throw error;
|
|
2616
2739
|
}
|
|
2617
|
-
await fsp4.mkdir(path5.dirname(filePath), { recursive: true });
|
|
2618
|
-
await fsp4.writeFile(filePath, source, "utf8");
|
|
2619
2740
|
}
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2741
|
+
function insertPhpSnippetBeforeWorkspaceAnchors(source, snippet) {
|
|
2742
|
+
for (const anchor of DEFAULT_PHP_SNIPPET_INSERTION_ANCHORS) {
|
|
2743
|
+
const candidate = source.replace(anchor, (match) => `${snippet}
|
|
2744
|
+
${match}`);
|
|
2745
|
+
if (candidate !== source) {
|
|
2746
|
+
return candidate;
|
|
2747
|
+
}
|
|
2623
2748
|
}
|
|
2624
|
-
|
|
2625
|
-
|
|
2749
|
+
return `${source.trimEnd()}
|
|
2750
|
+
${snippet}
|
|
2751
|
+
`;
|
|
2626
2752
|
}
|
|
2627
|
-
function
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
}) {
|
|
2633
|
-
if (scripts[scriptName] === undefined) {
|
|
2634
|
-
scripts[scriptName] = scriptValue;
|
|
2635
|
-
return;
|
|
2636
|
-
}
|
|
2637
|
-
if (scripts[scriptName] !== scriptValue) {
|
|
2638
|
-
warnings.push(`Preserved existing package script "${scriptName}"; add "${scriptValue}" manually if you want the generated integration command.`);
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
async function mutatePackageJson2(projectDir, mutate) {
|
|
2642
|
-
const packageJsonPath = path5.join(projectDir, "package.json");
|
|
2643
|
-
const packageJson = await readJsonFile(packageJsonPath, {
|
|
2644
|
-
context: "integration env package manifest"
|
|
2645
|
-
});
|
|
2646
|
-
mutate(packageJson);
|
|
2647
|
-
await fsp4.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, "\t")}
|
|
2648
|
-
`, "utf8");
|
|
2649
|
-
}
|
|
2650
|
-
function addIntegrationEnvPackageJsonEntries({
|
|
2651
|
-
integrationEnvSlug,
|
|
2652
|
-
packageManager,
|
|
2653
|
-
packageJson,
|
|
2654
|
-
withReleaseZip,
|
|
2655
|
-
service,
|
|
2656
|
-
warnings,
|
|
2657
|
-
withWpEnv
|
|
2658
|
-
}) {
|
|
2659
|
-
const devDependencies = {
|
|
2660
|
-
...packageJson.devDependencies ?? {}
|
|
2661
|
-
};
|
|
2662
|
-
if (withWpEnv && devDependencies["@wordpress/env"] === undefined) {
|
|
2663
|
-
devDependencies["@wordpress/env"] = WP_ENV_PACKAGE_VERSION;
|
|
2664
|
-
}
|
|
2665
|
-
packageJson.devDependencies = devDependencies;
|
|
2666
|
-
const scripts = {
|
|
2667
|
-
...packageJson.scripts ?? {}
|
|
2668
|
-
};
|
|
2669
|
-
addScriptIfMissing({
|
|
2670
|
-
scriptName: `smoke:${integrationEnvSlug}`,
|
|
2671
|
-
scriptValue: `node scripts/integration-smoke/${integrationEnvSlug}.mjs`,
|
|
2672
|
-
scripts,
|
|
2673
|
-
warnings
|
|
2674
|
-
});
|
|
2675
|
-
addScriptIfMissing({
|
|
2676
|
-
scriptName: "smoke:integration",
|
|
2677
|
-
scriptValue: formatRunScript(packageManager, `smoke:${integrationEnvSlug}`),
|
|
2678
|
-
scripts,
|
|
2679
|
-
warnings
|
|
2680
|
-
});
|
|
2681
|
-
if (withWpEnv) {
|
|
2682
|
-
addScriptIfMissing({
|
|
2683
|
-
scriptName: "wp-env:start",
|
|
2684
|
-
scriptValue: "wp-env start",
|
|
2685
|
-
scripts,
|
|
2686
|
-
warnings
|
|
2687
|
-
});
|
|
2688
|
-
addScriptIfMissing({
|
|
2689
|
-
scriptName: "wp-env:stop",
|
|
2690
|
-
scriptValue: "wp-env stop",
|
|
2691
|
-
scripts,
|
|
2692
|
-
warnings
|
|
2693
|
-
});
|
|
2694
|
-
addScriptIfMissing({
|
|
2695
|
-
scriptName: "wp-env:reset",
|
|
2696
|
-
scriptValue: "wp-env destroy all && wp-env start",
|
|
2697
|
-
scripts,
|
|
2698
|
-
warnings
|
|
2699
|
-
});
|
|
2700
|
-
}
|
|
2701
|
-
if (withReleaseZip) {
|
|
2702
|
-
addScriptIfMissing({
|
|
2703
|
-
scriptName: "release:zip",
|
|
2704
|
-
scriptValue: `${formatRunScript(packageManager, "sync-rest:package")} && ${formatRunScript(packageManager, "build")} && wp-scripts plugin-zip`,
|
|
2705
|
-
scripts,
|
|
2706
|
-
warnings
|
|
2707
|
-
});
|
|
2708
|
-
addScriptIfMissing({
|
|
2709
|
-
scriptName: "release:zip:check",
|
|
2710
|
-
scriptValue: `${formatRunScript(packageManager, "sync-rest:package:check")} && ${formatRunScript(packageManager, "build")}`,
|
|
2711
|
-
scripts,
|
|
2712
|
-
warnings
|
|
2713
|
-
});
|
|
2714
|
-
addScriptIfMissing({
|
|
2715
|
-
scriptName: "qa:check",
|
|
2716
|
-
scriptValue: `${formatRunScript(packageManager, "wp-typia:doctor:workspace")} && ${formatRunScript(packageManager, "release:zip:check")}`,
|
|
2717
|
-
scripts,
|
|
2718
|
-
warnings
|
|
2719
|
-
});
|
|
2720
|
-
}
|
|
2721
|
-
if (service === "docker-compose") {
|
|
2722
|
-
addScriptIfMissing({
|
|
2723
|
-
scriptName: "service:start",
|
|
2724
|
-
scriptValue: "docker compose -f docker-compose.integration.yml up -d",
|
|
2725
|
-
scripts,
|
|
2726
|
-
warnings
|
|
2727
|
-
});
|
|
2728
|
-
addScriptIfMissing({
|
|
2729
|
-
scriptName: "service:stop",
|
|
2730
|
-
scriptValue: "docker compose -f docker-compose.integration.yml down",
|
|
2731
|
-
scripts,
|
|
2732
|
-
warnings
|
|
2733
|
-
});
|
|
2753
|
+
function appendPhpSnippetBeforeClosingTag(source, snippet) {
|
|
2754
|
+
const closingTagPattern = /\?>\s*$/u;
|
|
2755
|
+
if (closingTagPattern.test(source)) {
|
|
2756
|
+
return source.replace(closingTagPattern, `${snippet}
|
|
2757
|
+
?>`);
|
|
2734
2758
|
}
|
|
2735
|
-
|
|
2759
|
+
return `${source.trimEnd()}
|
|
2760
|
+
${snippet}
|
|
2761
|
+
`;
|
|
2736
2762
|
}
|
|
2763
|
+
|
|
2764
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-integration-env.ts
|
|
2737
2765
|
async function runAddIntegrationEnvCommand({
|
|
2738
2766
|
cwd = process.cwd(),
|
|
2739
2767
|
integrationEnvName,
|
|
@@ -2745,15 +2773,15 @@ async function runAddIntegrationEnvCommand({
|
|
|
2745
2773
|
const integrationEnvSlug = assertValidGeneratedSlug("Integration environment name", normalizeBlockSlug(integrationEnvName), "wp-typia add integration-env <name> [--wp-env] [--release-zip]");
|
|
2746
2774
|
const serviceId = assertValidIntegrationEnvService(service);
|
|
2747
2775
|
const warnings = [];
|
|
2748
|
-
const packageJsonPath =
|
|
2749
|
-
const gitignorePath =
|
|
2750
|
-
const envExamplePath =
|
|
2751
|
-
const wpEnvPath =
|
|
2752
|
-
const dockerComposePath =
|
|
2753
|
-
const smokeDir =
|
|
2754
|
-
const docsDir =
|
|
2755
|
-
const smokeScriptPath =
|
|
2756
|
-
const docsPath =
|
|
2776
|
+
const packageJsonPath = path7.join(workspace.projectDir, "package.json");
|
|
2777
|
+
const gitignorePath = path7.join(workspace.projectDir, ".gitignore");
|
|
2778
|
+
const envExamplePath = path7.join(workspace.projectDir, ".env.example");
|
|
2779
|
+
const wpEnvPath = path7.join(workspace.projectDir, ".wp-env.json");
|
|
2780
|
+
const dockerComposePath = path7.join(workspace.projectDir, "docker-compose.integration.yml");
|
|
2781
|
+
const smokeDir = path7.join(workspace.projectDir, "scripts", "integration-smoke");
|
|
2782
|
+
const docsDir = path7.join(workspace.projectDir, "docs", "integration-env");
|
|
2783
|
+
const smokeScriptPath = path7.join(smokeDir, `${integrationEnvSlug}.mjs`);
|
|
2784
|
+
const docsPath = path7.join(docsDir, `${integrationEnvSlug}.md`);
|
|
2757
2785
|
const shouldRemoveSmokeDirOnRollback = !await pathExists(smokeDir);
|
|
2758
2786
|
const shouldRemoveDocsDirOnRollback = !await pathExists(docsDir);
|
|
2759
2787
|
await executeWorkspaceMutationPlan({
|
|
@@ -2797,7 +2825,7 @@ async function runAddIntegrationEnvCommand({
|
|
|
2797
2825
|
warnings
|
|
2798
2826
|
});
|
|
2799
2827
|
}
|
|
2800
|
-
await
|
|
2828
|
+
await mutateIntegrationEnvPackageJson(workspace.projectDir, (packageJson) => addIntegrationEnvPackageJsonEntries({
|
|
2801
2829
|
integrationEnvSlug,
|
|
2802
2830
|
packageManager: workspace.packageManager,
|
|
2803
2831
|
packageJson,
|
|
@@ -2820,7 +2848,7 @@ async function runAddIntegrationEnvCommand({
|
|
|
2820
2848
|
|
|
2821
2849
|
// ../wp-typia-project-tools/src/runtime/cli-validation.ts
|
|
2822
2850
|
import fs3 from "fs";
|
|
2823
|
-
import
|
|
2851
|
+
import path8 from "path";
|
|
2824
2852
|
function normalizeOptionalCliString(value) {
|
|
2825
2853
|
if (typeof value !== "string") {
|
|
2826
2854
|
return;
|
|
@@ -2829,14 +2857,14 @@ function normalizeOptionalCliString(value) {
|
|
|
2829
2857
|
return trimmed.length > 0 ? trimmed : undefined;
|
|
2830
2858
|
}
|
|
2831
2859
|
function looksLikeLocalCliPath(value) {
|
|
2832
|
-
return
|
|
2860
|
+
return path8.isAbsolute(value) || value.startsWith("./") || value.startsWith("../") || value.startsWith(".\\") || value.startsWith("..\\");
|
|
2833
2861
|
}
|
|
2834
2862
|
function resolveLocalCliPathOption(options) {
|
|
2835
2863
|
const normalizedValue = normalizeOptionalCliString(options.value);
|
|
2836
2864
|
if (!normalizedValue || !looksLikeLocalCliPath(normalizedValue)) {
|
|
2837
2865
|
return normalizedValue;
|
|
2838
2866
|
}
|
|
2839
|
-
const resolvedPath =
|
|
2867
|
+
const resolvedPath = path8.resolve(options.cwd, normalizedValue);
|
|
2840
2868
|
if (!fs3.existsSync(resolvedPath)) {
|
|
2841
2869
|
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, `\`${options.label}\` path does not exist: ${resolvedPath}. Check the path relative to ${options.cwd}.`);
|
|
2842
2870
|
}
|
|
@@ -3087,37 +3115,37 @@ async function collectScaffoldAnswers({
|
|
|
3087
3115
|
}
|
|
3088
3116
|
|
|
3089
3117
|
// ../wp-typia-project-tools/src/runtime/scaffold.ts
|
|
3090
|
-
import { promises as
|
|
3091
|
-
import
|
|
3118
|
+
import { promises as fsp14 } from "fs";
|
|
3119
|
+
import path20 from "path";
|
|
3092
3120
|
|
|
3093
3121
|
// ../wp-typia-project-tools/src/runtime/scaffold-apply-utils.ts
|
|
3094
|
-
import { promises as
|
|
3095
|
-
import
|
|
3122
|
+
import { promises as fsp8 } from "fs";
|
|
3123
|
+
import path12 from "path";
|
|
3096
3124
|
import { execSync as execSync3 } from "child_process";
|
|
3097
3125
|
import { fileURLToPath } from "url";
|
|
3098
3126
|
|
|
3099
3127
|
// ../wp-typia-project-tools/src/runtime/migration-ui-capability.ts
|
|
3100
|
-
import { promises as
|
|
3101
|
-
import
|
|
3128
|
+
import { promises as fsp6 } from "fs";
|
|
3129
|
+
import path9 from "path";
|
|
3102
3130
|
var INITIAL_MIGRATION_VERSION = "v1";
|
|
3103
3131
|
var BLOCK_METADATA_IMPORT_LINE = "import metadata from './block-metadata';";
|
|
3104
3132
|
var LEGACY_BLOCK_JSON_IMPORT_LINE = "import metadata from './block.json';";
|
|
3105
|
-
async function
|
|
3106
|
-
const packageJsonPath =
|
|
3133
|
+
async function mutatePackageJson2(projectDir, mutate) {
|
|
3134
|
+
const packageJsonPath = path9.join(projectDir, "package.json");
|
|
3107
3135
|
const packageJson = await readJsonFile(packageJsonPath, {
|
|
3108
3136
|
context: "migration UI package manifest"
|
|
3109
3137
|
});
|
|
3110
3138
|
mutate(packageJson);
|
|
3111
|
-
await
|
|
3139
|
+
await fsp6.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, "\t")}
|
|
3112
3140
|
`, "utf8");
|
|
3113
3141
|
}
|
|
3114
3142
|
async function patchFile(filePath, transform) {
|
|
3115
|
-
const source = await
|
|
3143
|
+
const source = await fsp6.readFile(filePath, "utf8");
|
|
3116
3144
|
const nextSource = transform(source);
|
|
3117
3145
|
if (nextSource === source) {
|
|
3118
3146
|
throw new Error(`Unable to apply migration UI patch for ${filePath}`);
|
|
3119
3147
|
}
|
|
3120
|
-
await
|
|
3148
|
+
await fsp6.writeFile(filePath, nextSource, "utf8");
|
|
3121
3149
|
}
|
|
3122
3150
|
function injectAfter(source, needle, insertion) {
|
|
3123
3151
|
if (source.includes(insertion)) {
|
|
@@ -3179,8 +3207,8 @@ function buildMigrationBlocks(templateId, variables) {
|
|
|
3179
3207
|
];
|
|
3180
3208
|
}
|
|
3181
3209
|
async function applySingleBlockPatches(projectDir, variables) {
|
|
3182
|
-
const editPath =
|
|
3183
|
-
const indexPath =
|
|
3210
|
+
const editPath = path9.join(projectDir, "src", "edit.tsx");
|
|
3211
|
+
const indexPath = path9.join(projectDir, "src", "index.tsx");
|
|
3184
3212
|
const deprecatedImport = `import { deprecated } from './migrations/generated/${variables.slugKebabCase}/deprecated';`;
|
|
3185
3213
|
const deprecatedLine = " deprecated,";
|
|
3186
3214
|
const dashboardImport = `import { MigrationDashboard } from './admin/migration-dashboard';`;
|
|
@@ -3201,10 +3229,10 @@ async function applySingleBlockPatches(projectDir, variables) {
|
|
|
3201
3229
|
});
|
|
3202
3230
|
}
|
|
3203
3231
|
async function applyCompoundPatches(projectDir, variables) {
|
|
3204
|
-
const parentEditPath =
|
|
3205
|
-
const parentIndexPath =
|
|
3206
|
-
const childIndexPath =
|
|
3207
|
-
const addChildScriptPath =
|
|
3232
|
+
const parentEditPath = path9.join(projectDir, "src", "blocks", variables.slugKebabCase, "edit.tsx");
|
|
3233
|
+
const parentIndexPath = path9.join(projectDir, "src", "blocks", variables.slugKebabCase, "index.tsx");
|
|
3234
|
+
const childIndexPath = path9.join(projectDir, "src", "blocks", `${variables.slugKebabCase}-item`, "index.tsx");
|
|
3235
|
+
const addChildScriptPath = path9.join(projectDir, "scripts", "add-compound-child.ts");
|
|
3208
3236
|
await patchFile(parentIndexPath, (source) => {
|
|
3209
3237
|
let nextSource = injectAfterBlockMetadataImport(source, `import { deprecated } from '../../migrations/generated/${variables.slugKebabCase}/deprecated';`);
|
|
3210
3238
|
nextSource = injectBefore(nextSource, "\tedit: Edit,", "\tdeprecated,");
|
|
@@ -3274,9 +3302,9 @@ async function applyMigrationUiCapability({
|
|
|
3274
3302
|
templateId,
|
|
3275
3303
|
variables
|
|
3276
3304
|
}) {
|
|
3277
|
-
const commonTemplateDir =
|
|
3305
|
+
const commonTemplateDir = path9.join(SHARED_MIGRATION_UI_TEMPLATE_ROOT, "common");
|
|
3278
3306
|
await copyInterpolatedDirectory(commonTemplateDir, projectDir, variables);
|
|
3279
|
-
await
|
|
3307
|
+
await mutatePackageJson2(projectDir, (packageJson) => {
|
|
3280
3308
|
const wpTypiaPackageVersion = getPackageVersions().wpTypiaPackageVersion;
|
|
3281
3309
|
const canonicalCliSpecifier = wpTypiaPackageVersion === "^0.0.0" ? "wp-typia" : `wp-typia@${wpTypiaPackageVersion.replace(/^[~^]/u, "")}`;
|
|
3282
3310
|
const migrationCli = (args) => formatPackageExecCommand(packageManager, canonicalCliSpecifier, `migrate ${args}`);
|
|
@@ -3528,9 +3556,9 @@ function mergeTextLines(primaryContent, existingContent) {
|
|
|
3528
3556
|
}
|
|
3529
3557
|
|
|
3530
3558
|
// ../wp-typia-project-tools/src/runtime/scaffold-package-manager-files.ts
|
|
3531
|
-
import { promises as
|
|
3559
|
+
import { promises as fsp7 } from "fs";
|
|
3532
3560
|
import { execSync as execSync2 } from "child_process";
|
|
3533
|
-
import
|
|
3561
|
+
import path10 from "path";
|
|
3534
3562
|
var LOCKFILES = {
|
|
3535
3563
|
bun: ["bun.lock", "bun.lockb"],
|
|
3536
3564
|
npm: ["package-lock.json"],
|
|
@@ -3538,16 +3566,16 @@ var LOCKFILES = {
|
|
|
3538
3566
|
yarn: ["yarn.lock"]
|
|
3539
3567
|
};
|
|
3540
3568
|
async function normalizePackageManagerFiles(targetDir, packageManagerId) {
|
|
3541
|
-
const yarnRcPath =
|
|
3569
|
+
const yarnRcPath = path10.join(targetDir, ".yarnrc.yml");
|
|
3542
3570
|
if (packageManagerId === "yarn") {
|
|
3543
|
-
await
|
|
3571
|
+
await fsp7.writeFile(yarnRcPath, `nodeLinker: node-modules
|
|
3544
3572
|
`, "utf8");
|
|
3545
3573
|
return;
|
|
3546
3574
|
}
|
|
3547
|
-
await
|
|
3575
|
+
await fsp7.rm(yarnRcPath, { force: true });
|
|
3548
3576
|
}
|
|
3549
3577
|
async function normalizePackageJson(targetDir, packageManagerId) {
|
|
3550
|
-
const packageJsonPath =
|
|
3578
|
+
const packageJsonPath = path10.join(targetDir, "package.json");
|
|
3551
3579
|
const packageJsonSource = await readOptionalUtf8File(packageJsonPath);
|
|
3552
3580
|
if (packageJsonSource === null) {
|
|
3553
3581
|
return;
|
|
@@ -3569,7 +3597,7 @@ async function normalizePackageJson(targetDir, packageManagerId) {
|
|
|
3569
3597
|
}
|
|
3570
3598
|
}
|
|
3571
3599
|
}
|
|
3572
|
-
await
|
|
3600
|
+
await fsp7.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, "\t")}
|
|
3573
3601
|
`, "utf8");
|
|
3574
3602
|
}
|
|
3575
3603
|
async function removeUnexpectedLockfiles(targetDir, packageManagerId) {
|
|
@@ -3579,7 +3607,7 @@ async function removeUnexpectedLockfiles(targetDir, packageManagerId) {
|
|
|
3579
3607
|
if (keep.has(filename)) {
|
|
3580
3608
|
return;
|
|
3581
3609
|
}
|
|
3582
|
-
await
|
|
3610
|
+
await fsp7.rm(path10.join(targetDir, filename), { force: true });
|
|
3583
3611
|
}));
|
|
3584
3612
|
}
|
|
3585
3613
|
async function defaultInstallDependencies({
|
|
@@ -3593,7 +3621,7 @@ async function defaultInstallDependencies({
|
|
|
3593
3621
|
}
|
|
3594
3622
|
// ../wp-typia-project-tools/src/runtime/scaffold-repository-reference.ts
|
|
3595
3623
|
import { createRequire } from "module";
|
|
3596
|
-
import
|
|
3624
|
+
import path11 from "path";
|
|
3597
3625
|
var require2 = createRequire(import.meta.url);
|
|
3598
3626
|
var DEFAULT_SCAFFOLD_REPOSITORY_REFERENCE = "imjlk/wp-typia";
|
|
3599
3627
|
function readRepositoryPackageManifest(packageJsonPath) {
|
|
@@ -3658,9 +3686,9 @@ function parseRepositoryReference(value) {
|
|
|
3658
3686
|
}
|
|
3659
3687
|
function getDefaultRepositoryManifestPaths() {
|
|
3660
3688
|
const candidatePaths = [
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3689
|
+
path11.resolve(PROJECT_TOOLS_PACKAGE_ROOT, "..", "..", "package.json"),
|
|
3690
|
+
path11.resolve(PROJECT_TOOLS_PACKAGE_ROOT, "..", "wp-typia", "package.json"),
|
|
3691
|
+
path11.join(PROJECT_TOOLS_PACKAGE_ROOT, "package.json"),
|
|
3664
3692
|
resolveInstalledPackageManifestPath("wp-typia"),
|
|
3665
3693
|
resolveInstalledPackageManifestPath("@wp-typia/project-tools")
|
|
3666
3694
|
].filter((candidatePath) => Boolean(candidatePath));
|
|
@@ -3687,7 +3715,7 @@ async function reportScaffoldProgress(onProgress, event) {
|
|
|
3687
3715
|
await onProgress?.(event);
|
|
3688
3716
|
}
|
|
3689
3717
|
var EPHEMERAL_NODE_MODULES_LINK_TYPE2 = process.platform === "win32" ? "junction" : "dir";
|
|
3690
|
-
var __dirname2 =
|
|
3718
|
+
var __dirname2 = path12.dirname(fileURLToPath(import.meta.url));
|
|
3691
3719
|
var LOCKFILES2 = {
|
|
3692
3720
|
bun: ["bun.lock", "bun.lockb"],
|
|
3693
3721
|
npm: ["package-lock.json"],
|
|
@@ -3695,11 +3723,11 @@ var LOCKFILES2 = {
|
|
|
3695
3723
|
yarn: ["yarn.lock"]
|
|
3696
3724
|
};
|
|
3697
3725
|
async function ensureDirectory(targetDir, allowExisting = false) {
|
|
3698
|
-
await
|
|
3726
|
+
await fsp8.mkdir(targetDir, { recursive: true });
|
|
3699
3727
|
if (allowExisting) {
|
|
3700
3728
|
return;
|
|
3701
3729
|
}
|
|
3702
|
-
const entries = await
|
|
3730
|
+
const entries = await fsp8.readdir(targetDir);
|
|
3703
3731
|
if (entries.length > 0) {
|
|
3704
3732
|
throw new Error(formatNonEmptyTargetDirectoryError(targetDir));
|
|
3705
3733
|
}
|
|
@@ -3710,42 +3738,42 @@ async function writeStarterManifestFiles2(targetDir, templateId, variables, arti
|
|
|
3710
3738
|
relativePath: `${artifact.relativeDir}/typia.manifest.json`
|
|
3711
3739
|
})) : getStarterManifestFiles(templateId, variables);
|
|
3712
3740
|
for (const { document, relativePath } of manifests) {
|
|
3713
|
-
const destinationPath =
|
|
3714
|
-
await
|
|
3715
|
-
await
|
|
3741
|
+
const destinationPath = path12.join(targetDir, relativePath);
|
|
3742
|
+
await fsp8.mkdir(path12.dirname(destinationPath), { recursive: true });
|
|
3743
|
+
await fsp8.writeFile(destinationPath, stringifyStarterManifest(document), "utf8");
|
|
3716
3744
|
}
|
|
3717
3745
|
}
|
|
3718
3746
|
async function writeBuiltInStructuralArtifacts(targetDir, artifacts) {
|
|
3719
3747
|
for (const artifact of artifacts) {
|
|
3720
|
-
const destinationDir =
|
|
3721
|
-
await
|
|
3722
|
-
await
|
|
3723
|
-
await
|
|
3748
|
+
const destinationDir = path12.join(targetDir, artifact.relativeDir);
|
|
3749
|
+
await fsp8.mkdir(destinationDir, { recursive: true });
|
|
3750
|
+
await fsp8.writeFile(path12.join(destinationDir, "types.ts"), artifact.typesSource, "utf8");
|
|
3751
|
+
await fsp8.writeFile(path12.join(destinationDir, "block.json"), stringifyBuiltInBlockJsonDocument(artifact.blockJsonDocument), "utf8");
|
|
3724
3752
|
}
|
|
3725
3753
|
}
|
|
3726
3754
|
async function writeBuiltInCodeArtifacts(targetDir, codeArtifacts) {
|
|
3727
3755
|
for (const artifact of codeArtifacts) {
|
|
3728
|
-
const destinationPath =
|
|
3729
|
-
await
|
|
3730
|
-
await
|
|
3756
|
+
const destinationPath = path12.join(targetDir, artifact.relativePath);
|
|
3757
|
+
await fsp8.mkdir(path12.dirname(destinationPath), { recursive: true });
|
|
3758
|
+
await fsp8.writeFile(destinationPath, artifact.source, "utf8");
|
|
3731
3759
|
}
|
|
3732
3760
|
}
|
|
3733
3761
|
async function resolveScaffoldGeneratorNodeModulesPath2() {
|
|
3734
|
-
const projectToolsPackageRoot =
|
|
3762
|
+
const projectToolsPackageRoot = path12.resolve(__dirname2, "..", "..");
|
|
3735
3763
|
const candidates = [
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3764
|
+
path12.join(projectToolsPackageRoot, "node_modules"),
|
|
3765
|
+
path12.resolve(projectToolsPackageRoot, "..", ".."),
|
|
3766
|
+
path12.resolve(projectToolsPackageRoot, "..", "..", "node_modules")
|
|
3739
3767
|
];
|
|
3740
3768
|
for (const candidate of candidates) {
|
|
3741
|
-
if (await pathExists(
|
|
3769
|
+
if (await pathExists(path12.join(candidate, "typia", "package.json"))) {
|
|
3742
3770
|
return candidate;
|
|
3743
3771
|
}
|
|
3744
3772
|
}
|
|
3745
3773
|
return null;
|
|
3746
3774
|
}
|
|
3747
3775
|
async function withEphemeralScaffoldNodeModules2(targetDir, callback) {
|
|
3748
|
-
const targetNodeModulesPath =
|
|
3776
|
+
const targetNodeModulesPath = path12.join(targetDir, "node_modules");
|
|
3749
3777
|
if (await pathExists(targetNodeModulesPath)) {
|
|
3750
3778
|
await callback();
|
|
3751
3779
|
return;
|
|
@@ -3754,11 +3782,11 @@ async function withEphemeralScaffoldNodeModules2(targetDir, callback) {
|
|
|
3754
3782
|
if (!sourceNodeModulesPath) {
|
|
3755
3783
|
throw new Error("Unable to resolve a node_modules directory with typia for scaffold-time REST artifact generation.");
|
|
3756
3784
|
}
|
|
3757
|
-
await
|
|
3785
|
+
await fsp8.symlink(sourceNodeModulesPath, targetNodeModulesPath, EPHEMERAL_NODE_MODULES_LINK_TYPE2);
|
|
3758
3786
|
try {
|
|
3759
3787
|
await callback();
|
|
3760
3788
|
} finally {
|
|
3761
|
-
await
|
|
3789
|
+
await fsp8.rm(targetNodeModulesPath, { force: true, recursive: true });
|
|
3762
3790
|
}
|
|
3763
3791
|
}
|
|
3764
3792
|
async function seedBuiltInPersistenceArtifacts2(targetDir, templateId, variables) {
|
|
@@ -3769,7 +3797,7 @@ async function seedBuiltInPersistenceArtifacts2(targetDir, templateId, variables
|
|
|
3769
3797
|
await withEphemeralScaffoldNodeModules2(targetDir, async () => {
|
|
3770
3798
|
if (templateId === "persistence") {
|
|
3771
3799
|
await syncPersistenceRestArtifacts({
|
|
3772
|
-
apiTypesFile:
|
|
3800
|
+
apiTypesFile: path12.join("src", "api-types.ts"),
|
|
3773
3801
|
outputDir: "src",
|
|
3774
3802
|
projectDir: targetDir,
|
|
3775
3803
|
variables
|
|
@@ -3777,27 +3805,27 @@ async function seedBuiltInPersistenceArtifacts2(targetDir, templateId, variables
|
|
|
3777
3805
|
return;
|
|
3778
3806
|
}
|
|
3779
3807
|
await syncPersistenceRestArtifacts({
|
|
3780
|
-
apiTypesFile:
|
|
3781
|
-
outputDir:
|
|
3808
|
+
apiTypesFile: path12.join("src", "blocks", variables.slugKebabCase, "api-types.ts"),
|
|
3809
|
+
outputDir: path12.join("src", "blocks", variables.slugKebabCase),
|
|
3782
3810
|
projectDir: targetDir,
|
|
3783
3811
|
variables
|
|
3784
3812
|
});
|
|
3785
3813
|
});
|
|
3786
3814
|
}
|
|
3787
3815
|
async function normalizePackageManagerFiles2(targetDir, packageManagerId) {
|
|
3788
|
-
const yarnRcPath =
|
|
3816
|
+
const yarnRcPath = path12.join(targetDir, ".yarnrc.yml");
|
|
3789
3817
|
if (packageManagerId === "yarn") {
|
|
3790
|
-
await
|
|
3818
|
+
await fsp8.writeFile(yarnRcPath, `nodeLinker: node-modules
|
|
3791
3819
|
`, "utf8");
|
|
3792
3820
|
return;
|
|
3793
3821
|
}
|
|
3794
|
-
await
|
|
3822
|
+
await fsp8.rm(yarnRcPath, { force: true });
|
|
3795
3823
|
}
|
|
3796
3824
|
async function removeQueryLoopPlaceholderFiles(projectDir, templateId) {
|
|
3797
3825
|
if (templateId !== "query-loop") {
|
|
3798
3826
|
return;
|
|
3799
3827
|
}
|
|
3800
|
-
await
|
|
3828
|
+
await fsp8.rm(path12.join(projectDir, "src", "validator-toolkit.ts"), {
|
|
3801
3829
|
force: true
|
|
3802
3830
|
});
|
|
3803
3831
|
}
|
|
@@ -3808,7 +3836,7 @@ async function removeUnexpectedLockfiles2(targetDir, packageManagerId) {
|
|
|
3808
3836
|
if (keep.has(filename)) {
|
|
3809
3837
|
return;
|
|
3810
3838
|
}
|
|
3811
|
-
await
|
|
3839
|
+
await fsp8.rm(path12.join(targetDir, filename), { force: true });
|
|
3812
3840
|
}));
|
|
3813
3841
|
}
|
|
3814
3842
|
async function replaceTextRecursively(targetDir, packageManagerId, {
|
|
@@ -3831,21 +3859,21 @@ async function replaceTextRecursively(targetDir, packageManagerId, {
|
|
|
3831
3859
|
manifestPaths: repositoryManifestPaths
|
|
3832
3860
|
});
|
|
3833
3861
|
async function visit(currentPath) {
|
|
3834
|
-
const stats = await
|
|
3862
|
+
const stats = await fsp8.stat(currentPath);
|
|
3835
3863
|
if (stats.isDirectory()) {
|
|
3836
|
-
const entries = await
|
|
3864
|
+
const entries = await fsp8.readdir(currentPath);
|
|
3837
3865
|
for (const entry of entries) {
|
|
3838
|
-
await visit(
|
|
3866
|
+
await visit(path12.join(currentPath, entry));
|
|
3839
3867
|
}
|
|
3840
3868
|
return;
|
|
3841
3869
|
}
|
|
3842
|
-
if (
|
|
3870
|
+
if (path12.basename(currentPath) === "package.json" || !textExtensions.has(path12.extname(currentPath))) {
|
|
3843
3871
|
return;
|
|
3844
3872
|
}
|
|
3845
|
-
const content = await
|
|
3873
|
+
const content = await fsp8.readFile(currentPath, "utf8");
|
|
3846
3874
|
const nextContent = replaceRepositoryReferencePlaceholders(transformPackageManagerText(content, packageManagerId), resolvedRepositoryReference);
|
|
3847
3875
|
if (nextContent !== content) {
|
|
3848
|
-
await
|
|
3876
|
+
await fsp8.writeFile(currentPath, nextContent, "utf8");
|
|
3849
3877
|
}
|
|
3850
3878
|
}
|
|
3851
3879
|
await visit(targetDir);
|
|
@@ -3917,17 +3945,17 @@ async function applyBuiltInScaffoldProjectFiles({
|
|
|
3917
3945
|
phase: "finalize-project",
|
|
3918
3946
|
title: "Finalizing scaffold output"
|
|
3919
3947
|
});
|
|
3920
|
-
const readmePath =
|
|
3948
|
+
const readmePath = path12.join(projectDir, "README.md");
|
|
3921
3949
|
if (!await pathExists(readmePath)) {
|
|
3922
|
-
await
|
|
3950
|
+
await fsp8.writeFile(readmePath, readmeContent ?? buildReadme(templateId, variables, packageManager, {
|
|
3923
3951
|
withMigrationUi,
|
|
3924
3952
|
withTestPreset,
|
|
3925
3953
|
withWpEnv
|
|
3926
3954
|
}), "utf8");
|
|
3927
3955
|
}
|
|
3928
|
-
const gitignorePath =
|
|
3956
|
+
const gitignorePath = path12.join(projectDir, ".gitignore");
|
|
3929
3957
|
const existingGitignore = await readOptionalUtf8File(gitignorePath) ?? "";
|
|
3930
|
-
await
|
|
3958
|
+
await fsp8.writeFile(gitignorePath, mergeTextLines(gitignoreContent ?? buildGitignore(), existingGitignore), "utf8");
|
|
3931
3959
|
await normalizePackageJson(projectDir, packageManager);
|
|
3932
3960
|
await applyGeneratedProjectDxPackageJson({
|
|
3933
3961
|
compoundPersistenceEnabled: isCompoundPersistenceEnabled(variables),
|
|
@@ -3958,31 +3986,31 @@ async function applyBuiltInScaffoldProjectFiles({
|
|
|
3958
3986
|
}
|
|
3959
3987
|
|
|
3960
3988
|
// ../wp-typia-project-tools/src/runtime/template-source-normalization.ts
|
|
3961
|
-
import
|
|
3989
|
+
import path16 from "path";
|
|
3962
3990
|
|
|
3963
3991
|
// ../wp-typia-project-tools/src/runtime/template-layers.ts
|
|
3964
|
-
import
|
|
3965
|
-
import { promises as
|
|
3992
|
+
import path13 from "path";
|
|
3993
|
+
import { promises as fsp9 } from "fs";
|
|
3966
3994
|
var TEMPLATE_LAYER_MANIFEST_FILENAME = "wp-typia.layers.json";
|
|
3967
3995
|
var TEMPLATE_LAYER_MANIFEST_VERSION = 1;
|
|
3968
3996
|
function resolveLayerPath(sourceRoot, relativePath) {
|
|
3969
|
-
const targetPath =
|
|
3970
|
-
const relativeTarget =
|
|
3971
|
-
if (relativeTarget.startsWith("..") ||
|
|
3997
|
+
const targetPath = path13.resolve(sourceRoot, relativePath);
|
|
3998
|
+
const relativeTarget = path13.relative(sourceRoot, targetPath);
|
|
3999
|
+
if (relativeTarget.startsWith("..") || path13.isAbsolute(relativeTarget)) {
|
|
3972
4000
|
throw new Error(`Template layer path "${relativePath}" must stay within ${sourceRoot}.`);
|
|
3973
4001
|
}
|
|
3974
4002
|
return targetPath;
|
|
3975
4003
|
}
|
|
3976
4004
|
async function assertNoSymlinks(sourceDir) {
|
|
3977
|
-
const stats = await
|
|
4005
|
+
const stats = await fsp9.lstat(sourceDir);
|
|
3978
4006
|
if (stats.isSymbolicLink()) {
|
|
3979
4007
|
throw new Error(`Template layer packages may not include symbolic links: ${sourceDir}`);
|
|
3980
4008
|
}
|
|
3981
4009
|
if (!stats.isDirectory()) {
|
|
3982
4010
|
return;
|
|
3983
4011
|
}
|
|
3984
|
-
for (const entry of await
|
|
3985
|
-
await assertNoSymlinks(
|
|
4012
|
+
for (const entry of await fsp9.readdir(sourceDir)) {
|
|
4013
|
+
await assertNoSymlinks(path13.join(sourceDir, entry));
|
|
3986
4014
|
}
|
|
3987
4015
|
}
|
|
3988
4016
|
function parseLayerDefinition(layerId, value) {
|
|
@@ -4011,7 +4039,7 @@ function parseLayerDefinition(layerId, value) {
|
|
|
4011
4039
|
};
|
|
4012
4040
|
}
|
|
4013
4041
|
async function loadExternalTemplateLayerManifest(sourceRoot) {
|
|
4014
|
-
const manifestPath =
|
|
4042
|
+
const manifestPath = path13.join(sourceRoot, TEMPLATE_LAYER_MANIFEST_FILENAME);
|
|
4015
4043
|
if (!await pathExists(manifestPath)) {
|
|
4016
4044
|
return null;
|
|
4017
4045
|
}
|
|
@@ -4111,7 +4139,7 @@ async function resolveExternalTemplateLayers({
|
|
|
4111
4139
|
return;
|
|
4112
4140
|
}
|
|
4113
4141
|
const layerDir = resolveLayerPath(sourceRoot, definition.path);
|
|
4114
|
-
const stats = await
|
|
4142
|
+
const stats = await fsp9.stat(layerDir).catch(() => null);
|
|
4115
4143
|
if (!stats || !stats.isDirectory()) {
|
|
4116
4144
|
throw new Error(`Layer "${layerId}" points to a missing directory: ${definition.path}`);
|
|
4117
4145
|
}
|
|
@@ -4149,8 +4177,8 @@ async function assertExternalTemplateLayersDoNotWriteProtectedOutputs({
|
|
|
4149
4177
|
}
|
|
4150
4178
|
|
|
4151
4179
|
// ../wp-typia-project-tools/src/runtime/template-source-external.ts
|
|
4152
|
-
import { promises as
|
|
4153
|
-
import
|
|
4180
|
+
import { promises as fsp10 } from "fs";
|
|
4181
|
+
import path14 from "path";
|
|
4154
4182
|
import { pathToFileURL } from "url";
|
|
4155
4183
|
|
|
4156
4184
|
// ../wp-typia-project-tools/src/runtime/external-template-guards.ts
|
|
@@ -4292,16 +4320,16 @@ function getTemplateWarning(key) {
|
|
|
4292
4320
|
return `Ignoring external template config key "${key}": ${TEMPLATE_WARNING_MESSAGE}`;
|
|
4293
4321
|
}
|
|
4294
4322
|
function resolveSourceSubpath(sourceDir, relativePath) {
|
|
4295
|
-
const targetPath =
|
|
4296
|
-
const relativeTarget =
|
|
4297
|
-
if (relativeTarget.startsWith("..") ||
|
|
4323
|
+
const targetPath = path14.resolve(sourceDir, relativePath);
|
|
4324
|
+
const relativeTarget = path14.relative(sourceDir, targetPath);
|
|
4325
|
+
if (relativeTarget.startsWith("..") || path14.isAbsolute(relativeTarget)) {
|
|
4298
4326
|
throw new Error(`Template path "${relativePath}" must stay within ${sourceDir}.`);
|
|
4299
4327
|
}
|
|
4300
4328
|
return targetPath;
|
|
4301
4329
|
}
|
|
4302
4330
|
async function findExternalTemplateEntry(sourceDir) {
|
|
4303
4331
|
for (const filename of EXTERNAL_TEMPLATE_ENTRY_CANDIDATES) {
|
|
4304
|
-
const candidate =
|
|
4332
|
+
const candidate = path14.join(sourceDir, filename);
|
|
4305
4333
|
if (await pathExists(candidate)) {
|
|
4306
4334
|
return candidate;
|
|
4307
4335
|
}
|
|
@@ -4317,7 +4345,7 @@ async function loadExternalTemplateConfig(sourceDir) {
|
|
|
4317
4345
|
label: `External template config "${entryPath}"`,
|
|
4318
4346
|
maxBytes: getExternalTemplateConfigMaxBytes()
|
|
4319
4347
|
});
|
|
4320
|
-
const entryStats = await
|
|
4348
|
+
const entryStats = await fsp10.stat(entryPath);
|
|
4321
4349
|
const moduleUrl = `${pathToFileURL(entryPath).href}?mtime=${entryStats.mtimeMs}`;
|
|
4322
4350
|
const loadedModule = await withExternalTemplateTimeout(`loading external template config "${entryPath}"`, () => import(moduleUrl));
|
|
4323
4351
|
const loadedConfig = loadedModule.default ?? loadedModule;
|
|
@@ -4424,21 +4452,21 @@ async function renderCreateBlockExternalTemplate(sourceDir, context, requestedVa
|
|
|
4424
4452
|
const { folderName, formatHint, templatePath } = resolveConfiguredTemplatePath(config, variantConfig);
|
|
4425
4453
|
const { path: tempRoot, cleanup } = await createManagedTempRoot("wp-typia-create-block-external-");
|
|
4426
4454
|
try {
|
|
4427
|
-
const renderedRoot =
|
|
4455
|
+
const renderedRoot = path14.join(tempRoot, "rendered");
|
|
4428
4456
|
const blockDir = resolveSourceSubpath(renderedRoot, folderName);
|
|
4429
4457
|
const view = await buildExternalTemplateView(context, config, selectedVariant, variantConfig);
|
|
4430
4458
|
const blockTemplateDir = resolveSourceSubpath(sourceDir, templatePath);
|
|
4431
4459
|
await copyRenderedDirectory(blockTemplateDir, blockDir, view, {
|
|
4432
4460
|
filter: async (sourcePath, _destinationPath, entry) => {
|
|
4433
|
-
const mustacheVariantPath =
|
|
4461
|
+
const mustacheVariantPath = path14.join(path14.dirname(sourcePath), `${entry.name}.mustache`);
|
|
4434
4462
|
return !(entry.isFile() && (entry.name === "package.json" || entry.name === "README.md") && await pathExists(mustacheVariantPath));
|
|
4435
4463
|
}
|
|
4436
4464
|
});
|
|
4437
4465
|
const assetsPath = typeof variantConfig.assetsPath === "string" ? variantConfig.assetsPath : config.assetsPath;
|
|
4438
4466
|
if (typeof assetsPath === "string" && assetsPath.trim().length > 0) {
|
|
4439
|
-
await copyRawDirectory(resolveSourceSubpath(sourceDir, assetsPath),
|
|
4467
|
+
await copyRawDirectory(resolveSourceSubpath(sourceDir, assetsPath), path14.join(tempRoot, "assets"));
|
|
4440
4468
|
}
|
|
4441
|
-
const assetsDir =
|
|
4469
|
+
const assetsDir = path14.join(tempRoot, "assets");
|
|
4442
4470
|
return {
|
|
4443
4471
|
assetsDir: await pathExists(assetsDir) ? assetsDir : undefined,
|
|
4444
4472
|
blockDir,
|
|
@@ -4455,8 +4483,8 @@ async function renderCreateBlockExternalTemplate(sourceDir, context, requestedVa
|
|
|
4455
4483
|
}
|
|
4456
4484
|
|
|
4457
4485
|
// ../wp-typia-project-tools/src/runtime/template-source-remote.ts
|
|
4458
|
-
import { promises as
|
|
4459
|
-
import
|
|
4486
|
+
import { promises as fsp11 } from "fs";
|
|
4487
|
+
import path15 from "path";
|
|
4460
4488
|
async function cleanupSeedRootPair(cleanup, seedCleanup) {
|
|
4461
4489
|
let cleanupError;
|
|
4462
4490
|
try {
|
|
@@ -4479,8 +4507,8 @@ function getDefaultCategoryFromBlockJson(blockJson) {
|
|
|
4479
4507
|
async function readRemoteBlockJsonAsync(blockDir) {
|
|
4480
4508
|
const sourceRoot = await getSeedSourceRoot(blockDir);
|
|
4481
4509
|
for (const candidate of [
|
|
4482
|
-
|
|
4483
|
-
|
|
4510
|
+
path15.join(blockDir, "block.json"),
|
|
4511
|
+
path15.join(sourceRoot, "block.json")
|
|
4484
4512
|
]) {
|
|
4485
4513
|
if (await pathExists(candidate)) {
|
|
4486
4514
|
return readJsonFile(candidate, {
|
|
@@ -4500,8 +4528,8 @@ async function getDefaultCategoryAsync(sourceDir) {
|
|
|
4500
4528
|
}
|
|
4501
4529
|
async function readTemplatePackageJsonAsync(sourceDir) {
|
|
4502
4530
|
for (const candidate of [
|
|
4503
|
-
|
|
4504
|
-
|
|
4531
|
+
path15.join(sourceDir, "package.json.mustache"),
|
|
4532
|
+
path15.join(sourceDir, "package.json")
|
|
4505
4533
|
]) {
|
|
4506
4534
|
if (!await pathExists(candidate)) {
|
|
4507
4535
|
continue;
|
|
@@ -4512,7 +4540,7 @@ async function readTemplatePackageJsonAsync(sourceDir) {
|
|
|
4512
4540
|
maxBytes: getExternalTemplatePackageJsonMaxBytes()
|
|
4513
4541
|
});
|
|
4514
4542
|
return {
|
|
4515
|
-
packageJson: safeJsonParse(await
|
|
4543
|
+
packageJson: safeJsonParse(await fsp11.readFile(candidate, "utf8"), {
|
|
4516
4544
|
context: "template metadata file",
|
|
4517
4545
|
filePath: candidate
|
|
4518
4546
|
}),
|
|
@@ -4541,16 +4569,16 @@ async function getTemplateProjectTypeAsync(sourceDir) {
|
|
|
4541
4569
|
}
|
|
4542
4570
|
async function normalizeWpTypiaTemplateSeed(seed) {
|
|
4543
4571
|
const { path: tempRoot, cleanup } = await createManagedTempRoot("wp-typia-template-source-");
|
|
4544
|
-
const normalizedDir =
|
|
4572
|
+
const normalizedDir = path15.join(tempRoot, "template");
|
|
4545
4573
|
try {
|
|
4546
4574
|
await copyRawDirectory(seed.blockDir, normalizedDir, {
|
|
4547
4575
|
filter: async (sourcePath, _targetPath, entry) => {
|
|
4548
|
-
const mustacheVariantPath =
|
|
4576
|
+
const mustacheVariantPath = path15.join(path15.dirname(sourcePath), `${entry.name}.mustache`);
|
|
4549
4577
|
return !(entry.isFile() && (entry.name === "package.json" || entry.name === "README.md") && await pathExists(mustacheVariantPath));
|
|
4550
4578
|
}
|
|
4551
4579
|
});
|
|
4552
4580
|
if (seed.assetsDir && await pathExists(seed.assetsDir)) {
|
|
4553
|
-
await
|
|
4581
|
+
await fsp11.cp(seed.assetsDir, path15.join(normalizedDir, "assets"), {
|
|
4554
4582
|
recursive: true,
|
|
4555
4583
|
force: true
|
|
4556
4584
|
});
|
|
@@ -4639,31 +4667,31 @@ function buildRemoteBlockJsonTemplate(blockJson) {
|
|
|
4639
4667
|
}
|
|
4640
4668
|
async function rewriteBlockJsonImports(directory) {
|
|
4641
4669
|
const textExtensions = new Set([".js", ".jsx", ".ts", ".tsx"]);
|
|
4642
|
-
const targetBlockJsonPath =
|
|
4670
|
+
const targetBlockJsonPath = path15.join(directory, "block.json");
|
|
4643
4671
|
async function visit(currentPath) {
|
|
4644
|
-
const stats = await
|
|
4672
|
+
const stats = await fsp11.stat(currentPath);
|
|
4645
4673
|
if (stats.isDirectory()) {
|
|
4646
|
-
const entries = await
|
|
4674
|
+
const entries = await fsp11.readdir(currentPath);
|
|
4647
4675
|
for (const entry of entries) {
|
|
4648
|
-
await visit(
|
|
4676
|
+
await visit(path15.join(currentPath, entry));
|
|
4649
4677
|
}
|
|
4650
4678
|
return;
|
|
4651
4679
|
}
|
|
4652
|
-
if (!textExtensions.has(
|
|
4680
|
+
if (!textExtensions.has(path15.extname(currentPath))) {
|
|
4653
4681
|
return;
|
|
4654
4682
|
}
|
|
4655
|
-
const content = await
|
|
4656
|
-
const relativeSpecifier =
|
|
4683
|
+
const content = await fsp11.readFile(currentPath, "utf8");
|
|
4684
|
+
const relativeSpecifier = path15.relative(path15.dirname(currentPath), targetBlockJsonPath).replace(/\\/g, "/");
|
|
4657
4685
|
const normalizedSpecifier = relativeSpecifier.startsWith(".") ? relativeSpecifier : `./${relativeSpecifier}`;
|
|
4658
4686
|
const next = content.replace(/(['"])\.{1,2}\/[^'"]*block\.json\1/g, `$1${normalizedSpecifier}$1`);
|
|
4659
4687
|
if (next !== content) {
|
|
4660
|
-
await
|
|
4688
|
+
await fsp11.writeFile(currentPath, next, "utf8");
|
|
4661
4689
|
}
|
|
4662
4690
|
}
|
|
4663
4691
|
await visit(directory);
|
|
4664
4692
|
}
|
|
4665
4693
|
async function patchRemotePackageJson(templateDir, needsInteractivity) {
|
|
4666
|
-
const packageJsonPath =
|
|
4694
|
+
const packageJsonPath = path15.join(templateDir, "package.json.mustache");
|
|
4667
4695
|
const packageJson = await readJsonFile(packageJsonPath, {
|
|
4668
4696
|
context: "remote package template manifest"
|
|
4669
4697
|
});
|
|
@@ -4686,16 +4714,16 @@ async function patchRemotePackageJson(templateDir, needsInteractivity) {
|
|
|
4686
4714
|
} else {
|
|
4687
4715
|
delete packageJson.dependencies;
|
|
4688
4716
|
}
|
|
4689
|
-
await
|
|
4717
|
+
await fsp11.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
4690
4718
|
`, "utf8");
|
|
4691
4719
|
}
|
|
4692
4720
|
async function getSeedSourceRoot(blockDir) {
|
|
4693
|
-
return await pathExists(
|
|
4721
|
+
return await pathExists(path15.join(blockDir, "src")) ? path15.join(blockDir, "src") : blockDir;
|
|
4694
4722
|
}
|
|
4695
4723
|
async function findSeedRenderPhp(seed) {
|
|
4696
4724
|
for (const candidate of [
|
|
4697
|
-
|
|
4698
|
-
|
|
4725
|
+
path15.join(seed.blockDir, "render.php"),
|
|
4726
|
+
path15.join(seed.rootDir, "render.php")
|
|
4699
4727
|
]) {
|
|
4700
4728
|
if (await pathExists(candidate)) {
|
|
4701
4729
|
return candidate;
|
|
@@ -4736,16 +4764,16 @@ async function removeSeedEntryConflicts(templateDir) {
|
|
|
4736
4764
|
"view.ts",
|
|
4737
4765
|
"view.tsx"
|
|
4738
4766
|
]) {
|
|
4739
|
-
await
|
|
4767
|
+
await fsp11.rm(path15.join(templateDir, "src", filename), { force: true });
|
|
4740
4768
|
}
|
|
4741
4769
|
}
|
|
4742
4770
|
async function normalizeCreateBlockSubset(seed, context) {
|
|
4743
4771
|
const { path: tempRoot, cleanup } = await createManagedTempRoot("wp-typia-remote-template-");
|
|
4744
4772
|
try {
|
|
4745
|
-
const templateDir =
|
|
4773
|
+
const templateDir = path15.join(tempRoot, "template");
|
|
4746
4774
|
const blockJson = await readRemoteBlockJsonAsync(seed.blockDir);
|
|
4747
4775
|
const sourceRoot = await getSeedSourceRoot(seed.blockDir);
|
|
4748
|
-
await
|
|
4776
|
+
await fsp11.mkdir(templateDir, { recursive: true });
|
|
4749
4777
|
for (const layerDir of getBuiltInTemplateLayerDirs("basic")) {
|
|
4750
4778
|
if (!await pathExists(layerDir)) {
|
|
4751
4779
|
if (isOmittableBuiltInTemplateLayerDir("basic", layerDir)) {
|
|
@@ -4753,29 +4781,29 @@ async function normalizeCreateBlockSubset(seed, context) {
|
|
|
4753
4781
|
}
|
|
4754
4782
|
throw new Error(`Built-in template layer is missing: ${layerDir}`);
|
|
4755
4783
|
}
|
|
4756
|
-
await
|
|
4784
|
+
await fsp11.cp(layerDir, templateDir, {
|
|
4757
4785
|
recursive: true,
|
|
4758
4786
|
force: true
|
|
4759
4787
|
});
|
|
4760
4788
|
}
|
|
4761
4789
|
await removeSeedEntryConflicts(templateDir);
|
|
4762
|
-
await
|
|
4790
|
+
await fsp11.cp(sourceRoot, path15.join(templateDir, "src"), {
|
|
4763
4791
|
recursive: true,
|
|
4764
4792
|
force: true
|
|
4765
4793
|
});
|
|
4766
4794
|
const remoteRenderPath = await findSeedRenderPhp(seed);
|
|
4767
4795
|
if (remoteRenderPath) {
|
|
4768
|
-
await
|
|
4796
|
+
await fsp11.copyFile(remoteRenderPath, path15.join(templateDir, "render.php"));
|
|
4769
4797
|
}
|
|
4770
4798
|
if (seed.assetsDir && await pathExists(seed.assetsDir)) {
|
|
4771
|
-
await
|
|
4799
|
+
await fsp11.cp(seed.assetsDir, path15.join(templateDir, "assets"), {
|
|
4772
4800
|
recursive: true,
|
|
4773
4801
|
force: true
|
|
4774
4802
|
});
|
|
4775
4803
|
}
|
|
4776
|
-
await
|
|
4777
|
-
await
|
|
4778
|
-
await rewriteBlockJsonImports(
|
|
4804
|
+
await fsp11.writeFile(path15.join(templateDir, "src", "types.ts"), buildRemoteTypesSource(blockJson, context), "utf8");
|
|
4805
|
+
await fsp11.writeFile(path15.join(templateDir, "src", "block.json"), buildRemoteBlockJsonTemplate(blockJson), "utf8");
|
|
4806
|
+
await rewriteBlockJsonImports(path15.join(templateDir, "src"));
|
|
4779
4807
|
const needsInteractivity = typeof blockJson.viewScriptModule === "string" || typeof blockJson.viewScript === "string" || (await Promise.all([
|
|
4780
4808
|
"view.js",
|
|
4781
4809
|
"view.jsx",
|
|
@@ -4783,7 +4811,7 @@ async function normalizeCreateBlockSubset(seed, context) {
|
|
|
4783
4811
|
"view.tsx",
|
|
4784
4812
|
"interactivity.js",
|
|
4785
4813
|
"interactivity.ts"
|
|
4786
|
-
].map((filename) => pathExists(
|
|
4814
|
+
].map((filename) => pathExists(path15.join(templateDir, "src", filename))))).some(Boolean);
|
|
4787
4815
|
await patchRemotePackageJson(templateDir, needsInteractivity);
|
|
4788
4816
|
return {
|
|
4789
4817
|
id: "remote:create-block-subset",
|
|
@@ -4835,7 +4863,7 @@ function getTemplateVariableContext(variables) {
|
|
|
4835
4863
|
};
|
|
4836
4864
|
}
|
|
4837
4865
|
async function detectTemplateSourceFormat(sourceDir) {
|
|
4838
|
-
if (await pathExists(
|
|
4866
|
+
if (await pathExists(path16.join(sourceDir, "package.json.mustache"))) {
|
|
4839
4867
|
return "wp-typia";
|
|
4840
4868
|
}
|
|
4841
4869
|
if (await loadExternalTemplateLayerManifest(sourceDir)) {
|
|
@@ -4847,15 +4875,15 @@ async function detectTemplateSourceFormat(sourceDir) {
|
|
|
4847
4875
|
if (await getTemplateProjectTypeAsync(sourceDir) !== null) {
|
|
4848
4876
|
return "wp-typia";
|
|
4849
4877
|
}
|
|
4850
|
-
const sourceRoot = await pathExists(
|
|
4878
|
+
const sourceRoot = await pathExists(path16.join(sourceDir, "src")) ? path16.join(sourceDir, "src") : sourceDir;
|
|
4851
4879
|
const blockJsonCandidates = [
|
|
4852
|
-
|
|
4853
|
-
|
|
4880
|
+
path16.join(sourceDir, "block.json"),
|
|
4881
|
+
path16.join(sourceRoot, "block.json")
|
|
4854
4882
|
];
|
|
4855
4883
|
const hasBlockJson = (await Promise.all(blockJsonCandidates.map((candidate) => pathExists(candidate)))).some(Boolean);
|
|
4856
|
-
const hasIndexFile = (await Promise.all(["index.js", "index.jsx", "index.ts", "index.tsx"].map((filename) => pathExists(
|
|
4857
|
-
const hasEditFile = (await Promise.all(["edit.js", "edit.jsx", "edit.ts", "edit.tsx"].map((filename) => pathExists(
|
|
4858
|
-
const hasSaveFile = (await Promise.all(["save.js", "save.jsx", "save.ts", "save.tsx"].map((filename) => pathExists(
|
|
4884
|
+
const hasIndexFile = (await Promise.all(["index.js", "index.jsx", "index.ts", "index.tsx"].map((filename) => pathExists(path16.join(sourceRoot, filename))))).some(Boolean);
|
|
4885
|
+
const hasEditFile = (await Promise.all(["edit.js", "edit.jsx", "edit.ts", "edit.tsx"].map((filename) => pathExists(path16.join(sourceRoot, filename))))).some(Boolean);
|
|
4886
|
+
const hasSaveFile = (await Promise.all(["save.js", "save.jsx", "save.ts", "save.tsx"].map((filename) => pathExists(path16.join(sourceRoot, filename))))).some(Boolean);
|
|
4859
4887
|
if (hasBlockJson && hasIndexFile && hasEditFile && hasSaveFile) {
|
|
4860
4888
|
return "create-block-subset";
|
|
4861
4889
|
}
|
|
@@ -4865,9 +4893,9 @@ async function detectTemplateSourceFormat(sourceDir) {
|
|
|
4865
4893
|
// ../wp-typia-project-tools/src/runtime/template-source-seeds.ts
|
|
4866
4894
|
var import_semver = __toESM(require_semver(), 1);
|
|
4867
4895
|
import fs6 from "fs";
|
|
4868
|
-
import { promises as
|
|
4896
|
+
import { promises as fsp13 } from "fs";
|
|
4869
4897
|
import { createRequire as createRequire2 } from "module";
|
|
4870
|
-
import
|
|
4898
|
+
import path19 from "path";
|
|
4871
4899
|
import { spawnSync } from "child_process";
|
|
4872
4900
|
|
|
4873
4901
|
// ../../node_modules/.bun/tar@7.5.13/node_modules/tar/dist/esm/index.min.js
|
|
@@ -8019,8 +8047,8 @@ var So = (s3) => {
|
|
|
8019
8047
|
|
|
8020
8048
|
// ../wp-typia-project-tools/src/runtime/template-source-cache.ts
|
|
8021
8049
|
import { createHash, randomUUID } from "crypto";
|
|
8022
|
-
import { promises as
|
|
8023
|
-
import
|
|
8050
|
+
import { promises as fsp12 } from "fs";
|
|
8051
|
+
import path18 from "path";
|
|
8024
8052
|
|
|
8025
8053
|
// ../wp-typia-project-tools/src/runtime/template-source-cache-markers.ts
|
|
8026
8054
|
var CACHE_MARKER_FILE = "wp-typia-template-cache.json";
|
|
@@ -8051,7 +8079,9 @@ function sanitizeExternalTemplateCacheMetadata(metadata) {
|
|
|
8051
8079
|
function parseExternalTemplateCacheEntryMarker(markerText) {
|
|
8052
8080
|
let marker;
|
|
8053
8081
|
try {
|
|
8054
|
-
marker =
|
|
8082
|
+
marker = safeJsonParse(markerText, {
|
|
8083
|
+
context: "external template cache entry marker"
|
|
8084
|
+
});
|
|
8055
8085
|
} catch {
|
|
8056
8086
|
return null;
|
|
8057
8087
|
}
|
|
@@ -8085,7 +8115,9 @@ function isExternalTemplateCacheEntryFreshForTtl(createdAtMs, nowMs, ttlMs) {
|
|
|
8085
8115
|
function parseExternalTemplateCachePruneMarker(markerText) {
|
|
8086
8116
|
let marker;
|
|
8087
8117
|
try {
|
|
8088
|
-
marker =
|
|
8118
|
+
marker = safeJsonParse(markerText, {
|
|
8119
|
+
context: "external template cache prune marker"
|
|
8120
|
+
});
|
|
8089
8121
|
} catch {
|
|
8090
8122
|
return null;
|
|
8091
8123
|
}
|
|
@@ -8140,7 +8172,7 @@ function formatExternalTemplateCachePruneMarker({
|
|
|
8140
8172
|
|
|
8141
8173
|
// ../wp-typia-project-tools/src/runtime/template-source-cache-policy.ts
|
|
8142
8174
|
import os2 from "os";
|
|
8143
|
-
import
|
|
8175
|
+
import path17 from "path";
|
|
8144
8176
|
var EXTERNAL_TEMPLATE_CACHE_ENV = "WP_TYPIA_EXTERNAL_TEMPLATE_CACHE";
|
|
8145
8177
|
var EXTERNAL_TEMPLATE_CACHE_DIR_ENV = "WP_TYPIA_EXTERNAL_TEMPLATE_CACHE_DIR";
|
|
8146
8178
|
var EXTERNAL_TEMPLATE_CACHE_TTL_DAYS_ENV = "WP_TYPIA_EXTERNAL_TEMPLATE_CACHE_TTL_DAYS";
|
|
@@ -8158,9 +8190,9 @@ function isExternalTemplateCacheEnabled(env = process.env) {
|
|
|
8158
8190
|
function getExternalTemplateCacheRoot(env = process.env) {
|
|
8159
8191
|
const configuredCacheDir = env[EXTERNAL_TEMPLATE_CACHE_DIR_ENV]?.trim();
|
|
8160
8192
|
if (configuredCacheDir) {
|
|
8161
|
-
return
|
|
8193
|
+
return path17.resolve(configuredCacheDir);
|
|
8162
8194
|
}
|
|
8163
|
-
return
|
|
8195
|
+
return path17.join(os2.tmpdir(), `wp-typia-template-source-cache-${getCurrentUserCacheSegment()}`);
|
|
8164
8196
|
}
|
|
8165
8197
|
function parseExternalTemplateCacheTtlDays(value) {
|
|
8166
8198
|
if (typeof value !== "string" && typeof value !== "number") {
|
|
@@ -8238,7 +8270,7 @@ function createExternalTemplateCacheKey(keyParts) {
|
|
|
8238
8270
|
}
|
|
8239
8271
|
async function isDirectoryPath(directory) {
|
|
8240
8272
|
try {
|
|
8241
|
-
const stats = await
|
|
8273
|
+
const stats = await fsp12.lstat(directory);
|
|
8242
8274
|
return stats.isDirectory() && !stats.isSymbolicLink();
|
|
8243
8275
|
} catch {
|
|
8244
8276
|
return false;
|
|
@@ -8246,7 +8278,7 @@ async function isDirectoryPath(directory) {
|
|
|
8246
8278
|
}
|
|
8247
8279
|
async function removeTemporaryCacheEntry(entryDir) {
|
|
8248
8280
|
try {
|
|
8249
|
-
await
|
|
8281
|
+
await fsp12.rm(entryDir, { force: true, recursive: true });
|
|
8250
8282
|
} catch {}
|
|
8251
8283
|
}
|
|
8252
8284
|
function getCurrentUid() {
|
|
@@ -8254,7 +8286,7 @@ function getCurrentUid() {
|
|
|
8254
8286
|
}
|
|
8255
8287
|
async function isPrivateCacheDirectory(directory) {
|
|
8256
8288
|
try {
|
|
8257
|
-
const stats = await
|
|
8289
|
+
const stats = await fsp12.lstat(directory);
|
|
8258
8290
|
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
8259
8291
|
return false;
|
|
8260
8292
|
}
|
|
@@ -8272,11 +8304,11 @@ async function isPrivateCacheDirectory(directory) {
|
|
|
8272
8304
|
}
|
|
8273
8305
|
async function ensurePrivateCacheDirectory(directory) {
|
|
8274
8306
|
try {
|
|
8275
|
-
await
|
|
8307
|
+
await fsp12.mkdir(directory, {
|
|
8276
8308
|
mode: PRIVATE_CACHE_DIRECTORY_MODE,
|
|
8277
8309
|
recursive: true
|
|
8278
8310
|
});
|
|
8279
|
-
const stats = await
|
|
8311
|
+
const stats = await fsp12.lstat(directory);
|
|
8280
8312
|
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
8281
8313
|
return false;
|
|
8282
8314
|
}
|
|
@@ -8286,7 +8318,7 @@ async function ensurePrivateCacheDirectory(directory) {
|
|
|
8286
8318
|
}
|
|
8287
8319
|
if (process.platform !== "win32") {
|
|
8288
8320
|
if ((stats.mode & 63) !== 0) {
|
|
8289
|
-
await
|
|
8321
|
+
await fsp12.chmod(directory, PRIVATE_CACHE_DIRECTORY_MODE);
|
|
8290
8322
|
}
|
|
8291
8323
|
}
|
|
8292
8324
|
return isPrivateCacheDirectory(directory);
|
|
@@ -8298,9 +8330,9 @@ function resolveCacheNamespaceDir(cacheRoot, namespace) {
|
|
|
8298
8330
|
if (namespace === "." || namespace === ".." || !SAFE_CACHE_NAMESPACE_SEGMENT.test(namespace)) {
|
|
8299
8331
|
return null;
|
|
8300
8332
|
}
|
|
8301
|
-
const namespaceDir =
|
|
8302
|
-
const relativeNamespaceDir =
|
|
8303
|
-
if (relativeNamespaceDir.length === 0 || relativeNamespaceDir.startsWith("..") ||
|
|
8333
|
+
const namespaceDir = path18.join(cacheRoot, namespace);
|
|
8334
|
+
const relativeNamespaceDir = path18.relative(cacheRoot, namespaceDir);
|
|
8335
|
+
if (relativeNamespaceDir.length === 0 || relativeNamespaceDir.startsWith("..") || path18.isAbsolute(relativeNamespaceDir)) {
|
|
8304
8336
|
return null;
|
|
8305
8337
|
}
|
|
8306
8338
|
return namespaceDir;
|
|
@@ -8312,14 +8344,14 @@ function getCacheEntryPaths(descriptor) {
|
|
|
8312
8344
|
if (!namespaceDir) {
|
|
8313
8345
|
return null;
|
|
8314
8346
|
}
|
|
8315
|
-
const entryDir =
|
|
8347
|
+
const entryDir = path18.join(namespaceDir, cacheKey);
|
|
8316
8348
|
return {
|
|
8317
8349
|
cacheKey,
|
|
8318
8350
|
cacheRoot,
|
|
8319
8351
|
entryDir,
|
|
8320
|
-
markerPath:
|
|
8352
|
+
markerPath: path18.join(entryDir, CACHE_MARKER_FILE),
|
|
8321
8353
|
namespaceDir,
|
|
8322
|
-
sourceDir:
|
|
8354
|
+
sourceDir: path18.join(entryDir, "source")
|
|
8323
8355
|
};
|
|
8324
8356
|
}
|
|
8325
8357
|
async function isReusableCacheEntry(entryDir, markerPath, sourceDir) {
|
|
@@ -8327,7 +8359,7 @@ async function isReusableCacheEntry(entryDir, markerPath, sourceDir) {
|
|
|
8327
8359
|
}
|
|
8328
8360
|
async function readCacheEntryMarker(markerPath) {
|
|
8329
8361
|
try {
|
|
8330
|
-
return parseExternalTemplateCacheEntryMarker(await
|
|
8362
|
+
return parseExternalTemplateCacheEntryMarker(await fsp12.readFile(markerPath, "utf8"));
|
|
8331
8363
|
} catch {
|
|
8332
8364
|
return null;
|
|
8333
8365
|
}
|
|
@@ -8343,22 +8375,22 @@ async function isReusableFreshCacheEntry(entryDir, markerPath, sourceDir, nowMs,
|
|
|
8343
8375
|
return marker !== null && isExternalTemplateCacheEntryFreshForTtl(marker.createdAtMs, nowMs, ttlMs);
|
|
8344
8376
|
}
|
|
8345
8377
|
function isPathInsideDirectory(directory, candidatePath) {
|
|
8346
|
-
const relativePath =
|
|
8347
|
-
return relativePath.length > 0 && !relativePath.startsWith("..") && !
|
|
8378
|
+
const relativePath = path18.relative(directory, candidatePath);
|
|
8379
|
+
return relativePath.length > 0 && !relativePath.startsWith("..") && !path18.isAbsolute(relativePath);
|
|
8348
8380
|
}
|
|
8349
8381
|
async function removeCacheEntryWithinRoot(cacheRoot, entryDir) {
|
|
8350
8382
|
if (!isPathInsideDirectory(cacheRoot, entryDir)) {
|
|
8351
8383
|
return false;
|
|
8352
8384
|
}
|
|
8353
8385
|
try {
|
|
8354
|
-
await
|
|
8386
|
+
await fsp12.rm(entryDir, { force: true, recursive: true });
|
|
8355
8387
|
return true;
|
|
8356
8388
|
} catch {
|
|
8357
8389
|
return false;
|
|
8358
8390
|
}
|
|
8359
8391
|
}
|
|
8360
8392
|
function getCachePruneMarkerPath(cacheRoot) {
|
|
8361
|
-
return
|
|
8393
|
+
return path18.join(cacheRoot, CACHE_PRUNE_MARKER_FILE);
|
|
8362
8394
|
}
|
|
8363
8395
|
async function shouldSkipExternalTemplateCachePrune({
|
|
8364
8396
|
cacheRoot,
|
|
@@ -8372,7 +8404,7 @@ async function shouldSkipExternalTemplateCachePrune({
|
|
|
8372
8404
|
}
|
|
8373
8405
|
let markerText;
|
|
8374
8406
|
try {
|
|
8375
|
-
markerText = await
|
|
8407
|
+
markerText = await fsp12.readFile(getCachePruneMarkerPath(cacheRoot), "utf8");
|
|
8376
8408
|
} catch {
|
|
8377
8409
|
return false;
|
|
8378
8410
|
}
|
|
@@ -8390,7 +8422,7 @@ async function writeExternalTemplateCachePruneMarker({
|
|
|
8390
8422
|
ttlMs
|
|
8391
8423
|
}) {
|
|
8392
8424
|
try {
|
|
8393
|
-
await
|
|
8425
|
+
await fsp12.writeFile(getCachePruneMarkerPath(cacheRoot), formatExternalTemplateCachePruneMarker({
|
|
8394
8426
|
nowMs,
|
|
8395
8427
|
pruneIntervalMs,
|
|
8396
8428
|
ttlMs
|
|
@@ -8432,7 +8464,7 @@ async function pruneExternalTemplateCache(options = {}) {
|
|
|
8432
8464
|
}
|
|
8433
8465
|
let namespaceEntries;
|
|
8434
8466
|
try {
|
|
8435
|
-
namespaceEntries = await
|
|
8467
|
+
namespaceEntries = await fsp12.readdir(cacheRoot, { withFileTypes: true });
|
|
8436
8468
|
} catch {
|
|
8437
8469
|
return result;
|
|
8438
8470
|
}
|
|
@@ -8448,7 +8480,7 @@ async function pruneExternalTemplateCache(options = {}) {
|
|
|
8448
8480
|
}
|
|
8449
8481
|
let cacheEntries;
|
|
8450
8482
|
try {
|
|
8451
|
-
cacheEntries = await
|
|
8483
|
+
cacheEntries = await fsp12.readdir(namespaceDir, { withFileTypes: true });
|
|
8452
8484
|
} catch {
|
|
8453
8485
|
result.skippedEntries += 1;
|
|
8454
8486
|
continue;
|
|
@@ -8461,14 +8493,14 @@ async function pruneExternalTemplateCache(options = {}) {
|
|
|
8461
8493
|
result.skippedEntries += 1;
|
|
8462
8494
|
continue;
|
|
8463
8495
|
}
|
|
8464
|
-
const entryDir =
|
|
8496
|
+
const entryDir = path18.join(namespaceDir, cacheEntry.name);
|
|
8465
8497
|
result.scannedEntries += 1;
|
|
8466
8498
|
if (!isPathInsideDirectory(cacheRoot, entryDir)) {
|
|
8467
8499
|
result.skippedEntries += 1;
|
|
8468
8500
|
continue;
|
|
8469
8501
|
}
|
|
8470
|
-
const markerPath =
|
|
8471
|
-
const sourceDir =
|
|
8502
|
+
const markerPath = path18.join(entryDir, CACHE_MARKER_FILE);
|
|
8503
|
+
const sourceDir = path18.join(entryDir, "source");
|
|
8472
8504
|
const marker = await getReusableCacheEntryMarker(entryDir, markerPath, sourceDir);
|
|
8473
8505
|
if (!marker) {
|
|
8474
8506
|
result.skippedEntries += 1;
|
|
@@ -8508,7 +8540,7 @@ async function findReusableExternalTemplateSourceCache(descriptor) {
|
|
|
8508
8540
|
await pruneExternalTemplateCache();
|
|
8509
8541
|
let entries;
|
|
8510
8542
|
try {
|
|
8511
|
-
entries = await
|
|
8543
|
+
entries = await fsp12.readdir(namespaceDir, { withFileTypes: true });
|
|
8512
8544
|
} catch {
|
|
8513
8545
|
return null;
|
|
8514
8546
|
}
|
|
@@ -8517,9 +8549,9 @@ async function findReusableExternalTemplateSourceCache(descriptor) {
|
|
|
8517
8549
|
if (!entry.isDirectory()) {
|
|
8518
8550
|
continue;
|
|
8519
8551
|
}
|
|
8520
|
-
const entryDir =
|
|
8521
|
-
const markerPath =
|
|
8522
|
-
const sourceDir =
|
|
8552
|
+
const entryDir = path18.join(namespaceDir, entry.name);
|
|
8553
|
+
const markerPath = path18.join(entryDir, CACHE_MARKER_FILE);
|
|
8554
|
+
const sourceDir = path18.join(entryDir, "source");
|
|
8523
8555
|
const marker = await getReusableCacheEntryMarker(entryDir, markerPath, sourceDir);
|
|
8524
8556
|
if (!marker || !isExternalTemplateCacheEntryFreshForTtl(marker.createdAtMs, nowMs, ttlMs) || !externalTemplateCacheMetadataMatches(marker.metadata, descriptor.metadata)) {
|
|
8525
8557
|
continue;
|
|
@@ -8561,16 +8593,16 @@ async function resolveExternalTemplateSourceCache(descriptor, populateSourceDir)
|
|
|
8561
8593
|
if (existingMarker) {
|
|
8562
8594
|
await removeCacheEntryWithinRoot(cacheRoot, entryDir);
|
|
8563
8595
|
}
|
|
8564
|
-
const temporaryEntryDir =
|
|
8565
|
-
const temporarySourceDir =
|
|
8596
|
+
const temporaryEntryDir = path18.join(namespaceDir, createTemporaryCacheEntryDirName(cacheKey));
|
|
8597
|
+
const temporarySourceDir = path18.join(temporaryEntryDir, "source");
|
|
8566
8598
|
let populateFailed = false;
|
|
8567
8599
|
try {
|
|
8568
|
-
await
|
|
8600
|
+
await fsp12.mkdir(temporarySourceDir, {
|
|
8569
8601
|
mode: PRIVATE_CACHE_DIRECTORY_MODE,
|
|
8570
8602
|
recursive: true
|
|
8571
8603
|
});
|
|
8572
8604
|
if (process.platform !== "win32") {
|
|
8573
|
-
await
|
|
8605
|
+
await fsp12.chmod(temporaryEntryDir, PRIVATE_CACHE_DIRECTORY_MODE);
|
|
8574
8606
|
}
|
|
8575
8607
|
try {
|
|
8576
8608
|
await populateSourceDir(temporarySourceDir);
|
|
@@ -8578,13 +8610,13 @@ async function resolveExternalTemplateSourceCache(descriptor, populateSourceDir)
|
|
|
8578
8610
|
populateFailed = true;
|
|
8579
8611
|
throw error;
|
|
8580
8612
|
}
|
|
8581
|
-
await
|
|
8613
|
+
await fsp12.writeFile(path18.join(temporaryEntryDir, CACHE_MARKER_FILE), formatExternalTemplateCacheEntryMarker({
|
|
8582
8614
|
cacheKey,
|
|
8583
8615
|
createdAt: new Date,
|
|
8584
8616
|
metadata: descriptor.metadata,
|
|
8585
8617
|
namespace: descriptor.namespace
|
|
8586
8618
|
}), "utf8");
|
|
8587
|
-
await
|
|
8619
|
+
await fsp12.rename(temporaryEntryDir, entryDir);
|
|
8588
8620
|
return {
|
|
8589
8621
|
cacheHit: false,
|
|
8590
8622
|
sourceDir
|
|
@@ -8655,9 +8687,9 @@ async function downloadNpmTemplateTarball(locator, resolvedVersion, tarballUrl,
|
|
|
8655
8687
|
if (!tarballResponse.ok) {
|
|
8656
8688
|
throw new Error(`Failed to download npm template tarball for ${locator.raw}: ${tarballResponse.status}`);
|
|
8657
8689
|
}
|
|
8658
|
-
const tarballPath =
|
|
8659
|
-
await
|
|
8660
|
-
await
|
|
8690
|
+
const tarballPath = path19.join(path19.dirname(unpackDir), "template.tgz");
|
|
8691
|
+
await fsp13.mkdir(unpackDir, { recursive: true });
|
|
8692
|
+
await fsp13.writeFile(tarballPath, await readBufferResponseWithLimit(tarballResponse, {
|
|
8661
8693
|
label: `npm template tarball for ${locator.raw}@${resolvedVersion}`,
|
|
8662
8694
|
maxBytes: getExternalTemplateTarballMaxBytes()
|
|
8663
8695
|
}));
|
|
@@ -8666,7 +8698,7 @@ async function downloadNpmTemplateTarball(locator, resolvedVersion, tarballUrl,
|
|
|
8666
8698
|
file: tarballPath,
|
|
8667
8699
|
strip: 1
|
|
8668
8700
|
});
|
|
8669
|
-
await
|
|
8701
|
+
await fsp13.rm(tarballPath, { force: true });
|
|
8670
8702
|
await assertNoSymlinks2(unpackDir);
|
|
8671
8703
|
}
|
|
8672
8704
|
function selectRegistryVersion(metadata, locator) {
|
|
@@ -8761,7 +8793,7 @@ async function fetchNpmTemplateSource(locator) {
|
|
|
8761
8793
|
}
|
|
8762
8794
|
const { path: tempRoot, cleanup } = await createManagedTempRoot("wp-typia-template-source-");
|
|
8763
8795
|
try {
|
|
8764
|
-
const unpackDir =
|
|
8796
|
+
const unpackDir = path19.join(tempRoot, "source");
|
|
8765
8797
|
await downloadNpmTemplateTarball(locator, resolvedVersion, tarballUrl, unpackDir);
|
|
8766
8798
|
return {
|
|
8767
8799
|
blockDir: unpackDir,
|
|
@@ -8777,7 +8809,7 @@ function resolveInstalledNpmTemplateSource(locator, cwd) {
|
|
|
8777
8809
|
if (locator.rawSpec !== "" && locator.rawSpec !== "*") {
|
|
8778
8810
|
return null;
|
|
8779
8811
|
}
|
|
8780
|
-
const workspacePackagesRoot =
|
|
8812
|
+
const workspacePackagesRoot = path19.resolve(PROJECT_TOOLS_PACKAGE_ROOT, "..");
|
|
8781
8813
|
if (fs6.existsSync(workspacePackagesRoot)) {
|
|
8782
8814
|
for (const entry of fs6.readdirSync(workspacePackagesRoot, {
|
|
8783
8815
|
withFileTypes: true
|
|
@@ -8785,8 +8817,8 @@ function resolveInstalledNpmTemplateSource(locator, cwd) {
|
|
|
8785
8817
|
if (!entry.isDirectory()) {
|
|
8786
8818
|
continue;
|
|
8787
8819
|
}
|
|
8788
|
-
const packageDir =
|
|
8789
|
-
const packageJsonPath =
|
|
8820
|
+
const packageDir = path19.join(workspacePackagesRoot, entry.name);
|
|
8821
|
+
const packageJsonPath = path19.join(packageDir, "package.json");
|
|
8790
8822
|
if (!fs6.existsSync(packageJsonPath)) {
|
|
8791
8823
|
continue;
|
|
8792
8824
|
}
|
|
@@ -8801,10 +8833,10 @@ function resolveInstalledNpmTemplateSource(locator, cwd) {
|
|
|
8801
8833
|
}
|
|
8802
8834
|
}
|
|
8803
8835
|
}
|
|
8804
|
-
const workspaceRequire = createRequire2(
|
|
8836
|
+
const workspaceRequire = createRequire2(path19.join(path19.resolve(cwd), "__wp_typia_template_resolver__.cjs"));
|
|
8805
8837
|
try {
|
|
8806
8838
|
const packageJsonPath = fs6.realpathSync(workspaceRequire.resolve(`${locator.name}/package.json`));
|
|
8807
|
-
const sourceDir =
|
|
8839
|
+
const sourceDir = path19.dirname(packageJsonPath);
|
|
8808
8840
|
return {
|
|
8809
8841
|
blockDir: sourceDir,
|
|
8810
8842
|
rootDir: sourceDir
|
|
@@ -8813,11 +8845,11 @@ function resolveInstalledNpmTemplateSource(locator, cwd) {
|
|
|
8813
8845
|
const errorCode = typeof error === "object" && error !== null && "code" in error ? String(error.code) : "";
|
|
8814
8846
|
if (errorCode === "MODULE_NOT_FOUND" || errorCode === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
8815
8847
|
for (const basePath of workspaceRequire.resolve.paths(locator.name) ?? []) {
|
|
8816
|
-
const packageJsonPath =
|
|
8848
|
+
const packageJsonPath = path19.join(basePath, locator.name, "package.json");
|
|
8817
8849
|
if (!fs6.existsSync(packageJsonPath)) {
|
|
8818
8850
|
continue;
|
|
8819
8851
|
}
|
|
8820
|
-
const sourceDir =
|
|
8852
|
+
const sourceDir = path19.dirname(fs6.realpathSync(packageJsonPath));
|
|
8821
8853
|
return {
|
|
8822
8854
|
blockDir: sourceDir,
|
|
8823
8855
|
rootDir: sourceDir
|
|
@@ -8829,7 +8861,7 @@ function resolveInstalledNpmTemplateSource(locator, cwd) {
|
|
|
8829
8861
|
}
|
|
8830
8862
|
}
|
|
8831
8863
|
async function isOfficialWorkspaceTemplateSeedAsync(seed) {
|
|
8832
|
-
const packageJsonPath =
|
|
8864
|
+
const packageJsonPath = path19.join(seed.rootDir, "package.json");
|
|
8833
8865
|
if (!await pathExists(packageJsonPath)) {
|
|
8834
8866
|
return false;
|
|
8835
8867
|
}
|
|
@@ -8843,15 +8875,15 @@ async function isOfficialWorkspaceTemplateSeedAsync(seed) {
|
|
|
8843
8875
|
}
|
|
8844
8876
|
}
|
|
8845
8877
|
async function assertNoSymlinks2(sourceDir) {
|
|
8846
|
-
const stats = await
|
|
8878
|
+
const stats = await fsp13.lstat(sourceDir);
|
|
8847
8879
|
if (stats.isSymbolicLink()) {
|
|
8848
8880
|
throw new Error(`Template sources may not include symbolic links: ${sourceDir}`);
|
|
8849
8881
|
}
|
|
8850
8882
|
if (!stats.isDirectory()) {
|
|
8851
8883
|
return;
|
|
8852
8884
|
}
|
|
8853
|
-
for (const entry of await
|
|
8854
|
-
await assertNoSymlinks2(
|
|
8885
|
+
for (const entry of await fsp13.readdir(sourceDir)) {
|
|
8886
|
+
await assertNoSymlinks2(path19.join(sourceDir, entry));
|
|
8855
8887
|
}
|
|
8856
8888
|
}
|
|
8857
8889
|
function runGitTemplateCommand(args, label, options = {}) {
|
|
@@ -8880,9 +8912,9 @@ function getGitHubTemplateRepositoryUrl(locator) {
|
|
|
8880
8912
|
return `https://github.com/${locator.owner}/${locator.repo}.git`;
|
|
8881
8913
|
}
|
|
8882
8914
|
async function resolveGitHubTemplateDirectory(checkoutDir, locator) {
|
|
8883
|
-
const sourceDir =
|
|
8884
|
-
const relativeSourceDir =
|
|
8885
|
-
if (relativeSourceDir.startsWith("..") ||
|
|
8915
|
+
const sourceDir = path19.resolve(checkoutDir, locator.sourcePath);
|
|
8916
|
+
const relativeSourceDir = path19.relative(checkoutDir, sourceDir);
|
|
8917
|
+
if (relativeSourceDir.startsWith("..") || path19.isAbsolute(relativeSourceDir)) {
|
|
8886
8918
|
throw new Error("GitHub template path must stay within the cloned repository.");
|
|
8887
8919
|
}
|
|
8888
8920
|
if (!await pathExists(sourceDir)) {
|
|
@@ -9071,7 +9103,7 @@ async function resolveGitHubTemplateSource(locator) {
|
|
|
9071
9103
|
}
|
|
9072
9104
|
}
|
|
9073
9105
|
const { path: remoteRoot, cleanup } = await createManagedTempRoot("wp-typia-template-source-");
|
|
9074
|
-
const checkoutDir =
|
|
9106
|
+
const checkoutDir = path19.join(remoteRoot, "source");
|
|
9075
9107
|
try {
|
|
9076
9108
|
cloneGitHubTemplateSource(locator, checkoutDir);
|
|
9077
9109
|
const sourceDir = await resolveGitHubTemplateDirectory(checkoutDir, locator);
|
|
@@ -9088,7 +9120,7 @@ async function resolveGitHubTemplateSource(locator) {
|
|
|
9088
9120
|
}
|
|
9089
9121
|
async function resolveTemplateSeed(locator, cwd) {
|
|
9090
9122
|
if (locator.kind === "path") {
|
|
9091
|
-
const sourceDir =
|
|
9123
|
+
const sourceDir = path19.resolve(cwd, locator.templatePath);
|
|
9092
9124
|
if (!await pathExists(sourceDir)) {
|
|
9093
9125
|
throw new Error(`Template path does not exist: ${sourceDir}`);
|
|
9094
9126
|
}
|
|
@@ -9977,7 +10009,7 @@ function toPhpSingleQuotedString(value) {
|
|
|
9977
10009
|
return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
9978
10010
|
}
|
|
9979
10011
|
|
|
9980
|
-
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-
|
|
10012
|
+
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-basic-artifacts.ts
|
|
9981
10013
|
var BASIC_STYLE_TEMPLATE = `/**
|
|
9982
10014
|
* {{title}} Block Styles
|
|
9983
10015
|
*/
|
|
@@ -10048,58 +10080,529 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
|
10048
10080
|
<?php esc_html_e( 'Server render placeholder.', '{{textDomain}}' ); ?>
|
|
10049
10081
|
</div>
|
|
10050
10082
|
`;
|
|
10051
|
-
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10083
|
+
function buildBasicArtifacts(variables) {
|
|
10084
|
+
return [
|
|
10085
|
+
renderArtifact("src/editor.scss", BASIC_EDITOR_STYLE_TEMPLATE, variables),
|
|
10086
|
+
renderArtifact("src/style.scss", BASIC_STYLE_TEMPLATE, variables),
|
|
10087
|
+
renderArtifact("src/render.php", BASIC_RENDER_TEMPLATE, variables)
|
|
10088
|
+
];
|
|
10089
|
+
}
|
|
10090
|
+
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-compound-templates.ts
|
|
10091
|
+
var COMPOUND_PERSISTENCE_RENDER_TARGETS_TEMPLATE = `<?php
|
|
10092
|
+
/**
|
|
10093
|
+
* Alternate render target helpers for the {{title}} compound parent block.
|
|
10094
|
+
*
|
|
10095
|
+
* @package {{pascalCase}}
|
|
10096
|
+
*/
|
|
10057
10097
|
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
}
|
|
10098
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
10099
|
+
exit;
|
|
10100
|
+
}
|
|
10062
10101
|
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
}
|
|
10102
|
+
if ( ! function_exists( '{{phpPrefix}}_{{slugSnakeCase}}_build_render_context' ) ) {
|
|
10103
|
+
function {{phpPrefix}}_{{slugSnakeCase}}_build_render_context( $attributes, $content, $block ) {
|
|
10104
|
+
$validator_path = __DIR__ . '/typia-validator.php';
|
|
10105
|
+
if ( ! file_exists( $validator_path ) ) {
|
|
10106
|
+
return null;
|
|
10107
|
+
}
|
|
10070
10108
|
|
|
10071
|
-
|
|
10072
|
-
|
|
10073
|
-
|
|
10074
|
-
|
|
10075
|
-
background: #f0f0f1;
|
|
10076
|
-
border-radius: 999px;
|
|
10077
|
-
}
|
|
10109
|
+
$validator = require $validator_path;
|
|
10110
|
+
if ( ! is_object( $validator ) || ! method_exists( $validator, 'apply_defaults' ) || ! method_exists( $validator, 'validate' ) ) {
|
|
10111
|
+
return null;
|
|
10112
|
+
}
|
|
10078
10113
|
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10114
|
+
$normalized = $validator->apply_defaults( is_array( $attributes ) ? $attributes : array() );
|
|
10115
|
+
$validation = $validator->validate( $normalized );
|
|
10116
|
+
$resource_key = isset( $normalized['resourceKey'] ) ? (string) $normalized['resourceKey'] : '';
|
|
10117
|
+
$heading = isset( $normalized['heading'] ) ? (string) $normalized['heading'] : {{titlePhpLiteral}};
|
|
10118
|
+
$intro = isset( $normalized['intro'] ) ? (string) $normalized['intro'] : '';
|
|
10119
|
+
$button_label = isset( $normalized['buttonLabel'] ) ? (string) $normalized['buttonLabel'] : 'Persist Count';
|
|
10120
|
+
$show_count = ! empty( $normalized['showCount'] );
|
|
10121
|
+
$show_dividers = ! empty( $normalized['showDividers'] );
|
|
10122
|
+
$post_id = is_object( $block ) && isset( $block->context['postId'] )
|
|
10123
|
+
? (int) $block->context['postId']
|
|
10124
|
+
: (int) get_queried_object_id();
|
|
10125
|
+
$storage_mode = '{{dataStorageMode}}';
|
|
10126
|
+
$persistence_policy = '{{persistencePolicy}}';
|
|
10084
10127
|
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
color: #3858e9;
|
|
10089
|
-
opacity: 0;
|
|
10090
|
-
transition: opacity 0.2s ease;
|
|
10128
|
+
$notice_message = 'authenticated' === $persistence_policy
|
|
10129
|
+
? __( 'Sign in to persist this counter.', '{{textDomain}}' )
|
|
10130
|
+
: __( 'Public writes are temporarily unavailable.', '{{textDomain}}' );
|
|
10091
10131
|
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
}
|
|
10132
|
+
if ( empty( $validation['valid'] ) || '' === $resource_key ) {
|
|
10133
|
+
return null;
|
|
10134
|
+
}
|
|
10096
10135
|
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10136
|
+
{{phpPrefix}}_record_rendered_block_instance(
|
|
10137
|
+
(int) $post_id,
|
|
10138
|
+
'{{namespace}}/{{slugKebabCase}}',
|
|
10139
|
+
$resource_key
|
|
10140
|
+
);
|
|
10101
10141
|
|
|
10102
|
-
|
|
10142
|
+
$web_context = array(
|
|
10143
|
+
'bootstrapReady' => false,
|
|
10144
|
+
'buttonLabel' => $button_label,
|
|
10145
|
+
'canWrite' => false,
|
|
10146
|
+
'client' => array(
|
|
10147
|
+
'writeExpiry' => 0,
|
|
10148
|
+
'writeNonce' => '',
|
|
10149
|
+
'writeToken' => '',
|
|
10150
|
+
),
|
|
10151
|
+
'count' => 0,
|
|
10152
|
+
'error' => '',
|
|
10153
|
+
'isBootstrapping' => false,
|
|
10154
|
+
'isLoading' => false,
|
|
10155
|
+
'isSaving' => false,
|
|
10156
|
+
'persistencePolicy' => $persistence_policy,
|
|
10157
|
+
'postId' => (int) $post_id,
|
|
10158
|
+
'resourceKey' => $resource_key,
|
|
10159
|
+
'showCount' => $show_count,
|
|
10160
|
+
'storage' => $storage_mode,
|
|
10161
|
+
);
|
|
10162
|
+
|
|
10163
|
+
$allowed_inner_html = wp_kses_allowed_html( 'post' );
|
|
10164
|
+
|
|
10165
|
+
foreach ( $allowed_inner_html as &$allowed_attributes ) {
|
|
10166
|
+
if ( ! is_array( $allowed_attributes ) ) {
|
|
10167
|
+
continue;
|
|
10168
|
+
}
|
|
10169
|
+
|
|
10170
|
+
$allowed_attributes['data-wp-bind--disabled'] = true;
|
|
10171
|
+
$allowed_attributes['data-wp-bind--hidden'] = true;
|
|
10172
|
+
$allowed_attributes['data-wp-bind--value'] = true;
|
|
10173
|
+
$allowed_attributes['data-wp-class'] = true;
|
|
10174
|
+
$allowed_attributes['data-wp-class--active'] = true;
|
|
10175
|
+
$allowed_attributes['data-wp-context'] = true;
|
|
10176
|
+
$allowed_attributes['data-wp-init'] = true;
|
|
10177
|
+
$allowed_attributes['data-wp-interactive'] = true;
|
|
10178
|
+
$allowed_attributes['data-wp-on--click'] = true;
|
|
10179
|
+
$allowed_attributes['data-wp-on--mouseenter'] = true;
|
|
10180
|
+
$allowed_attributes['data-wp-on--mouseleave'] = true;
|
|
10181
|
+
$allowed_attributes['data-wp-run--mounted'] = true;
|
|
10182
|
+
$allowed_attributes['data-wp-style--width'] = true;
|
|
10183
|
+
$allowed_attributes['data-wp-text'] = true;
|
|
10184
|
+
}
|
|
10185
|
+
unset( $allowed_attributes );
|
|
10186
|
+
|
|
10187
|
+
return array(
|
|
10188
|
+
'buttonLabel' => $button_label,
|
|
10189
|
+
'frontendClassName' => '{{cssClassName}}',
|
|
10190
|
+
'heading' => $heading,
|
|
10191
|
+
'intro' => $intro,
|
|
10192
|
+
'isVisible' => true,
|
|
10193
|
+
'normalized' => $normalized,
|
|
10194
|
+
'noticeMessage' => $notice_message,
|
|
10195
|
+
'postId' => (int) $post_id,
|
|
10196
|
+
'resourceKey' => $resource_key,
|
|
10197
|
+
'sanitizedContent' => wp_kses( $content, $allowed_inner_html ),
|
|
10198
|
+
'showCount' => $show_count,
|
|
10199
|
+
'showDividers' => $show_dividers,
|
|
10200
|
+
'title' => {{titleJson}},
|
|
10201
|
+
'webContext' => $web_context,
|
|
10202
|
+
);
|
|
10203
|
+
}
|
|
10204
|
+
}
|
|
10205
|
+
|
|
10206
|
+
if ( ! function_exists( '{{phpPrefix}}_{{slugSnakeCase}}_render_target' ) ) {
|
|
10207
|
+
function {{phpPrefix}}_{{slugSnakeCase}}_render_target( string $target, $attributes, $content = '', $block = null ): string {
|
|
10208
|
+
$context = {{phpPrefix}}_{{slugSnakeCase}}_build_render_context( $attributes, $content, $block );
|
|
10209
|
+
if ( null === $context ) {
|
|
10210
|
+
return '';
|
|
10211
|
+
}
|
|
10212
|
+
|
|
10213
|
+
$target_context = apply_filters(
|
|
10214
|
+
'{{phpPrefix}}_{{slugSnakeCase}}_render_target_context',
|
|
10215
|
+
$context,
|
|
10216
|
+
$target,
|
|
10217
|
+
$attributes,
|
|
10218
|
+
$block
|
|
10219
|
+
);
|
|
10220
|
+
|
|
10221
|
+
$markup = '';
|
|
10222
|
+
switch ( $target ) {
|
|
10223
|
+
case 'email':
|
|
10224
|
+
$parts = array(
|
|
10225
|
+
'<div class="' . esc_attr( $target_context['frontendClassName'] ) . '-email">',
|
|
10226
|
+
'<h3>' . esc_html( $target_context['heading'] ) . '</h3>',
|
|
10227
|
+
);
|
|
10228
|
+
if ( '' !== $target_context['intro'] ) {
|
|
10229
|
+
$parts[] = '<p>' . esc_html( $target_context['intro'] ) . '</p>';
|
|
10230
|
+
}
|
|
10231
|
+
if ( ! empty( $target_context['showCount'] ) ) {
|
|
10232
|
+
$parts[] = '<p><strong>' . esc_html__( 'Count', '{{textDomain}}' ) . ':</strong> ' . esc_html( (string) $target_context['webContext']['count'] ) . '</p>';
|
|
10233
|
+
}
|
|
10234
|
+
$parts[] = wp_kses_post( $target_context['sanitizedContent'] );
|
|
10235
|
+
$parts[] = '<p>' . esc_html( $target_context['noticeMessage'] ) . '</p>';
|
|
10236
|
+
$parts[] = '</div>';
|
|
10237
|
+
$markup = implode( '', $parts );
|
|
10238
|
+
break;
|
|
10239
|
+
case 'mjml':
|
|
10240
|
+
$markup = '<mjml><mj-body><mj-section><mj-column><mj-text font-weight="700">' . esc_html( $target_context['heading'] ) . '</mj-text>';
|
|
10241
|
+
if ( '' !== $target_context['intro'] ) {
|
|
10242
|
+
$markup .= '<mj-text>' . esc_html( $target_context['intro'] ) . '</mj-text>';
|
|
10243
|
+
}
|
|
10244
|
+
if ( ! empty( $target_context['showCount'] ) ) {
|
|
10245
|
+
$markup .= '<mj-text>' . esc_html__( 'Count', '{{textDomain}}' ) . ': ' . esc_html( (string) $target_context['webContext']['count'] ) . '</mj-text>';
|
|
10246
|
+
}
|
|
10247
|
+
$markup .= '<mj-text>' . esc_html( wp_strip_all_tags( $target_context['sanitizedContent'] ) ) . '</mj-text>';
|
|
10248
|
+
$markup .= '<mj-text>' . esc_html( $target_context['noticeMessage'] ) . '</mj-text></mj-column></mj-section></mj-body></mjml>';
|
|
10249
|
+
break;
|
|
10250
|
+
case 'plain-text':
|
|
10251
|
+
$markup = implode(
|
|
10252
|
+
"\\n",
|
|
10253
|
+
array_filter(
|
|
10254
|
+
array(
|
|
10255
|
+
$target_context['heading'],
|
|
10256
|
+
$target_context['intro'],
|
|
10257
|
+
wp_strip_all_tags( $target_context['sanitizedContent'] ),
|
|
10258
|
+
! empty( $target_context['showCount'] )
|
|
10259
|
+
? sprintf( '%s: %s', __( 'Count', '{{textDomain}}' ), (string) $target_context['webContext']['count'] )
|
|
10260
|
+
: null,
|
|
10261
|
+
$target_context['noticeMessage'],
|
|
10262
|
+
),
|
|
10263
|
+
static fn( $value ) => is_string( $value ) && '' !== $value
|
|
10264
|
+
)
|
|
10265
|
+
);
|
|
10266
|
+
break;
|
|
10267
|
+
case 'web':
|
|
10268
|
+
default:
|
|
10269
|
+
$wrapper_attributes = get_block_wrapper_attributes(
|
|
10270
|
+
array(
|
|
10271
|
+
'class' => '{{cssClassName}}',
|
|
10272
|
+
'data-show-dividers' => $target_context['showDividers'] ? 'true' : 'false',
|
|
10273
|
+
'data-wp-context' => wp_json_encode( $target_context['webContext'] ),
|
|
10274
|
+
'data-wp-init' => 'callbacks.init',
|
|
10275
|
+
'data-wp-interactive' => '{{slugKebabCase}}',
|
|
10276
|
+
'data-wp-run--mounted' => 'callbacks.mounted',
|
|
10277
|
+
)
|
|
10278
|
+
);
|
|
10279
|
+
ob_start();
|
|
10280
|
+
?>
|
|
10281
|
+
<div <?php echo $wrapper_attributes; ?>>
|
|
10282
|
+
<h3 class="{{cssClassName}}__heading"><?php echo esc_html( $target_context['heading'] ); ?></h3>
|
|
10283
|
+
<?php if ( '' !== $target_context['intro'] ) : ?>
|
|
10284
|
+
<p class="{{cssClassName}}__intro"><?php echo esc_html( $target_context['intro'] ); ?></p>
|
|
10285
|
+
<?php endif; ?>
|
|
10286
|
+
<p
|
|
10287
|
+
class="{{cssClassName}}__notice"
|
|
10288
|
+
data-wp-bind--hidden="!context.bootstrapReady || context.canWrite"
|
|
10289
|
+
hidden
|
|
10290
|
+
>
|
|
10291
|
+
<?php echo esc_html( $target_context['noticeMessage'] ); ?>
|
|
10292
|
+
</p>
|
|
10293
|
+
<p
|
|
10294
|
+
class="{{cssClassName}}__error"
|
|
10295
|
+
role="status"
|
|
10296
|
+
aria-live="polite"
|
|
10297
|
+
aria-atomic="true"
|
|
10298
|
+
data-wp-bind--hidden="!context.error"
|
|
10299
|
+
data-wp-text="context.error"
|
|
10300
|
+
hidden
|
|
10301
|
+
></p>
|
|
10302
|
+
<?php if ( ! empty( $target_context['showCount'] ) ) : ?>
|
|
10303
|
+
<div class="{{cssClassName}}__counter">
|
|
10304
|
+
<span
|
|
10305
|
+
class="{{cssClassName}}__count"
|
|
10306
|
+
role="status"
|
|
10307
|
+
aria-live="polite"
|
|
10308
|
+
aria-atomic="true"
|
|
10309
|
+
data-wp-text="context.count"
|
|
10310
|
+
>0</span>
|
|
10311
|
+
<button
|
|
10312
|
+
type="button"
|
|
10313
|
+
disabled
|
|
10314
|
+
data-wp-bind--disabled="!context.canWrite"
|
|
10315
|
+
data-wp-on--click="actions.increment"
|
|
10316
|
+
>
|
|
10317
|
+
<?php echo esc_html( $target_context['buttonLabel'] ); ?>
|
|
10318
|
+
</button>
|
|
10319
|
+
</div>
|
|
10320
|
+
<?php endif; ?>
|
|
10321
|
+
<div class="{{cssClassName}}__items">
|
|
10322
|
+
<?php echo wp_kses_post( $target_context['sanitizedContent'] ); ?>
|
|
10323
|
+
</div>
|
|
10324
|
+
</div>
|
|
10325
|
+
<?php
|
|
10326
|
+
$markup = (string) ob_get_clean();
|
|
10327
|
+
break;
|
|
10328
|
+
}
|
|
10329
|
+
|
|
10330
|
+
return apply_filters(
|
|
10331
|
+
'{{phpPrefix}}_{{slugSnakeCase}}_render_target_markup',
|
|
10332
|
+
$markup,
|
|
10333
|
+
$target,
|
|
10334
|
+
$target_context
|
|
10335
|
+
);
|
|
10336
|
+
}
|
|
10337
|
+
}
|
|
10338
|
+
`;
|
|
10339
|
+
var COMPOUND_STYLE_TEMPLATE = `.{{cssClassName}} {
|
|
10340
|
+
border: 1px solid #dcdcde;
|
|
10341
|
+
border-radius: 12px;
|
|
10342
|
+
padding: 1.25rem;
|
|
10343
|
+
background: #fff;
|
|
10344
|
+
}
|
|
10345
|
+
|
|
10346
|
+
.{{cssClassName}}__heading {
|
|
10347
|
+
margin: 0 0 0.5rem;
|
|
10348
|
+
font-size: 1.2rem;
|
|
10349
|
+
}
|
|
10350
|
+
|
|
10351
|
+
.{{cssClassName}}__intro {
|
|
10352
|
+
margin: 0 0 1rem;
|
|
10353
|
+
color: #50575e;
|
|
10354
|
+
}
|
|
10355
|
+
|
|
10356
|
+
.{{cssClassName}}__items {
|
|
10357
|
+
display: grid;
|
|
10358
|
+
gap: 0.75rem;
|
|
10359
|
+
}
|
|
10360
|
+
|
|
10361
|
+
.{{cssClassName}}[data-show-dividers='true'] .{{compoundChildCssClassName}} {
|
|
10362
|
+
border-top: 1px solid #dcdcde;
|
|
10363
|
+
padding-top: 0.75rem;
|
|
10364
|
+
}
|
|
10365
|
+
|
|
10366
|
+
.{{cssClassName}}[data-show-dividers='true'] .{{compoundChildCssClassName}}:first-child {
|
|
10367
|
+
border-top: 0;
|
|
10368
|
+
padding-top: 0;
|
|
10369
|
+
}
|
|
10370
|
+
`;
|
|
10371
|
+
var COMPOUND_PERSISTENCE_RENDER_TEMPLATE = `<?php
|
|
10372
|
+
/**
|
|
10373
|
+
* Dynamic render entry for the {{title}} compound parent block.
|
|
10374
|
+
*
|
|
10375
|
+
* @package {{pascalCase}}
|
|
10376
|
+
*/
|
|
10377
|
+
|
|
10378
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
10379
|
+
exit;
|
|
10380
|
+
}
|
|
10381
|
+
|
|
10382
|
+
$validator_path = __DIR__ . '/typia-validator.php';
|
|
10383
|
+
if ( ! file_exists( $validator_path ) ) {
|
|
10384
|
+
return '';
|
|
10385
|
+
}
|
|
10386
|
+
|
|
10387
|
+
$validator = require $validator_path;
|
|
10388
|
+
if ( ! is_object( $validator ) || ! method_exists( $validator, 'apply_defaults' ) || ! method_exists( $validator, 'validate' ) ) {
|
|
10389
|
+
return '';
|
|
10390
|
+
}
|
|
10391
|
+
|
|
10392
|
+
$normalized = $validator->apply_defaults( is_array( $attributes ) ? $attributes : array() );
|
|
10393
|
+
$validation = $validator->validate( $normalized );
|
|
10394
|
+
$resource_key = isset( $normalized['resourceKey'] ) ? (string) $normalized['resourceKey'] : '';
|
|
10395
|
+
$heading = isset( $normalized['heading'] ) ? (string) $normalized['heading'] : {{titlePhpLiteral}};
|
|
10396
|
+
$intro = isset( $normalized['intro'] ) ? (string) $normalized['intro'] : '';
|
|
10397
|
+
$button_label = isset( $normalized['buttonLabel'] ) ? (string) $normalized['buttonLabel'] : 'Persist Count';
|
|
10398
|
+
$show_count = ! empty( $normalized['showCount'] );
|
|
10399
|
+
$show_dividers = ! empty( $normalized['showDividers'] );
|
|
10400
|
+
$post_id = is_object( $block ) && isset( $block->context['postId'] )
|
|
10401
|
+
? (int) $block->context['postId']
|
|
10402
|
+
: (int) get_queried_object_id();
|
|
10403
|
+
$storage_mode = '{{dataStorageMode}}';
|
|
10404
|
+
$persistence_policy = '{{persistencePolicy}}';
|
|
10405
|
+
|
|
10406
|
+
$notice_message = 'authenticated' === $persistence_policy
|
|
10407
|
+
? __( 'Sign in to persist this counter.', '{{textDomain}}' )
|
|
10408
|
+
: __( 'Public writes are temporarily unavailable.', '{{textDomain}}' );
|
|
10409
|
+
|
|
10410
|
+
if ( empty( $validation['valid'] ) || '' === $resource_key ) {
|
|
10411
|
+
return '';
|
|
10412
|
+
}
|
|
10413
|
+
|
|
10414
|
+
{{phpPrefix}}_record_rendered_block_instance(
|
|
10415
|
+
(int) $post_id,
|
|
10416
|
+
'{{namespace}}/{{slugKebabCase}}',
|
|
10417
|
+
$resource_key
|
|
10418
|
+
);
|
|
10419
|
+
|
|
10420
|
+
$context = array(
|
|
10421
|
+
'bootstrapReady' => false,
|
|
10422
|
+
'buttonLabel' => $button_label,
|
|
10423
|
+
'canWrite' => false,
|
|
10424
|
+
'client' => array(
|
|
10425
|
+
'writeExpiry' => 0,
|
|
10426
|
+
'writeNonce' => '',
|
|
10427
|
+
'writeToken' => '',
|
|
10428
|
+
),
|
|
10429
|
+
'count' => 0,
|
|
10430
|
+
'error' => '',
|
|
10431
|
+
'isBootstrapping' => false,
|
|
10432
|
+
'isLoading' => false,
|
|
10433
|
+
'isSaving' => false,
|
|
10434
|
+
'persistencePolicy' => $persistence_policy,
|
|
10435
|
+
'postId' => (int) $post_id,
|
|
10436
|
+
'resourceKey' => $resource_key,
|
|
10437
|
+
'showCount' => $show_count,
|
|
10438
|
+
'storage' => $storage_mode,
|
|
10439
|
+
);
|
|
10440
|
+
|
|
10441
|
+
$allowed_inner_html = wp_kses_allowed_html( 'post' );
|
|
10442
|
+
|
|
10443
|
+
foreach ( $allowed_inner_html as &$allowed_attributes ) {
|
|
10444
|
+
if ( ! is_array( $allowed_attributes ) ) {
|
|
10445
|
+
continue;
|
|
10446
|
+
}
|
|
10447
|
+
|
|
10448
|
+
$allowed_attributes['data-wp-bind--disabled'] = true;
|
|
10449
|
+
$allowed_attributes['data-wp-bind--hidden'] = true;
|
|
10450
|
+
$allowed_attributes['data-wp-bind--value'] = true;
|
|
10451
|
+
$allowed_attributes['data-wp-class'] = true;
|
|
10452
|
+
$allowed_attributes['data-wp-class--active'] = true;
|
|
10453
|
+
$allowed_attributes['data-wp-context'] = true;
|
|
10454
|
+
$allowed_attributes['data-wp-init'] = true;
|
|
10455
|
+
$allowed_attributes['data-wp-interactive'] = true;
|
|
10456
|
+
$allowed_attributes['data-wp-on--click'] = true;
|
|
10457
|
+
$allowed_attributes['data-wp-on--mouseenter'] = true;
|
|
10458
|
+
$allowed_attributes['data-wp-on--mouseleave'] = true;
|
|
10459
|
+
$allowed_attributes['data-wp-run--mounted'] = true;
|
|
10460
|
+
$allowed_attributes['data-wp-style--width'] = true;
|
|
10461
|
+
$allowed_attributes['data-wp-text'] = true;
|
|
10462
|
+
}
|
|
10463
|
+
unset( $allowed_attributes );
|
|
10464
|
+
|
|
10465
|
+
$sanitized_content = wp_kses( $content, $allowed_inner_html );
|
|
10466
|
+
|
|
10467
|
+
$wrapper_attributes = get_block_wrapper_attributes(
|
|
10468
|
+
array(
|
|
10469
|
+
'class' => '{{cssClassName}}',
|
|
10470
|
+
'data-show-dividers' => $show_dividers ? 'true' : 'false',
|
|
10471
|
+
'data-wp-context' => wp_json_encode( $context ),
|
|
10472
|
+
'data-wp-init' => 'callbacks.init',
|
|
10473
|
+
'data-wp-interactive' => '{{slugKebabCase}}',
|
|
10474
|
+
'data-wp-run--mounted' => 'callbacks.mounted',
|
|
10475
|
+
)
|
|
10476
|
+
);
|
|
10477
|
+
?>
|
|
10478
|
+
|
|
10479
|
+
<div <?php echo $wrapper_attributes; ?>>
|
|
10480
|
+
<h3 class="{{cssClassName}}__heading"><?php echo esc_html( $heading ); ?></h3>
|
|
10481
|
+
<?php if ( '' !== $intro ) : ?>
|
|
10482
|
+
<p class="{{cssClassName}}__intro"><?php echo esc_html( $intro ); ?></p>
|
|
10483
|
+
<?php endif; ?>
|
|
10484
|
+
<p
|
|
10485
|
+
class="{{cssClassName}}__notice"
|
|
10486
|
+
data-wp-bind--hidden="!context.bootstrapReady || context.canWrite"
|
|
10487
|
+
hidden
|
|
10488
|
+
>
|
|
10489
|
+
<?php echo esc_html( $notice_message ); ?>
|
|
10490
|
+
</p>
|
|
10491
|
+
<p
|
|
10492
|
+
class="{{cssClassName}}__error"
|
|
10493
|
+
role="status"
|
|
10494
|
+
aria-live="polite"
|
|
10495
|
+
aria-atomic="true"
|
|
10496
|
+
data-wp-bind--hidden="!context.error"
|
|
10497
|
+
data-wp-text="context.error"
|
|
10498
|
+
hidden
|
|
10499
|
+
></p>
|
|
10500
|
+
<?php if ( $show_count ) : ?>
|
|
10501
|
+
<div class="{{cssClassName}}__counter">
|
|
10502
|
+
<span
|
|
10503
|
+
class="{{cssClassName}}__count"
|
|
10504
|
+
role="status"
|
|
10505
|
+
aria-live="polite"
|
|
10506
|
+
aria-atomic="true"
|
|
10507
|
+
data-wp-text="context.count"
|
|
10508
|
+
>0</span>
|
|
10509
|
+
<button
|
|
10510
|
+
type="button"
|
|
10511
|
+
disabled
|
|
10512
|
+
data-wp-bind--disabled="!context.canWrite"
|
|
10513
|
+
data-wp-on--click="actions.increment"
|
|
10514
|
+
>
|
|
10515
|
+
<?php echo esc_html( $button_label ); ?>
|
|
10516
|
+
</button>
|
|
10517
|
+
</div>
|
|
10518
|
+
<?php endif; ?>
|
|
10519
|
+
<div class="{{cssClassName}}__items">
|
|
10520
|
+
<?php echo $sanitized_content; ?>
|
|
10521
|
+
</div>
|
|
10522
|
+
</div>
|
|
10523
|
+
`;
|
|
10524
|
+
|
|
10525
|
+
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-compound-artifacts.ts
|
|
10526
|
+
function buildCompoundArtifacts(variables) {
|
|
10527
|
+
const alternateRenderTargets = getScaffoldAlternateRenderTargets(variables);
|
|
10528
|
+
const artifacts = [
|
|
10529
|
+
renderArtifact(`src/blocks/${variables.slugKebabCase}/style.scss`, COMPOUND_STYLE_TEMPLATE, variables)
|
|
10530
|
+
];
|
|
10531
|
+
if (isCompoundPersistenceEnabled(variables)) {
|
|
10532
|
+
const renderView = {
|
|
10533
|
+
...variables,
|
|
10534
|
+
titlePhpLiteral: toPhpSingleQuotedString(variables.title)
|
|
10535
|
+
};
|
|
10536
|
+
if (alternateRenderTargets.enabled) {
|
|
10537
|
+
artifacts.push(renderArtifact(`src/blocks/${variables.slugKebabCase}/render-targets.php`, COMPOUND_PERSISTENCE_RENDER_TARGETS_TEMPLATE, renderView), buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render.php`, "web", variables));
|
|
10538
|
+
if (alternateRenderTargets.hasEmail) {
|
|
10539
|
+
artifacts.push(buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render-email.php`, "email", variables));
|
|
10540
|
+
}
|
|
10541
|
+
if (alternateRenderTargets.hasMjml) {
|
|
10542
|
+
artifacts.push(buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render-mjml.php`, "mjml", variables));
|
|
10543
|
+
}
|
|
10544
|
+
if (alternateRenderTargets.hasPlainText) {
|
|
10545
|
+
artifacts.push(buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render-text.php`, "plain-text", variables));
|
|
10546
|
+
}
|
|
10547
|
+
return artifacts;
|
|
10548
|
+
}
|
|
10549
|
+
artifacts.push(renderArtifact(`src/blocks/${variables.slugKebabCase}/render.php`, COMPOUND_PERSISTENCE_RENDER_TEMPLATE, renderView));
|
|
10550
|
+
}
|
|
10551
|
+
return artifacts;
|
|
10552
|
+
}
|
|
10553
|
+
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-interactivity-artifacts.ts
|
|
10554
|
+
var INTERACTIVITY_STYLE_TEMPLATE = `.{{cssClassName}} {
|
|
10555
|
+
position: relative;
|
|
10556
|
+
padding: 1rem;
|
|
10557
|
+
border: 1px solid #dcdcde;
|
|
10558
|
+
border-radius: 0.75rem;
|
|
10559
|
+
background: #fff;
|
|
10560
|
+
|
|
10561
|
+
&__content {
|
|
10562
|
+
display: grid;
|
|
10563
|
+
gap: 0.75rem;
|
|
10564
|
+
}
|
|
10565
|
+
|
|
10566
|
+
&__counter {
|
|
10567
|
+
display: inline-flex;
|
|
10568
|
+
gap: 0.35rem;
|
|
10569
|
+
align-items: center;
|
|
10570
|
+
font-size: 0.9rem;
|
|
10571
|
+
font-weight: 600;
|
|
10572
|
+
}
|
|
10573
|
+
|
|
10574
|
+
&__progress {
|
|
10575
|
+
width: 100%;
|
|
10576
|
+
height: 0.5rem;
|
|
10577
|
+
overflow: hidden;
|
|
10578
|
+
background: #f0f0f1;
|
|
10579
|
+
border-radius: 999px;
|
|
10580
|
+
}
|
|
10581
|
+
|
|
10582
|
+
&__progress-bar {
|
|
10583
|
+
height: 100%;
|
|
10584
|
+
background: #3858e9;
|
|
10585
|
+
transition: width 0.2s ease;
|
|
10586
|
+
}
|
|
10587
|
+
|
|
10588
|
+
&__animation {
|
|
10589
|
+
min-height: 1.5rem;
|
|
10590
|
+
font-size: 0.85rem;
|
|
10591
|
+
color: #3858e9;
|
|
10592
|
+
opacity: 0;
|
|
10593
|
+
transition: opacity 0.2s ease;
|
|
10594
|
+
|
|
10595
|
+
&.is-active {
|
|
10596
|
+
opacity: 1;
|
|
10597
|
+
}
|
|
10598
|
+
}
|
|
10599
|
+
|
|
10600
|
+
&__completion {
|
|
10601
|
+
font-weight: 700;
|
|
10602
|
+
color: #06752d;
|
|
10603
|
+
}
|
|
10604
|
+
|
|
10605
|
+
&__reset {
|
|
10103
10606
|
align-self: start;
|
|
10104
10607
|
padding: 0.4rem 0.7rem;
|
|
10105
10608
|
border: 1px solid #dcdcde;
|
|
@@ -10117,7 +10620,14 @@ var INTERACTIVITY_EDITOR_STYLE_TEMPLATE = `/**
|
|
|
10117
10620
|
outline: 1px dashed #ddd;
|
|
10118
10621
|
outline-offset: -1px;
|
|
10119
10622
|
}
|
|
10120
|
-
`;
|
|
10623
|
+
`;
|
|
10624
|
+
function buildInteractivityArtifacts(variables) {
|
|
10625
|
+
return [
|
|
10626
|
+
renderArtifact("src/editor.scss", INTERACTIVITY_EDITOR_STYLE_TEMPLATE, variables),
|
|
10627
|
+
renderArtifact("src/style.scss", INTERACTIVITY_STYLE_TEMPLATE, variables)
|
|
10628
|
+
];
|
|
10629
|
+
}
|
|
10630
|
+
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-persistence-templates.ts
|
|
10121
10631
|
var PERSISTENCE_STYLE_TEMPLATE = `.{{cssClassName}} {
|
|
10122
10632
|
border: 1px solid #dcdcde;
|
|
10123
10633
|
border-radius: 12px;
|
|
@@ -10451,280 +10961,32 @@ if ( ! function_exists( '{{phpPrefix}}_{{slugSnakeCase}}_render_target' ) ) {
|
|
|
10451
10961
|
</p>
|
|
10452
10962
|
<p
|
|
10453
10963
|
class="{{frontendCssClassName}}__error"
|
|
10454
|
-
role="status"
|
|
10455
|
-
aria-live="polite"
|
|
10456
|
-
aria-atomic="true"
|
|
10457
|
-
data-wp-bind--hidden="!context.error"
|
|
10458
|
-
data-wp-text="context.error"
|
|
10459
|
-
hidden
|
|
10460
|
-
></p>
|
|
10461
|
-
<?php if ( ! empty( $target_context['showCount'] ) ) : ?>
|
|
10462
|
-
<span
|
|
10463
|
-
class="{{frontendCssClassName}}__count"
|
|
10464
|
-
role="status"
|
|
10465
|
-
aria-live="polite"
|
|
10466
|
-
aria-atomic="true"
|
|
10467
|
-
data-wp-text="context.count"
|
|
10468
|
-
>
|
|
10469
|
-
0
|
|
10470
|
-
</span>
|
|
10471
|
-
<?php endif; ?>
|
|
10472
|
-
<button
|
|
10473
|
-
type="button"
|
|
10474
|
-
disabled
|
|
10475
|
-
data-wp-bind--disabled="!context.canWrite"
|
|
10476
|
-
data-wp-on--click="actions.increment"
|
|
10477
|
-
>
|
|
10478
|
-
<?php echo esc_html( $target_context['buttonLabel'] ); ?>
|
|
10479
|
-
</button>
|
|
10480
|
-
</div>
|
|
10481
|
-
</div>
|
|
10482
|
-
<?php
|
|
10483
|
-
$markup = (string) ob_get_clean();
|
|
10484
|
-
break;
|
|
10485
|
-
}
|
|
10486
|
-
|
|
10487
|
-
return apply_filters(
|
|
10488
|
-
'{{phpPrefix}}_{{slugSnakeCase}}_render_target_markup',
|
|
10489
|
-
$markup,
|
|
10490
|
-
$target,
|
|
10491
|
-
$target_context
|
|
10492
|
-
);
|
|
10493
|
-
}
|
|
10494
|
-
}
|
|
10495
|
-
`;
|
|
10496
|
-
var COMPOUND_PERSISTENCE_RENDER_TARGETS_TEMPLATE = `<?php
|
|
10497
|
-
/**
|
|
10498
|
-
* Alternate render target helpers for the {{title}} compound parent block.
|
|
10499
|
-
*
|
|
10500
|
-
* @package {{pascalCase}}
|
|
10501
|
-
*/
|
|
10502
|
-
|
|
10503
|
-
if ( ! defined( 'ABSPATH' ) ) {
|
|
10504
|
-
exit;
|
|
10505
|
-
}
|
|
10506
|
-
|
|
10507
|
-
if ( ! function_exists( '{{phpPrefix}}_{{slugSnakeCase}}_build_render_context' ) ) {
|
|
10508
|
-
function {{phpPrefix}}_{{slugSnakeCase}}_build_render_context( $attributes, $content, $block ) {
|
|
10509
|
-
$validator_path = __DIR__ . '/typia-validator.php';
|
|
10510
|
-
if ( ! file_exists( $validator_path ) ) {
|
|
10511
|
-
return null;
|
|
10512
|
-
}
|
|
10513
|
-
|
|
10514
|
-
$validator = require $validator_path;
|
|
10515
|
-
if ( ! is_object( $validator ) || ! method_exists( $validator, 'apply_defaults' ) || ! method_exists( $validator, 'validate' ) ) {
|
|
10516
|
-
return null;
|
|
10517
|
-
}
|
|
10518
|
-
|
|
10519
|
-
$normalized = $validator->apply_defaults( is_array( $attributes ) ? $attributes : array() );
|
|
10520
|
-
$validation = $validator->validate( $normalized );
|
|
10521
|
-
$resource_key = isset( $normalized['resourceKey'] ) ? (string) $normalized['resourceKey'] : '';
|
|
10522
|
-
$heading = isset( $normalized['heading'] ) ? (string) $normalized['heading'] : {{titlePhpLiteral}};
|
|
10523
|
-
$intro = isset( $normalized['intro'] ) ? (string) $normalized['intro'] : '';
|
|
10524
|
-
$button_label = isset( $normalized['buttonLabel'] ) ? (string) $normalized['buttonLabel'] : 'Persist Count';
|
|
10525
|
-
$show_count = ! empty( $normalized['showCount'] );
|
|
10526
|
-
$show_dividers = ! empty( $normalized['showDividers'] );
|
|
10527
|
-
$post_id = is_object( $block ) && isset( $block->context['postId'] )
|
|
10528
|
-
? (int) $block->context['postId']
|
|
10529
|
-
: (int) get_queried_object_id();
|
|
10530
|
-
$storage_mode = '{{dataStorageMode}}';
|
|
10531
|
-
$persistence_policy = '{{persistencePolicy}}';
|
|
10532
|
-
|
|
10533
|
-
$notice_message = 'authenticated' === $persistence_policy
|
|
10534
|
-
? __( 'Sign in to persist this counter.', '{{textDomain}}' )
|
|
10535
|
-
: __( 'Public writes are temporarily unavailable.', '{{textDomain}}' );
|
|
10536
|
-
|
|
10537
|
-
if ( empty( $validation['valid'] ) || '' === $resource_key ) {
|
|
10538
|
-
return null;
|
|
10539
|
-
}
|
|
10540
|
-
|
|
10541
|
-
{{phpPrefix}}_record_rendered_block_instance(
|
|
10542
|
-
(int) $post_id,
|
|
10543
|
-
'{{namespace}}/{{slugKebabCase}}',
|
|
10544
|
-
$resource_key
|
|
10545
|
-
);
|
|
10546
|
-
|
|
10547
|
-
$web_context = array(
|
|
10548
|
-
'bootstrapReady' => false,
|
|
10549
|
-
'buttonLabel' => $button_label,
|
|
10550
|
-
'canWrite' => false,
|
|
10551
|
-
'client' => array(
|
|
10552
|
-
'writeExpiry' => 0,
|
|
10553
|
-
'writeNonce' => '',
|
|
10554
|
-
'writeToken' => '',
|
|
10555
|
-
),
|
|
10556
|
-
'count' => 0,
|
|
10557
|
-
'error' => '',
|
|
10558
|
-
'isBootstrapping' => false,
|
|
10559
|
-
'isLoading' => false,
|
|
10560
|
-
'isSaving' => false,
|
|
10561
|
-
'persistencePolicy' => $persistence_policy,
|
|
10562
|
-
'postId' => (int) $post_id,
|
|
10563
|
-
'resourceKey' => $resource_key,
|
|
10564
|
-
'showCount' => $show_count,
|
|
10565
|
-
'storage' => $storage_mode,
|
|
10566
|
-
);
|
|
10567
|
-
|
|
10568
|
-
$allowed_inner_html = wp_kses_allowed_html( 'post' );
|
|
10569
|
-
|
|
10570
|
-
foreach ( $allowed_inner_html as &$allowed_attributes ) {
|
|
10571
|
-
if ( ! is_array( $allowed_attributes ) ) {
|
|
10572
|
-
continue;
|
|
10573
|
-
}
|
|
10574
|
-
|
|
10575
|
-
$allowed_attributes['data-wp-bind--disabled'] = true;
|
|
10576
|
-
$allowed_attributes['data-wp-bind--hidden'] = true;
|
|
10577
|
-
$allowed_attributes['data-wp-bind--value'] = true;
|
|
10578
|
-
$allowed_attributes['data-wp-class'] = true;
|
|
10579
|
-
$allowed_attributes['data-wp-class--active'] = true;
|
|
10580
|
-
$allowed_attributes['data-wp-context'] = true;
|
|
10581
|
-
$allowed_attributes['data-wp-init'] = true;
|
|
10582
|
-
$allowed_attributes['data-wp-interactive'] = true;
|
|
10583
|
-
$allowed_attributes['data-wp-on--click'] = true;
|
|
10584
|
-
$allowed_attributes['data-wp-on--mouseenter'] = true;
|
|
10585
|
-
$allowed_attributes['data-wp-on--mouseleave'] = true;
|
|
10586
|
-
$allowed_attributes['data-wp-run--mounted'] = true;
|
|
10587
|
-
$allowed_attributes['data-wp-style--width'] = true;
|
|
10588
|
-
$allowed_attributes['data-wp-text'] = true;
|
|
10589
|
-
}
|
|
10590
|
-
unset( $allowed_attributes );
|
|
10591
|
-
|
|
10592
|
-
return array(
|
|
10593
|
-
'buttonLabel' => $button_label,
|
|
10594
|
-
'frontendClassName' => '{{cssClassName}}',
|
|
10595
|
-
'heading' => $heading,
|
|
10596
|
-
'intro' => $intro,
|
|
10597
|
-
'isVisible' => true,
|
|
10598
|
-
'normalized' => $normalized,
|
|
10599
|
-
'noticeMessage' => $notice_message,
|
|
10600
|
-
'postId' => (int) $post_id,
|
|
10601
|
-
'resourceKey' => $resource_key,
|
|
10602
|
-
'sanitizedContent' => wp_kses( $content, $allowed_inner_html ),
|
|
10603
|
-
'showCount' => $show_count,
|
|
10604
|
-
'showDividers' => $show_dividers,
|
|
10605
|
-
'title' => {{titleJson}},
|
|
10606
|
-
'webContext' => $web_context,
|
|
10607
|
-
);
|
|
10608
|
-
}
|
|
10609
|
-
}
|
|
10610
|
-
|
|
10611
|
-
if ( ! function_exists( '{{phpPrefix}}_{{slugSnakeCase}}_render_target' ) ) {
|
|
10612
|
-
function {{phpPrefix}}_{{slugSnakeCase}}_render_target( string $target, $attributes, $content = '', $block = null ): string {
|
|
10613
|
-
$context = {{phpPrefix}}_{{slugSnakeCase}}_build_render_context( $attributes, $content, $block );
|
|
10614
|
-
if ( null === $context ) {
|
|
10615
|
-
return '';
|
|
10616
|
-
}
|
|
10617
|
-
|
|
10618
|
-
$target_context = apply_filters(
|
|
10619
|
-
'{{phpPrefix}}_{{slugSnakeCase}}_render_target_context',
|
|
10620
|
-
$context,
|
|
10621
|
-
$target,
|
|
10622
|
-
$attributes,
|
|
10623
|
-
$block
|
|
10624
|
-
);
|
|
10625
|
-
|
|
10626
|
-
$markup = '';
|
|
10627
|
-
switch ( $target ) {
|
|
10628
|
-
case 'email':
|
|
10629
|
-
$parts = array(
|
|
10630
|
-
'<div class="' . esc_attr( $target_context['frontendClassName'] ) . '-email">',
|
|
10631
|
-
'<h3>' . esc_html( $target_context['heading'] ) . '</h3>',
|
|
10632
|
-
);
|
|
10633
|
-
if ( '' !== $target_context['intro'] ) {
|
|
10634
|
-
$parts[] = '<p>' . esc_html( $target_context['intro'] ) . '</p>';
|
|
10635
|
-
}
|
|
10636
|
-
if ( ! empty( $target_context['showCount'] ) ) {
|
|
10637
|
-
$parts[] = '<p><strong>' . esc_html__( 'Count', '{{textDomain}}' ) . ':</strong> ' . esc_html( (string) $target_context['webContext']['count'] ) . '</p>';
|
|
10638
|
-
}
|
|
10639
|
-
$parts[] = wp_kses_post( $target_context['sanitizedContent'] );
|
|
10640
|
-
$parts[] = '<p>' . esc_html( $target_context['noticeMessage'] ) . '</p>';
|
|
10641
|
-
$parts[] = '</div>';
|
|
10642
|
-
$markup = implode( '', $parts );
|
|
10643
|
-
break;
|
|
10644
|
-
case 'mjml':
|
|
10645
|
-
$markup = '<mjml><mj-body><mj-section><mj-column><mj-text font-weight="700">' . esc_html( $target_context['heading'] ) . '</mj-text>';
|
|
10646
|
-
if ( '' !== $target_context['intro'] ) {
|
|
10647
|
-
$markup .= '<mj-text>' . esc_html( $target_context['intro'] ) . '</mj-text>';
|
|
10648
|
-
}
|
|
10649
|
-
if ( ! empty( $target_context['showCount'] ) ) {
|
|
10650
|
-
$markup .= '<mj-text>' . esc_html__( 'Count', '{{textDomain}}' ) . ': ' . esc_html( (string) $target_context['webContext']['count'] ) . '</mj-text>';
|
|
10651
|
-
}
|
|
10652
|
-
$markup .= '<mj-text>' . esc_html( wp_strip_all_tags( $target_context['sanitizedContent'] ) ) . '</mj-text>';
|
|
10653
|
-
$markup .= '<mj-text>' . esc_html( $target_context['noticeMessage'] ) . '</mj-text></mj-column></mj-section></mj-body></mjml>';
|
|
10654
|
-
break;
|
|
10655
|
-
case 'plain-text':
|
|
10656
|
-
$markup = implode(
|
|
10657
|
-
"\\n",
|
|
10658
|
-
array_filter(
|
|
10659
|
-
array(
|
|
10660
|
-
$target_context['heading'],
|
|
10661
|
-
$target_context['intro'],
|
|
10662
|
-
wp_strip_all_tags( $target_context['sanitizedContent'] ),
|
|
10663
|
-
! empty( $target_context['showCount'] )
|
|
10664
|
-
? sprintf( '%s: %s', __( 'Count', '{{textDomain}}' ), (string) $target_context['webContext']['count'] )
|
|
10665
|
-
: null,
|
|
10666
|
-
$target_context['noticeMessage'],
|
|
10667
|
-
),
|
|
10668
|
-
static fn( $value ) => is_string( $value ) && '' !== $value
|
|
10669
|
-
)
|
|
10670
|
-
);
|
|
10671
|
-
break;
|
|
10672
|
-
case 'web':
|
|
10673
|
-
default:
|
|
10674
|
-
$wrapper_attributes = get_block_wrapper_attributes(
|
|
10675
|
-
array(
|
|
10676
|
-
'class' => '{{cssClassName}}',
|
|
10677
|
-
'data-show-dividers' => $target_context['showDividers'] ? 'true' : 'false',
|
|
10678
|
-
'data-wp-context' => wp_json_encode( $target_context['webContext'] ),
|
|
10679
|
-
'data-wp-init' => 'callbacks.init',
|
|
10680
|
-
'data-wp-interactive' => '{{slugKebabCase}}',
|
|
10681
|
-
'data-wp-run--mounted' => 'callbacks.mounted',
|
|
10682
|
-
)
|
|
10683
|
-
);
|
|
10684
|
-
ob_start();
|
|
10685
|
-
?>
|
|
10686
|
-
<div <?php echo $wrapper_attributes; ?>>
|
|
10687
|
-
<h3 class="{{cssClassName}}__heading"><?php echo esc_html( $target_context['heading'] ); ?></h3>
|
|
10688
|
-
<?php if ( '' !== $target_context['intro'] ) : ?>
|
|
10689
|
-
<p class="{{cssClassName}}__intro"><?php echo esc_html( $target_context['intro'] ); ?></p>
|
|
10690
|
-
<?php endif; ?>
|
|
10691
|
-
<p
|
|
10692
|
-
class="{{cssClassName}}__notice"
|
|
10693
|
-
data-wp-bind--hidden="!context.bootstrapReady || context.canWrite"
|
|
10694
|
-
hidden
|
|
10695
|
-
>
|
|
10696
|
-
<?php echo esc_html( $target_context['noticeMessage'] ); ?>
|
|
10697
|
-
</p>
|
|
10698
|
-
<p
|
|
10699
|
-
class="{{cssClassName}}__error"
|
|
10700
|
-
role="status"
|
|
10701
|
-
aria-live="polite"
|
|
10702
|
-
aria-atomic="true"
|
|
10703
|
-
data-wp-bind--hidden="!context.error"
|
|
10704
|
-
data-wp-text="context.error"
|
|
10705
|
-
hidden
|
|
10706
|
-
></p>
|
|
10707
|
-
<?php if ( ! empty( $target_context['showCount'] ) ) : ?>
|
|
10708
|
-
<div class="{{cssClassName}}__counter">
|
|
10964
|
+
role="status"
|
|
10965
|
+
aria-live="polite"
|
|
10966
|
+
aria-atomic="true"
|
|
10967
|
+
data-wp-bind--hidden="!context.error"
|
|
10968
|
+
data-wp-text="context.error"
|
|
10969
|
+
hidden
|
|
10970
|
+
></p>
|
|
10971
|
+
<?php if ( ! empty( $target_context['showCount'] ) ) : ?>
|
|
10709
10972
|
<span
|
|
10710
|
-
class="{{
|
|
10973
|
+
class="{{frontendCssClassName}}__count"
|
|
10711
10974
|
role="status"
|
|
10712
10975
|
aria-live="polite"
|
|
10713
10976
|
aria-atomic="true"
|
|
10714
10977
|
data-wp-text="context.count"
|
|
10715
|
-
>0</span>
|
|
10716
|
-
<button
|
|
10717
|
-
type="button"
|
|
10718
|
-
disabled
|
|
10719
|
-
data-wp-bind--disabled="!context.canWrite"
|
|
10720
|
-
data-wp-on--click="actions.increment"
|
|
10721
10978
|
>
|
|
10722
|
-
|
|
10723
|
-
</
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10979
|
+
0
|
|
10980
|
+
</span>
|
|
10981
|
+
<?php endif; ?>
|
|
10982
|
+
<button
|
|
10983
|
+
type="button"
|
|
10984
|
+
disabled
|
|
10985
|
+
data-wp-bind--disabled="!context.canWrite"
|
|
10986
|
+
data-wp-on--click="actions.increment"
|
|
10987
|
+
>
|
|
10988
|
+
<?php echo esc_html( $target_context['buttonLabel'] ); ?>
|
|
10989
|
+
</button>
|
|
10728
10990
|
</div>
|
|
10729
10991
|
</div>
|
|
10730
10992
|
<?php
|
|
@@ -10741,51 +11003,8 @@ if ( ! function_exists( '{{phpPrefix}}_{{slugSnakeCase}}_render_target' ) ) {
|
|
|
10741
11003
|
}
|
|
10742
11004
|
}
|
|
10743
11005
|
`;
|
|
10744
|
-
var COMPOUND_STYLE_TEMPLATE = `.{{cssClassName}} {
|
|
10745
|
-
border: 1px solid #dcdcde;
|
|
10746
|
-
border-radius: 12px;
|
|
10747
|
-
padding: 1.25rem;
|
|
10748
|
-
background: #fff;
|
|
10749
|
-
}
|
|
10750
|
-
|
|
10751
|
-
.{{cssClassName}}__heading {
|
|
10752
|
-
margin: 0 0 0.5rem;
|
|
10753
|
-
font-size: 1.2rem;
|
|
10754
|
-
}
|
|
10755
|
-
|
|
10756
|
-
.{{cssClassName}}__intro {
|
|
10757
|
-
margin: 0 0 1rem;
|
|
10758
|
-
color: #50575e;
|
|
10759
|
-
}
|
|
10760
|
-
|
|
10761
|
-
.{{cssClassName}}__items {
|
|
10762
|
-
display: grid;
|
|
10763
|
-
gap: 0.75rem;
|
|
10764
|
-
}
|
|
10765
|
-
|
|
10766
|
-
.{{cssClassName}}[data-show-dividers='true'] .{{compoundChildCssClassName}} {
|
|
10767
|
-
border-top: 1px solid #dcdcde;
|
|
10768
|
-
padding-top: 0.75rem;
|
|
10769
|
-
}
|
|
10770
11006
|
|
|
10771
|
-
|
|
10772
|
-
border-top: 0;
|
|
10773
|
-
padding-top: 0;
|
|
10774
|
-
}
|
|
10775
|
-
`;
|
|
10776
|
-
function buildBasicArtifacts(variables) {
|
|
10777
|
-
return [
|
|
10778
|
-
renderArtifact("src/editor.scss", BASIC_EDITOR_STYLE_TEMPLATE, variables),
|
|
10779
|
-
renderArtifact("src/style.scss", BASIC_STYLE_TEMPLATE, variables),
|
|
10780
|
-
renderArtifact("src/render.php", BASIC_RENDER_TEMPLATE, variables)
|
|
10781
|
-
];
|
|
10782
|
-
}
|
|
10783
|
-
function buildInteractivityArtifacts(variables) {
|
|
10784
|
-
return [
|
|
10785
|
-
renderArtifact("src/editor.scss", INTERACTIVITY_EDITOR_STYLE_TEMPLATE, variables),
|
|
10786
|
-
renderArtifact("src/style.scss", INTERACTIVITY_STYLE_TEMPLATE, variables)
|
|
10787
|
-
];
|
|
10788
|
-
}
|
|
11007
|
+
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-persistence-artifacts.ts
|
|
10789
11008
|
function buildPersistenceArtifacts(variables) {
|
|
10790
11009
|
const alternateRenderTargets = getScaffoldAlternateRenderTargets(variables);
|
|
10791
11010
|
if (!alternateRenderTargets.enabled) {
|
|
@@ -10810,187 +11029,6 @@ function buildPersistenceArtifacts(variables) {
|
|
|
10810
11029
|
}
|
|
10811
11030
|
return artifacts;
|
|
10812
11031
|
}
|
|
10813
|
-
function buildCompoundArtifacts(variables) {
|
|
10814
|
-
const alternateRenderTargets = getScaffoldAlternateRenderTargets(variables);
|
|
10815
|
-
const artifacts = [
|
|
10816
|
-
renderArtifact(`src/blocks/${variables.slugKebabCase}/style.scss`, COMPOUND_STYLE_TEMPLATE, variables)
|
|
10817
|
-
];
|
|
10818
|
-
if (isCompoundPersistenceEnabled(variables)) {
|
|
10819
|
-
const renderView = {
|
|
10820
|
-
...variables,
|
|
10821
|
-
titlePhpLiteral: toPhpSingleQuotedString(variables.title)
|
|
10822
|
-
};
|
|
10823
|
-
if (alternateRenderTargets.enabled) {
|
|
10824
|
-
artifacts.push(renderArtifact(`src/blocks/${variables.slugKebabCase}/render-targets.php`, COMPOUND_PERSISTENCE_RENDER_TARGETS_TEMPLATE, renderView), buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render.php`, "web", variables));
|
|
10825
|
-
if (alternateRenderTargets.hasEmail) {
|
|
10826
|
-
artifacts.push(buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render-email.php`, "email", variables));
|
|
10827
|
-
}
|
|
10828
|
-
if (alternateRenderTargets.hasMjml) {
|
|
10829
|
-
artifacts.push(buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render-mjml.php`, "mjml", variables));
|
|
10830
|
-
}
|
|
10831
|
-
if (alternateRenderTargets.hasPlainText) {
|
|
10832
|
-
artifacts.push(buildAlternateRenderEntryArtifact(`src/blocks/${variables.slugKebabCase}/render-text.php`, "plain-text", variables));
|
|
10833
|
-
}
|
|
10834
|
-
return artifacts;
|
|
10835
|
-
}
|
|
10836
|
-
const renderSource = `<?php
|
|
10837
|
-
/**
|
|
10838
|
-
* Dynamic render entry for the {{title}} compound parent block.
|
|
10839
|
-
*
|
|
10840
|
-
* @package {{pascalCase}}
|
|
10841
|
-
*/
|
|
10842
|
-
|
|
10843
|
-
if ( ! defined( 'ABSPATH' ) ) {
|
|
10844
|
-
exit;
|
|
10845
|
-
}
|
|
10846
|
-
|
|
10847
|
-
$validator_path = __DIR__ . '/typia-validator.php';
|
|
10848
|
-
if ( ! file_exists( $validator_path ) ) {
|
|
10849
|
-
return '';
|
|
10850
|
-
}
|
|
10851
|
-
|
|
10852
|
-
$validator = require $validator_path;
|
|
10853
|
-
if ( ! is_object( $validator ) || ! method_exists( $validator, 'apply_defaults' ) || ! method_exists( $validator, 'validate' ) ) {
|
|
10854
|
-
return '';
|
|
10855
|
-
}
|
|
10856
|
-
|
|
10857
|
-
$normalized = $validator->apply_defaults( is_array( $attributes ) ? $attributes : array() );
|
|
10858
|
-
$validation = $validator->validate( $normalized );
|
|
10859
|
-
$resource_key = isset( $normalized['resourceKey'] ) ? (string) $normalized['resourceKey'] : '';
|
|
10860
|
-
$heading = isset( $normalized['heading'] ) ? (string) $normalized['heading'] : {{titlePhpLiteral}};
|
|
10861
|
-
$intro = isset( $normalized['intro'] ) ? (string) $normalized['intro'] : '';
|
|
10862
|
-
$button_label = isset( $normalized['buttonLabel'] ) ? (string) $normalized['buttonLabel'] : 'Persist Count';
|
|
10863
|
-
$show_count = ! empty( $normalized['showCount'] );
|
|
10864
|
-
$show_dividers = ! empty( $normalized['showDividers'] );
|
|
10865
|
-
$post_id = is_object( $block ) && isset( $block->context['postId'] )
|
|
10866
|
-
? (int) $block->context['postId']
|
|
10867
|
-
: (int) get_queried_object_id();
|
|
10868
|
-
$storage_mode = '{{dataStorageMode}}';
|
|
10869
|
-
$persistence_policy = '{{persistencePolicy}}';
|
|
10870
|
-
|
|
10871
|
-
$notice_message = 'authenticated' === $persistence_policy
|
|
10872
|
-
? __( 'Sign in to persist this counter.', '{{textDomain}}' )
|
|
10873
|
-
: __( 'Public writes are temporarily unavailable.', '{{textDomain}}' );
|
|
10874
|
-
|
|
10875
|
-
if ( empty( $validation['valid'] ) || '' === $resource_key ) {
|
|
10876
|
-
return '';
|
|
10877
|
-
}
|
|
10878
|
-
|
|
10879
|
-
{{phpPrefix}}_record_rendered_block_instance(
|
|
10880
|
-
(int) $post_id,
|
|
10881
|
-
'{{namespace}}/{{slugKebabCase}}',
|
|
10882
|
-
$resource_key
|
|
10883
|
-
);
|
|
10884
|
-
|
|
10885
|
-
$context = array(
|
|
10886
|
-
'bootstrapReady' => false,
|
|
10887
|
-
'buttonLabel' => $button_label,
|
|
10888
|
-
'canWrite' => false,
|
|
10889
|
-
'client' => array(
|
|
10890
|
-
'writeExpiry' => 0,
|
|
10891
|
-
'writeNonce' => '',
|
|
10892
|
-
'writeToken' => '',
|
|
10893
|
-
),
|
|
10894
|
-
'count' => 0,
|
|
10895
|
-
'error' => '',
|
|
10896
|
-
'isBootstrapping' => false,
|
|
10897
|
-
'isLoading' => false,
|
|
10898
|
-
'isSaving' => false,
|
|
10899
|
-
'persistencePolicy' => $persistence_policy,
|
|
10900
|
-
'postId' => (int) $post_id,
|
|
10901
|
-
'resourceKey' => $resource_key,
|
|
10902
|
-
'showCount' => $show_count,
|
|
10903
|
-
'storage' => $storage_mode,
|
|
10904
|
-
);
|
|
10905
|
-
|
|
10906
|
-
$allowed_inner_html = wp_kses_allowed_html( 'post' );
|
|
10907
|
-
|
|
10908
|
-
foreach ( $allowed_inner_html as &$allowed_attributes ) {
|
|
10909
|
-
if ( ! is_array( $allowed_attributes ) ) {
|
|
10910
|
-
continue;
|
|
10911
|
-
}
|
|
10912
|
-
|
|
10913
|
-
$allowed_attributes['data-wp-bind--disabled'] = true;
|
|
10914
|
-
$allowed_attributes['data-wp-bind--hidden'] = true;
|
|
10915
|
-
$allowed_attributes['data-wp-bind--value'] = true;
|
|
10916
|
-
$allowed_attributes['data-wp-class'] = true;
|
|
10917
|
-
$allowed_attributes['data-wp-class--active'] = true;
|
|
10918
|
-
$allowed_attributes['data-wp-context'] = true;
|
|
10919
|
-
$allowed_attributes['data-wp-init'] = true;
|
|
10920
|
-
$allowed_attributes['data-wp-interactive'] = true;
|
|
10921
|
-
$allowed_attributes['data-wp-on--click'] = true;
|
|
10922
|
-
$allowed_attributes['data-wp-on--mouseenter'] = true;
|
|
10923
|
-
$allowed_attributes['data-wp-on--mouseleave'] = true;
|
|
10924
|
-
$allowed_attributes['data-wp-run--mounted'] = true;
|
|
10925
|
-
$allowed_attributes['data-wp-style--width'] = true;
|
|
10926
|
-
$allowed_attributes['data-wp-text'] = true;
|
|
10927
|
-
}
|
|
10928
|
-
unset( $allowed_attributes );
|
|
10929
|
-
|
|
10930
|
-
$sanitized_content = wp_kses( $content, $allowed_inner_html );
|
|
10931
|
-
|
|
10932
|
-
$wrapper_attributes = get_block_wrapper_attributes(
|
|
10933
|
-
array(
|
|
10934
|
-
'class' => '{{cssClassName}}',
|
|
10935
|
-
'data-show-dividers' => $show_dividers ? 'true' : 'false',
|
|
10936
|
-
'data-wp-context' => wp_json_encode( $context ),
|
|
10937
|
-
'data-wp-init' => 'callbacks.init',
|
|
10938
|
-
'data-wp-interactive' => '{{slugKebabCase}}',
|
|
10939
|
-
'data-wp-run--mounted' => 'callbacks.mounted',
|
|
10940
|
-
)
|
|
10941
|
-
);
|
|
10942
|
-
?>
|
|
10943
|
-
|
|
10944
|
-
<div <?php echo $wrapper_attributes; ?>>
|
|
10945
|
-
<h3 class="{{cssClassName}}__heading"><?php echo esc_html( $heading ); ?></h3>
|
|
10946
|
-
<?php if ( '' !== $intro ) : ?>
|
|
10947
|
-
<p class="{{cssClassName}}__intro"><?php echo esc_html( $intro ); ?></p>
|
|
10948
|
-
<?php endif; ?>
|
|
10949
|
-
<p
|
|
10950
|
-
class="{{cssClassName}}__notice"
|
|
10951
|
-
data-wp-bind--hidden="!context.bootstrapReady || context.canWrite"
|
|
10952
|
-
hidden
|
|
10953
|
-
>
|
|
10954
|
-
<?php echo esc_html( $notice_message ); ?>
|
|
10955
|
-
</p>
|
|
10956
|
-
<p
|
|
10957
|
-
class="{{cssClassName}}__error"
|
|
10958
|
-
role="status"
|
|
10959
|
-
aria-live="polite"
|
|
10960
|
-
aria-atomic="true"
|
|
10961
|
-
data-wp-bind--hidden="!context.error"
|
|
10962
|
-
data-wp-text="context.error"
|
|
10963
|
-
hidden
|
|
10964
|
-
></p>
|
|
10965
|
-
<?php if ( $show_count ) : ?>
|
|
10966
|
-
<div class="{{cssClassName}}__counter">
|
|
10967
|
-
<span
|
|
10968
|
-
class="{{cssClassName}}__count"
|
|
10969
|
-
role="status"
|
|
10970
|
-
aria-live="polite"
|
|
10971
|
-
aria-atomic="true"
|
|
10972
|
-
data-wp-text="context.count"
|
|
10973
|
-
>0</span>
|
|
10974
|
-
<button
|
|
10975
|
-
type="button"
|
|
10976
|
-
disabled
|
|
10977
|
-
data-wp-bind--disabled="!context.canWrite"
|
|
10978
|
-
data-wp-on--click="actions.increment"
|
|
10979
|
-
>
|
|
10980
|
-
<?php echo esc_html( $button_label ); ?>
|
|
10981
|
-
</button>
|
|
10982
|
-
</div>
|
|
10983
|
-
<?php endif; ?>
|
|
10984
|
-
<div class="{{cssClassName}}__items">
|
|
10985
|
-
<?php echo $sanitized_content; ?>
|
|
10986
|
-
</div>
|
|
10987
|
-
</div>
|
|
10988
|
-
`;
|
|
10989
|
-
artifacts.push(renderArtifact(`src/blocks/${variables.slugKebabCase}/render.php`, renderSource, renderView));
|
|
10990
|
-
}
|
|
10991
|
-
return artifacts;
|
|
10992
|
-
}
|
|
10993
|
-
|
|
10994
11032
|
// ../wp-typia-project-tools/src/runtime/built-in-block-non-ts-artifacts.ts
|
|
10995
11033
|
function buildBuiltInNonTsArtifacts({
|
|
10996
11034
|
templateId,
|
|
@@ -14544,17 +14582,17 @@ async function scaffoldProject({
|
|
|
14544
14582
|
phase: "finalize-project",
|
|
14545
14583
|
title: "Finalizing scaffold output"
|
|
14546
14584
|
});
|
|
14547
|
-
const readmePath =
|
|
14585
|
+
const readmePath = path20.join(projectDir, "README.md");
|
|
14548
14586
|
if (!await pathExists(readmePath)) {
|
|
14549
|
-
await
|
|
14587
|
+
await fsp14.writeFile(readmePath, buildReadme(resolvedTemplateId, variables, resolvedPackageManager, {
|
|
14550
14588
|
withMigrationUi: isBuiltInTemplate || isWorkspace ? withMigrationUi : false,
|
|
14551
14589
|
withTestPreset: isBuiltInTemplate ? withTestPreset : false,
|
|
14552
14590
|
withWpEnv: isBuiltInTemplate ? withWpEnv : false
|
|
14553
14591
|
}), "utf8");
|
|
14554
14592
|
}
|
|
14555
|
-
const gitignorePath =
|
|
14556
|
-
const existingGitignore = await pathExists(gitignorePath) ? await
|
|
14557
|
-
await
|
|
14593
|
+
const gitignorePath = path20.join(projectDir, ".gitignore");
|
|
14594
|
+
const existingGitignore = await pathExists(gitignorePath) ? await fsp14.readFile(gitignorePath, "utf8") : "";
|
|
14595
|
+
await fsp14.writeFile(gitignorePath, mergeTextLines(buildGitignore(), existingGitignore), "utf8");
|
|
14558
14596
|
await normalizePackageJson(projectDir, resolvedPackageManager);
|
|
14559
14597
|
if (isBuiltInTemplate) {
|
|
14560
14598
|
const variableGroups = getScaffoldTemplateVariableGroups(variables);
|
|
@@ -14640,4 +14678,4 @@ async function resolveOptionalInteractiveExternalLayerId({
|
|
|
14640
14678
|
|
|
14641
14679
|
export { syncPersistenceRestArtifacts, copyInterpolatedDirectory, listInterpolatedDirectoryOutputs, getPrimaryDevelopmentScript, getOptionalOnboardingSteps, getOptionalOnboardingNote, getOptionalOnboardingShortNote, isCompoundPersistenceEnabled, formatNonEmptyTargetDirectoryError, executeWorkspaceMutationPlan, insertPhpSnippetBeforeWorkspaceAnchors, appendPhpSnippetBeforeClosingTag, runAddIntegrationEnvCommand, resolveExternalTemplateLayers, resolveTemplateSeed, normalizeOptionalCliString, resolveLocalCliPathOption, assertExternalLayerCompositionOptions, assertBuiltInTemplateVariantAllowed, parseAlternateRenderTargets, parseCompoundInnerBlocksPreset, OPTIONAL_WORDPRESS_AI_CLIENT_COMPATIBILITY, REQUIRED_WORKSPACE_ABILITY_COMPATIBILITY, resolveScaffoldCompatibilityPolicy, createScaffoldCompatibilityConfig, renderScaffoldCompatibilityConfig, updatePluginHeaderCompatibility, getDefaultAnswers, resolveTemplateId, resolvePackageManagerId, collectScaffoldAnswers, DATA_STORAGE_MODES, PERSISTENCE_POLICIES, isDataStorageMode, isPersistencePolicy, resolveCreateProfileId, scaffoldProject, resolveOptionalInteractiveExternalLayerId };
|
|
14642
14680
|
|
|
14643
|
-
//# debugId=
|
|
14681
|
+
//# debugId=F4E5CC39251E69C964756E2164756E21
|