create-wp-typia 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.
- package/README.md +33 -0
- package/dist/cli.js +87837 -0
- package/dist/highlights-eq9cgrbb.scm +604 -0
- package/dist/highlights-ghv9g403.scm +205 -0
- package/dist/highlights-hk7bwhj4.scm +284 -0
- package/dist/highlights-r812a2qc.scm +150 -0
- package/dist/highlights-x6tmsnaa.scm +115 -0
- package/dist/injections-73j83es3.scm +27 -0
- package/dist/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
- package/dist/tree-sitter-markdown-411r6y9b.wasm +0 -0
- package/dist/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
- package/dist/tree-sitter-typescript-zxjzwt75.wasm +0 -0
- package/dist/tree-sitter-zig-e78zbjpm.wasm +0 -0
- package/lib/entry.js +29 -0
- package/lib/node-cli.js +326 -0
- package/lib/package-managers.d.ts +29 -0
- package/lib/package-managers.js +170 -0
- package/lib/scaffold.d.ts +64 -0
- package/lib/scaffold.js +565 -0
- package/lib/template-registry.d.ts +18 -0
- package/lib/template-registry.js +58 -0
- package/package.json +64 -0
- package/src/cli.ts +329 -0
- package/templates/advanced/README.md.mustache +70 -0
- package/templates/advanced/block.json.mustache +42 -0
- package/templates/advanced/index.js +21 -0
- package/templates/advanced/package.json.mustache +48 -0
- package/templates/advanced/scripts/generate-migrations.ts.mustache +267 -0
- package/templates/advanced/scripts/lib/typia-metadata-core.ts +806 -0
- package/templates/advanced/scripts/migration-cli.ts.mustache +260 -0
- package/templates/advanced/scripts/sync-types-to-block-json.ts.mustache +25 -0
- package/templates/advanced/src/admin/migration-dashboard.tsx.mustache +450 -0
- package/templates/advanced/src/components/ErrorBoundary.tsx.mustache +47 -0
- package/templates/advanced/src/deprecated.ts.mustache +184 -0
- package/templates/advanced/src/edit.tsx.mustache +93 -0
- package/templates/advanced/src/hooks/useDebounce.ts.mustache +20 -0
- package/templates/advanced/src/hooks/useLocalStorage.ts.mustache +31 -0
- package/templates/advanced/src/hooks.ts.mustache +56 -0
- package/templates/advanced/src/index.tsx.mustache +16 -0
- package/templates/advanced/src/migration-detector.ts.mustache +417 -0
- package/templates/advanced/src/migrations/index.ts.mustache +361 -0
- package/templates/advanced/src/save.tsx.mustache +40 -0
- package/templates/advanced/src/style.scss.mustache +84 -0
- package/templates/advanced/src/types/versions.ts.mustache +108 -0
- package/templates/advanced/src/types.ts.mustache +45 -0
- package/templates/advanced/src/utils/classnames.ts.mustache +51 -0
- package/templates/advanced/src/utils/debounce.ts.mustache +37 -0
- package/templates/advanced/src/utils/index.ts.mustache +7 -0
- package/templates/advanced/src/utils/uuid.ts.mustache +17 -0
- package/templates/advanced/src/validators.ts.mustache +39 -0
- package/templates/advanced/src/view.ts.mustache +59 -0
- package/templates/advanced/tsconfig.json.mustache +9 -0
- package/templates/advanced/webpack.config.js.mustache +85 -0
- package/templates/basic/package.json.mustache +39 -0
- package/templates/basic/scripts/lib/typia-metadata-core.ts +806 -0
- package/templates/basic/scripts/sync-types-to-block-json.ts +25 -0
- package/templates/basic/src/block.json +51 -0
- package/templates/basic/src/edit.tsx +85 -0
- package/templates/basic/src/hooks.ts +75 -0
- package/templates/basic/src/index.tsx +37 -0
- package/templates/basic/src/save.tsx +27 -0
- package/templates/basic/src/style.scss +42 -0
- package/templates/basic/src/types.ts +47 -0
- package/templates/basic/src/validators.ts +39 -0
- package/templates/basic/tsconfig.json +20 -0
- package/templates/basic/webpack.config.js +85 -0
- package/templates/full/package.json.mustache +40 -0
- package/templates/full/scripts/lib/typia-metadata-core.ts +806 -0
- package/templates/full/scripts/sync-types-to-block-json.ts.mustache +25 -0
- package/templates/full/src/block.json.mustache +121 -0
- package/templates/full/src/edit.tsx.mustache +300 -0
- package/templates/full/src/editor.scss.mustache +251 -0
- package/templates/full/src/hooks.ts.mustache +140 -0
- package/templates/full/src/index.tsx.mustache +27 -0
- package/templates/full/src/save.tsx.mustache +39 -0
- package/templates/full/src/style.scss.mustache +224 -0
- package/templates/full/src/types.ts.mustache +34 -0
- package/templates/full/src/validators.ts.mustache +84 -0
- package/templates/full/tsconfig.json.mustache +9 -0
- package/templates/full/webpack.config.js.mustache +85 -0
- package/templates/interactivity/package.json.mustache +41 -0
- package/templates/interactivity/scripts/lib/typia-metadata-core.ts +806 -0
- package/templates/interactivity/scripts/sync-types-to-block-json.ts.mustache +25 -0
- package/templates/interactivity/src/block.json.mustache +75 -0
- package/templates/interactivity/src/edit.tsx.mustache +206 -0
- package/templates/interactivity/src/interactivity.ts.mustache +183 -0
- package/templates/interactivity/src/save.tsx.mustache +87 -0
- package/templates/interactivity/src/types.ts.mustache +29 -0
- package/templates/interactivity/tsconfig.json.mustache +9 -0
- package/templates/interactivity/webpack.config.js.mustache +85 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* š§ {{title}} Migration CLI Tool
|
|
5
|
+
*
|
|
6
|
+
* Command-line interface for detecting and managing block migrations
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { program } from 'commander';
|
|
10
|
+
import { scanSiteForMigrations, generateMigrationReport, detectBlockMigration } from '../src/migration-detector';
|
|
11
|
+
import { autoMigrate } from '../src/migrations';
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.name('{{slug}}-migration')
|
|
17
|
+
.description('{{title}} block migration management tool')
|
|
18
|
+
.version('1.0.0');
|
|
19
|
+
|
|
20
|
+
// Detect command - analyze specific block data
|
|
21
|
+
program
|
|
22
|
+
.command('detect')
|
|
23
|
+
.description('Detect if block attributes need migration')
|
|
24
|
+
.option('-f, --file <path>', 'JSON file with block attributes')
|
|
25
|
+
.option('-d, --data <json>', 'Inline JSON block attributes')
|
|
26
|
+
.option('--verbose', 'Show detailed analysis')
|
|
27
|
+
.action(async (options) => {
|
|
28
|
+
try {
|
|
29
|
+
let attributes;
|
|
30
|
+
|
|
31
|
+
if (options.file) {
|
|
32
|
+
const filePath = path.resolve(options.file);
|
|
33
|
+
if (!fs.existsSync(filePath)) {
|
|
34
|
+
console.error(`ā File not found: ${filePath}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
attributes = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
38
|
+
console.log(`š Analyzing block data from: ${filePath}`);
|
|
39
|
+
} else if (options.data) {
|
|
40
|
+
attributes = JSON.parse(options.data);
|
|
41
|
+
console.log('š Analyzing inline block data');
|
|
42
|
+
} else {
|
|
43
|
+
console.error('ā Either --file or --data must be provided');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const analysis = detectBlockMigration(attributes);
|
|
48
|
+
|
|
49
|
+
// Display results
|
|
50
|
+
console.log('\nš Migration Analysis Results:');
|
|
51
|
+
console.log('ā'.repeat(50));
|
|
52
|
+
console.log(`Current Version: ${analysis.currentVersion}`);
|
|
53
|
+
console.log(`Target Version: ${analysis.targetVersion}`);
|
|
54
|
+
console.log(`Confidence: ${(analysis.confidence * 100).toFixed(1)}%`);
|
|
55
|
+
console.log(`Needs Migration: ${analysis.needsMigration ? 'ā
YES' : 'ā NO'}`);
|
|
56
|
+
|
|
57
|
+
if (analysis.reasons.length > 0) {
|
|
58
|
+
console.log('\nš Reasons:');
|
|
59
|
+
analysis.reasons.forEach(reason => console.log(` ⢠${reason}`));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (analysis.warnings.length > 0) {
|
|
63
|
+
console.log('\nā ļø Warnings:');
|
|
64
|
+
analysis.warnings.forEach(warning => console.log(` ⢠${warning}`));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (analysis.affectedFields.added.length > 0 ||
|
|
68
|
+
analysis.affectedFields.modified.length > 0) {
|
|
69
|
+
console.log('\nš§ Affected Fields:');
|
|
70
|
+
if (analysis.affectedFields.added.length > 0) {
|
|
71
|
+
console.log(` Added: ${analysis.affectedFields.added.join(', ')}`);
|
|
72
|
+
}
|
|
73
|
+
if (analysis.affectedFields.modified.length > 0) {
|
|
74
|
+
console.log(` Modified: ${analysis.affectedFields.modified.join(', ')}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (options.verbose) {
|
|
79
|
+
console.log('\nš Raw Attributes:');
|
|
80
|
+
console.log(JSON.stringify(attributes, null, 2));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Exit with appropriate code
|
|
84
|
+
process.exit(analysis.needsMigration ? 1 : 0);
|
|
85
|
+
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('ā Detection failed:', error.message);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Migrate command - perform migration on specific data
|
|
93
|
+
program
|
|
94
|
+
.command('migrate')
|
|
95
|
+
.description('Migrate block attributes to current version')
|
|
96
|
+
.option('-f, --file <path>', 'JSON file with block attributes')
|
|
97
|
+
.option('-d, --data <json>', 'Inline JSON block attributes')
|
|
98
|
+
.option('-o, --output <path>', 'Output file for migrated data')
|
|
99
|
+
.option('--dry-run', 'Show what would be migrated without changing anything')
|
|
100
|
+
.action(async (options) => {
|
|
101
|
+
try {
|
|
102
|
+
let attributes;
|
|
103
|
+
let inputSource = 'unknown';
|
|
104
|
+
|
|
105
|
+
if (options.file) {
|
|
106
|
+
const filePath = path.resolve(options.file);
|
|
107
|
+
if (!fs.existsSync(filePath)) {
|
|
108
|
+
console.error(`ā File not found: ${filePath}`);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
attributes = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
112
|
+
inputSource = filePath;
|
|
113
|
+
console.log(`š Loading block data from: ${filePath}`);
|
|
114
|
+
} else if (options.data) {
|
|
115
|
+
attributes = JSON.parse(options.data);
|
|
116
|
+
inputSource = 'inline data';
|
|
117
|
+
console.log('š Processing inline block data');
|
|
118
|
+
} else {
|
|
119
|
+
console.error('ā Either --file or --data must be provided');
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log('\nš Pre-migration analysis...');
|
|
124
|
+
const preAnalysis = detectBlockMigration(attributes);
|
|
125
|
+
|
|
126
|
+
if (!preAnalysis.needsMigration) {
|
|
127
|
+
console.log('ā
Block is already at current version, no migration needed');
|
|
128
|
+
process.exit(0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log(`š Migrating from v${preAnalysis.currentVersion} to v${preAnalysis.targetVersion}...`);
|
|
132
|
+
|
|
133
|
+
if (options.dryRun) {
|
|
134
|
+
console.log('š« DRY RUN - No changes will be made');
|
|
135
|
+
console.log('\nChanges that would be applied:');
|
|
136
|
+
preAnalysis.reasons.forEach(reason => console.log(` ⢠${reason}`));
|
|
137
|
+
process.exit(0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Perform migration
|
|
141
|
+
const migrationResult = autoMigrate(attributes);
|
|
142
|
+
const migrated = migrationResult.data;
|
|
143
|
+
|
|
144
|
+
// Verify migration
|
|
145
|
+
const postAnalysis = detectBlockMigration(migrated);
|
|
146
|
+
|
|
147
|
+
console.log('\nā
Migration completed successfully!');
|
|
148
|
+
console.log(`š Post-migration version: v${postAnalysis.currentVersion}`);
|
|
149
|
+
|
|
150
|
+
// Output results
|
|
151
|
+
if (options.output) {
|
|
152
|
+
const outputPath = path.resolve(options.output);
|
|
153
|
+
fs.writeFileSync(outputPath, JSON.stringify(migrated, null, 2));
|
|
154
|
+
console.log(`š¾ Migrated data saved to: ${outputPath}`);
|
|
155
|
+
} else {
|
|
156
|
+
console.log('\nš Migrated attributes:');
|
|
157
|
+
console.log(JSON.stringify(migrated, null, 2));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('ā Migration failed:', error.message);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Scan command - scan site for blocks needing migration
|
|
167
|
+
program
|
|
168
|
+
.command('scan')
|
|
169
|
+
.description('Scan WordPress site for blocks needing migration')
|
|
170
|
+
.option('--block-name <name>', 'Specific block to scan for', '{{namespace}}/{{slug}}')
|
|
171
|
+
.option('--report <path>', 'Generate markdown report to file')
|
|
172
|
+
.option('--json <path>', 'Export results as JSON')
|
|
173
|
+
.option('--summary', 'Show summary only')
|
|
174
|
+
.action(async (options) => {
|
|
175
|
+
try {
|
|
176
|
+
console.log(`š Scanning site for ${options.blockName} blocks...`);
|
|
177
|
+
|
|
178
|
+
const results = await scanSiteForMigrations(options.blockName);
|
|
179
|
+
|
|
180
|
+
if (results.length === 0) {
|
|
181
|
+
console.log('ā
No blocks found that need migration');
|
|
182
|
+
process.exit(0);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const needsMigration = results.filter(r => r.analysis.needsMigration);
|
|
186
|
+
const hasWarnings = results.filter(r => r.analysis.warnings.length > 0);
|
|
187
|
+
|
|
188
|
+
console.log('\nš Scan Results:');
|
|
189
|
+
console.log('ā'.repeat(40));
|
|
190
|
+
console.log(`Total blocks: ${results.length}`);
|
|
191
|
+
console.log(`Need migration: ${needsMigration.length}`);
|
|
192
|
+
console.log(`Have warnings: ${hasWarnings.length}`);
|
|
193
|
+
|
|
194
|
+
if (!options.summary) {
|
|
195
|
+
console.log('\nš§ Blocks needing migration:');
|
|
196
|
+
needsMigration.forEach((result, index) => {
|
|
197
|
+
console.log(`\n${index + 1}. "${result.postTitle}" (Post #${result.postId})`);
|
|
198
|
+
console.log(` Version: v${result.analysis.currentVersion} ā v${result.analysis.targetVersion}`);
|
|
199
|
+
console.log(` Confidence: ${(result.analysis.confidence * 100).toFixed(1)}%`);
|
|
200
|
+
if (result.analysis.reasons.length > 0) {
|
|
201
|
+
console.log(` Reasons: ${result.analysis.reasons.join(', ')}`);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Generate reports
|
|
207
|
+
if (options.report) {
|
|
208
|
+
const report = generateMigrationReport(results);
|
|
209
|
+
fs.writeFileSync(path.resolve(options.report), report);
|
|
210
|
+
console.log(`\nš Report saved to: ${options.report}`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (options.json) {
|
|
214
|
+
fs.writeFileSync(path.resolve(options.json), JSON.stringify(results, null, 2));
|
|
215
|
+
console.log(`\nš¾ JSON data saved to: ${options.json}`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Exit with error code if migrations needed
|
|
219
|
+
process.exit(needsMigration.length > 0 ? 1 : 0);
|
|
220
|
+
|
|
221
|
+
} catch (error) {
|
|
222
|
+
console.error('ā Site scan failed:', error.message);
|
|
223
|
+
process.exit(1);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Stats command - show migration statistics
|
|
228
|
+
program
|
|
229
|
+
.command('stats')
|
|
230
|
+
.description('Show migration system statistics')
|
|
231
|
+
.action(() => {
|
|
232
|
+
console.log('š {{title}} Migration System Stats:');
|
|
233
|
+
console.log('ā'.repeat(50));
|
|
234
|
+
console.log(`Block name: {{namespace}}/{{slug}}`);
|
|
235
|
+
console.log(`Current version: 3.0.0`);
|
|
236
|
+
console.log(`Supported versions: 1.0.0, 2.0.0, 3.0.0`);
|
|
237
|
+
console.log(`Auto-migration: ā
Enabled`);
|
|
238
|
+
console.log(`Typia validation: ā
Enabled`);
|
|
239
|
+
console.log(`WordPress integration: ā
Enabled`);
|
|
240
|
+
console.log(`CLI tools: ā
Available`);
|
|
241
|
+
|
|
242
|
+
console.log('\nš§ Available Commands:');
|
|
243
|
+
console.log(' detect - Analyze block for migration needs');
|
|
244
|
+
console.log(' migrate - Perform migration on block data');
|
|
245
|
+
console.log(' scan - Scan WordPress site for blocks');
|
|
246
|
+
console.log(' stats - Show system statistics');
|
|
247
|
+
|
|
248
|
+
console.log('\nš Quick Examples:');
|
|
249
|
+
console.log(' {{slug}}-migration detect --file block.json');
|
|
250
|
+
console.log(' {{slug}}-migration migrate --file old-block.json --output new-block.json');
|
|
251
|
+
console.log(' {{slug}}-migration scan --report migration-report.md');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Parse command line arguments
|
|
255
|
+
program.parse();
|
|
256
|
+
|
|
257
|
+
// If no command provided, show help
|
|
258
|
+
if (!process.argv.slice(2).length) {
|
|
259
|
+
program.outputHelp();
|
|
260
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { syncBlockMetadata } from "./lib/typia-metadata-core";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const result = await syncBlockMetadata({
|
|
5
|
+
blockJsonFile: "block.json",
|
|
6
|
+
manifestFile: "typia.manifest.json",
|
|
7
|
+
sourceTypeName: "{{titleCase}}Attributes",
|
|
8
|
+
typesFile: "src/types.ts",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
console.log("ā
block.json and typia.manifest.json were generated from TypeScript types!");
|
|
12
|
+
console.log("š Generated attributes:", result.attributeNames);
|
|
13
|
+
|
|
14
|
+
if (result.lossyProjectionWarnings.length > 0) {
|
|
15
|
+
console.warn("ā ļø Some Typia constraints were preserved only in typia.manifest.json:");
|
|
16
|
+
for (const warning of result.lossyProjectionWarnings) {
|
|
17
|
+
console.warn(` - ${warning}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main().catch((error) => {
|
|
23
|
+
console.error("ā Type sync failed:", error);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|