@wp-typia/create 0.1.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.
Files changed (95) hide show
  1. package/README.md +43 -0
  2. package/dist/cli.js +2492 -0
  3. package/dist/runtime/cli-core.js +222 -0
  4. package/dist/runtime/index.js +4 -0
  5. package/dist/runtime/migration-constants.js +14 -0
  6. package/dist/runtime/migration-diff.js +521 -0
  7. package/dist/runtime/migration-fixtures.js +89 -0
  8. package/dist/runtime/migration-manifest.js +129 -0
  9. package/dist/runtime/migration-project.js +167 -0
  10. package/dist/runtime/migration-render.js +267 -0
  11. package/dist/runtime/migration-types.js +1 -0
  12. package/dist/runtime/migration-utils.js +184 -0
  13. package/dist/runtime/migrations.js +232 -0
  14. package/dist/runtime/package-managers.js +135 -0
  15. package/dist/runtime/scaffold.js +334 -0
  16. package/dist/runtime/template-registry.js +75 -0
  17. package/package.json +65 -0
  18. package/templates/advanced/README.md.mustache +150 -0
  19. package/templates/advanced/block.json.mustache +43 -0
  20. package/templates/advanced/index.js +21 -0
  21. package/templates/advanced/package.json.mustache +47 -0
  22. package/templates/advanced/render.php.mustache +83 -0
  23. package/templates/advanced/scripts/lib/typia-metadata-core.ts +1413 -0
  24. package/templates/advanced/scripts/sync-types-to-block-json.ts.mustache +32 -0
  25. package/templates/advanced/src/admin/migration-dashboard.tsx.mustache +315 -0
  26. package/templates/advanced/src/components/ErrorBoundary.tsx.mustache +47 -0
  27. package/templates/advanced/src/deprecated.ts.mustache +2 -0
  28. package/templates/advanced/src/edit.tsx.mustache +97 -0
  29. package/templates/advanced/src/hooks/useDebounce.ts.mustache +20 -0
  30. package/templates/advanced/src/hooks/useLocalStorage.ts.mustache +31 -0
  31. package/templates/advanced/src/hooks.ts.mustache +56 -0
  32. package/templates/advanced/src/index.tsx.mustache +18 -0
  33. package/templates/advanced/src/migration-detector.ts.mustache +9 -0
  34. package/templates/advanced/src/migrations/config.ts.mustache +8 -0
  35. package/templates/advanced/src/migrations/examples/rename-transform-union/README.md.mustache +23 -0
  36. package/templates/advanced/src/migrations/examples/rename-transform-union/fixture.example.json.mustache +36 -0
  37. package/templates/advanced/src/migrations/examples/rename-transform-union/rule.example.ts.mustache +47 -0
  38. package/templates/advanced/src/migrations/fixtures/README.md.mustache +3 -0
  39. package/templates/advanced/src/migrations/generated/deprecated.ts.mustache +3 -0
  40. package/templates/advanced/src/migrations/generated/registry.ts.mustache +9 -0
  41. package/templates/advanced/src/migrations/generated/verify.ts.mustache +1 -0
  42. package/templates/advanced/src/migrations/helpers.ts.mustache +354 -0
  43. package/templates/advanced/src/migrations/index.ts.mustache +616 -0
  44. package/templates/advanced/src/migrations/rules/README.md.mustache +3 -0
  45. package/templates/advanced/src/migrations/versions/README.md.mustache +3 -0
  46. package/templates/advanced/src/save.tsx.mustache +12 -0
  47. package/templates/advanced/src/style.scss.mustache +84 -0
  48. package/templates/advanced/src/types.ts.mustache +46 -0
  49. package/templates/advanced/src/utils/classnames.ts.mustache +51 -0
  50. package/templates/advanced/src/utils/debounce.ts.mustache +37 -0
  51. package/templates/advanced/src/utils/index.ts.mustache +7 -0
  52. package/templates/advanced/src/utils/uuid.ts.mustache +17 -0
  53. package/templates/advanced/src/validators.ts.mustache +39 -0
  54. package/templates/advanced/src/view.ts.mustache +59 -0
  55. package/templates/advanced/tsconfig.json.mustache +20 -0
  56. package/templates/advanced/webpack.config.js.mustache +95 -0
  57. package/templates/basic/package.json.mustache +39 -0
  58. package/templates/basic/scripts/lib/typia-metadata-core.ts +1413 -0
  59. package/templates/basic/scripts/sync-types-to-block-json.ts +25 -0
  60. package/templates/basic/src/block.json +51 -0
  61. package/templates/basic/src/edit.tsx +85 -0
  62. package/templates/basic/src/hooks.ts +75 -0
  63. package/templates/basic/src/index.tsx +37 -0
  64. package/templates/basic/src/save.tsx +27 -0
  65. package/templates/basic/src/style.scss +42 -0
  66. package/templates/basic/src/types.ts +48 -0
  67. package/templates/basic/src/validators.ts +39 -0
  68. package/templates/basic/tsconfig.json +20 -0
  69. package/templates/basic/webpack.config.js +89 -0
  70. package/templates/full/package.json.mustache +40 -0
  71. package/templates/full/scripts/lib/typia-metadata-core.ts +1413 -0
  72. package/templates/full/scripts/sync-types-to-block-json.ts.mustache +32 -0
  73. package/templates/full/src/block.json.mustache +120 -0
  74. package/templates/full/src/edit.tsx.mustache +300 -0
  75. package/templates/full/src/editor.scss.mustache +251 -0
  76. package/templates/full/src/hooks.ts.mustache +141 -0
  77. package/templates/full/src/index.tsx.mustache +27 -0
  78. package/templates/full/src/save.tsx.mustache +39 -0
  79. package/templates/full/src/style.scss.mustache +224 -0
  80. package/templates/full/src/types.ts.mustache +35 -0
  81. package/templates/full/src/validators.ts.mustache +84 -0
  82. package/templates/full/tsconfig.json.mustache +20 -0
  83. package/templates/full/webpack.config.js.mustache +89 -0
  84. package/templates/interactivity/package.json.mustache +41 -0
  85. package/templates/interactivity/scripts/lib/typia-metadata-core.ts +1413 -0
  86. package/templates/interactivity/scripts/sync-types-to-block-json.ts.mustache +32 -0
  87. package/templates/interactivity/src/block.json.mustache +74 -0
  88. package/templates/interactivity/src/edit.tsx.mustache +206 -0
  89. package/templates/interactivity/src/index.tsx.mustache +20 -0
  90. package/templates/interactivity/src/interactivity.ts.mustache +183 -0
  91. package/templates/interactivity/src/save.tsx.mustache +87 -0
  92. package/templates/interactivity/src/style.scss.mustache +60 -0
  93. package/templates/interactivity/src/types.ts.mustache +30 -0
  94. package/templates/interactivity/tsconfig.json.mustache +20 -0
  95. package/templates/interactivity/webpack.config.js.mustache +89 -0
@@ -0,0 +1,46 @@
1
+ import type { TextAlignment } from "@wp-typia/block-types/block-editor/alignment";
2
+ import { tags } from "typia";
3
+
4
+ /**
5
+ * {{title}} block attributes with Typia validation
6
+ */
7
+ export interface {{titleCase}}Attributes {
8
+ /**
9
+ * Unique identifier
10
+ */
11
+ id?: string & tags.Format<"uuid">;
12
+
13
+ /**
14
+ * Block version for migrations
15
+ */
16
+ version?: number & tags.Type<"uint32"> & tags.Default<1>;
17
+
18
+ /**
19
+ * Custom CSS class
20
+ */
21
+ className?: string & tags.MaxLength<100>;
22
+
23
+ /**
24
+ * Main content
25
+ */
26
+ content: string & tags.MinLength<0> & tags.MaxLength<1000> & tags.Default<"">;
27
+
28
+ /**
29
+ * Text alignment
30
+ */
31
+ alignment?: TextAlignment & tags.Default<"left">;
32
+
33
+ /**
34
+ * Is the block visible
35
+ */
36
+ isVisible?: boolean & tags.Default<true>;
37
+ }
38
+
39
+ /**
40
+ * {{title}} interactivity state
41
+ */
42
+ export interface {{titleCase}}State {
43
+ isActive: boolean;
44
+ isLoading: boolean;
45
+ error?: string;
46
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Conditional classnames utility
3
+ */
4
+ export function classNames(...args: (string | Record<string, boolean> | undefined | null | false)[]): string {
5
+ const classes: string[] = [];
6
+
7
+ for (const arg of args) {
8
+ if (!arg) continue;
9
+
10
+ if (typeof arg === 'string') {
11
+ classes.push(arg);
12
+ } else if (typeof arg === 'object') {
13
+ for (const [key, value] of Object.entries(arg)) {
14
+ if (value) {
15
+ classes.push(key);
16
+ }
17
+ }
18
+ }
19
+ }
20
+
21
+ return classes.join(' ');
22
+ }
23
+
24
+ /**
25
+ * Generate block class with BEM methodology
26
+ */
27
+ export function blockClass(
28
+ blockName: string,
29
+ element?: string,
30
+ modifier?: string | Record<string, boolean>
31
+ ): string {
32
+ let className = blockName;
33
+
34
+ if (element) {
35
+ className += `__${element}`;
36
+ }
37
+
38
+ if (modifier) {
39
+ if (typeof modifier === 'string') {
40
+ className += `--${modifier}`;
41
+ } else {
42
+ for (const [mod, enabled] of Object.entries(modifier)) {
43
+ if (enabled) {
44
+ className += `--${mod}`;
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ return className;
51
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Debounce function
3
+ */
4
+ export function debounce<T extends (...args: any[]) => void>(
5
+ func: T,
6
+ wait: number
7
+ ): (...args: Parameters<T>) => void {
8
+ let timeout: NodeJS.Timeout;
9
+
10
+ return function executedFunction(...args: Parameters<T>) {
11
+ const later = () => {
12
+ clearTimeout(timeout);
13
+ func(...args);
14
+ };
15
+
16
+ clearTimeout(timeout);
17
+ timeout = setTimeout(later, wait);
18
+ };
19
+ }
20
+
21
+ /**
22
+ * Throttle function
23
+ */
24
+ export function throttle<T extends (...args: any[]) => void>(
25
+ func: T,
26
+ limit: number
27
+ ): (...args: Parameters<T>) => void {
28
+ let inThrottle: boolean;
29
+
30
+ return function executedFunction(...args: Parameters<T>) {
31
+ if (!inThrottle) {
32
+ func.apply(this, args);
33
+ inThrottle = true;
34
+ setTimeout(() => inThrottle = false, limit);
35
+ }
36
+ };
37
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * {{title}} utilities
3
+ */
4
+
5
+ export * from './uuid';
6
+ export * from './classnames';
7
+ export * from './debounce';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Generate UUID v4
3
+ */
4
+ export function generateUUID(): string {
5
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
6
+ const r = Math.random() * 16 | 0;
7
+ const v = c === 'x' ? r : (r & 0x3 | 0x8);
8
+ return v.toString(16);
9
+ });
10
+ }
11
+
12
+ /**
13
+ * Generate short ID (8 characters)
14
+ */
15
+ export function generateShortId(): string {
16
+ return Math.random().toString(36).substring(2, 10);
17
+ }
@@ -0,0 +1,39 @@
1
+ import typia from "typia";
2
+ import { {{titleCase}}Attributes } from "./types";
3
+
4
+ /**
5
+ * Typia validators for the block attributes
6
+ */
7
+ export const validators = {
8
+ validate: typia.createValidate<{{titleCase}}Attributes>(),
9
+ assert: typia.createAssert<{{titleCase}}Attributes>(),
10
+ is: typia.createIs<{{titleCase}}Attributes>(),
11
+ random: typia.createRandom<{{titleCase}}Attributes>(),
12
+ clone: typia.misc.createClone<{{titleCase}}Attributes>(),
13
+ prune: typia.misc.createPrune<{{titleCase}}Attributes>(),
14
+ };
15
+
16
+ /**
17
+ * Create safe attribute updater with validation
18
+ */
19
+ export function createAttributeUpdater(
20
+ attributes: {{titleCase}}Attributes,
21
+ setAttributes: (attrs: Partial<{{titleCase}}Attributes>) => void,
22
+ validator = validators.validate
23
+ ) {
24
+ return <K extends keyof {{titleCase}}Attributes>(
25
+ key: K,
26
+ value: {{titleCase}}Attributes[K]
27
+ ) => {
28
+ const newAttrs = { ...attributes, [key]: value };
29
+
30
+ const validation = validator(newAttrs);
31
+ if (validation.success) {
32
+ setAttributes({ [key]: value } as Partial<{{titleCase}}Attributes>);
33
+ return true;
34
+ } else {
35
+ console.error(`Validation failed for ${String(key)}:`, validation.errors);
36
+ return false;
37
+ }
38
+ };
39
+ }
@@ -0,0 +1,59 @@
1
+ import { store, getContext } from '@wordpress/interactivity';
2
+ import { {{titleCase}}State } from './types';
3
+
4
+ const { state, actions, callbacks } = store('{{namespace}}/{{slug}}', {
5
+ state: {
6
+ isActive: false,
7
+ isVisible: true,
8
+ isLoading: false,
9
+ } as {{titleCase}}State,
10
+
11
+ actions: {
12
+ toggle() {
13
+ state.isActive = !state.isActive;
14
+ console.log('{{titleCase}} toggled:', state.isActive);
15
+ },
16
+
17
+ hide() {
18
+ state.isVisible = false;
19
+ },
20
+
21
+ show() {
22
+ state.isVisible = true;
23
+ },
24
+
25
+ async loadContent() {
26
+ state.isLoading = true;
27
+
28
+ try {
29
+ // Simulate async operation
30
+ await new Promise(resolve => setTimeout(resolve, 1000));
31
+
32
+ // Get context data
33
+ const context = getContext<{
34
+ content: string;
35
+ alignment: string;
36
+ }>();
37
+
38
+ console.log('{{titleCase}} content loaded:', context);
39
+
40
+ } catch (error) {
41
+ state.error = error instanceof Error ? error.message : 'Unknown error';
42
+ console.error('{{titleCase}} loading failed:', error);
43
+ } finally {
44
+ state.isLoading = false;
45
+ }
46
+ }
47
+ },
48
+
49
+ callbacks: {
50
+ init() {
51
+ console.log('{{titleCase}} initialized with Typia validation and Interactivity API');
52
+ },
53
+
54
+ mounted() {
55
+ const context = getContext();
56
+ console.log('{{titleCase}} mounted with context:', context);
57
+ }
58
+ },
59
+ });
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "jsx": "react-jsx",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "moduleResolution": "node",
13
+ "resolveJsonModule": true,
14
+ "isolatedModules": true,
15
+ "noEmit": true,
16
+ "baseUrl": "."
17
+ },
18
+ "include": ["src/**/*"],
19
+ "exclude": ["node_modules", "build"]
20
+ }
@@ -0,0 +1,95 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const defaultConfig = require("@wordpress/scripts/config/webpack.config");
4
+
5
+ const METADATA_FILENAMES = new Set([
6
+ "block.json",
7
+ "render.php",
8
+ "typia.manifest.json",
9
+ "typia-validator.php",
10
+ "typia-migration-registry.php",
11
+ ]);
12
+
13
+ class MetadataAssetPlugin {
14
+ apply(compiler) {
15
+ compiler.hooks.thisCompilation.tap("MetadataAssetPlugin", (compilation) => {
16
+ compilation.hooks.processAssets.tap(
17
+ {
18
+ name: "MetadataAssetPlugin",
19
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
20
+ },
21
+ () => {
22
+ for (const entry of getMetadataEntries()) {
23
+ if (compilation.getAsset(entry.outputPath)) {
24
+ continue;
25
+ }
26
+
27
+ compilation.emitAsset(
28
+ entry.outputPath,
29
+ new compiler.webpack.sources.RawSource(fs.readFileSync(entry.inputPath)),
30
+ );
31
+ }
32
+ },
33
+ );
34
+ });
35
+ }
36
+ }
37
+
38
+ function getMetadataEntries() {
39
+ const entries = [];
40
+
41
+ for (const filename of METADATA_FILENAMES) {
42
+ const rootFilePath = path.resolve(process.cwd(), filename);
43
+ if (fs.existsSync(rootFilePath)) {
44
+ entries.push({
45
+ inputPath: rootFilePath,
46
+ outputPath: filename,
47
+ });
48
+ }
49
+ }
50
+
51
+ const srcDir = path.resolve(process.cwd(), "src");
52
+ if (!fs.existsSync(srcDir)) {
53
+ return entries;
54
+ }
55
+
56
+ for (const inputPath of findMetadataFiles(srcDir)) {
57
+ entries.push({
58
+ inputPath,
59
+ outputPath: path.relative(srcDir, inputPath),
60
+ });
61
+ }
62
+
63
+ return entries;
64
+ }
65
+
66
+ function findMetadataFiles(directory) {
67
+ const metadataFiles = [];
68
+
69
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
70
+ const entryPath = path.join(directory, entry.name);
71
+
72
+ if (entry.isDirectory()) {
73
+ metadataFiles.push(...findMetadataFiles(entryPath));
74
+ continue;
75
+ }
76
+ if (entry.isFile() && METADATA_FILENAMES.has(entry.name)) {
77
+ metadataFiles.push(entryPath);
78
+ }
79
+ }
80
+
81
+ return metadataFiles;
82
+ }
83
+
84
+ module.exports = async () => {
85
+ const { default: UnpluginTypia } = await import("@typia/unplugin/webpack");
86
+
87
+ return {
88
+ ...defaultConfig,
89
+ plugins: [
90
+ UnpluginTypia(),
91
+ ...(defaultConfig.plugins || []),
92
+ new MetadataAssetPlugin(),
93
+ ],
94
+ };
95
+ };
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "{{slug}}",
3
+ "version": "0.1.0",
4
+ "packageManager": "bun@1.3.10",
5
+ "description": "{{description}}",
6
+ "author": "{{author}}",
7
+ "license": "GPL-2.0-or-later",
8
+ "main": "build/index.js",
9
+ "scripts": {
10
+ "sync-types": "tsx scripts/sync-types-to-block-json.ts",
11
+ "build": "bun run sync-types && wp-scripts build",
12
+ "start": "bun run sync-types && wp-scripts start",
13
+ "dev": "bun run start",
14
+ "lint:js": "wp-scripts lint-js",
15
+ "lint:css": "wp-scripts lint-style",
16
+ "lint": "bun run lint:js && bun run lint:css",
17
+ "format": "wp-scripts format"
18
+ },
19
+ "devDependencies": {
20
+ "@wp-typia/block-types": "^0.1.0",
21
+ "ajv": "^8.18.0",
22
+ "@types/wordpress__block-editor": "^11.5.17",
23
+ "@types/wordpress__blocks": "^12.5.18",
24
+ "@types/wordpress__components": "^23.8.0",
25
+ "@wordpress/browserslist-config": "^6.42.0",
26
+ "@wordpress/scripts": "^30.22.0",
27
+ "@typia/unplugin": "^12.0.1",
28
+ "tsx": "^4.20.5",
29
+ "typescript": "^5.9.2",
30
+ "typia": "^12.0.1"
31
+ },
32
+ "dependencies": {
33
+ "@wordpress/block-editor": "^15.2.0",
34
+ "@wordpress/blocks": "^15.2.0",
35
+ "@wordpress/components": "^30.2.0",
36
+ "@wordpress/element": "^6.29.0",
37
+ "@wordpress/i18n": "^6.2.0"
38
+ }
39
+ }