@@ -16,15 +16,7 @@ class MonorepoGenerator {
1616 private readonly PACKAGE_COUNT = 1000 ;
1717 private readonly MAX_DEPS_PER_PACKAGE = 8 ;
1818 private readonly MIN_DEPS_PER_PACKAGE = 2 ;
19- private readonly SCRIPT_NAMES = [
20- 'build' ,
21- 'test' ,
22- 'lint' ,
23- 'dev' ,
24- 'start' ,
25- 'prepare' ,
26- 'compile' ,
27- ] ;
19+ private readonly SCRIPT_NAMES = [ 'build' , 'test' , 'lint' , 'dev' , 'start' , 'prepare' , 'compile' ] ;
2820 private readonly CATEGORIES = [ 'core' , 'util' , 'feature' , 'service' , 'app' ] ;
2921
3022 constructor ( private rootDir : string ) { }
@@ -43,10 +35,7 @@ class MonorepoGenerator {
4335 return `${ category } -${ paddedIndex } ` ;
4436 }
4537
46- private generateScriptCommand (
47- scriptName : string ,
48- packageName : string ,
49- ) : string {
38+ private generateScriptCommand ( scriptName : string , packageName : string ) : string {
5039 const commands = [
5140 `echo "Running ${ scriptName } for ${ packageName } "` ,
5241 `node scripts/${ scriptName } .js` ,
@@ -87,14 +76,8 @@ class MonorepoGenerator {
8776 return scripts ;
8877 }
8978
90- private selectDependencies (
91- currentIndex : number ,
92- availablePackages : string [ ] ,
93- ) : string [ ] {
94- const numDeps = this . getRandomInt (
95- this . MIN_DEPS_PER_PACKAGE ,
96- this . MAX_DEPS_PER_PACKAGE ,
97- ) ;
79+ private selectDependencies ( currentIndex : number , availablePackages : string [ ] ) : string [ ] {
80+ const numDeps = this . getRandomInt ( this . MIN_DEPS_PER_PACKAGE , this . MAX_DEPS_PER_PACKAGE ) ;
9881 const dependencies = new Set < string > ( ) ;
9982
10083 // Create a complex graph by selecting dependencies from different layers
@@ -108,10 +91,7 @@ class MonorepoGenerator {
10891 return [ ] ;
10992 }
11093
111- while (
112- dependencies . size < numDeps &&
113- dependencies . size < eligiblePackages . length
114- ) {
94+ while ( dependencies . size < numDeps && dependencies . size < eligiblePackages . length ) {
11595 const dep = this . getRandomElement ( eligiblePackages ) ;
11696 dependencies . add ( dep ) ;
11797 }
@@ -147,8 +127,7 @@ class MonorepoGenerator {
147127 const hasVitePlusConfig = Math . random ( ) > 0.3 ;
148128
149129 // Select dependencies from packages created before this one
150- const dependencies =
151- i === 0 ? [ ] : this . selectDependencies ( i , allPackageNames . slice ( 0 , i ) ) ;
130+ const dependencies = i === 0 ? [ ] : this . selectDependencies ( i , allPackageNames . slice ( 0 , i ) ) ;
152131
153132 this . packages . set ( packageName , {
154133 name : packageName ,
@@ -182,15 +161,9 @@ class MonorepoGenerator {
182161
183162 // Create the scenario: A has build, B doesn't, C has build
184163 const scriptName = this . getRandomElement ( this . SCRIPT_NAMES ) ;
185- pkgA . scripts [ scriptName ] = this . generateScriptCommand (
186- scriptName ,
187- nameA ,
188- ) ;
164+ pkgA . scripts [ scriptName ] = this . generateScriptCommand ( scriptName , nameA ) ;
189165 delete pkgB . scripts [ scriptName ] ; // B doesn't have the script
190- pkgC . scripts [ scriptName ] = this . generateScriptCommand (
191- scriptName ,
192- nameC ,
193- ) ;
166+ pkgC . scripts [ scriptName ] = this . generateScriptCommand ( scriptName , nameC ) ;
194167 }
195168 }
196169 }
@@ -217,10 +190,7 @@ class MonorepoGenerator {
217190 ) ,
218191 } ;
219192
220- fs . writeFileSync (
221- path . join ( packageDir , 'package.json' ) ,
222- JSON . stringify ( packageJson , null , 2 ) ,
223- ) ;
193+ fs . writeFileSync ( path . join ( packageDir , 'package.json' ) , JSON . stringify ( packageJson , null , 2 ) ) ;
224194
225195 // Write source file
226196 const indexContent = `// ${ pkg . name } module
@@ -303,10 +273,7 @@ module.exports = { ${pkg.name.replace('-', '_')} };
303273 const pnpmWorkspace = `packages:
304274 - 'packages/*'
305275` ;
306- fs . writeFileSync (
307- path . join ( this . rootDir , 'pnpm-workspace.yaml' ) ,
308- pnpmWorkspace ,
309- ) ;
276+ fs . writeFileSync ( path . join ( this . rootDir , 'pnpm-workspace.yaml' ) , pnpmWorkspace ) ;
310277
311278 // Write root vite-plus.json
312279 const rootVitePlusConfig = {
@@ -331,9 +298,7 @@ module.exports = { ${pkg.name.replace('-', '_')} };
331298 JSON . stringify ( rootVitePlusConfig , null , 2 ) ,
332299 ) ;
333300
334- console . log (
335- `Successfully generated monorepo with ${ this . PACKAGE_COUNT } packages!` ,
336- ) ;
301+ console . log ( `Successfully generated monorepo with ${ this . PACKAGE_COUNT } packages!` ) ;
337302 console . log ( `Location: ${ this . rootDir } ` ) ;
338303
339304 // Print some statistics
@@ -362,9 +327,7 @@ module.exports = { ${pkg.name.replace('-', '_')} };
362327 console . log ( '\nStatistics:' ) ;
363328 console . log ( `- Total packages: ${ this . packages . size } ` ) ;
364329 console . log (
365- `- Average dependencies per package: ${ (
366- totalDeps / this . packages . size
367- ) . toFixed ( 2 ) } `,
330+ `- Average dependencies per package: ${ ( totalDeps / this . packages . size ) . toFixed ( 2 ) } ` ,
368331 ) ;
369332 console . log ( `- Max dependencies in a package: ${ maxDeps } ` ) ;
370333 console . log ( `- Packages with vite-plus.json: ${ packagesWithVitePlus } ` ) ;
0 commit comments