@@ -6,34 +6,56 @@ const path = require('path');
66const MODULES_BASE_DIR = path . join ( 'src' , 'Modules' ) ;
77// ---------------------
88
9- /**
10- * Converts a string to PascalCase.
11- * e.g., "my-wallet" -> "MyWallet"
12- * @param {string } str
13- * @returns {string }
14- */
159const toPascalCase = ( str ) => {
1610 return str
1711 . match ( / [ A - Z ] { 2 , } (? = [ A - Z ] [ a - z ] + [ 0 - 9 ] * | \b ) | [ A - Z ] ? [ a - z ] + [ 0 - 9 ] * | [ A - Z ] | [ 0 - 9 ] + / g)
1812 . map ( x => x . charAt ( 0 ) . toUpperCase ( ) + x . slice ( 1 ) . toLowerCase ( ) )
1913 . join ( '' ) ;
2014} ;
2115
22- /**
23- * Gets the module name from command line arguments.
24- * Looks for a '--name' flag.
25- * @returns {string } The module name in PascalCase.
26- */
2716const getModuleName = ( ) => {
28- const argIndex = process . argv . indexOf ( '--name' ) ;
29- if ( argIndex === - 1 || ! process . argv [ argIndex + 1 ] ) {
30- console . error ( '❌ Error: Please provide a module name with the --name flag.' ) ;
31- console . error ( ' > Example: npm run generate:module -- --name Wallet' ) ;
17+ const argv = process . argv . slice ( 2 ) ;
18+ let name ;
19+
20+ for ( let i = 0 ; i < argv . length ; i ++ ) {
21+ const arg = argv [ i ] ;
22+
23+ if ( arg === '--name' || arg === '-n' ) {
24+ name = argv [ i + 1 ] ;
25+ i ++ ;
26+ continue ;
27+ }
28+
29+ if ( arg . startsWith ( '--name=' ) ) {
30+ name = arg . split ( '=' ) . slice ( 1 ) . join ( '=' ) ;
31+ continue ;
32+ }
33+
34+ if ( arg . startsWith ( '-n=' ) ) {
35+ name = arg . split ( '=' ) . slice ( 1 ) . join ( '=' ) ;
36+ continue ;
37+ }
38+
39+ // Fallback: first non-flag is treated as the name
40+ if ( ! arg . startsWith ( '-' ) && ! name ) {
41+ name = arg ;
42+ }
43+ }
44+
45+ if ( ! name ) {
46+ console . error ( '❌ Error: Please provide a module name.' ) ;
47+ console . error ( ' > Examples:' ) ;
48+ console . error ( ' npm run generate:module Wallet' ) ;
49+ console . error ( ' npm run generate:module -- --name Wallet' ) ;
50+ console . error ( ' node ./scripts/generateModules.js --name Wallet' ) ;
3251 process . exit ( 1 ) ;
3352 }
34- return toPascalCase ( process . argv [ argIndex + 1 ] ) ;
53+
54+ return toPascalCase ( name ) ;
3555} ;
3656
57+
58+
3759// --- TEMPLATES ---
3860// These functions return the boilerplate content for each file.
3961
0 commit comments