wp-typia 0.20.4 → 0.21.0

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 CHANGED
@@ -13,10 +13,15 @@ Use this package for new projects:
13
13
  Extend an existing workspace with:
14
14
 
15
15
  - `wp-typia add block counter-card --template basic`
16
+ - `wp-typia add style callout-emphasis --block counter-card`
17
+ - `wp-typia add transform quote-to-counter --from core/quote --to counter-card`
16
18
  - `wp-typia add binding-source hero-data`
19
+ - `wp-typia add binding-source hero-data --block counter-card --attribute headline`
17
20
  - `wp-typia add rest-resource snapshots --namespace my-plugin/v1 --methods list,read,create`
18
21
  - `wp-typia add ability review-workflow`
19
22
  - `wp-typia add ai-feature brief-suggestions --namespace my-plugin/v1`
23
+ - `wp-typia add editor-plugin review-workflow --slot sidebar`
24
+ - `wp-typia add editor-plugin seo-notes --slot document-setting-panel`
20
25
  - `wp-typia add hooked-block counter-card --anchor core/post-content --position after`
21
26
 
22
27
  `wp-typia <project-dir>` remains available as a backward-compatible alias to
@@ -0,0 +1,19 @@
1
+ export type ArgvWalkerMetadata = {
2
+ longValueOptions: Iterable<string>;
3
+ shortValueOptions: Iterable<string>;
4
+ };
5
+
6
+ export declare function collectPositionalIndexes(
7
+ argv: string[],
8
+ metadata: ArgvWalkerMetadata,
9
+ ): number[];
10
+
11
+ export declare function findFirstPositionalIndex(
12
+ argv: string[],
13
+ metadata: ArgvWalkerMetadata,
14
+ ): number;
15
+
16
+ export declare function findFirstPositional(
17
+ argv: string[],
18
+ metadata: ArgvWalkerMetadata,
19
+ ): string | undefined;
@@ -0,0 +1,53 @@
1
+ function normalizeOptionSet(values) {
2
+ return values instanceof Set ? values : new Set(values);
3
+ }
4
+
5
+ export function collectPositionalIndexes(argv, metadata) {
6
+ const longValueOptionSet = normalizeOptionSet(metadata.longValueOptions);
7
+ const shortValueOptionSet = normalizeOptionSet(metadata.shortValueOptions);
8
+ const positionalIndexes = [];
9
+
10
+ for (let index = 0; index < argv.length; index += 1) {
11
+ const arg = argv[index];
12
+ if (arg === '--') {
13
+ for (let restIndex = index + 1; restIndex < argv.length; restIndex += 1) {
14
+ positionalIndexes.push(restIndex);
15
+ }
16
+ break;
17
+ }
18
+ if (!arg.startsWith('-') || arg === '-') {
19
+ positionalIndexes.push(index);
20
+ continue;
21
+ }
22
+ if (arg.startsWith('--')) {
23
+ if (arg.includes('=')) {
24
+ continue;
25
+ }
26
+ const next = argv[index + 1];
27
+ if (longValueOptionSet.has(arg) && next && !next.startsWith('-')) {
28
+ index += 1;
29
+ }
30
+ continue;
31
+ }
32
+ if (
33
+ arg.length === 2 &&
34
+ shortValueOptionSet.has(arg) &&
35
+ argv[index + 1] &&
36
+ !argv[index + 1].startsWith('-')
37
+ ) {
38
+ index += 1;
39
+ }
40
+ }
41
+
42
+ return positionalIndexes;
43
+ }
44
+
45
+ export function findFirstPositionalIndex(argv, metadata) {
46
+ const positionalIndexes = collectPositionalIndexes(argv, metadata);
47
+ return positionalIndexes[0] ?? -1;
48
+ }
49
+
50
+ export function findFirstPositional(argv, metadata) {
51
+ const firstPositionalIndex = findFirstPositionalIndex(argv, metadata);
52
+ return firstPositionalIndex === -1 ? undefined : argv[firstPositionalIndex];
53
+ }
@@ -1,4 +1,4 @@
1
- // This file was automatically generated by `bun run generate`.
1
+ // This file was automatically generated by `node scripts/generate-routing-metadata.mjs`.
2
2
  // Do not edit directly.
3
3
 
4
4
  export declare const fullRuntimeCommands: readonly string[];
@@ -1,44 +1,44 @@
1
- // This file was automatically generated by `bun run generate`.
1
+ // This file was automatically generated by `node scripts/generate-routing-metadata.mjs`.
2
2
  // Do not edit directly.
3
3
 
4
4
  export const fullRuntimeCommands = Object.freeze([
5
- "mcp",
6
- "skills",
7
- "completions",
8
- "complete"
5
+ 'mcp',
6
+ 'skills',
7
+ 'completions',
8
+ 'complete',
9
9
  ]);
10
10
  export const longValueOptions = Object.freeze([
11
- "--alternate-render-targets",
12
- "--anchor",
13
- "--block",
14
- "--config",
15
- "--current-migration-version",
16
- "--data-storage",
17
- "--external-layer-id",
18
- "--external-layer-source",
19
- "--format",
20
- "--from-migration-version",
21
- "--id",
22
- "--inner-blocks-preset",
23
- "--iterations",
24
- "--methods",
25
- "--migration-version",
26
- "--namespace",
27
- "--output-dir",
28
- "--package-manager",
29
- "--persistence-policy",
30
- "--php-prefix",
31
- "--position",
32
- "--query-post-type",
33
- "--seed",
34
- "--slot",
35
- "--template",
36
- "--text-domain",
37
- "--to-migration-version",
38
- "--variant"
39
- ]);
40
- export const shortValueOptions = Object.freeze([
41
- "-c",
42
- "-p",
43
- "-t"
11
+ '--alternate-render-targets',
12
+ '--anchor',
13
+ '--attribute',
14
+ '--block',
15
+ '--config',
16
+ '--current-migration-version',
17
+ '--data-storage',
18
+ '--external-layer-id',
19
+ '--external-layer-source',
20
+ '--format',
21
+ '--from',
22
+ '--from-migration-version',
23
+ '--id',
24
+ '--inner-blocks-preset',
25
+ '--iterations',
26
+ '--methods',
27
+ '--migration-version',
28
+ '--namespace',
29
+ '--output-dir',
30
+ '--package-manager',
31
+ '--persistence-policy',
32
+ '--php-prefix',
33
+ '--position',
34
+ '--query-post-type',
35
+ '--seed',
36
+ '--slot',
37
+ '--source',
38
+ '--template',
39
+ '--text-domain',
40
+ '--to',
41
+ '--to-migration-version',
42
+ '--variant',
44
43
  ]);
44
+ export const shortValueOptions = Object.freeze(['-c', '-p', '-t']);
package/bin/wp-typia.js CHANGED
@@ -1,125 +1,113 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fs from "node:fs";
4
- import { spawnSync } from "node:child_process";
5
- import path from "node:path";
6
- import { fileURLToPath, pathToFileURL } from "node:url";
3
+ import fs from 'node:fs';
4
+ import { spawnSync } from 'node:child_process';
5
+ import path from 'node:path';
6
+ import { fileURLToPath, pathToFileURL } from 'node:url';
7
7
 
8
8
  import {
9
- fullRuntimeCommands,
10
- longValueOptions,
11
- shortValueOptions,
12
- } from "./routing-metadata.generated.js";
13
-
14
- const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
15
- const cliEntrypoint = path.join(packageRoot, "dist-bunli", "cli.js");
16
- const nodeCliEntrypoint = path.join(packageRoot, "dist-bunli", "node-cli.js");
17
- const bunBinary = process.env.BUN_BIN || "bun";
9
+ fullRuntimeCommands,
10
+ longValueOptions,
11
+ shortValueOptions,
12
+ } from './routing-metadata.generated.js';
13
+ import { findFirstPositional } from './argv-walker.js';
14
+
15
+ const packageRoot = path.resolve(
16
+ path.dirname(fileURLToPath(import.meta.url)),
17
+ '..',
18
+ );
19
+ const cliEntrypoint = path.join(packageRoot, 'dist-bunli', 'cli.js');
20
+ const nodeCliEntrypoint = path.join(packageRoot, 'dist-bunli', 'node-cli.js');
21
+ const bunBinary = process.env.BUN_BIN || 'bun';
18
22
  const fullRuntimeCommandSet = new Set(fullRuntimeCommands);
19
23
  const longValueOptionSet = new Set(longValueOptions);
20
24
  const shortValueOptionSet = new Set(shortValueOptions);
21
- const buildScriptEntrypoint = path.join(packageRoot, "scripts", "build-bunli-runtime.ts");
22
- const sourceCliEntrypoint = path.join(packageRoot, "src", "cli.ts");
25
+ const buildScriptEntrypoint = path.join(
26
+ packageRoot,
27
+ 'scripts',
28
+ 'build-bunli-runtime.ts',
29
+ );
30
+ const sourceCliEntrypoint = path.join(packageRoot, 'src', 'cli.ts');
23
31
  const standaloneGuidance =
24
- "Prefer not to install Bun? Use the standalone wp-typia binary from the GitHub release assets.";
25
-
26
- function firstPositional(argv) {
27
- for (let index = 0; index < argv.length; index += 1) {
28
- const arg = argv[index];
29
- if (!arg || arg === "--") {
30
- break;
31
- }
32
- if (shortValueOptionSet.has(arg) || longValueOptionSet.has(arg)) {
33
- index += 1;
34
- continue;
35
- }
36
- if (arg.startsWith("--")) {
37
- const separatorIndex = arg.indexOf("=");
38
- if (
39
- separatorIndex > 0 &&
40
- longValueOptionSet.has(arg.slice(0, separatorIndex))
41
- ) {
42
- continue;
43
- }
44
- }
45
- if (arg.startsWith("-") && arg !== "-") {
46
- continue;
47
- }
48
- return arg;
49
- }
50
- return undefined;
51
- }
32
+ 'Prefer not to install Bun? Use the standalone wp-typia binary from the GitHub release assets.';
52
33
 
53
34
  function isWorkingBunBinary() {
54
- const bunCheck = spawnSync(bunBinary, ["--version"], {
55
- env: process.env,
56
- stdio: "ignore",
57
- });
35
+ const bunCheck = spawnSync(bunBinary, ['--version'], {
36
+ env: process.env,
37
+ stdio: 'ignore',
38
+ });
58
39
 
59
- return !bunCheck.error && bunCheck.status === 0;
40
+ return !bunCheck.error && bunCheck.status === 0;
60
41
  }
61
42
 
62
43
  function canAutobuildSourceCheckout() {
63
- return fs.existsSync(buildScriptEntrypoint) && fs.existsSync(sourceCliEntrypoint);
44
+ return (
45
+ fs.existsSync(buildScriptEntrypoint) && fs.existsSync(sourceCliEntrypoint)
46
+ );
64
47
  }
65
48
 
66
49
  function ensureBuiltRuntime() {
67
- if (fs.existsSync(cliEntrypoint) && fs.existsSync(nodeCliEntrypoint)) {
68
- return true;
69
- }
50
+ if (fs.existsSync(cliEntrypoint) && fs.existsSync(nodeCliEntrypoint)) {
51
+ return true;
52
+ }
70
53
 
71
- if (!canAutobuildSourceCheckout() || !isWorkingBunBinary()) {
72
- return false;
73
- }
54
+ if (!canAutobuildSourceCheckout() || !isWorkingBunBinary()) {
55
+ return false;
56
+ }
74
57
 
75
- const buildResult = spawnSync(bunBinary, ["run", "build"], {
76
- cwd: packageRoot,
77
- env: process.env,
78
- stdio: "inherit",
79
- });
58
+ const buildResult = spawnSync(bunBinary, ['run', 'build'], {
59
+ cwd: packageRoot,
60
+ env: process.env,
61
+ stdio: 'inherit',
62
+ });
80
63
 
81
- if (buildResult.status !== 0) {
82
- process.exit(buildResult.status ?? 1);
83
- }
64
+ if (buildResult.status !== 0) {
65
+ process.exit(buildResult.status ?? 1);
66
+ }
84
67
 
85
- return fs.existsSync(cliEntrypoint) && fs.existsSync(nodeCliEntrypoint);
68
+ return fs.existsSync(cliEntrypoint) && fs.existsSync(nodeCliEntrypoint);
86
69
  }
87
70
 
88
71
  const argv = process.argv.slice(2);
89
- const command = firstPositional(argv);
90
- const shouldUseFullRuntime = command ? fullRuntimeCommandSet.has(command) : false;
72
+ const command = findFirstPositional(argv, {
73
+ longValueOptions: longValueOptionSet,
74
+ shortValueOptions: shortValueOptionSet,
75
+ });
76
+ const shouldUseFullRuntime = command
77
+ ? fullRuntimeCommandSet.has(command)
78
+ : false;
91
79
  const hasBuiltRuntime = ensureBuiltRuntime();
92
80
  const hasWorkingBun = isWorkingBunBinary();
93
81
 
94
82
  // Keep common help on the human-readable Node fallback even when Bun is present.
95
83
  if (hasWorkingBun && hasBuiltRuntime && shouldUseFullRuntime) {
96
- const result = spawnSync(bunBinary, [cliEntrypoint, ...argv], {
97
- cwd: process.cwd(),
98
- env: process.env,
99
- stdio: "inherit",
100
- });
101
- process.exit(result.status ?? 1);
84
+ const result = spawnSync(bunBinary, [cliEntrypoint, ...argv], {
85
+ cwd: process.cwd(),
86
+ env: process.env,
87
+ stdio: 'inherit',
88
+ });
89
+ process.exit(result.status ?? 1);
102
90
  }
103
91
 
104
92
  if (shouldUseFullRuntime) {
105
- if (!hasBuiltRuntime) {
106
- console.error(
107
- "Error: wp-typia could not locate its built CLI runtime. Reinstall the published package, or run `bun run build` when using a source checkout.",
108
- );
109
- process.exit(1);
110
- }
111
-
112
- console.error(
113
- `Error: wp-typia ${command} requires Bun. Install Bun locally, run with bunx, or set BUN_BIN to a working Bun executable. ${standaloneGuidance}`,
114
- );
115
- process.exit(1);
93
+ if (!hasBuiltRuntime) {
94
+ console.error(
95
+ 'Error: wp-typia could not locate its built CLI runtime. Reinstall the published package, or run `bun run build` when using a source checkout.',
96
+ );
97
+ process.exit(1);
98
+ }
99
+
100
+ console.error(
101
+ `Error: wp-typia ${command} requires Bun. Install Bun locally, run with bunx, or set BUN_BIN to a working Bun executable. ${standaloneGuidance}`,
102
+ );
103
+ process.exit(1);
116
104
  }
117
105
 
118
106
  if (!hasBuiltRuntime || !fs.existsSync(nodeCliEntrypoint)) {
119
- console.error(
120
- "Error: wp-typia could not locate its Node fallback runtime. Reinstall the published package, or run `bun run build` when using a source checkout.",
121
- );
122
- process.exit(1);
107
+ console.error(
108
+ 'Error: wp-typia could not locate its Node fallback runtime. Reinstall the published package, or run `bun run build` when using a source checkout.',
109
+ );
110
+ process.exit(1);
123
111
  }
124
112
 
125
113
  const cliModule = await import(pathToFileURL(nodeCliEntrypoint).href);